Skip to content

Commit 15e7c7d

Browse files
avargitster
authored andcommitted
bundle.c: use a temporary variable for OIDs and names
In preparation for moving away from accessing the OID and name via the "oid" and "name" slots in a subsequent commit, change the code that accesses it to use named variables. This makes the subsequent change smaller. Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Acked-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent db6bfb9 commit 15e7c7d

File tree

2 files changed

+22
-10
lines changed

2 files changed

+22
-10
lines changed

bundle.c

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,9 @@ static int list_refs(struct ref_list *r, int argc, const char **argv)
156156
int i;
157157

158158
for (i = 0; i < r->nr; i++) {
159+
struct object_id *oid;
160+
const char *name;
161+
159162
if (argc > 1) {
160163
int j;
161164
for (j = 1; j < argc; j++)
@@ -164,8 +167,10 @@ static int list_refs(struct ref_list *r, int argc, const char **argv)
164167
if (j == argc)
165168
continue;
166169
}
167-
printf("%s %s\n", oid_to_hex(&r->list[i].oid),
168-
r->list[i].name);
170+
171+
oid = &r->list[i].oid;
172+
name = r->list[i].name;
173+
printf("%s %s\n", oid_to_hex(oid), name);
169174
}
170175
return 0;
171176
}
@@ -194,15 +199,17 @@ int verify_bundle(struct repository *r,
194199
repo_init_revisions(r, &revs, NULL);
195200
for (i = 0; i < p->nr; i++) {
196201
struct ref_list_entry *e = p->list + i;
197-
struct object *o = parse_object(r, &e->oid);
202+
const char *name = e->name;
203+
struct object_id *oid = &e->oid;
204+
struct object *o = parse_object(r, oid);
198205
if (o) {
199206
o->flags |= PREREQ_MARK;
200-
add_pending_object(&revs, o, e->name);
207+
add_pending_object(&revs, o, name);
201208
continue;
202209
}
203210
if (++ret == 1)
204211
error("%s", message);
205-
error("%s %s", oid_to_hex(&e->oid), e->name);
212+
error("%s %s", oid_to_hex(oid), name);
206213
}
207214
if (revs.pending.nr != p->nr)
208215
return ret;
@@ -219,19 +226,22 @@ int verify_bundle(struct repository *r,
219226

220227
for (i = 0; i < p->nr; i++) {
221228
struct ref_list_entry *e = p->list + i;
222-
struct object *o = parse_object(r, &e->oid);
229+
const char *name = e->name;
230+
struct object_id *oid = &e->oid;
231+
struct object *o = parse_object(r, oid);
223232
assert(o); /* otherwise we'd have returned early */
224233
if (o->flags & SHOWN)
225234
continue;
226235
if (++ret == 1)
227236
error("%s", message);
228-
error("%s %s", oid_to_hex(&e->oid), e->name);
237+
error("%s %s", oid_to_hex(oid), name);
229238
}
230239

231240
/* Clean up objects used, as they will be reused. */
232241
for (i = 0; i < p->nr; i++) {
233242
struct ref_list_entry *e = p->list + i;
234-
commit = lookup_commit_reference_gently(r, &e->oid, 1);
243+
struct object_id *oid = &e->oid;
244+
commit = lookup_commit_reference_gently(r, oid, 1);
235245
if (commit)
236246
clear_commit_marks(commit, ALL_REV_FLAGS);
237247
}

transport.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,10 @@ static struct ref *get_refs_from_bundle(struct transport *transport,
148148

149149
for (i = 0; i < data->header.references.nr; i++) {
150150
struct ref_list_entry *e = data->header.references.list + i;
151-
struct ref *ref = alloc_ref(e->name);
152-
oidcpy(&ref->old_oid, &e->oid);
151+
const char *name = e->name;
152+
struct ref *ref = alloc_ref(name);
153+
struct object_id *oid = &e->oid;
154+
oidcpy(&ref->old_oid, oid);
153155
ref->next = result;
154156
result = ref;
155157
}

0 commit comments

Comments
 (0)