builtin/fast-export: convert to struct object_id
In addition to converting to struct object_id, write some hardcoded buffer sizes in terms of GIT_SHA1_RAWSZ. Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
brian m. carlson committed
Feb 21, 2017 at 23:47 UTC
273f8ee8c0974545b9f70f49295ad8ad49ab06cd
1 file changed
+29
-29
builtin/fast-export.c
+29
-29
@@ -212,7 +212,7 @@ static char *anonymize_blob(unsigned long *size)
212
return strbuf_detach(&out, NULL);
213
}
214
215
-static void export_blob(const unsigned char *sha1)
215
+static void export_blob(const struct object_id *oid)
216
{
217
unsigned long size;
218
enum object_type type;
@@ -223,34 +223,34 @@ static void export_blob(const unsigned char *sha1)
223
if (no_data)
224
return;
225
226
- if (is_null_sha1(sha1))
226
+ if (is_null_oid(oid))
227
return;
228
229
- object = lookup_object(sha1);
229
+ object = lookup_object(oid->hash);
230
if (object && object->flags & SHOWN)
231
return;
232
233
if (anonymize) {
234
buf = anonymize_blob(&size);
235
- object = (struct object *)lookup_blob(sha1);
235
+ object = (struct object *)lookup_blob(oid->hash);
236
eaten = 0;
237
} else {
238
- buf = read_sha1_file(sha1, &type, &size);
238
+ buf = read_sha1_file(oid->hash, &type, &size);
239
if (!buf)
240
- die ("Could not read blob %s", sha1_to_hex(sha1));
241
- if (check_sha1_signature(sha1, buf, size, typename(type)) < 0)
242
- die("sha1 mismatch in blob %s", sha1_to_hex(sha1));
243
- object = parse_object_buffer(sha1, type, size, buf, &eaten);
240
+ die ("Could not read blob %s", oid_to_hex(oid));
241
+ if (check_sha1_signature(oid->hash, buf, size, typename(type)) < 0)
242
+ die("sha1 mismatch in blob %s", oid_to_hex(oid));
243
+ object = parse_object_buffer(oid->hash, type, size, buf, &eaten);
244
}
245
246
if (!object)
247
- die("Could not read blob %s", sha1_to_hex(sha1));
247
+ die("Could not read blob %s", oid_to_hex(oid));
248
249
mark_next_object(object);
250
251
printf("blob\nmark :%"PRIu32"\ndata %lu\n", last_idnum, size);
252
if (size && fwrite(buf, size, 1, stdout) != 1)
253
- die_errno ("Could not write blob '%s'", sha1_to_hex(sha1));
253
+ die_errno ("Could not write blob '%s'", oid_to_hex(oid));
254
printf("\n");
255
256
show_progress();
@@ -323,19 +323,19 @@ static void print_path(const char *path)
323
}
324
}
325
326
-static void *generate_fake_sha1(const void *old, size_t *len)
326
+static void *generate_fake_oid(const void *old, size_t *len)
327
{
328
static uint32_t counter = 1; /* avoid null sha1 */
329
- unsigned char *out = xcalloc(20, 1);
330
- put_be32(out + 16, counter++);
329
+ unsigned char *out = xcalloc(GIT_SHA1_RAWSZ, 1);
330
+ put_be32(out + GIT_SHA1_RAWSZ - 4, counter++);
331
return out;
332
}
333
334
-static const unsigned char *anonymize_sha1(const unsigned char *sha1)
334
+static const unsigned char *anonymize_sha1(const struct object_id *oid)
335
{
336
static struct hashmap sha1s;
337
- size_t len = 20;
338
- return anonymize_mem(&sha1s, generate_fake_sha1, sha1, &len);
337
+ size_t len = GIT_SHA1_RAWSZ;
338
+ return anonymize_mem(&sha1s, generate_fake_oid, oid, &len);
339
}
340
341
static void show_filemodify(struct diff_queue_struct *q,
@@ -383,7 +383,7 @@ static void show_filemodify(struct diff_queue_struct *q,
383
if (no_data || S_ISGITLINK(spec->mode))
384
printf("M %06o %s ", spec->mode,
385
sha1_to_hex(anonymize ?
386
- anonymize_sha1(spec->oid.hash) :
386
+ anonymize_sha1(&spec->oid) :
387
spec->oid.hash));
388
else {
389
struct object *object = lookup_object(spec->oid.hash);
@@ -572,7 +572,7 @@ static void handle_commit(struct commit *commit, struct rev_info *rev)
572
/* Export the referenced blobs, and remember the marks. */
573
for (i = 0; i < diff_queued_diff.nr; i++)
574
if (!S_ISGITLINK(diff_queued_diff.queue[i]->two->mode))
575
- export_blob(diff_queued_diff.queue[i]->two->oid.hash);
575
+ export_blob(&diff_queued_diff.queue[i]->two->oid);
576
577
refname = commit->util;
578
if (anonymize) {
@@ -797,14 +797,14 @@ static void get_tags_and_duplicates(struct rev_cmdline_info *info)
797
798
for (i = 0; i < info->nr; i++) {
799
struct rev_cmdline_entry *e = info->rev + i;
800
- unsigned char sha1[20];
800
+ struct object_id oid;
801
struct commit *commit;
802
char *full_name;
803
804
if (e->flags & UNINTERESTING)
805
continue;
806
807
- if (dwim_ref(e->name, strlen(e->name), sha1, &full_name) != 1)
807
+ if (dwim_ref(e->name, strlen(e->name), oid.hash, &full_name) != 1)
808
continue;
809
810
if (refspecs) {
@@ -828,7 +828,7 @@ static void get_tags_and_duplicates(struct rev_cmdline_info *info)
828
case OBJ_COMMIT:
829
break;
830
case OBJ_BLOB:
831
- export_blob(commit->object.oid.hash);
831
+ export_blob(&commit->object.oid);
832
continue;
833
default: /* OBJ_TAG (nested tags) is already handled */
834
warning("Tag points to object of unexpected type %s, skipping.",
@@ -912,7 +912,7 @@ static void import_marks(char *input_file)
912
while (fgets(line, sizeof(line), f)) {
913
uint32_t mark;
914
char *line_end, *mark_end;
915
- unsigned char sha1[20];
915
+ struct object_id oid;
916
struct object *object;
917
struct commit *commit;
918
enum object_type type;
@@ -924,28 +924,28 @@ static void import_marks(char *input_file)
924
925
mark = strtoumax(line + 1, &mark_end, 10);
926
if (!mark || mark_end == line + 1
927
- || *mark_end != ' ' || get_sha1_hex(mark_end + 1, sha1))
927
+ || *mark_end != ' ' || get_oid_hex(mark_end + 1, &oid))
928
die("corrupt mark line: %s", line);
929
930
if (last_idnum < mark)
931
last_idnum = mark;
932
933
- type = sha1_object_info(sha1, NULL);
933
+ type = sha1_object_info(oid.hash, NULL);
934
if (type < 0)
935
- die("object not found: %s", sha1_to_hex(sha1));
935
+ die("object not found: %s", oid_to_hex(&oid));
936
937
if (type != OBJ_COMMIT)
938
/* only commits */
939
continue;
940
941
- commit = lookup_commit(sha1);
941
+ commit = lookup_commit(oid.hash);
942
if (!commit)
943
- die("not a commit? can't happen: %s", sha1_to_hex(sha1));
943
+ die("not a commit? can't happen: %s", oid_to_hex(&oid));
944
945
object = &commit->object;
946
947
if (object->flags & SHOWN)
948
- error("Object %s already has a mark", sha1_to_hex(sha1));
948
+ error("Object %s already has a mark", oid_to_hex(&oid));
949
950
mark_object(object, mark);
951