Skip to content

Commit 7011ce1

Browse files
committed
Merge branch 'fc/fetch-with-import-fix' into maint
Code restructuring during 2.20 period broke fetching tags via "import" based transports. * fc/fetch-with-import-fix: fetch: fix regression with transport helpers fetch: make the code more understandable fetch: trivial cleanup t5801 (remote-helpers): add test to fetch tags t5801 (remote-helpers): cleanup refspec stuff
2 parents dea6737 + f80d922 commit 7011ce1

File tree

3 files changed

+45
-23
lines changed

3 files changed

+45
-23
lines changed

builtin/fetch.c

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ static int will_fetch(struct ref **head, const unsigned char *sha1)
239239
struct refname_hash_entry {
240240
struct hashmap_entry ent; /* must be the first member */
241241
struct object_id oid;
242+
int ignore;
242243
char refname[FLEX_ARRAY];
243244
};
244245

@@ -287,6 +288,11 @@ static int refname_hash_exists(struct hashmap *map, const char *refname)
287288
return !!hashmap_get_from_hash(map, strhash(refname), refname);
288289
}
289290

291+
static void clear_item(struct refname_hash_entry *item)
292+
{
293+
item->ignore = 1;
294+
}
295+
290296
static void find_non_local_tags(const struct ref *refs,
291297
struct ref **head,
292298
struct ref ***tail)
@@ -319,7 +325,7 @@ static void find_non_local_tags(const struct ref *refs,
319325
!will_fetch(head, ref->old_oid.hash) &&
320326
!has_object_file_with_flags(&item->oid, OBJECT_INFO_QUICK) &&
321327
!will_fetch(head, item->oid.hash))
322-
oidclr(&item->oid);
328+
clear_item(item);
323329
item = NULL;
324330
continue;
325331
}
@@ -333,7 +339,7 @@ static void find_non_local_tags(const struct ref *refs,
333339
if (item &&
334340
!has_object_file_with_flags(&item->oid, OBJECT_INFO_QUICK) &&
335341
!will_fetch(head, item->oid.hash))
336-
oidclr(&item->oid);
342+
clear_item(item);
337343

338344
item = NULL;
339345

@@ -354,27 +360,29 @@ static void find_non_local_tags(const struct ref *refs,
354360
if (item &&
355361
!has_object_file_with_flags(&item->oid, OBJECT_INFO_QUICK) &&
356362
!will_fetch(head, item->oid.hash))
357-
oidclr(&item->oid);
363+
clear_item(item);
358364

359365
/*
360366
* For all the tags in the remote_refs_list,
361367
* add them to the list of refs to be fetched
362368
*/
363369
for_each_string_list_item(remote_ref_item, &remote_refs_list) {
364370
const char *refname = remote_ref_item->string;
371+
struct ref *rm;
365372

366373
item = hashmap_get_from_hash(&remote_refs, strhash(refname), refname);
367374
if (!item)
368375
BUG("unseen remote ref?");
369376

370377
/* Unless we have already decided to ignore this item... */
371-
if (!is_null_oid(&item->oid)) {
372-
struct ref *rm = alloc_ref(item->refname);
373-
rm->peer_ref = alloc_ref(item->refname);
374-
oidcpy(&rm->old_oid, &item->oid);
375-
**tail = rm;
376-
*tail = &rm->next;
377-
}
378+
if (item->ignore)
379+
continue;
380+
381+
rm = alloc_ref(item->refname);
382+
rm->peer_ref = alloc_ref(item->refname);
383+
oidcpy(&rm->old_oid, &item->oid);
384+
**tail = rm;
385+
*tail = &rm->next;
378386
}
379387
hashmap_free(&remote_refs, 1);
380388
string_list_clear(&remote_refs_list, 0);

t/t5801-remote-helpers.sh

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ test_expect_success 'forced push' '
126126
'
127127

128128
test_expect_success 'cloning without refspec' '
129-
GIT_REMOTE_TESTGIT_REFSPEC="" \
129+
GIT_REMOTE_TESTGIT_NOREFSPEC=1 \
130130
git clone "testgit::${PWD}/server" local2 2>error &&
131131
test_i18ngrep "this remote helper should implement refspec capability" error &&
132132
compare_refs local2 HEAD server HEAD
@@ -135,7 +135,7 @@ test_expect_success 'cloning without refspec' '
135135
test_expect_success 'pulling without refspecs' '
136136
(cd local2 &&
137137
git reset --hard &&
138-
GIT_REMOTE_TESTGIT_REFSPEC="" git pull 2>../error) &&
138+
GIT_REMOTE_TESTGIT_NOREFSPEC=1 git pull 2>../error) &&
139139
test_i18ngrep "this remote helper should implement refspec capability" error &&
140140
compare_refs local2 HEAD server HEAD
141141
'
@@ -145,8 +145,8 @@ test_expect_success 'pushing without refspecs' '
145145
(cd local2 &&
146146
echo content >>file &&
147147
git commit -a -m ten &&
148-
GIT_REMOTE_TESTGIT_REFSPEC="" &&
149-
export GIT_REMOTE_TESTGIT_REFSPEC &&
148+
GIT_REMOTE_TESTGIT_NOREFSPEC=1 &&
149+
export GIT_REMOTE_TESTGIT_NOREFSPEC &&
150150
test_must_fail git push 2>../error) &&
151151
test_i18ngrep "remote-helper doesn.t support push; refspec needed" error
152152
'
@@ -303,4 +303,14 @@ test_expect_success 'fetch url' '
303303
compare_refs server HEAD local FETCH_HEAD
304304
'
305305

306+
test_expect_success 'fetch tag' '
307+
(cd server &&
308+
git tag v1.0
309+
) &&
310+
(cd local &&
311+
git fetch
312+
) &&
313+
compare_refs local v1.0 server v1.0
314+
'
315+
306316
test_done

t/t5801/git-remote-testgit

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@ fi
1111
url=$2
1212

1313
dir="$GIT_DIR/testgit/$alias"
14-
prefix="refs/testgit/$alias"
1514

16-
default_refspec="refs/heads/*:${prefix}/heads/*"
15+
h_refspec="refs/heads/*:refs/testgit/$alias/heads/*"
16+
t_refspec="refs/tags/*:refs/testgit/$alias/tags/*"
1717

18-
refspec="${GIT_REMOTE_TESTGIT_REFSPEC-$default_refspec}"
19-
20-
test -z "$refspec" && prefix="refs"
18+
if test -n "$GIT_REMOTE_TESTGIT_NOREFSPEC"
19+
then
20+
h_refspec=""
21+
t_refspec=""
22+
fi
2123

2224
GIT_DIR="$url/.git"
2325
export GIT_DIR
@@ -40,7 +42,8 @@ do
4042
capabilities)
4143
echo 'import'
4244
echo 'export'
43-
test -n "$refspec" && echo "refspec $refspec"
45+
test -n "$h_refspec" && echo "refspec $h_refspec"
46+
test -n "$t_refspec" && echo "refspec $t_refspec"
4447
if test -n "$gitmarks"
4548
then
4649
echo "*import-marks $gitmarks"
@@ -52,7 +55,7 @@ do
5255
echo
5356
;;
5457
list)
55-
git for-each-ref --format='? %(refname)' 'refs/heads/'
58+
git for-each-ref --format='? %(refname)' 'refs/heads/' 'refs/tags/'
5659
head=$(git symbolic-ref HEAD)
5760
echo "@$head HEAD"
5861
echo
@@ -81,10 +84,11 @@ do
8184

8285
echo "feature done"
8386
git fast-export \
87+
${h_refspec:+"--refspec=$h_refspec"} \
88+
${t_refspec:+"--refspec=$t_refspec"} \
8489
${testgitmarks:+"--import-marks=$testgitmarks"} \
8590
${testgitmarks:+"--export-marks=$testgitmarks"} \
86-
$refs |
87-
sed -e "s#refs/heads/#${prefix}/heads/#g"
91+
$refs
8892
echo "done"
8993
;;
9094
export)

0 commit comments

Comments
 (0)