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

Re: [PATCH] git clone depth of 0 not possible.

From
Junio C Hamano <gitster@pobox.com>
Date
Jan 8, 2013, 07:36 UTC
Message-ID
<7vd2xggm8a.fsf@alter.siamese.dyndns.org>
In-Reply-To
<7vip78go6b.fsf@alter.siamese.dyndns.org>
Junio C Hamano <gitster@pobox.com> writes:
Show 25 quoted lines
> Jonathan Nieder <jrnieder@gmail.com> writes:
>
>> Stefan Beller wrote:
>>
>>> Currently it is not possible to have a shallow depth of
>>> just 0, i.e. only one commit in that repository after cloning.
>>> The minimum number of commits is 2, caused by depth=1.
>>
>> Sounds buggy.  Would anything break if we were to make --depth=1 mean
>> "1 deep, including the tip commit"?
>
> As long as we do not change the meaning of the "shallow" count going
> over the wire (i.e. the number we receive from the user will be
> fudged, so that user's "depth 1" that used to mean "the tip and one
> behind it" is expressed as "depth 2" at the end-user level, and we
> send over the wire the number that corresponded to the old "depth
> 1"), I do not think anything will break, and then --depth=0 may
> magically start meaning "only the tip; its immediate parents will
> not be transferred and recorded as the shallow boundary in the
> receiving repository".
>
> I do not mind carrying such a (technially) backward incompatible
> change in jn/clone-2.0-depth-off-by-one branch, keep it cooking in
> 'next' for a while and push it out together with other "2.0" topics
> in a future release ;-).

Speaking of --depth, I think in Git 2.0 we should fix the semantics of "deepening" done with "git fetch".

Its "--depth" parameter is used to specify the new depth of the history that you can tangle from the updated tip of remote tracking branches, and it has a rather unpleasant ramifications.

Suppose you start from "git clone --depth=1 $there". You have the today's snapshot, and one parent behind it. You keep working happily with the code and then realize that you want to know a bit more history behind the snapshot you started from.

 (upstream)
  ---o---o---o---A---B
 (you)
                 A---B
So you do:
    $ git fetch --depth=3
 (upstream)
  ---o---o---o---A---B---C---D---E---F---...---W---X---Y---Z
 (you)
                 A---B                         W---X---Y---Z

But in the meantime, if the upstream accumulated 20+ commits, you end up getting the commit at the updated tip of the upstream, and 3 generations of parents behind it. There will be a 10+ commit worth of gap between the bottom of the new shallow history and the old tip you have been working on, and the history becomes disjoint.

I think we need a protocol update to fix this; instead of sending "Now I want your tips and N commits behind it, please update my shallow bottom accordingly", which creates the above by giving you Z and 3 generations back and updates your cut-off point to W, the receiving end should be able to ask "I have a shallow history that cuts off at these commits. I want to get the history leading up to your tips, and also deepen the history further back from my current cut-off points by N commits", so that you would instead end up with something like this:

 (you)
     o---o---o---A---B---C---D---E---F---...---W---X---Y---Z

That is, truly "deepen my history by 3". We could call that "git fetch --deepen=3" or something.

Previous: Junio C HamanoNext: Junio C Hamano
Message 5 of 29 in “git clone depth of 0 not possible.”
  1. git clone depth of 0 not possible.Stefan Beller, Jan 7, 2013
  2. Documentation on depth option in git clone.Stefan Beller, Jan 7, 2013
  3. Jonathan NiederJan 8, 2013
  4. Junio C HamanoJan 8, 2013
  5. Junio C HamanoJan 8, 2013
  6. Junio C HamanoJan 8, 2013
  7. Duy NguyenJan 8, 2013
  8. Stefan BellerJan 8, 2013
  9. Duy NguyenJan 8, 2013
  10. Junio C HamanoJan 8, 2013
  11. Duy NguyenJan 8, 2013
  12. Junio C HamanoJan 8, 2013
  13. Matthijs KooijmanMay 28, 2013
  14. Jonathan NiederMay 28, 2013
  15. Jonathan NiederMay 28, 2013
  16. Matthijs KooijmanMay 28, 2013
  17. Jonathan NiederMay 28, 2013
  18. Junio C HamanoMay 28, 2013
  19. Matthijs KooijmanMay 30, 2013
  20. Junio C HamanoJun 2, 2013
  21. Matthijs KooijmanJul 9, 2013
  22. Matthijs KooijmanJul 11, 2013
  23. 1/3 upload-pack: Remove a piece of dead codeMatthijs Kooijman, Jul 11, 2013
  24. 2/3 upload-pack: Introduce new "fixed-off-by-one-depth" server featureMatthijs Kooijman, Jul 11, 2013
  25. 3/3 fetch-pack: Request fixed-off-by-one-depth when availableMatthijs Kooijman, Jul 11, 2013
  26. Duy NguyenJul 11, 2013
  27. Junio C HamanoJul 11, 2013
  28. Duy NguyenJan 8, 2013
  29. Junio C HamanoJan 8, 2013

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.