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>
This commit is contained in:

committed by
Junio C Hamano

parent
79d3a236c5
commit
48d25cae22
27
fetch-pack.c
27
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
|
||||
|
Reference in New Issue
Block a user