From: Junio C Hamano <gitster@pobox.com>
To: git@vger.kernel.org
Subject: [PATCH 1/5] upload-pack.c: refactor receive_needs()
Date: Sun, 30 Nov 2008 01:57:32 -0800 [thread overview]
Message-ID: <1228039053-31099-5-git-send-email-gitster@pobox.com> (raw)
In-Reply-To: <1228039053-31099-4-git-send-email-gitster@pobox.com>
At the end of the function it had a block of "shallow fetch" support code
that assumed it will be the last protocol extension ever by returning
early. Move the bulky code away into a separate function to make it
maintainable.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
upload-pack.c | 97 ++++++++++++++++++++++++++++++---------------------------
1 files changed, 51 insertions(+), 46 deletions(-)
diff --git a/upload-pack.c b/upload-pack.c
index e5adbc0..4029019 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -444,6 +444,56 @@ static int get_common_commits(void)
}
}
+static void exchange_shallows(int depth, struct object_array *shallows)
+{
+ if (depth == 0 && shallows->nr == 0)
+ return;
+ if (depth > 0) {
+ struct commit_list *result, *backup;
+ int i;
+ backup = result = get_shallow_commits(&want_obj, depth,
+ SHALLOW, NOT_SHALLOW);
+ while (result) {
+ struct object *object = &result->item->object;
+ if (!(object->flags & (CLIENT_SHALLOW|NOT_SHALLOW))) {
+ packet_write(1, "shallow %s",
+ sha1_to_hex(object->sha1));
+ register_shallow(object->sha1);
+ }
+ result = result->next;
+ }
+ free_commit_list(backup);
+ for (i = 0; i < shallows->nr; i++) {
+ struct object *object = shallows->objects[i].item;
+ if (object->flags & NOT_SHALLOW) {
+ struct commit_list *parents;
+ packet_write(1, "unshallow %s",
+ sha1_to_hex(object->sha1));
+ object->flags &= ~CLIENT_SHALLOW;
+ /* make sure the real parents are parsed */
+ unregister_shallow(object->sha1);
+ object->parsed = 0;
+ if (parse_commit((struct commit *)object))
+ die("invalid commit");
+ parents = ((struct commit *)object)->parents;
+ while (parents) {
+ add_object_array(&parents->item->object,
+ NULL, &want_obj);
+ parents = parents->next;
+ }
+ }
+ /* make sure commit traversal conforms to client */
+ register_shallow(object->sha1);
+ }
+ packet_flush(1);
+ } else
+ if (shallows->nr > 0) {
+ int i;
+ for (i = 0; i < shallows->nr; i++)
+ register_shallow(shallows->objects[i].item->sha1);
+ }
+}
+
static void receive_needs(void)
{
struct object_array shallows = {0, 0, NULL};
@@ -520,52 +570,7 @@ static void receive_needs(void)
}
if (debug_fd)
write_in_full(debug_fd, "#E\n", 3);
- if (depth == 0 && shallows.nr == 0)
- return;
- if (depth > 0) {
- struct commit_list *result, *backup;
- int i;
- backup = result = get_shallow_commits(&want_obj, depth,
- SHALLOW, NOT_SHALLOW);
- while (result) {
- struct object *object = &result->item->object;
- if (!(object->flags & (CLIENT_SHALLOW|NOT_SHALLOW))) {
- packet_write(1, "shallow %s",
- sha1_to_hex(object->sha1));
- register_shallow(object->sha1);
- }
- result = result->next;
- }
- free_commit_list(backup);
- for (i = 0; i < shallows.nr; i++) {
- struct object *object = shallows.objects[i].item;
- if (object->flags & NOT_SHALLOW) {
- struct commit_list *parents;
- packet_write(1, "unshallow %s",
- sha1_to_hex(object->sha1));
- object->flags &= ~CLIENT_SHALLOW;
- /* make sure the real parents are parsed */
- unregister_shallow(object->sha1);
- object->parsed = 0;
- if (parse_commit((struct commit *)object))
- die("invalid commit");
- parents = ((struct commit *)object)->parents;
- while (parents) {
- add_object_array(&parents->item->object,
- NULL, &want_obj);
- parents = parents->next;
- }
- }
- /* make sure commit traversal conforms to client */
- register_shallow(object->sha1);
- }
- packet_flush(1);
- } else
- if (shallows.nr > 0) {
- int i;
- for (i = 0; i < shallows.nr; i++)
- register_shallow(shallows.objects[i].item->sha1);
- }
+ exchange_shallows(depth, &shallows);
free(shallows.objects);
}
--
1.6.0.4.850.g6bd829
next prev parent reply other threads:[~2008-11-30 10:00 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-11-30 9:57 [PATCH 5/5] clone: test the new HEAD detection logic Junio C Hamano
2008-11-30 9:57 ` [PATCH 4/5] upload-pack: implement protocol extension "symbolic-ref" Junio C Hamano
2008-11-30 9:57 ` [PATCH 3/5] clone: find the current branch more explicitly Junio C Hamano
2008-11-30 9:57 ` [PATCH 2/5] get_remote_heads(): do not assume that the conversation is one-way Junio C Hamano
2008-11-30 9:57 ` Junio C Hamano [this message]
2008-11-30 9:57 ` [PATCH 0/5] Detecting HEAD more reliably while cloning Junio C Hamano
2008-11-30 10:04 ` Junio C Hamano
2008-12-01 2:54 ` Junio C Hamano
2008-11-30 18:10 ` [PATCH 3/5] clone: find the current branch more explicitly Jeff King
2008-11-30 18:02 ` [PATCH 4/5] upload-pack: implement protocol extension "symbolic-ref" Jeff King
2008-12-01 14:03 ` Junio C Hamano
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=1228039053-31099-5-git-send-email-gitster@pobox.com \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
/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).