summaryrefslogtreecommitdiff
path: root/object.h
diff options
context:
space:
mode:
authorTaylor Blau <me@ttaylorr.com>2020-07-08 21:10:53 (GMT)
committerJunio C Hamano <gitster@pobox.com>2020-07-08 23:13:46 (GMT)
commitce16364e897e70a17bd1864b6007719eeec959f3 (patch)
tree1d3d8c13dbb374921d02926647f6b4671fc58319 /object.h
parent37b9dcabfc48b0cbce638140279878dac37aec73 (diff)
downloadgit-ce16364e897e70a17bd1864b6007719eeec959f3.zip
git-ce16364e897e70a17bd1864b6007719eeec959f3.tar.gz
git-ce16364e897e70a17bd1864b6007719eeec959f3.tar.bz2
commit.c: don't persist substituted parents when unshallowing
Since 37b9dcabfc (shallow.c: use '{commit,rollback}_shallow_file', 2020-04-22), Git knows how to reset stat-validity checks for the $GIT_DIR/shallow file, allowing it to change between a shallow and non-shallow state in the same process (e.g., in the case of 'git fetch --unshallow'). However, when $GIT_DIR/shallow changes, Git does not alter or remove any grafts (nor substituted parents) in memory. This comes up in a "git fetch --unshallow" with fetch.writeCommitGraph set to true. Ordinarily in a shallow repository (and before 37b9dcabfc, even in this case), commit_graph_compatible() would return false, indicating that the repository should not be used to write a commit-graphs (since commit-graph files cannot represent a shallow history). But since 37b9dcabfc, in an --unshallow operation that check succeeds. Thus even though the repository isn't shallow any longer (that is, we have all of the objects), the in-core representation of those objects still has munged parents at the shallow boundaries. When the commit-graph write proceeds, we use the incorrect parentage, producing wrong results. There are two ways for a user to work around this: either (1) set 'fetch.writeCommitGraph' to 'false', or (2) drop the commit-graph after unshallowing. One way to fix this would be to reset the parsed object pool entirely (flushing the cache and thus preventing subsequent reads from modifying their parents) after unshallowing. That would produce a problem when callers have a now-stale reference to the old pool, and so this patch implements a different approach. Instead, attach a new bit to the pool, 'substituted_parent', which indicates if the repository *ever* stored a commit which had its parents modified (i.e., the shallow boundary prior to unshallowing). This bit needs to be sticky because all reads subsequent to modifying a commit's parents are unreliable when unshallowing. Modify the check in 'commit_graph_compatible' to take this bit into account, and correctly avoid generating commit-graphs in this case, thus solving the bug. Helped-by: Derrick Stolee <dstolee@microsoft.com> Helped-by: Jonathan Nieder <jrnieder@gmail.com> Reported-by: Jay Conrod <jayconrod@google.com> Reviewed-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Taylor Blau <me@ttaylorr.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'object.h')
-rw-r--r--object.h1
1 files changed, 1 insertions, 0 deletions
diff --git a/object.h b/object.h
index 2dbabfc..4327ec0 100644
--- a/object.h
+++ b/object.h
@@ -26,6 +26,7 @@ struct parsed_object_pool {
char *alternate_shallow_file;
int commit_graft_prepared;
+ int substituted_parent;
struct buffer_slab *buffer_slab;
};