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

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Johan Herland
Date: Monday, March 3, 2008 - 8:02 pm

On Monday 03 March 2008, Daniel Barkalow wrote:

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
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[RFC] Build in clone, Daniel Barkalow, (Mon Feb 25, 2:12 pm)
Re: [RFC] Build in clone, Johan Herland, (Mon Feb 25, 7:21 pm)
Re: [RFC] Build in clone, Johannes Schindelin, (Tue Feb 26, 4:14 am)
Re: [RFC] Build in clone, Johan Herland, (Tue Feb 26, 5:19 am)
Re: [RFC] Build in clone, Johan Herland, (Tue Feb 26, 5:58 am)
Re: [RFC] Build in clone, Johan Herland, (Tue Feb 26, 6:37 am)
Re: [PATCH] Fix premature free of ref_lists while writing ..., Johannes Schindelin, (Tue Feb 26, 8:42 am)
Re: [PATCH] Fix premature call to git_config() causing t10 ..., Johannes Schindelin, (Tue Feb 26, 8:47 am)
Re: [RFC] Build in clone, Daniel Barkalow, (Tue Feb 26, 10:36 am)
Re: [RFC] Build in clone, Kristian , (Tue Feb 26, 11:53 am)
Re: [PATCH] Fix premature call to git_config() causing t10 ..., Johannes Schindelin, (Tue Feb 26, 3:40 pm)
[PATCH] builtin-clone: create remotes/origin/HEAD symref, ..., Johannes Schindelin, (Sat Mar 1, 10:57 pm)
[PATCH, fixed] builtin-clone: create remotes/origin/HEAD s ..., Johannes Schindelin, (Sat Mar 1, 11:25 pm)
[PATCH] builtin clone: support bundles, Johannes Schindelin, (Sun Mar 2, 12:46 am)
Re: [PATCH] builtin clone: support bundles, Daniel Barkalow, (Sun Mar 2, 9:19 am)
Re: [PATCH] builtin clone: support bundles, Daniel Barkalow, (Sun Mar 2, 9:48 am)
Re: [PATCH] builtin clone: support bundles, Johannes Schindelin, (Sun Mar 2, 10:34 am)
Re: [PATCH] builtin clone: support bundles, Junio C Hamano, (Sun Mar 2, 10:50 am)
Re: [PATCH] builtin clone: support bundles, Junio C Hamano, (Sun Mar 2, 10:54 am)
Re: [PATCH] builtin clone: support bundles, Santi Béjar, (Sun Mar 2, 5:04 pm)
Re: [PATCH, fixed] builtin-clone: create remotes/origin/HE ..., Johannes Schindelin, (Mon Mar 3, 10:10 am)
Re: [PATCH, fixed] builtin-clone: create remotes/origin/HE ..., Johannes Schindelin, (Mon Mar 3, 12:55 pm)
Re: [PATCH] Add test for cloning with "--reference" repo b ..., Johan Herland, (Mon Mar 3, 8:02 pm)