Skip to content

Commit 4e38e9b

Browse files
committed
Merge branch 'jk/fast-export-object-lookup'
* jk/fast-export-object-lookup: fast-export: do not load blob objects twice fast-export: rename handle_object function
2 parents 62bd0c0 + 30b939c commit 4e38e9b

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

builtin/fast-export.c

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -113,29 +113,32 @@ static void show_progress(void)
113113
printf("progress %d objects\n", counter);
114114
}
115115

116-
static void handle_object(const unsigned char *sha1)
116+
static void export_blob(const unsigned char *sha1)
117117
{
118118
unsigned long size;
119119
enum object_type type;
120120
char *buf;
121121
struct object *object;
122+
int eaten;
122123

123124
if (no_data)
124125
return;
125126

126127
if (is_null_sha1(sha1))
127128
return;
128129

129-
object = parse_object(sha1);
130-
if (!object)
131-
die ("Could not read blob %s", sha1_to_hex(sha1));
132-
133-
if (object->flags & SHOWN)
130+
object = lookup_object(sha1);
131+
if (object && object->flags & SHOWN)
134132
return;
135133

136134
buf = read_sha1_file(sha1, &type, &size);
137135
if (!buf)
138136
die ("Could not read blob %s", sha1_to_hex(sha1));
137+
if (check_sha1_signature(sha1, buf, size, typename(type)) < 0)
138+
die("sha1 mismatch in blob %s", sha1_to_hex(sha1));
139+
object = parse_object_buffer(sha1, type, size, buf, &eaten);
140+
if (!object)
141+
die("Could not read blob %s", sha1_to_hex(sha1));
139142

140143
mark_next_object(object);
141144

@@ -147,7 +150,8 @@ static void handle_object(const unsigned char *sha1)
147150
show_progress();
148151

149152
object->flags |= SHOWN;
150-
free(buf);
153+
if (!eaten)
154+
free(buf);
151155
}
152156

153157
static int depth_first(const void *a_, const void *b_)
@@ -312,7 +316,7 @@ static void handle_commit(struct commit *commit, struct rev_info *rev)
312316
/* Export the referenced blobs, and remember the marks. */
313317
for (i = 0; i < diff_queued_diff.nr; i++)
314318
if (!S_ISGITLINK(diff_queued_diff.queue[i]->two->mode))
315-
handle_object(diff_queued_diff.queue[i]->two->sha1);
319+
export_blob(diff_queued_diff.queue[i]->two->sha1);
316320

317321
mark_next_object(&commit->object);
318322
if (!is_encoding_utf8(encoding))
@@ -512,7 +516,7 @@ static void get_tags_and_duplicates(struct rev_cmdline_info *info,
512516
commit = (struct commit *)tag;
513517
break;
514518
case OBJ_BLOB:
515-
handle_object(tag->object.sha1);
519+
export_blob(tag->object.sha1);
516520
continue;
517521
default: /* OBJ_TAG (nested tags) is already handled */
518522
warning("Tag points to object of unexpected type %s, skipping.",

0 commit comments

Comments
 (0)