git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] bundle: split out a helper function to compute and write prerequisites

From
Junio C Hamano <gitster@pobox.com>
Date
Oct 30, 2014, 18:08 UTC
Message-ID
<xmqqh9ylwhv2.fsf_-_@gitster.dls.corp.google.com>
In-Reply-To
<xmqqlhnyy9e2.fsf@gitster.dls.corp.google.com>

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 <gitster@pobox.com>
---
 * And this is to address the first one in the three-bullet list.
 bundle.c | 59 +++++++++++++++++++++++++++++++++++------------------------
 1 file changed, 35 insertions(+), 24 deletions(-)
diff --git a/bundle.c b/bundle.c
index 9c87532..0ca8737 100644
--- a/bundle.c
+++ b/bundle.c
@@ -270,33 +270,15 @@ static int write_pack_data(int bundle_fd, struct lock_file *lock, struct rev_inf
 	return 0;
 }
 
-int create_bundle(struct bundle_header *header, const char *path,
-		  int argc, const char **argv)
+static int compute_and_write_prerequistes(int bundle_fd,
+					  struct rev_info *revs,
+					  int argc, const char **argv)
 {
-	static struct lock_file lock;
-	int bundle_fd = -1;
-	int bundle_to_stdout;
-	int i, ref_count = 0;
-	struct strbuf buf = STRBUF_INIT;
-	struct rev_info revs;
 	struct child_process rls = CHILD_PROCESS_INIT;
+	struct strbuf buf = STRBUF_INIT;
 	FILE *rls_fout;
+	int i;
 
-	bundle_to_stdout = !strcmp(path, "-");
-	if (bundle_to_stdout)
-		bundle_fd = 1;
-	else
-		bundle_fd = hold_lock_file_for_update(&lock, path,
-						      LOCK_DIE_ON_ERROR);
-
-	/* write signature */
-	write_or_die(bundle_fd, bundle_signature, strlen(bundle_signature));
-
-	/* init revs to list objects for pack-objects later */
-	save_commit_buffer = 0;
-	init_revisions(&revs, NULL);
-
-	/* write prerequisites */
 	argv_array_pushl(&rls.args,
 			 "rev-list", "--boundary", "--pretty=oneline",
 			 NULL);
@@ -314,7 +296,7 @@ int create_bundle(struct bundle_header *header, const char *path,
 			if (!get_sha1_hex(buf.buf + 1, sha1)) {
 				struct object *object = parse_object_or_die(sha1, buf.buf);
 				object->flags |= UNINTERESTING;
-				add_pending_object(&revs, object, buf.buf);
+				add_pending_object(revs, object, buf.buf);
 			}
 		} else if (!get_sha1_hex(buf.buf, sha1)) {
 			struct object *object = parse_object_or_die(sha1, buf.buf);
@@ -325,6 +307,35 @@ int create_bundle(struct bundle_header *header, const char *path,
 	fclose(rls_fout);
 	if (finish_command(&rls))
 		return error(_("rev-list died"));
+	return 0;
+}
+
+int create_bundle(struct bundle_header *header, const char *path,
+		  int argc, const char **argv)
+{
+	static struct lock_file lock;
+	int bundle_fd = -1;
+	int bundle_to_stdout;
+	int i, ref_count = 0;
+	struct rev_info revs;
+
+	bundle_to_stdout = !strcmp(path, "-");
+	if (bundle_to_stdout)
+		bundle_fd = 1;
+	else
+		bundle_fd = hold_lock_file_for_update(&lock, path,
+						      LOCK_DIE_ON_ERROR);
+
+	/* write signature */
+	write_or_die(bundle_fd, bundle_signature, strlen(bundle_signature));
+
+	/* init revs to list objects for pack-objects later */
+	save_commit_buffer = 0;
+	init_revisions(&revs, NULL);
+
+	/* write prerequisites */
+	if (compute_and_write_prerequistes(bundle_fd, &revs, argc, argv))
+		return -1;
 
 	/* write references */
 	argc = setup_revisions(argc, argv, &revs, NULL);
-- 
2.1.3-612-g493e79e
Previous: Jeff KingNext: Jeff King
Message 7 of 25 in “use child_process_init() to initialize struct child_process variables”
  1. use child_process_init() to initialize struct child_process variablesRené Scharfe, Oct 28, 2014
  2. mike.gorchak.qnx@gmail.comOct 28, 2014
  3. Jeff KingOct 29, 2014
  4. Junio C HamanoOct 29, 2014
  5. Junio C HamanoOct 30, 2014
  6. Jeff KingOct 30, 2014
  7. bundle: split out a helper function to compute and write prerequisitesJunio C Hamano, Oct 30, 2014
  8. Jeff KingOct 30, 2014
  9. Jeff KingOct 30, 2014
  10. Philip OakleyOct 31, 2014
  11. Junio C HamanoOct 31, 2014
  12. Jeff KingNov 1, 2014
  13. Philip OakleyNov 2, 2014
  14. Junio C HamanoNov 3, 2014
  15. Jeff KingNov 3, 2014
  16. Junio C HamanoNov 3, 2014
  17. Junio C HamanoNov 4, 2014
  18. Jeff KingNov 4, 2014
  19. Junio C HamanoNov 5, 2014
  20. Philip OakleyNov 5, 2014
  21. Philip OakleyNov 5, 2014
  22. Jeff KingNov 5, 2014
  23. Philip OakleyNov 5, 2014
  24. René ScharfeNov 9, 2014
  25. Jeff KingNov 10, 2014

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.