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

Shallow submodule efficiency

From
Martin von Gagern <martin.vgagern@gmx.net>
Date
Jun 28, 2016, 05:39 UTC
Message-ID
<f572d4ee-c618-6501-a8e5-717feca3ed7c@gmx.net>
Hi!

I have the feeling that “git submodule update --depth 1” is less clever than it could be. Here is one example I observed with git 2.0.0:

  git init foo
  cd foo
  git clone --single-branch \
            -b v0.99 https://github.com/git/git.git git-scm
  git submodule add https://github.com/git/git.git git-scm
  git commit -m Submod
  git clone --dissociate . ../bar
  cd ../bar
  git submodule update --init --depth 1 git-scm
This will download quite a bit of history, then result in an error message:
  error: no such remote ref a3eb250f996bf5e12376ec88622c4ccaabf20ea8
  Fetched in submodule path 'git-scm', but it did not contain
  a3eb250f996bf5e12376ec88622c4ccaabf20ea8. Direct fetching of that
  commit failed.

That seems so avoidable, since the commit in question is a tag, so it would be perfectly possible to fetch that specific commit from the server directly. Something like the following commands would do the trick:

  git fetch $url $(git ls-remote $url | \
                   awk /$sha1/'{print $2}' | sed 's/\^{}//')

If the commit in question is NOT a ref, then whether asking for it by unlisted SHA1 is supported will probably depend on the server's uploadpack.allowReachableSHA1InWant setting. I guess this is a reason why fb43e31 made the fetch for a specific SHA1 a fallback after the fetch for the default branch. Nevertheless, in case of “--depth 1” I think it would make sense to abort early: if none of the listed refs matches the requested one, and asking by SHA1 isn't supported by the server, then there is no point in fetching anything, since we won't be able to satisfy the submodule requirement either way.

For the case of “--depth n” with n > 1, I was wondering whether it would make sense to prefer the branch listed in submodule.‹name›.branch over the default branch.

I think shallow submodules would be very useful to embed libraries into projects, without too much care for history (and without the download times getting it entails), but with efficient updates to affected files only in case of a change in library version. But not being able to get a specific tag as a shallow submodule is a major showstopper here, I think.

Greetings,
 Martin von Gagern
Next: Stefan Beller
Message 1 of 4 in “Shallow submodule efficiency”
  1. Martin von GagernJun 28, 2016
  2. Stefan BellerJun 28, 2016
  3. Martin von GagernJun 28, 2016
  4. Stefan BellerJun 28, 2016

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.