Skip to content

Commit e8eb251

Browse files
committed
bundle: split out a helper function to compute and write prerequisites
The new helper compute_and_write_prerequistes() is ugly, but it cannot be avoided. Ideally we should avoid a function that computes and does I/O at the same time, but the prerequisites lines in the output needs the human readable title only to help the recipient of the bundle. The code copies them straight from the rev-list output and immediately discards as no other internal computation needs that information. Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5e626b9 commit e8eb251

File tree

1 file changed

+35
-24
lines changed

1 file changed

+35
-24
lines changed

bundle.c

Lines changed: 35 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -270,33 +270,15 @@ static int write_pack_data(int bundle_fd, struct lock_file *lock, struct rev_inf
270270
return 0;
271271
}
272272

273-
int create_bundle(struct bundle_header *header, const char *path,
274-
int argc, const char **argv)
273+
static int compute_and_write_prerequisites(int bundle_fd,
274+
struct rev_info *revs,
275+
int argc, const char **argv)
275276
{
276-
static struct lock_file lock;
277-
int bundle_fd = -1;
278-
int bundle_to_stdout;
279-
int i, ref_count = 0;
280-
struct strbuf buf = STRBUF_INIT;
281-
struct rev_info revs;
282277
struct child_process rls = CHILD_PROCESS_INIT;
278+
struct strbuf buf = STRBUF_INIT;
283279
FILE *rls_fout;
280+
int i;
284281

285-
bundle_to_stdout = !strcmp(path, "-");
286-
if (bundle_to_stdout)
287-
bundle_fd = 1;
288-
else
289-
bundle_fd = hold_lock_file_for_update(&lock, path,
290-
LOCK_DIE_ON_ERROR);
291-
292-
/* write signature */
293-
write_or_die(bundle_fd, bundle_signature, strlen(bundle_signature));
294-
295-
/* init revs to list objects for pack-objects later */
296-
save_commit_buffer = 0;
297-
init_revisions(&revs, NULL);
298-
299-
/* write prerequisites */
300282
argv_array_pushl(&rls.args,
301283
"rev-list", "--boundary", "--pretty=oneline",
302284
NULL);
@@ -314,7 +296,7 @@ int create_bundle(struct bundle_header *header, const char *path,
314296
if (!get_sha1_hex(buf.buf + 1, sha1)) {
315297
struct object *object = parse_object_or_die(sha1, buf.buf);
316298
object->flags |= UNINTERESTING;
317-
add_pending_object(&revs, object, buf.buf);
299+
add_pending_object(revs, object, buf.buf);
318300
}
319301
} else if (!get_sha1_hex(buf.buf, sha1)) {
320302
struct object *object = parse_object_or_die(sha1, buf.buf);
@@ -325,6 +307,35 @@ int create_bundle(struct bundle_header *header, const char *path,
325307
fclose(rls_fout);
326308
if (finish_command(&rls))
327309
return error(_("rev-list died"));
310+
return 0;
311+
}
312+
313+
int create_bundle(struct bundle_header *header, const char *path,
314+
int argc, const char **argv)
315+
{
316+
static struct lock_file lock;
317+
int bundle_fd = -1;
318+
int bundle_to_stdout;
319+
int i, ref_count = 0;
320+
struct rev_info revs;
321+
322+
bundle_to_stdout = !strcmp(path, "-");
323+
if (bundle_to_stdout)
324+
bundle_fd = 1;
325+
else
326+
bundle_fd = hold_lock_file_for_update(&lock, path,
327+
LOCK_DIE_ON_ERROR);
328+
329+
/* write signature */
330+
write_or_die(bundle_fd, bundle_signature, strlen(bundle_signature));
331+
332+
/* init revs to list objects for pack-objects later */
333+
save_commit_buffer = 0;
334+
init_revisions(&revs, NULL);
335+
336+
/* write prerequisites */
337+
if (compute_and_write_prerequisites(bundle_fd, &revs, argc, argv))
338+
return -1;
328339

329340
/* write references */
330341
argc = setup_revisions(argc, argv, &revs, NULL);

0 commit comments

Comments
 (0)