All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
To: git@vger.kernel.org, Junio C Hamano <gitster@pobox.com>
Cc: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Subject: [PATCH 3/5] Move write_shallow_commits to fetch-pack.c
Date: Thu, 18 Aug 2011 19:29:36 +0700	[thread overview]
Message-ID: <1313670578-2939-4-git-send-email-pclouds@gmail.com> (raw)
In-Reply-To: <1313670578-2939-1-git-send-email-pclouds@gmail.com>

This function produces network traffic and should be in fetch-pack. It
has been in commit.c because it needs to iterate (private) graft
list. It can now do so using for_each_commit_graft().

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 builtin/fetch-pack.c |   30 ++++++++++++++++++++++++++++++
 commit.c             |   18 ------------------
 commit.h             |    1 -
 3 files changed, 30 insertions(+), 19 deletions(-)

diff --git a/builtin/fetch-pack.c b/builtin/fetch-pack.c
index 4367984..cb5b20a 100644
--- a/builtin/fetch-pack.c
+++ b/builtin/fetch-pack.c
@@ -185,6 +185,36 @@ static void consume_shallow_list(int fd)
 	}
 }
 
+struct write_shallow_data {
+	struct strbuf *out;
+	int use_pack_protocol;
+	int count;
+};
+
+static int write_one_shallow(const struct commit_graft *graft, void *cb_data)
+{
+	struct write_shallow_data *data = cb_data;
+	const char *hex = sha1_to_hex(graft->sha1);
+	data->count++;
+	if (data->use_pack_protocol)
+		packet_buf_write(data->out, "shallow %s", hex);
+	else {
+		strbuf_addstr(data->out, hex);
+		strbuf_addch(data->out, '\n');
+	}
+	return 0;
+}
+
+static int write_shallow_commits(struct strbuf *out, int use_pack_protocol)
+{
+	struct write_shallow_data data;
+	data.out = out;
+	data.use_pack_protocol = use_pack_protocol;
+	data.count = 0;
+	for_each_commit_graft(write_one_shallow, &data);
+	return data.count;
+}
+
 static enum ack_type get_ack(int fd, unsigned char *result_sha1)
 {
 	static char line[1000];
diff --git a/commit.c b/commit.c
index efd647d..661ff0d 100644
--- a/commit.c
+++ b/commit.c
@@ -234,24 +234,6 @@ int for_each_commit_graft(each_commit_graft_fn fn, void *cb_data)
 	return ret;
 }
 
-int write_shallow_commits(struct strbuf *out, int use_pack_protocol)
-{
-	int i, count = 0;
-	for (i = 0; i < commit_graft_nr; i++)
-		if (commit_graft[i]->nr_parent < 0) {
-			const char *hex =
-				sha1_to_hex(commit_graft[i]->sha1);
-			count++;
-			if (use_pack_protocol)
-				packet_buf_write(out, "shallow %s", hex);
-			else {
-				strbuf_addstr(out, hex);
-				strbuf_addch(out, '\n');
-			}
-		}
-	return count;
-}
-
 int unregister_shallow(const unsigned char *sha1)
 {
 	int pos = commit_graft_pos(sha1);
diff --git a/commit.h b/commit.h
index 9030d42..82d5aeb 100644
--- a/commit.h
+++ b/commit.h
@@ -155,7 +155,6 @@ extern struct commit_list *get_octopus_merge_bases(struct commit_list *in);
 
 extern int register_shallow(const unsigned char *sha1);
 extern int unregister_shallow(const unsigned char *sha1);
-extern int write_shallow_commits(struct strbuf *out, int use_pack_protocol);
 extern int for_each_commit_graft(each_commit_graft_fn, void *);
 extern int is_repository_shallow(void);
 extern struct commit_list *get_shallow_commits(struct object_array *heads,
-- 
1.7.4.74.g639db

  parent reply	other threads:[~2011-08-18 12:30 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-08-17 15:02 [PATCH] log: decorate grafted commits with "grafted" Nguyễn Thái Ngọc Duy
2011-08-17 18:48 ` Junio C Hamano
2011-08-18  2:02   ` Nguyen Thai Ngoc Duy
2011-08-18 12:29 ` [PATCH v2 0/5] Decorate grafts and replaces Nguyễn Thái Ngọc Duy
2011-08-18 12:29   ` [PATCH 1/5] decoration: do not mis-decorate refs with same prefix Nguyễn Thái Ngọc Duy
2011-08-18 17:58     ` Junio C Hamano
2011-08-18 12:29   ` [PATCH 2/5] Add for_each_commit_graft() to iterate all grafts Nguyễn Thái Ngọc Duy
2011-08-18 12:29   ` Nguyễn Thái Ngọc Duy [this message]
2011-08-18 18:01     ` [PATCH 3/5] Move write_shallow_commits to fetch-pack.c Junio C Hamano
2011-08-18 12:29   ` [PATCH 4/5] log: decorate grafted commits with "grafted" Nguyễn Thái Ngọc Duy
2011-08-18 18:10     ` Junio C Hamano
2011-08-18 12:29   ` [PATCH 5/5] log: decorate "replaced" on to replaced commits Nguyễn Thái Ngọc Duy
2011-08-18 18:16     ` Junio C Hamano
2011-08-19 12:43       ` [PATCH] " Nguyễn Thái Ngọc Duy

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=1313670578-2939-4-git-send-email-pclouds@gmail.com \
    --to=pclouds@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.