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

Re: [PATCH] Add test for cloning with "--reference" repo being a subset of source repo

From
Johan Herland <johan@herland.net>
Date
Mar 4, 2008, 03:02 UTC
Message-ID
<200803040402.57993.johan@herland.net>
In-Reply-To
<alpine.LNX.1.00.0803031318000.19665@iabervon.org>
On Monday 03 March 2008, Daniel Barkalow wrote:
Show 8 quoted lines
> On Mon, 3 Mar 2008, Johan Herland wrote:
> 
> > Not sure what's going on here, yet, but I thought I'd give you a heads up.
> 
> I figured it out, and pushed out a fix; it was doing everything correctly, 
> but it wrote to the alternates files after the library had read that file, 
> so it then didn't notice that it actually had the objects that are in the 
> second alternate repository.

Thanks. After looking a bit more at the original test repo where I found this issue, I discovered another, similar bug. This one seems ugly; brace yourself:

In some cases (I'm not exactly sure of all the preconditions) when
cloning with "--reference", it seems git tries to access a loose object
in the "--reference" repo instead of in the cloned repo, even if that
object is already present in the cloned repo and _missing_ in the
"--reference" repo. The symptom is this error message:
    error: Trying to write ref $ref with nonexistant object $sha1

After playing around with this in gdb, it seems the problem is all the way down in sha1_file_name() (sha1_file.c). This function is responsible for generating the loose object filename for a given $sha1. It keeps a static char *base which is initially set to the object directory name, and then calls fill_sha1_path() to copy the rest of the object filename into the following bytes. On subsequent calls, only the fill_sha1_path() part is done, thereby reusing the base from the previous invocation.

What I observe is that this base is not reset after accessing loose objects in the "--reference" repo. Thus, later when accessing objects in the cloned repo, sha1_file_name() generates incorrect filenames (pointing to the "--reference" repo instead of the cloned repo).

Of course, this often goes undetected since the "--reference" repo often have the same loose objects as the clone.

Unfortunately (from a builtin git-clone's POV) this seems to be symptomatic of a deeper problem in this part of the code: Using function-static variables as caches only works as far as the cache is in sync with reality. Especially when switching between multiple repositories within the same process, it seems that several of these variables are left with invalid data in them. This needs to be fixed, if not only for now, then at least as part of the libification effort.

I'm not sure what is the best way of fixing this issue; my initial guess is to move these function-static variables out to file-level, and make sure they're properly reset whenever the appropriate context is changed (typically when set_git_dir() is called, I guess).

Here are the function-static variables I immediately found in sha1_file.c
(there may be more, both in sha1_file.c and in other files):
- sha1_file_name(): static char *base
- sha1_pack_name(): static char *base
- sha1_pack_index_name(): static char *base
- find_pack_entry(): static struct packed_git *last_found
  (not sure about this one)

I will follow up this email with two patches, one adding the failing test, and one providing a simple fix for that specific test (although very much insufficient as a fix for the actual issue described above).

...Johan
-- 
Johan Herland, <johan@herland.net>
www.herland.net
Previous: Daniel BarkalowNext: Johan Herland
Message 37 of 47 in “[RFC] Build in clone”
  1. Daniel BarkalowFeb 25, 2008
  2. Johan HerlandFeb 26, 2008
  3. Johannes SchindelinFeb 26, 2008
  4. Johan HerlandFeb 26, 2008
  5. Johan HerlandFeb 26, 2008
  6. Johan HerlandFeb 26, 2008
  7. Fix premature free of ref_lists while writing temporary refs to fileJohan Herland, Feb 26, 2008
  8. Johannes SchindelinFeb 26, 2008
  9. Johan HerlandFeb 26, 2008
  10. Daniel BarkalowFeb 26, 2008
  11. Johan HerlandFeb 26, 2008
  12. Fix premature call to git_config() causing t1020-subdirectory to failJohan Herland, Feb 26, 2008
  13. Johannes SchindelinFeb 26, 2008
  14. Daniel BarkalowFeb 26, 2008
  15. Johannes SchindelinFeb 26, 2008
  16. Daniel BarkalowFeb 26, 2008
  17. Junio C HamanoFeb 27, 2008
  18. Daniel BarkalowFeb 27, 2008
  19. Junio C HamanoFeb 27, 2008
  20. Daniel BarkalowFeb 27, 2008
  21. Junio C HamanoFeb 27, 2008
  22. Daniel BarkalowFeb 27, 2008
  23. Daniel BarkalowFeb 26, 2008
  24. Kristian HøgsbergFeb 26, 2008
  25. builtin-clone: create remotes/origin/HEAD symref, if guessedJohannes Schindelin, Mar 2, 2008
  26. builtin-clone: create remotes/origin/HEAD symref, if guessedJohannes Schindelin, Mar 2, 2008
  27. builtin clone: support bundlesJohannes Schindelin, Mar 2, 2008
  28. Daniel BarkalowMar 2, 2008
  29. Santi BéjarMar 3, 2008
  30. Daniel BarkalowMar 2, 2008
  31. Johannes SchindelinMar 2, 2008
  32. Junio C HamanoMar 2, 2008
  33. Junio C HamanoMar 2, 2008
  34. Add test for cloning with "--reference" repo being a subset of source repoJohan Herland, Mar 3, 2008
  35. Daniel BarkalowMar 3, 2008
  36. Daniel BarkalowMar 3, 2008
  37. Johan HerlandMar 4, 2008
  38. 1/2 Add test illustrating issues with sha1_file_name() and switching reposJohan Herland, Mar 4, 2008
  39. 2/2 Overly simplistic fix for issue with sha1_file_name() and switching reposJohan Herland, Mar 4, 2008
  40. Daniel BarkalowMar 4, 2008
  41. Daniel BarkalowMar 5, 2008
  42. Johan HerlandMar 5, 2008
  43. Kristian HøgsbergMar 3, 2008
  44. Pierre HabouzitMar 3, 2008
  45. Johannes SchindelinMar 3, 2008
  46. Johannes SchindelinMar 3, 2008
  47. Johan HerlandMar 3, 2008

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.