Skip to content

Commit 27a43ea

Browse files
committed
subtree: more robustly distinguish subtree and mainline commits
Prevent a mainline commit without $dir being treated as a subtree commit and pulling in the entire mainline history. Any valid subtree commit will have only valid subtree commits as parents, which will be unchanged by check_parents. Signed-off-by: Tom Clarkson <[email protected]>
1 parent a76a496 commit 27a43ea

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

contrib/subtree/git-subtree.sh

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,6 @@ cache_setup () {
224224
fi
225225
mkdir -p "$cachedir" ||
226226
die "Can't create new cachedir: $cachedir"
227-
mkdir -p "$cachedir/notree" ||
228-
die "Can't create new cachedir: $cachedir/notree"
229227
debug "Using cachedir: $cachedir" >&2
230228
}
231229

@@ -255,18 +253,11 @@ check_parents () {
255253
local indent=$(($2 + 1))
256254
for miss in $missed
257255
do
258-
if ! test -r "$cachedir/notree/$miss"
259-
then
260-
debug " unprocessed parent commit: $miss ($indent)"
261-
process_split_commit "$miss" "" "$indent"
262-
fi
256+
debug " unprocessed parent commit: $miss ($indent)"
257+
process_split_commit "$miss" "" "$indent"
263258
done
264259
}
265260

266-
set_notree () {
267-
echo "1" > "$cachedir/notree/$1"
268-
}
269-
270261
cache_set () {
271262
oldrev="$1"
272263
newrev="$2"
@@ -721,11 +712,18 @@ process_split_commit () {
721712
# vs. a mainline commit? Does it matter?
722713
if test -z "$tree"
723714
then
724-
set_notree "$rev"
725715
if test -n "$newparents"
726716
then
727-
cache_set "$rev" "$rev"
717+
if test "$newparents" = "$parents"
718+
then
719+
# if all parents were subtrees, this can be a subtree commit
720+
cache_set "$rev" "$rev"
721+
else
722+
# a mainline commit with tree missing is equivalent to the initial commit
723+
cache_set "$rev" ""
724+
fi
728725
else
726+
# no parents with valid subtree mappings means a commit prior to subtree add
729727
cache_set "$rev" ""
730728
fi
731729
return

0 commit comments

Comments
 (0)