Skip to content

Commit f10d31c

Browse files
phil-blaingitster
authored andcommitted
subtree: process 'git-subtree-split' trailer in separate function
Both functions 'find_latest_squash' (called by 'git subtree merge --squash' and 'git subtree split --rejoin') and 'find_existing_splits' (called by git 'subtree split') loop through commits that have a 'git-subtree-dir' trailer, and then process the 'git-subtree-mainline' and 'git-subtree-split' trailers for those commits. The processing done for the 'git-subtree-split' trailer is simple: we check if the object exists with 'rev-parse' and set the variable 'sub' to the object name, or we die if the object does not exist. In a future commit we will add more steps to the processing of this trailer in order to make the code more robust. To reduce code duplication, move the processing of the 'git-subtree-split' trailer to a dedicated function, 'process_subtree_split_trailer'. Signed-off-by: Philippe Blain <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7990142 commit f10d31c

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

contrib/subtree/git-subtree.sh

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,15 @@ try_remove_previous () {
371371
fi
372372
}
373373

374+
# Usage: process_subtree_split_trailer SPLIT_HASH MAIN_HASH
375+
process_subtree_split_trailer () {
376+
assert test $# = 2
377+
b="$1"
378+
sq="$2"
379+
sub="$(git rev-parse --verify --quiet "$b^{commit}")" ||
380+
die "fatal: could not rev-parse split hash $b from commit $sq"
381+
}
382+
374383
# Usage: find_latest_squash DIR
375384
find_latest_squash () {
376385
assert test $# = 1
@@ -395,8 +404,7 @@ find_latest_squash () {
395404
main="$b"
396405
;;
397406
git-subtree-split:)
398-
sub="$(git rev-parse --verify --quiet "$b^{commit}")" ||
399-
die "fatal: could not rev-parse split hash $b from commit $sq"
407+
process_subtree_split_trailer "$b" "$sq"
400408
;;
401409
END)
402410
if test -n "$sub"
@@ -447,8 +455,7 @@ find_existing_splits () {
447455
main="$b"
448456
;;
449457
git-subtree-split:)
450-
sub="$(git rev-parse --verify --quiet "$b^{commit}")" ||
451-
die "fatal: could not rev-parse split hash $b from commit $sq"
458+
process_subtree_split_trailer "$b" "$sq"
452459
;;
453460
END)
454461
debug "Main is: '$main'"

0 commit comments

Comments
 (0)