summaryrefslogtreecommitdiff
path: root/fetch-pack.c
diff options
context:
space:
mode:
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>2013-12-05 20:02:42 +0700
committerJunio C Hamano <gitster@pobox.com>2013-12-10 16:14:17 -0800
commit48d25cae22667dfc2c31ad620172c0f0a3ac1490 (patch)
tree9e757eeeff528d48a7184c72675f838361537a42 /fetch-pack.c
parent79d3a236c551ad59719a6835bee03a1446296e65 (diff)
downloadgit-48d25cae22667dfc2c31ad620172c0f0a3ac1490.tar.gz
fetch: add --update-shallow to accept refs that update .git/shallow
The same steps are done as in when --update-shallow is not given. The only difference is we now add all shallow commits in "ours" and "theirs" to .git/shallow (aka "step 8"). Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'fetch-pack.c')
-rw-r--r--fetch-pack.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/fetch-pack.c b/fetch-pack.c
index 34c544d0ca..a2d1b4ab28 100644
--- a/fetch-pack.c
+++ b/fetch-pack.c
@@ -993,6 +993,33 @@ static void update_shallow(struct fetch_pack_args *args,
sha1_array_append(&ref, sought[i]->old_sha1);
si->ref = &ref;
+ if (args->update_shallow) {
+ /*
+ * remote is also shallow, .git/shallow may be updated
+ * so all refs can be accepted. Make sure we only add
+ * shallow roots that are actually reachable from new
+ * refs.
+ */
+ struct sha1_array extra = SHA1_ARRAY_INIT;
+ unsigned char (*sha1)[20] = si->shallow->sha1;
+ assign_shallow_commits_to_refs(si, NULL, NULL);
+ if (!si->nr_ours && !si->nr_theirs) {
+ sha1_array_clear(&ref);
+ return;
+ }
+ for (i = 0; i < si->nr_ours; i++)
+ sha1_array_append(&extra, sha1[si->ours[i]]);
+ for (i = 0; i < si->nr_theirs; i++)
+ sha1_array_append(&extra, sha1[si->theirs[i]]);
+ setup_alternate_shallow(&shallow_lock,
+ &alternate_shallow_file,
+ &extra);
+ commit_lock_file(&shallow_lock);
+ sha1_array_clear(&extra);
+ sha1_array_clear(&ref);
+ return;
+ }
+
/*
* remote is also shallow, check what ref is safe to update
* without updating .git/shallow