Skip to content

Commit d31f378

Browse files
committed
Merge branch 'mh/war-on-extra-refs'
* mh/war-on-extra-refs: refs: remove the extra_refs API clone: do not add alternate references to extra_refs everything_local(): mark alternate refs as complete fetch-pack.c: inline insert_alternate_refs() fetch-pack.c: rename some parameters from "path" to "refname" clone.c: move more code into the "if (refs)" conditional t5700: document a failure of alternates to affect fetch
2 parents 3c1e0d6 + cf6672e commit d31f378

File tree

5 files changed

+64
-75
lines changed

5 files changed

+64
-75
lines changed

builtin/clone.c

Lines changed: 20 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -232,9 +232,6 @@ static int add_one_reference(struct string_list_item *item, void *cb_data)
232232
{
233233
char *ref_git;
234234
struct strbuf alternate = STRBUF_INIT;
235-
struct remote *remote;
236-
struct transport *transport;
237-
const struct ref *extra;
238235

239236
/* Beware: real_path() and mkpath() return static buffer */
240237
ref_git = xstrdup(real_path(item->string));
@@ -249,14 +246,6 @@ static int add_one_reference(struct string_list_item *item, void *cb_data)
249246
strbuf_addf(&alternate, "%s/objects", ref_git);
250247
add_to_alternates_file(alternate.buf);
251248
strbuf_release(&alternate);
252-
253-
remote = remote_get(ref_git);
254-
transport = transport_get(remote, ref_git);
255-
for (extra = transport_get_remote_refs(transport); extra;
256-
extra = extra->next)
257-
add_extra_ref(extra->name, extra->old_sha1, 0);
258-
259-
transport_disconnect(transport);
260249
free(ref_git);
261250
return 0;
262251
}
@@ -500,7 +489,6 @@ static void update_remote_refs(const struct ref *refs,
500489
const char *msg)
501490
{
502491
if (refs) {
503-
clear_extra_refs();
504492
write_remote_refs(mapped_refs);
505493
if (option_single_branch)
506494
write_followtags(refs, msg);
@@ -813,28 +801,28 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
813801
}
814802

815803
refs = transport_get_remote_refs(transport);
816-
mapped_refs = refs ? wanted_peer_refs(refs, refspec) : NULL;
817804

818-
/*
819-
* transport_get_remote_refs() may return refs with null sha-1
820-
* in mapped_refs (see struct transport->get_refs_list
821-
* comment). In that case we need fetch it early because
822-
* remote_head code below relies on it.
823-
*
824-
* for normal clones, transport_get_remote_refs() should
825-
* return reliable ref set, we can delay cloning until after
826-
* remote HEAD check.
827-
*/
828-
for (ref = refs; ref; ref = ref->next)
829-
if (is_null_sha1(ref->old_sha1)) {
830-
complete_refs_before_fetch = 0;
831-
break;
832-
}
805+
if (refs) {
806+
mapped_refs = wanted_peer_refs(refs, refspec);
807+
/*
808+
* transport_get_remote_refs() may return refs with null sha-1
809+
* in mapped_refs (see struct transport->get_refs_list
810+
* comment). In that case we need fetch it early because
811+
* remote_head code below relies on it.
812+
*
813+
* for normal clones, transport_get_remote_refs() should
814+
* return reliable ref set, we can delay cloning until after
815+
* remote HEAD check.
816+
*/
817+
for (ref = refs; ref; ref = ref->next)
818+
if (is_null_sha1(ref->old_sha1)) {
819+
complete_refs_before_fetch = 0;
820+
break;
821+
}
833822

834-
if (!is_local && !complete_refs_before_fetch && refs)
835-
transport_fetch_refs(transport, mapped_refs);
823+
if (!is_local && !complete_refs_before_fetch)
824+
transport_fetch_refs(transport, mapped_refs);
836825

837-
if (refs) {
838826
remote_head = find_ref_by_name(refs, "HEAD");
839827
remote_head_points_at =
840828
guess_remote_head(remote_head, mapped_refs, 0);
@@ -852,6 +840,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
852840
}
853841
else {
854842
warning(_("You appear to have cloned an empty repository."));
843+
mapped_refs = NULL;
855844
our_head_points_at = NULL;
856845
remote_head_points_at = NULL;
857846
remote_head = NULL;

builtin/fetch-pack.c

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -58,19 +58,19 @@ static void rev_list_push(struct commit *commit, int mark)
5858
}
5959
}
6060

61-
static int rev_list_insert_ref(const char *path, const unsigned char *sha1, int flag, void *cb_data)
61+
static int rev_list_insert_ref(const char *refname, const unsigned char *sha1, int flag, void *cb_data)
6262
{
63-
struct object *o = deref_tag(parse_object(sha1), path, 0);
63+
struct object *o = deref_tag(parse_object(sha1), refname, 0);
6464

6565
if (o && o->type == OBJ_COMMIT)
6666
rev_list_push((struct commit *)o, SEEN);
6767

6868
return 0;
6969
}
7070

71-
static int clear_marks(const char *path, const unsigned char *sha1, int flag, void *cb_data)
71+
static int clear_marks(const char *refname, const unsigned char *sha1, int flag, void *cb_data)
7272
{
73-
struct object *o = deref_tag(parse_object(sha1), path, 0);
73+
struct object *o = deref_tag(parse_object(sha1), refname, 0);
7474

7575
if (o && o->type == OBJ_COMMIT)
7676
clear_commit_marks((struct commit *)o,
@@ -256,11 +256,6 @@ static void insert_one_alternate_ref(const struct ref *ref, void *unused)
256256
rev_list_insert_ref(NULL, ref->old_sha1, 0, NULL);
257257
}
258258

259-
static void insert_alternate_refs(void)
260-
{
261-
for_each_alternate_ref(insert_one_alternate_ref, NULL);
262-
}
263-
264259
#define INITIAL_FLUSH 16
265260
#define PIPESAFE_FLUSH 32
266261
#define LARGE_FLUSH 1024
@@ -295,7 +290,7 @@ static int find_common(int fd[2], unsigned char *result_sha1,
295290
marked = 1;
296291

297292
for_each_ref(rev_list_insert_ref, NULL);
298-
insert_alternate_refs();
293+
for_each_alternate_ref(insert_one_alternate_ref, NULL);
299294

300295
fetching = 0;
301296
for ( ; refs ; refs = refs->next) {
@@ -493,7 +488,7 @@ static int find_common(int fd[2], unsigned char *result_sha1,
493488

494489
static struct commit_list *complete;
495490

496-
static int mark_complete(const char *path, const unsigned char *sha1, int flag, void *cb_data)
491+
static int mark_complete(const char *refname, const unsigned char *sha1, int flag, void *cb_data)
497492
{
498493
struct object *o = parse_object(sha1);
499494

@@ -586,6 +581,11 @@ static void filter_refs(struct ref **refs, int nr_match, char **match)
586581
*refs = newlist;
587582
}
588583

584+
static void mark_alternate_complete(const struct ref *ref, void *unused)
585+
{
586+
mark_complete(NULL, ref->old_sha1, 0, NULL);
587+
}
588+
589589
static int everything_local(struct ref **refs, int nr_match, char **match)
590590
{
591591
struct ref *ref;
@@ -614,6 +614,7 @@ static int everything_local(struct ref **refs, int nr_match, char **match)
614614

615615
if (!args.depth) {
616616
for_each_ref(mark_complete, NULL);
617+
for_each_alternate_ref(mark_alternate_complete, NULL);
617618
if (cutoff)
618619
mark_recent_complete_commits(cutoff);
619620
}

refs.c

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -183,12 +183,6 @@ static struct ref_cache {
183183

184184
static struct ref_entry *current_ref;
185185

186-
/*
187-
* Never call sort_ref_array() on the extra_refs, because it is
188-
* allowed to contain entries with duplicate names.
189-
*/
190-
static struct ref_array extra_refs;
191-
192186
static void clear_ref_array(struct ref_array *array)
193187
{
194188
int i;
@@ -289,16 +283,6 @@ static void read_packed_refs(FILE *f, struct ref_array *array)
289283
}
290284
}
291285

292-
void add_extra_ref(const char *refname, const unsigned char *sha1, int flag)
293-
{
294-
add_ref(&extra_refs, create_ref_entry(refname, sha1, flag, 0));
295-
}
296-
297-
void clear_extra_refs(void)
298-
{
299-
clear_ref_array(&extra_refs);
300-
}
301-
302286
static struct ref_array *get_packed_refs(struct ref_cache *refs)
303287
{
304288
if (!refs->did_packed) {
@@ -733,16 +717,11 @@ int peel_ref(const char *refname, unsigned char *sha1)
733717
static int do_for_each_ref(const char *submodule, const char *base, each_ref_fn fn,
734718
int trim, int flags, void *cb_data)
735719
{
736-
int retval = 0, i, p = 0, l = 0;
720+
int retval = 0, p = 0, l = 0;
737721
struct ref_cache *refs = get_ref_cache(submodule);
738722
struct ref_array *packed = get_packed_refs(refs);
739723
struct ref_array *loose = get_loose_refs(refs);
740724

741-
struct ref_array *extra = &extra_refs;
742-
743-
for (i = 0; i < extra->nr; i++)
744-
retval = do_one_ref(base, fn, trim, flags, cb_data, extra->refs[i]);
745-
746725
sort_ref_array(packed);
747726
sort_ref_array(loose);
748727
while (p < packed->nr && l < loose->nr) {

refs.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,6 @@ extern void warn_dangling_symref(FILE *fp, const char *msg_fmt, const char *refn
5656
*/
5757
extern void add_packed_ref(const char *refname, const unsigned char *sha1);
5858

59-
/*
60-
* Extra refs will be listed by for_each_ref() before any actual refs
61-
* for the duration of this process or until clear_extra_refs() is
62-
* called. Only extra refs added before for_each_ref() is called will
63-
* be listed on a given call of for_each_ref().
64-
*/
65-
extern void add_extra_ref(const char *refname, const unsigned char *sha1, int flags);
66-
extern void clear_extra_refs(void);
6759
extern int ref_exists(const char *);
6860

6961
extern int peel_ref(const char *refname, unsigned char *sha1);

t/t5700-clone-reference.sh

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,13 @@ test_cmp expected current'
5252

5353
cd "$base_dir"
5454

55-
rm -f "$U"
55+
rm -f "$U.D"
5656

5757
test_expect_success 'cloning with reference (no -l -s)' \
58-
'GIT_DEBUG_SEND_PACK=3 git clone --reference B "file://$(pwd)/A" D 3>"$U"'
58+
'GIT_DEBUG_SEND_PACK=3 git clone --reference B "file://$(pwd)/A" D 3>"$U.D"'
5959

6060
test_expect_success 'fetched no objects' \
61-
'! grep "^want" "$U"'
61+
'! grep "^want" "$U.D"'
6262

6363
cd "$base_dir"
6464

@@ -153,4 +153,32 @@ test_expect_success 'clone with reference from a tagged repository' '
153153
git clone --reference=A A I
154154
'
155155

156+
test_expect_success 'prepare branched repository' '
157+
git clone A J &&
158+
(
159+
cd J &&
160+
git checkout -b other master^ &&
161+
echo other >otherfile &&
162+
git add otherfile &&
163+
git commit -m other &&
164+
git checkout master
165+
)
166+
'
167+
168+
rm -f "$U.K"
169+
170+
test_expect_success 'fetch with incomplete alternates' '
171+
git init K &&
172+
echo "$base_dir/A/.git/objects" >K/.git/objects/info/alternates &&
173+
(
174+
cd K &&
175+
git remote add J "file://$base_dir/J" &&
176+
GIT_DEBUG_SEND_PACK=3 git fetch J 3>"$U.K"
177+
) &&
178+
master_object=$(cd A && git for-each-ref --format="%(objectname)" refs/heads/master) &&
179+
! grep "^want $master_object" "$U.K" &&
180+
tag_object=$(cd A && git for-each-ref --format="%(objectname)" refs/tags/HEAD) &&
181+
! grep "^want $tag_object" "$U.K"
182+
'
183+
156184
test_done

0 commit comments

Comments
 (0)