git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jonathan Nieder <jrnieder@gmail.com>
To: Joey Hess <joey@kitenet.net>
Cc: git@vger.kernel.org, 554682@bugs.debian.org,
	Adam Brewster <adambrewster@gmail.com>,
	Johannes Schindelin <Johannes.Schindelin@gmx.de>
Subject: [PATCH 4/8] bundle: split table of contents output into its own function
Date: Sat, 26 Jun 2010 01:21:16 -0500	[thread overview]
Message-ID: <20100626062116.GE15881@burratino> (raw)
In-Reply-To: <20100626061735.GA15881@burratino>

Isolate another piece of create_bundle() to work on.

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
 bundle.c |   78 +++++++++++++++++++++++++++++++++++---------------------------
 1 files changed, 44 insertions(+), 34 deletions(-)

diff --git a/bundle.c b/bundle.c
index e90b5c5..8ba6479 100644
--- a/bundle.c
+++ b/bundle.c
@@ -245,45 +245,20 @@ static int list_prerequisites(int bundle_fd, struct rev_info *revs,
 	return 0;
 }
 
-int create_bundle(struct bundle_header *header, const char *path,
-		int argc, const char **argv)
+static int bundle_list_refs(int bundle_fd,
+		int argc, const char **argv, struct rev_info *revs)
 {
-	static struct lock_file lock;
-	int bundle_fd = -1;
-	int bundle_to_stdout;
-	const char **argv_pack = xmalloc(5 * sizeof(const char *));
 	int i, ref_count = 0;
-	struct rev_info revs;
-	struct child_process rls;
 
-	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 (list_prerequisites(bundle_fd, &revs, argc, argv))
-		return -1;
-
-	/* write references */
-	argc = setup_revisions(argc, argv, &revs, NULL);
+	argc = setup_revisions(argc, argv, revs, NULL);
 
 	if (argc > 1)
 		return error("unrecognized argument: %s'", argv[1]);
 
-	object_array_remove_duplicates(&revs.pending);
+	object_array_remove_duplicates(&revs->pending);
 
-	for (i = 0; i < revs.pending.nr; i++) {
-		struct object_array_entry *e = revs.pending.objects + i;
+	for (i = 0; i < revs->pending.nr; i++) {
+		struct object_array_entry *e = revs->pending.objects + i;
 		unsigned char sha1[20];
 		char *ref;
 		const char *display_ref;
@@ -298,7 +273,7 @@ int create_bundle(struct bundle_header *header, const char *path,
 		display_ref = (flag & REF_ISSYMREF) ? e->name : ref;
 
 		if (e->item->type == OBJ_TAG &&
-				!is_tag_in_date_range(e->item, &revs)) {
+				!is_tag_in_date_range(e->item, revs)) {
 			e->item->flags |= UNINTERESTING;
 			continue;
 		}
@@ -344,7 +319,7 @@ int create_bundle(struct bundle_header *header, const char *path,
 				 */
 				obj = parse_object(sha1);
 				obj->flags |= SHOWN;
-				add_pending_object(&revs, obj, e->name);
+				add_pending_object(revs, obj, e->name);
 			}
 			free(ref);
 			continue;
@@ -358,7 +333,42 @@ int create_bundle(struct bundle_header *header, const char *path,
 		free(ref);
 	}
 	if (!ref_count)
-		die ("Refusing to create empty bundle.");
+		die("Refusing to create empty bundle.");
+	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;
+	const char **argv_pack = xmalloc(5 * sizeof(const char *));
+	struct rev_info revs;
+	struct child_process rls;
+	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 */
+	if (list_prerequisites(bundle_fd, &revs, argc, argv))
+		return -1;
+
+	/* write references */
+	if (bundle_list_refs(bundle_fd, argc, argv, &revs))
+		return -1;
 
 	/* end header */
 	write_or_die(bundle_fd, "\n", 1);
-- 
1.7.1.198.g8d802

  parent reply	other threads:[~2010-06-26  6:21 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-01-19  0:26 bug: git-bundle create foo --stdin -> segfault Joey Hess
2010-01-19 23:52 ` Johannes Schindelin
2010-04-19  7:14 ` [PATCH 0/2] test bundle --stdin, fix objects_array_remove_duplicates() Jonathan Nieder
2010-04-19  8:03   ` [PATCH 1/2] t5704 (bundle): add tests for bundle --stdin Jonathan Nieder
2010-04-19  8:03   ` [PATCH 2/2] fix "bundle --stdin" segfault Jonathan Nieder
2010-04-20  5:16   ` [PATCH 0/2] test bundle --stdin, fix objects_array_remove_duplicates() Junio C Hamano
2010-06-26  6:17 ` [RFC/PATCH 0/8] Re: bug: git-bundle create foo --stdin -> segfault Jonathan Nieder
2010-06-26  6:19   ` [PATCH 1/8] bundle: split basis discovery into its own function Jonathan Nieder
2010-06-26  6:20   ` [PATCH 2/8] bundle: use libified rev-list --boundary Jonathan Nieder
2010-06-30 17:57     ` Junio C Hamano
2010-06-30 20:34       ` Jonathan Nieder
2010-06-26  6:20   ` [PATCH 3/8] bundle: give list_prerequisites() loop body its own function Jonathan Nieder
2010-06-30 18:04     ` Junio C Hamano
2010-06-30 20:37       ` Jonathan Nieder
2010-06-26  6:21   ` Jonathan Nieder [this message]
2010-06-26  6:22   ` [PATCH 5/8] bundle: reuse setup_revisions result Jonathan Nieder
2010-06-26  6:28   ` [PATCH 6/8] Fix bundle --stdin Jonathan Nieder
2010-06-26  6:29   ` [RFC/PATCH 7/8] bundle: Keep names of basis refs after discovery Jonathan Nieder
2010-06-26  6:31   ` [PATCH 8/8] bundle_create: Do not exit when given no revs to bundle Jonathan Nieder

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20100626062116.GE15881@burratino \
    --to=jrnieder@gmail.com \
    --cc=554682@bugs.debian.org \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=adambrewster@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=joey@kitenet.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).