]> git.ipfire.org Git - thirdparty/git.git/commitdiff
fetch: use ref_namespaces during prefetch
authorDerrick Stolee <derrickstolee@github.com>
Fri, 5 Aug 2022 17:58:43 +0000 (17:58 +0000)
committerJunio C Hamano <gitster@pobox.com>
Fri, 5 Aug 2022 21:13:13 +0000 (14:13 -0700)
The "refs/prefetch/" namespace is used by 'git fetch --prefetch' as a
replacement of the destination of the refpsec for a remote. Git also
removes refspecs that include tags.

Instead of using string literals for the 'refs/tags/ and
'refs/prefetch/' namespaces, use the entries in the ref_namespaces
array.

This kind of change could be done in many places around the codebase,
but we are isolating only to this change because of the way the
refs/prefetch/ namespace somewhat motivated the creation of the
ref_namespaces array.

Signed-off-by: Derrick Stolee <derrickstolee@github.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/fetch.c

index ac29c2b1ae34df79f8a2bd62318dc714a1f37e24..78a6be49f7e01e77affce281348cc715dc1567c8 100644 (file)
@@ -490,7 +490,9 @@ static void filter_prefetch_refspec(struct refspec *rs)
                        continue;
                if (!rs->items[i].dst ||
                    (rs->items[i].src &&
-                    !strncmp(rs->items[i].src, "refs/tags/", 10))) {
+                    !strncmp(rs->items[i].src,
+                             ref_namespace[NAMESPACE_TAGS].ref,
+                             strlen(ref_namespace[NAMESPACE_TAGS].ref)))) {
                        int j;
 
                        free(rs->items[i].src);
@@ -506,7 +508,7 @@ static void filter_prefetch_refspec(struct refspec *rs)
                }
 
                old_dst = rs->items[i].dst;
-               strbuf_addstr(&new_dst, "refs/prefetch/");
+               strbuf_addstr(&new_dst, ref_namespace[NAMESPACE_PREFETCH].ref);
 
                /*
                 * If old_dst starts with "refs/", then place