Skip to content

Commit 5e626b9

Browse files
committed
bundle: split out a helper function to create pack data
The create_bundle() function, while it does one single logical thing, takes a rather large implementation to do so. Let's start separating what it does into smaller steps to make it easier to see what is going on. This is a first step to separate out the actual pack-data generation, after the earlier part of the function figures out which part of the history to place in the bundle. Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8828f29 commit 5e626b9

File tree

1 file changed

+37
-27
lines changed

1 file changed

+37
-27
lines changed

bundle.c

Lines changed: 37 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,41 @@ static int is_tag_in_date_range(struct object *tag, struct rev_info *revs)
235235
return result;
236236
}
237237

238+
static int write_pack_data(int bundle_fd, struct lock_file *lock, struct rev_info *revs)
239+
{
240+
struct child_process pack_objects = CHILD_PROCESS_INIT;
241+
int i;
242+
243+
argv_array_pushl(&pack_objects.args,
244+
"pack-objects", "--all-progress-implied",
245+
"--stdout", "--thin", "--delta-base-offset",
246+
NULL);
247+
pack_objects.in = -1;
248+
pack_objects.out = bundle_fd;
249+
pack_objects.git_cmd = 1;
250+
if (start_command(&pack_objects))
251+
return error(_("Could not spawn pack-objects"));
252+
253+
/*
254+
* start_command closed bundle_fd if it was > 1
255+
* so set the lock fd to -1 so commit_lock_file()
256+
* won't fail trying to close it.
257+
*/
258+
lock->fd = -1;
259+
260+
for (i = 0; i < revs->pending.nr; i++) {
261+
struct object *object = revs->pending.objects[i].item;
262+
if (object->flags & UNINTERESTING)
263+
write_or_die(pack_objects.in, "^", 1);
264+
write_or_die(pack_objects.in, sha1_to_hex(object->sha1), 40);
265+
write_or_die(pack_objects.in, "\n", 1);
266+
}
267+
close(pack_objects.in);
268+
if (finish_command(&pack_objects))
269+
return error(_("pack-objects died"));
270+
return 0;
271+
}
272+
238273
int create_bundle(struct bundle_header *header, const char *path,
239274
int argc, const char **argv)
240275
{
@@ -381,34 +416,9 @@ int create_bundle(struct bundle_header *header, const char *path,
381416
write_or_die(bundle_fd, "\n", 1);
382417

383418
/* write pack */
384-
child_process_init(&rls);
385-
argv_array_pushl(&rls.args,
386-
"pack-objects", "--all-progress-implied",
387-
"--stdout", "--thin", "--delta-base-offset",
388-
NULL);
389-
rls.in = -1;
390-
rls.out = bundle_fd;
391-
rls.git_cmd = 1;
392-
if (start_command(&rls))
393-
return error(_("Could not spawn pack-objects"));
394-
395-
/*
396-
* start_command closed bundle_fd if it was > 1
397-
* so set the lock fd to -1 so commit_lock_file()
398-
* won't fail trying to close it.
399-
*/
400-
lock.fd = -1;
419+
if (write_pack_data(bundle_fd, &lock, &revs))
420+
return -1;
401421

402-
for (i = 0; i < revs.pending.nr; i++) {
403-
struct object *object = revs.pending.objects[i].item;
404-
if (object->flags & UNINTERESTING)
405-
write_or_die(rls.in, "^", 1);
406-
write_or_die(rls.in, sha1_to_hex(object->sha1), 40);
407-
write_or_die(rls.in, "\n", 1);
408-
}
409-
close(rls.in);
410-
if (finish_command(&rls))
411-
return error(_("pack-objects died"));
412422
if (!bundle_to_stdout) {
413423
if (commit_lock_file(&lock))
414424
die_errno(_("cannot create '%s'"), path);

0 commit comments

Comments
 (0)