Skip to content

Commit b8607f3

Browse files
bk2204gitster
authored andcommitted
bundle: convert to struct object_id
Convert the bundle code, plus the sole external user of struct ref_list_entry, to use struct object_id. Include cache.h from within bundle.h to provide the definition. Convert some of the hash parsing code to use parse_oid_hex to avoid needing to hard-code constant values. Signed-off-by: brian m. carlson <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent af6730e commit b8607f3

File tree

3 files changed

+21
-18
lines changed

3 files changed

+21
-18
lines changed

bundle.c

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212

1313
static const char bundle_signature[] = "# v2 git bundle\n";
1414

15-
static void add_to_ref_list(const unsigned char *sha1, const char *name,
15+
static void add_to_ref_list(const struct object_id *oid, const char *name,
1616
struct ref_list *list)
1717
{
1818
ALLOC_GROW(list->list, list->nr + 1, list->alloc);
19-
hashcpy(list->list[list->nr].sha1, sha1);
19+
oidcpy(&list->list[list->nr].oid, oid);
2020
list->list[list->nr].name = xstrdup(name);
2121
list->nr++;
2222
}
@@ -40,8 +40,9 @@ static int parse_bundle_header(int fd, struct bundle_header *header,
4040
/* The bundle header ends with an empty line */
4141
while (!strbuf_getwholeline_fd(&buf, fd, '\n') &&
4242
buf.len && buf.buf[0] != '\n') {
43-
unsigned char sha1[20];
43+
struct object_id oid;
4444
int is_prereq = 0;
45+
const char *p;
4546

4647
if (*buf.buf == '-') {
4748
is_prereq = 1;
@@ -54,19 +55,19 @@ static int parse_bundle_header(int fd, struct bundle_header *header,
5455
* Prerequisites have object name that is optionally
5556
* followed by SP and subject line.
5657
*/
57-
if (get_sha1_hex(buf.buf, sha1) ||
58-
(buf.len > 40 && !isspace(buf.buf[40])) ||
59-
(!is_prereq && buf.len <= 40)) {
58+
if (parse_oid_hex(buf.buf, &oid, &p) ||
59+
(*p && !isspace(*p)) ||
60+
(!is_prereq && !*p)) {
6061
if (report_path)
6162
error(_("unrecognized header: %s%s (%d)"),
6263
(is_prereq ? "-" : ""), buf.buf, (int)buf.len);
6364
status = -1;
6465
break;
6566
} else {
6667
if (is_prereq)
67-
add_to_ref_list(sha1, "", &header->prerequisites);
68+
add_to_ref_list(&oid, "", &header->prerequisites);
6869
else
69-
add_to_ref_list(sha1, buf.buf + 41, &header->references);
70+
add_to_ref_list(&oid, p + 1, &header->references);
7071
}
7172
}
7273

@@ -115,7 +116,7 @@ static int list_refs(struct ref_list *r, int argc, const char **argv)
115116
if (j == argc)
116117
continue;
117118
}
118-
printf("%s %s\n", sha1_to_hex(r->list[i].sha1),
119+
printf("%s %s\n", oid_to_hex(&r->list[i].oid),
119120
r->list[i].name);
120121
}
121122
return 0;
@@ -141,15 +142,15 @@ int verify_bundle(struct bundle_header *header, int verbose)
141142
init_revisions(&revs, NULL);
142143
for (i = 0; i < p->nr; i++) {
143144
struct ref_list_entry *e = p->list + i;
144-
struct object *o = parse_object(e->sha1);
145+
struct object *o = parse_object(e->oid.hash);
145146
if (o) {
146147
o->flags |= PREREQ_MARK;
147148
add_pending_object(&revs, o, e->name);
148149
continue;
149150
}
150151
if (++ret == 1)
151152
error("%s", message);
152-
error("%s %s", sha1_to_hex(e->sha1), e->name);
153+
error("%s %s", oid_to_hex(&e->oid), e->name);
153154
}
154155
if (revs.pending.nr != p->nr)
155156
return ret;
@@ -285,16 +286,16 @@ static int compute_and_write_prerequisites(int bundle_fd,
285286
return -1;
286287
rls_fout = xfdopen(rls.out, "r");
287288
while (strbuf_getwholeline(&buf, rls_fout, '\n') != EOF) {
288-
unsigned char sha1[20];
289+
struct object_id oid;
289290
if (buf.len > 0 && buf.buf[0] == '-') {
290291
write_or_die(bundle_fd, buf.buf, buf.len);
291-
if (!get_sha1_hex(buf.buf + 1, sha1)) {
292-
struct object *object = parse_object_or_die(sha1, buf.buf);
292+
if (!get_oid_hex(buf.buf + 1, &oid)) {
293+
struct object *object = parse_object_or_die(oid.hash, buf.buf);
293294
object->flags |= UNINTERESTING;
294295
add_pending_object(revs, object, buf.buf);
295296
}
296-
} else if (!get_sha1_hex(buf.buf, sha1)) {
297-
struct object *object = parse_object_or_die(sha1, buf.buf);
297+
} else if (!get_oid_hex(buf.buf, &oid)) {
298+
struct object *object = parse_object_or_die(oid.hash, buf.buf);
298299
object->flags |= SHOWN;
299300
}
300301
}

bundle.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
#ifndef BUNDLE_H
22
#define BUNDLE_H
33

4+
#include "cache.h"
5+
46
struct ref_list {
57
unsigned int nr, alloc;
68
struct ref_list_entry {
7-
unsigned char sha1[20];
9+
struct object_id oid;
810
char *name;
911
} *list;
1012
};

transport.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ static struct ref *get_refs_from_bundle(struct transport *transport, int for_pus
8787
for (i = 0; i < data->header.references.nr; i++) {
8888
struct ref_list_entry *e = data->header.references.list + i;
8989
struct ref *ref = alloc_ref(e->name);
90-
hashcpy(ref->old_oid.hash, e->sha1);
90+
oidcpy(&ref->old_oid, &e->oid);
9191
ref->next = result;
9292
result = ref;
9393
}

0 commit comments

Comments
 (0)