git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: reducing object store size with remote alternates or shallow clone?

From
BCBrandon Casey <brandon.casey.ctr@nrlssc.navy.mil>
Date
Aug 24, 2010, 23:29 UTC
Message-ID
<pzml8liT3RErVlMrdxbSkHmhBs1RMvwYma9UXgvG6WY@cipher.nrlssc.navy.mil>
In-Reply-To
<7vfwy3vnti.fsf@alter.siamese.dyndns.org>
On 08/24/2010 01:59 PM, Junio C Hamano wrote:
Show 20 quoted lines
> Brandon Casey <brandon.casey.ctr@nrlssc.navy.mil> writes:
> 
>> On 08/24/2010 11:45 AM, Junio C Hamano wrote:
>>
>>> How about doing
>>>
>>>     $ LINUS=git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git
>>
>>>     $ git fetch $LINUS
>>>     $ git bundle create myfork.bundle HEAD..master
>>
>> I think you mean
>>
>>       $ git fetch $LINUS master
>>       $ git bundle create myfork.bundle FETCH_HEAD..master
> 
> Thanks, of course you are right.
> 
> Strictly speaking, as I know there is only one branch in the repository of
> Linus, there is no need to say "master" when fetching

Hmm. It appears that if the current checked-out branch has a configured merge ref, then a fetch that supplies a repository url (not a remote name) and no fetch refspec, will not fall back to fetch HEAD from the remote repository.

i.e. the following fetch does not retrieve any objects nor update FETCH_HEAD
   $ git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git linux
   $ cd linux
   $ git fetch git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git

but, if you create a new branch, that has no merge ref configuration, then git behaves as expected:

   $ git branch foo
   $ git checkout foo
   $ git fetch git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git
Namely we retrieve new objects and update FETCH_HEAD:
   From git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6
   * branch            HEAD       -> FETCH_HEAD
I think the problem is in builtin/fetch.c: get_ref_map().

When fetch is called as above, with a repository url but no refspec, we get this call sequence:

   cmd_fetch -> fetch_one
     fetch_one -> do_fetch(argc = 0)
       do_fetch -> get_ref_map(ref_count = 0)
         line 148: has_merge is assigned 1 since the current checked out
                   branch has a merge ref configured
         The 'if' branch is entered, the 'for' loop is not entered,
         ref_map retains its NULL initialization value and
         get_ref_map() returns NULL
       do_fetch -> fetch_refs(ref_map = NULL)
         and the transports do nothing since no refs have been requested
Perhaps the fix should look something like this (warning copy/paste):
diff --git a/builtin/fetch.c b/builtin/fetch.c
index fab3fce..218e71d 100644
--- a/builtin/fetch.c
+++ b/builtin/fetch.c
@@ -146,7 +146,8 @@ static struct ref *get_ref_map(struct transport *transport,
                struct remote *remote = transport->remote;
                struct branch *branch = branch_get(NULL);
                int has_merge = branch_has_merge_config(branch);
-               if (remote && (remote->fetch_refspec_nr || has_merge)) {
+               if (remote && (remote->fetch_refspec_nr || (has_merge &&
+                               !strcmp(branch->remote_name, remote->name)))) {
                        for (i = 0; i < remote->fetch_refspec_nr; i++) {
                                get_fetch_map(remote_refs, &remote->fetch[i], &tail, 0);
                                if (remote->fetch[i].dst &&


-Brandon
Previous: Junio C HamanoNext: Brandon Casey
Message 5 of 13 in “reducing object store size with remote alternates or shallow clone?”
  1. Kumar GalaAug 24, 2010
  2. Junio C HamanoAug 24, 2010
  3. Brandon CaseyAug 24, 2010
  4. Junio C HamanoAug 24, 2010
  5. Brandon CaseyAug 24, 2010
  6. 1/2 t/t5510: demonstrate failure to fetch when current branch has merge refBrandon Casey, Aug 25, 2010
  7. Junio C HamanoAug 25, 2010
  8. 2/2 builtin/fetch.c: ignore merge config when not fetching from branch's remoteBrandon Casey, Aug 25, 2010
  9. Jonathan NiederAug 25, 2010
  10. Brandon CaseyAug 25, 2010
  11. Junio C HamanoAug 25, 2010
  12. 1/2 builtin/fetch.c: comment that branch->remote_name is usable when has_mergeBrandon Casey, Sep 9, 2010
  13. 2/2 t/t5510-fetch.sh: improve testing with explicit URL and merge specBrandon Casey, Sep 9, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.