contrib/subtree: add repo url to commit messages
PATCH 1/1 contrib/subtree: add repo url to commit messages
For recalling where a subtree came from; git-subtree operations 'add' and 'pull', when called with the <repository> parameter add this to the commit message:
git-subtree-repo: <repo_url>
Other operations that don't have the <repository> information, like 'merge' and 'add' without <repository>, are unchanged. Users with such a workflow will continue to be on their own with the --message parameter, if they'd like to record where the subtree came from.
--- contrib/subtree/git-subtree.sh | 73 ++++++++++++++++++++++++++++-------------- 1 file changed, 49 insertions(+), 24 deletions(-)
contrib/subtree/git-subtree.sh +49 -24
@@ -335,18 +335,21 @@ add_msg() dir="$1" latest_old="$2" latest_new="$3" + repo="$4" # optional if [ -n "$message" ]; then commit_message="$message" else commit_message="Add '$dir/' from commit '$latest_new'" fi - cat <<-EOF - $commit_message - - git-subtree-dir: $dir - git-subtree-mainline: $latest_old - git-subtree-split: $latest_new - EOF + echo $commit_message + echo + echo git-subtree-dir: $dir + echo git-subtree-mainline: $latest_old + echo git-subtree-split: $latest_new + if [ -n "$repo" ]; then + repo_url=$(get_repository_url "$repo") + echo "git-subtree-repo: $repo_url" + fi } add_squashed_msg()
@@ -382,8 +385,9 @@ squash_msg() dir="$1" oldsub="$2" newsub="$3" + repo="$4" # optional newsub_short=$(git rev-parse --short "$newsub") - + if [ -n "$oldsub" ]; then oldsub_short=$(git rev-parse --short "$oldsub") echo "Squashed '$dir/' changes from $oldsub_short..$newsub_short"
@@ -397,6 +401,10 @@ squash_msg() echo echo "git-subtree-dir: $dir" echo "git-subtree-split: $newsub" + if [ -n "$repo" ]; then + repo_url=$(get_repository_url "$repo") + echo "git-subtree-repo: $repo_url" + fi } toptree_for_commit()
@@ -440,12 +448,13 @@ new_squash_commit() old="$1" oldsub="$2" newsub="$3" + repo="$4" # optional tree=$(toptree_for_commit $newsub) || exit $? if [ -n "$old" ]; then - squash_msg "$dir" "$oldsub" "$newsub" | + squash_msg "$dir" "$oldsub" "$newsub" "$repo" | git commit-tree "$tree" -p "$old" || exit $? else - squash_msg "$dir" "" "$newsub" | + squash_msg "$dir" "" "$newsub" "$repo" | git commit-tree "$tree" || exit $? fi }
@@ -517,6 +526,16 @@ ensure_valid_ref_format() die "'$1' does not look like a ref" } +get_repository_url() +{ + repo=$1 + repo_url=$(git config --get remote.$repo.url) + if [ -z "$repo_url" ]; then + repo_url=$repo + fi + echo $repo_url +} + cmd_add() { if [ -e "$dir" ]; then
@@ -548,19 +567,18 @@ cmd_add() cmd_add_repository() { echo "git fetch" "$@" - repository=$1 + repo=$1 refspec=$2 git fetch "$@" || exit $? revs=FETCH_HEAD - set -- $revs + set -- $revs $repo cmd_add_commit "$@" } cmd_add_commit() { - revs=$(git rev-parse $default --revs-only "$@") || exit $? - set -- $revs - rev="$1" + rev=$(git rev-parse $default --revs-only "$1") || exit $? + repo="$2" # optional debug "Adding $dir as '$rev'..." git read-tree --prefix="$dir" $rev || exit $?
@@ -575,12 +593,12 @@ cmd_add_commit() fi if [ -n "$squash" ]; then - rev=$(new_squash_commit "" "" "$rev") || exit $? + rev=$(new_squash_commit "" "" "$rev" "$repo") || exit $? commit=$(add_squashed_msg "$rev" "$dir" | git commit-tree $tree $headp -p "$rev") || exit $? else revp=$(peel_committish "$rev") && - commit=$(add_msg "$dir" "$headrev" "$rev" | + commit=$(add_msg "$dir" "$headrev" "$rev" "$repo" | git commit-tree $tree $headp -p "$revp") || exit $? fi git reset "$commit" || exit $?
@@ -609,7 +627,8 @@ cmd_split() else unrevs="$(find_existing_splits "$dir" "$revs")" fi - +e + rev="$1" # We can't restrict rev-list to only $dir here, because some of our # parents have the $dir contents the root, and those won't match. # (and rev-list --follow doesn't seem to solve this)
@@ -683,15 +702,20 @@ cmd_split() cmd_merge() { - revs=$(git rev-parse $default --revs-only "$@") || exit $? + revs=$(git rev-parse $default --revs-only "$1") || exit $? ensure_clean - set -- $revs if [ $# -ne 1 ]; then die "You must provide exactly one revision. Got: '$revs'" fi + do_merge "$@" +} + +do_merge() +{ rev="$1" - + repo="$2" # optional + if [ -n "$squash" ]; then first_split="$(find_latest_squash "$dir")" if [ -z "$first_split" ]; then
@@ -704,7 +728,7 @@ cmd_merge() say "Subtree is already at commit $rev." exit 0 fi - new=$(new_squash_commit "$old" "$sub" "$rev") || exit $? + new=$(new_squash_commit "$old" "$sub" "$rev" "$repo") || exit $? debug "New squash commit: $new" rev="$new" fi
@@ -730,12 +754,13 @@ cmd_pull() if [ $# -ne 2 ]; then die "You must provide <repository> <ref>" fi + repo=$1 ensure_clean ensure_valid_ref_format "$2" git fetch "$@" || exit $? revs=FETCH_HEAD - set -- $revs - cmd_merge "$@" + set -- $revs $repo + do_merge "$@" } cmd_push()
Signature · 1 line
2.7.1
Quoted 9 lines · Mathias Nyman
For recalling where a subtree came from; git-subtree operations 'add' and 'pull', when called with the <repository> parameter add this to the commit message:
git-subtree-repo: <repo_url>Other operations that don't have the <repository> information, like 'merge' and 'add' without <repository>, are unchanged. Users with such a workflow will continue to be on their own with the --message parameter, if they'd like to record where the subtree came from.
I'm not a subtree user, so review comments below are superficial...
Quoted 16 lines
Signed-off-by Mathias Nyman <[email protected]>Based-on-patch-by Nicola Paolucci <[email protected]>---
contrib/subtree/git-subtree.sh +1
-2@@ -335,18 +335,21 @@ add_msg() dir="$1" latest_old="$2" latest_new="$3" + repo="$4" # optional if [ -n "$message" ]; then commit_message="$message" else commit_message="Add '$dir/' from commit '$latest_new'" fi - cat <<-EOF - $commit_message
contrib/subtree/git-subtree.sh add_msg() · line 348
Quoted 10 lines
contrib/subtree/git-subtree.sh +5
-5- - git-subtree-dir: $dir - git-subtree-mainline: $latest_old - git-subtree-split: $latest_new - EOF + echo $commit_message + echo + echo git-subtree-dir: $dir + echo git-subtree-mainline: $latest_old + echo git-subtree-split: $latest_new
It's not clear why this code was changed to use a series of echo's in place of the single cat. Although the net result is the same, this appears to be mere code churn. If your intention was to make it similar to how squash_msg() uses a series of echo's, then that might make sense, however, rejoin_msg() uses the same single 'cat' as add_msg(), so inconsistency remains. Thus, it's not clear what the intention is.
Quoted 8 lines
contrib/subtree/git-subtree.sh +4
-0+ if [ -n "$repo" ]; then + repo_url=$(get_repository_url "$repo") + echo "git-subtree-repo: $repo_url" + fi } add_squashed_msg()
contrib/subtree/git-subtree.sh squash_msg() · line 390
Quoted 7 lines
contrib/subtree/git-subtree.sh +2
-1@@ -382,8 +385,9 @@ squash_msg() dir="$1" oldsub="$2" newsub="$3" + repo="$4" # optional newsub_short=$(git rev-parse --short "$newsub") - +
Okay, this change is removing an unnecessary tab. Perhaps the commit message can say that the patch fixes a few whitespace inconsistencies while touching nearby code.
More below...
Quoted 48 lines
contrib/subtree/git-subtree.sh +17
-2if [ -n "$oldsub" ]; then oldsub_short=$(git rev-parse --short "$oldsub") echo "Squashed '$dir/' changes from $oldsub_short..$newsub_short"@@ -397,6 +401,10 @@ squash_msg() echo echo "git-subtree-dir: $dir" echo "git-subtree-split: $newsub" + if [ -n "$repo" ]; then + repo_url=$(get_repository_url "$repo") + echo "git-subtree-repo: $repo_url" + fi } toptree_for_commit()@@ -440,12 +448,13 @@ new_squash_commit() old="$1" oldsub="$2" newsub="$3" + repo="$4" # optional tree=$(toptree_for_commit $newsub) || exit $? if [ -n "$old" ]; then - squash_msg "$dir" "$oldsub" "$newsub" | + squash_msg "$dir" "$oldsub" "$newsub" "$repo" | git commit-tree "$tree" -p "$old" || exit $? else - squash_msg "$dir" "" "$newsub" | + squash_msg "$dir" "" "$newsub" "$repo" | git commit-tree "$tree" || exit $? fi }@@ -517,6 +526,16 @@ ensure_valid_ref_format() die "'$1' does not look like a ref" } +get_repository_url() +{ + repo=$1 + repo_url=$(git config --get remote.$repo.url) + if [ -z "$repo_url" ]; then + repo_url=$repo + fi + echo $repo_url +} + cmd_add() { if [ -e "$dir" ]; then
contrib/subtree/git-subtree.sh cmd_add() · line 570
Quoted 5 lines
contrib/subtree/git-subtree.sh +1
-1@@ -548,19 +567,18 @@ cmd_add() cmd_add_repository() { echo "git fetch" "$@" - repository=$1 + repo=$1
Hmm, so 'repository' was present already but unused in this function, and now you're using it. I suppose you renamed it 'repo' for consistency with other 'repo' variable the patch introduces elsewhere.
contrib/subtree/git-subtree.sh cmd_add() · line 575
Quoted 6 lines
contrib/subtree/git-subtree.sh +1
-1refspec=$2 git fetch "$@" || exit $? revs=FETCH_HEAD - set -- $revs + set -- $revs $repo cmd_add_commit "$@"
The original code intentionally allowed passing a set of revs to cmd_add_commit(), however, you've repurposed it (below) so that it accepts one rev and an (optional) repo. Therefore, there doesn't seem to be much value anymore to using "set --" when you could just do:
cmd_add_commit $revs $repo
Or am I missing something obvious?
(Of course, the original code unconditionally used "set --" even while setting 'revs' to hardcoded FETCH_HEAD, so I suppose this isn't any worse, but still...)
contrib/subtree/git-subtree.sh cmd_add() · line 580
Quoted 8 lines
contrib/subtree/git-subtree.sh +1
-3} cmd_add_commit() { - revs=$(git rev-parse $default --revs-only "$@") || exit $? - set -- $revs - rev="$1" + rev=$(git rev-parse $default --revs-only "$1") || exit $?
An audit of call callers of cmd_add_commit() shows that it was only ever invoked with a single rev, so this change to make it accept a single rev plus an optional repo seems safe. However, I wonder if it would make sense to keep the more flexible interface (in case future callers might need the functionality) by passing repo in as the first argument (using an empty string, for instance, for the optional bit) and then taking all subsequent arguments as revs, but perhaps that's overkill since it doesn't seem to care about revs other than the first one.
cmd_merge() still goes through the "set --" dance which you've removed here, even though an audit of all its callers pass in only a single rev, so that seems inconsistent...
Quoted 20 lines
contrib/subtree/git-subtree.sh +3
-2+ repo="$2" # optional debug "Adding $dir as '$rev'..." git read-tree --prefix="$dir" $rev || exit $?@@ -575,12 +593,12 @@ cmd_add_commit() fi if [ -n "$squash" ]; then - rev=$(new_squash_commit "" "" "$rev") || exit $? + rev=$(new_squash_commit "" "" "$rev" "$repo") || exit $? commit=$(add_squashed_msg "$rev" "$dir" | git commit-tree $tree $headp -p "$rev") || exit $? else revp=$(peel_committish "$rev") && - commit=$(add_msg "$dir" "$headrev" "$rev" | + commit=$(add_msg "$dir" "$headrev" "$rev" "$repo" | git commit-tree $tree $headp -p "$revp") || exit $? fi git reset "$commit" || exit $?
contrib/subtree/git-subtree.sh cmd_split() · line 630
Quoted 5 lines
contrib/subtree/git-subtree.sh +1
-1@@ -609,7 +627,8 @@ cmd_split() else unrevs="$(find_existing_splits "$dir" "$revs")" fi - +e
So, you're replacing a line containing a single tab with a line containing a single 'e'. Seems fishy.
contrib/subtree/git-subtree.sh cmd_split() · line 705
Quoted 10 lines
contrib/subtree/git-subtree.sh +2
-1+ rev="$1" # We can't restrict rev-list to only $dir here, because some of our # parents have the $dir contents the root, and those won't match. # (and rev-list --follow doesn't seem to solve this)@@ -683,15 +702,20 @@ cmd_split() cmd_merge() { - revs=$(git rev-parse $default --revs-only "$@") || exit $? + revs=$(git rev-parse $default --revs-only "$1") || exit $?
Why is this variable still named 'revs' (plural) since you're only passing in $1 now rather than $@?
contrib/subtree/git-subtree.sh cmd_split() · line 707
Quoted 3 lines
contrib/subtree/git-subtree.sh +0
-1ensure_clean - set -- $revs
Do you still need this "set --" or am I missing something?
contrib/subtree/git-subtree.sh cmd_split() · line 710
Quoted 3 lines
contrib/subtree/git-subtree.sh +0
-0if [ $# -ne 1 ]; then die "You must provide exactly one revision. Got: '$revs'" fi
Ditto with the conditional, considering that you only ever look at $1 now rather than $@.
Quoted 24 lines
contrib/subtree/git-subtree.sh +8
-2+ do_merge "$@" +} + +do_merge() +{ rev="$1" - + repo="$2" # optional + if [ -n "$squash" ]; then first_split="$(find_latest_squash "$dir")" if [ -z "$first_split" ]; then@@ -704,7 +728,7 @@ cmd_merge() say "Subtree is already at commit $rev." exit 0 fi - new=$(new_squash_commit "$old" "$sub" "$rev") || exit $? + new=$(new_squash_commit "$old" "$sub" "$rev" "$repo") || exit $? debug "New squash commit: $new" rev="$new" fi@@ -730,12 +754,13 @@ cmd_pull() if [ $# -ne 2 ]; then die "You must provide <repository> <ref>"
contrib/subtree/git-subtree.sh cmd_pull() · line 763
Quoted 10 lines
contrib/subtree/git-subtree.sh +3
-2fi + repo=$1 ensure_clean ensure_valid_ref_format "$2" git fetch "$@" || exit $? revs=FETCH_HEAD - set -- $revs - cmd_merge "$@" + set -- $revs $repo + do_merge "$@"
Same question as above. Is "set --" still buying you anything over just:
do_merge $revs $repo
?
Quoted 5 lines
contrib/subtree/git-subtree.sh +0
-1} cmd_push() --2.7.1
Quoted 6 lines · Eric Sunshine
Quoted 5 lines · Mathias Nyman
For recalling where a subtree came from; git-subtree operations 'add' and 'pull', when called with the <repository> parameter add this to the commit message:
git-subtree-repo: <repo_url>
Quoted 7 lines
Quoted 4 lines
Other operations that don't have the <repository> information, like 'merge' and 'add' without <repository>, are unchanged. Users with such a workflow will continue to be on their own with the --message parameter, if they'd like to record where the subtree came from.
I'm not a subtree user, so review comments below are superficial...
Thank you for reviewing; will send PATCH v2 shortly.
Quoted 27 lines
Quoted 16 lines
Signed-off-by Mathias Nyman <[email protected]>Based-on-patch-by Nicola Paolucci <[email protected]>---
contrib/subtree/git-subtree.sh +1
-2@@ -335,18 +335,21 @@ add_msg() dir="$1" latest_old="$2" latest_new="$3" + repo="$4" # optional if [ -n "$message" ]; then commit_message="$message" else commit_message="Add '$dir/' from commit '$latest_new'" fi - cat <<-EOF - $commit_messagecontrib/subtree/git-subtree.sh add_msg() · line 348
Quoted 10 lines
contrib/subtree/git-subtree.sh +5
-5- - git-subtree-dir: $dir - git-subtree-mainline: $latest_old - git-subtree-split: $latest_new - EOF + echo $commit_message + echo + echo git-subtree-dir: $dir + echo git-subtree-mainline: $latest_old + echo git-subtree-split: $latest_new
Quoted 8 lines
It's not clear why this code was changed to use a series of echo's in place of the single cat. Although the net result is the same, this appears to be mere code churn. If your intention was to make it similar to how
squash_msg()uses a series of echo's, then that might make sense, however,rejoin_msg()uses the same single 'cat' asadd_msg(), so inconsistency remains. Thus, it's not clear what the intention is.
Using a mixutre of heredoc and echo felt messy. But I'll change it back to heredoc here, and through out the commit aim for near-zero refactoring.
Quoted 20 lines
Quoted 8 lines
contrib/subtree/git-subtree.sh +4
-0+ if [ -n "$repo" ]; then + repo_url=$(get_repository_url "$repo") + echo "git-subtree-repo: $repo_url" + fi } add_squashed_msg()contrib/subtree/git-subtree.sh squash_msg() · line 390
Quoted 7 lines
contrib/subtree/git-subtree.sh +2
-1@@ -382,8 +385,9 @@ squash_msg() dir="$1" oldsub="$2" newsub="$3" + repo="$4" # optional newsub_short=$(git rev-parse --short "$newsub") - +Okay, this change is removing an unnecessary tab. Perhaps the commit message can say that the patch fixes a few whitespace inconsistencies while touching nearby code.
Quoted 2 lines
More below...
Will undo the whitespace fixing.
Quoted 49 lines
Quoted 49 lines
contrib/subtree/git-subtree.sh +17
-2if [ -n "$oldsub" ]; then oldsub_short=$(git rev-parse --short "$oldsub") echo "Squashed '$dir/' changes from $oldsub_short..$newsub_short"@@ -397,6 +401,10 @@ squash_msg() echo echo "git-subtree-dir: $dir" echo "git-subtree-split: $newsub" + if [ -n "$repo" ]; then + repo_url=$(get_repository_url "$repo") + echo "git-subtree-repo: $repo_url" + fi } toptree_for_commit()@@ -440,12 +448,13 @@ new_squash_commit() old="$1" oldsub="$2" newsub="$3" + repo="$4" # optional tree=$(toptree_for_commit $newsub) || exit $? if [ -n "$old" ]; then - squash_msg "$dir" "$oldsub" "$newsub" | + squash_msg "$dir" "$oldsub" "$newsub" "$repo" | git commit-tree "$tree" -p "$old" || exit $? else - squash_msg "$dir" "" "$newsub" | + squash_msg "$dir" "" "$newsub" "$repo" | git commit-tree "$tree" || exit $? fi }@@ -517,6 +526,16 @@ ensure_valid_ref_format() die "'$1' does not look like a ref" } +get_repository_url() +{ + repo=$1 + repo_url=$(git config --get remote.$repo.url) + if [ -z "$repo_url" ]; then + repo_url=$repo + fi + echo $repo_url +} + cmd_add() { if [ -e "$dir" ]; then@@ -548,19 +567,18 @@ cmd_add() cmd_add_repository()
Quoted 9 lines
contrib/subtree/git-subtree.sh cmd_add() · line 570
Quoted 4 lines
contrib/subtree/git-subtree.sh +1
-1{ echo "git fetch" "$@" - repository=$1 + repo=$1Hmm, so 'repository' was present already but unused in this function, and now you're using it. I suppose you renamed it 'repo' for consistency with other 'repo' variable the patch introduces elsewhere.
Yes.
Quoted 12 lines
contrib/subtree/git-subtree.sh cmd_add() · line 575
Quoted 6 lines
contrib/subtree/git-subtree.sh +1
-1refspec=$2 git fetch "$@" || exit $? revs=FETCH_HEAD - set -- $revs + set -- $revs $repo cmd_add_commit "$@"The original code intentionally allowed passing a set of revs to
cmd_add_commit(), however, you've repurposed it (below) so that it accepts one rev and an (optional) repo. Therefore, there doesn't seem to be much value anymore to using "set --" when you could just do:
Quoted 8 lines
cmd_add_commit$revs $repoOr am I missing something obvious?
(Of course, the original code unconditionally used "set --" even while setting 'revs' to hardcoded
FETCH_HEAD, so I suppose this isn't any worse, but still...)
Will leave this as is; your suggestion would mean refactoring the 'set --' quirks, which I tried not to do.
Quoted 9 lines
contrib/subtree/git-subtree.sh cmd_add() · line 580
Quoted 8 lines
contrib/subtree/git-subtree.sh +1
-3} cmd_add_commit() { - revs=$(git rev-parse $default --revs-only "$@") || exit $? - set -- $revs - rev="$1" + rev=$(git rev-parse $default --revs-only "$1") || exit $?
Quoted 10 lines
An audit of call callers of
cmd_add_commit()shows that it was only ever invoked with a single rev, so this change to make it accept a single rev plus an optional repo seems safe. However, I wonder if it would make sense to keep the more flexible interface (in case future callers might need the functionality) by passing repo in as the first argument (using an empty string, for instance, for the optional bit) and then taking all subsequent arguments as revs, but perhaps that's overkill since it doesn't seem to care about revs other than the first one.
I think it makes sense to refactor the general 'set --' dance in git-subtree.sh all together.
Quoted 4 lines
cmd_merge()still goes through the "set --" dance which you've removed here, even though an audit of all its callers pass in only a single rev, so that seems inconsistent...
I'll readd this 'set --' dance here for consistency.
Quoted 20 lines
Quoted 20 lines
contrib/subtree/git-subtree.sh +3
-2+ repo="$2" # optional debug "Adding $dir as '$rev'..." git read-tree --prefix="$dir" $rev || exit $?@@ -575,12 +593,12 @@ cmd_add_commit() fi if [ -n "$squash" ]; then - rev=$(new_squash_commit "" "" "$rev") || exit $? + rev=$(new_squash_commit "" "" "$rev" "$repo") || exit $? commit=$(add_squashed_msg "$rev" "$dir" | git commit-tree $tree $headp -p "$rev") || exit $? else revp=$(peel_committish "$rev") && - commit=$(add_msg "$dir" "$headrev" "$rev" | + commit=$(add_msg "$dir" "$headrev" "$rev" "$repo" | git commit-tree $tree $headp -p "$revp") || exit $? fi git reset "$commit" || exit $?@@ -609,7 +627,8 @@ cmd_split()
Quoted 9 lines
contrib/subtree/git-subtree.sh cmd_split() · line 630
Quoted 5 lines
contrib/subtree/git-subtree.sh +1
-1else unrevs="$(find_existing_splits "$dir" "$revs")" fi - +eSo, you're replacing a line containing a single tab with a line containing a single 'e'. Seems fishy.
Great typo find!
Quoted 6 lines
Quoted 6 lines
contrib/subtree/git-subtree.sh +1
-0+ rev="$1" # We can't restrict rev-list to only $dir here, because some of our # parents have the $dir contents the root, and those won't match. # (and rev-list --follow doesn't seem to solve this)@@ -683,15 +702,20 @@ cmd_split()
Quoted 8 lines
contrib/subtree/git-subtree.sh cmd_split() · line 705
Quoted 4 lines
contrib/subtree/git-subtree.sh +1
-1cmd_merge() { - revs=$(git rev-parse $default --revs-only "$@") || exit $? + revs=$(git rev-parse $default --revs-only "$1") || exit $?Why is this variable still named 'revs' (plural) since you're only passing in $1 now rather than $@?
Because technically the result can still be more then one rev I guess. Consider 'git rev-parse HEAD~1..HEAD', which would return two hashes.
Quoted 4 lines
contrib/subtree/git-subtree.sh cmd_split() · line 707
Quoted 3 lines
contrib/subtree/git-subtree.sh +0
-1ensure_clean - set -- $revs
Quoted 9 lines
Do you still need this "set --" or am I missing something?
contrib/subtree/git-subtree.sh cmd_split() · line 710
Quoted 3 lines
contrib/subtree/git-subtree.sh +0
-0if [ $# -ne 1 ]; then die "You must provide exactly one revision. Got: '$revs'" fiDitto with the conditional, considering that you only ever look at $1 now rather than $@.
This will handle the case where 'git rev-parse' caught more than one hash earlier.
Quoted 37 lines
Quoted 24 lines
contrib/subtree/git-subtree.sh +8
-2+ do_merge "$@" +} + +do_merge() +{ rev="$1" - + repo="$2" # optional + if [ -n "$squash" ]; then first_split="$(find_latest_squash "$dir")" if [ -z "$first_split" ]; then@@ -704,7 +728,7 @@ cmd_merge() say "Subtree is already at commit $rev." exit 0 fi - new=$(new_squash_commit "$old" "$sub" "$rev") || exit $? + new=$(new_squash_commit "$old" "$sub" "$rev" "$repo") || exit $? debug "New squash commit: $new" rev="$new" fi@@ -730,12 +754,13 @@ cmd_pull() if [ $# -ne 2 ]; then die "You must provide <repository> <ref>"contrib/subtree/git-subtree.sh cmd_pull() · line 763
Quoted 10 lines
contrib/subtree/git-subtree.sh +3
-2fi + repo=$1 ensure_clean ensure_valid_ref_format "$2" git fetch "$@" || exit $? revs=FETCH_HEAD - set -- $revs - cmd_merge "$@" + set -- $revs $repo + do_merge "$@"Same question as above. Is "set --" still buying you anything over just:
Quoted 4 lines
do_merge$revs $repo?
No. But I will not deviate from the function parameter passing method ('set --') used throughout git-subtree.sh in this commit. I do think parameter passing in git-subtree.sh deserves a separate no-functional-changes refactoring commit though.
Quoted 5 lines
Quoted 5 lines
contrib/subtree/git-subtree.sh +0
-1} cmd_push() --2.7.1
Quoted 24 lines · Mathias Nyman
Quoted 15 lines · Eric Sunshine
contrib/subtree/git-subtree.sh add_msg() · line 348
Quoted 12 lines · Mathias Nyman
contrib/subtree/git-subtree.sh +5
-7- cat <<-EOF - $commit_message - - git-subtree-dir: $dir - git-subtree-mainline: $latest_old - git-subtree-split: $latest_new - EOF + echo $commit_message + echo + echo git-subtree-dir: $dir + echo git-subtree-mainline: $latest_old + echo git-subtree-split: $latest_newQuoted 7 lines
It's not clear why this code was changed to use a series of echo's in place of the single cat. Although the net result is the same, this appears to be mere code churn. If your intention was to make it similar to how
squash_msg()uses a series of echo's, then that might make sense, however,rejoin_msg()uses the same single 'cat' asadd_msg(), so inconsistency remains. Thus, it's not clear what the intention is.
Quoted 3 lines
Using a mixutre of heredoc and echo felt messy. But I'll change it back to heredoc here, and through out the commit aim for near-zero refactoring.
An alternative would be to have a preparatory patch which unifies the heredoc vs. echo issue across add_msg(), squash_msg(), rejoin_msg(), but I wouldn't insist upon it (that's just more work for you). Leaving this bit alone is a reasonable choice.
Quoted 11 lines
Quoted 9 lines
contrib/subtree/git-subtree.sh squash_msg() · line 390
Quoted 4 lines
contrib/subtree/git-subtree.sh +2
-1+ repo="$4" # optional newsub_short=$(git rev-parse --short "$newsub") - +Okay, this change is removing an unnecessary tab. Perhaps the commit message can say that the patch fixes a few whitespace inconsistencies while touching nearby code.
Will undo the whitespace fixing.
Oh, I wasn't insisting that you should undo the whitespace fix. Typically, you'd make such fixes in a preparatory cleanup patch, but since there are only two cases here that you've fixed, it probably wouldn't hurt to retain them (if that's all there are in the file). The reason I suggested mentioning the whitespace fixes in the commit message is to let the reviewer know that they weren't cases of you accidentally making unwanted whitespace changes (like inserting tabs rather than removing them). As it was, as a reviewer, I had to go through extra effort to determine whether you had made a fix or had accidentally botched something.
Quoted 10 lines
Quoted 7 lines
contrib/subtree/git-subtree.sh cmd_split() · line 705
Quoted 4 lines
cmd_merge()
{contrib/subtree/git-subtree.sh +1
-1- revs=$(git rev-parse $default --revs-only "$@") || exit $? + revs=$(git rev-parse $default --revs-only "$1") || exit $?Why is this variable still named 'revs' (plural) since you're only passing in $1 now rather than $@?
Because technically the result can still be more then one rev I guess. Consider 'git rev-parse HEAD~1..HEAD', which would return two hashes.
Okay, so I was missing something obvious.
Quoted 46 lines · Eric Sunshine
Quoted 24 lines · Mathias Nyman
Quoted 15 lines · Eric Sunshine
contrib/subtree/git-subtree.sh add_msg() · line 348
Quoted 12 lines · Mathias Nyman
contrib/subtree/git-subtree.sh +5
-7- cat <<-EOF - $commit_message - - git-subtree-dir: $dir - git-subtree-mainline: $latest_old - git-subtree-split: $latest_new - EOF + echo $commit_message + echo + echo git-subtree-dir: $dir + echo git-subtree-mainline: $latest_old + echo git-subtree-split: $latest_newQuoted 7 lines
It's not clear why this code was changed to use a series of echo's in place of the single cat. Although the net result is the same, this appears to be mere code churn. If your intention was to make it similar to how
squash_msg()uses a series of echo's, then that might make sense, however,rejoin_msg()uses the same single 'cat' asadd_msg(), so inconsistency remains. Thus, it's not clear what the intention is.Quoted 3 lines
Using a mixutre of heredoc and echo felt messy. But I'll change it back to heredoc here, and through out the commit aim for near-zero refactoring.
An alternative would be to have a preparatory patch which unifies the heredoc vs. echo issue across
add_msg(),squash_msg(),rejoin_msg(), but I wouldn't insist upon it (that's just more work for you). Leaving this bit alone is a reasonable choice.Quoted 11 lines
Quoted 9 lines
contrib/subtree/git-subtree.sh squash_msg() · line 390
Quoted 4 lines
contrib/subtree/git-subtree.sh +2
-1+ repo="$4" # optional newsub_short=$(git rev-parse --short "$newsub") - +Okay, this change is removing an unnecessary tab. Perhaps the commit message can say that the patch fixes a few whitespace inconsistencies while touching nearby code.
Will undo the whitespace fixing.
Quoted 11 lines
Oh, I wasn't insisting that you should undo the whitespace fix. Typically, you'd make such fixes in a preparatory cleanup patch, but since there are only two cases here that you've fixed, it probably wouldn't hurt to retain them (if that's all there are in the file). The reason I suggested mentioning the whitespace fixes in the commit message is to let the reviewer know that they weren't cases of you accidentally making unwanted whitespace changes (like inserting tabs rather than removing them). As it was, as a reviewer, I had to go through extra effort to determine whether you had made a fix or had accidentally botched something.
Not fixing any whitespace inconsistencies felt like the consistent way to go in this commit.
Would be great to have some feedback on the core idea of this change, before spending more time on it. Anyone?
Quoted 12 lines
Quoted 10 lines
Quoted 7 lines
contrib/subtree/git-subtree.sh cmd_split() · line 705
Quoted 4 lines
cmd_merge()
{contrib/subtree/git-subtree.sh +1
-1- revs=$(git rev-parse $default --revs-only "$@") || exit $? + revs=$(git rev-parse $default --revs-only "$1") || exit $?Why is this variable still named 'revs' (plural) since you're only passing in $1 now rather than $@?
Because technically the result can still be more then one rev I guess. Consider 'git rev-parse HEAD~1..HEAD', which would return two hashes.
Okay, so I was missing something obvious.
Quoted 4 lines · Mathias Nyman
For recalling where a subtree came from; git-subtree operations 'add' and 'pull', when called with the <repository> parameter add this to the commit message:
git-subtree-repo: <repo_url>
I am sorry it tooks a couple of months to respond. I am finally coming up for air at work.
What is the future intent of this? I've toyed with the idea of adding something like this either as commit message metadata or in .gitconfig but every time I get ready to pull the trigger, I question what it will be used for.
Having been using git-subtree in anger for a couple of years now, I frequently pull subtree updates from multiple sources, so noting a particular repository is not only mostly meaningless, it may actually be misleading in that a quick perusal of the logs may lead one to think commits were draw from fewer places than they actually were.
I don't think it would be a good idea, for example, to have git-subtree use this information to auto-guess from where to pull future commits. Again, I think that would be misleading behavior.
-David
Quoted 197 lines
Other operations that don't have the <repository> information, like 'merge' and 'add' without <repository>, are unchanged. Users with such a workflow will continue to be on their own with the --message parameter, if they'd like to record where the subtree came from.
Signed-off-by Mathias Nyman <[email protected]>Based-on-patch-by Nicola Paolucci <[email protected]>--- contrib/subtree/git-subtree.sh | 73 ++++++++++++++++++++++++++++-------------- 1 file changed, 49 insertions(+), 24 deletions(-)contrib/subtree/git-subtree.sh +49
-24@@ -335,18 +335,21 @@ add_msg() dir="$1" latest_old="$2" latest_new="$3" + repo="$4" # optional if [ -n "$message" ]; then commit_message="$message" else commit_message="Add '$dir/' from commit '$latest_new'" fi - cat <<-EOF - $commit_message - - git-subtree-dir: $dir - git-subtree-mainline: $latest_old - git-subtree-split: $latest_new - EOF + echo $commit_message + echo + echo git-subtree-dir: $dir + echo git-subtree-mainline: $latest_old + echo git-subtree-split: $latest_new + if [ -n "$repo" ]; then + repo_url=$(get_repository_url "$repo") + echo "git-subtree-repo: $repo_url" + fi } add_squashed_msg()@@ -382,8 +385,9 @@ squash_msg() dir="$1" oldsub="$2" newsub="$3" + repo="$4" # optional newsub_short=$(git rev-parse --short "$newsub") - + if [ -n "$oldsub" ]; then oldsub_short=$(git rev-parse --short "$oldsub") echo "Squashed '$dir/' changes from $oldsub_short..$newsub_short"@@ -397,6 +401,10 @@ squash_msg() echo echo "git-subtree-dir: $dir" echo "git-subtree-split: $newsub" + if [ -n "$repo" ]; then + repo_url=$(get_repository_url "$repo") + echo "git-subtree-repo: $repo_url" + fi } toptree_for_commit()@@ -440,12 +448,13 @@ new_squash_commit() old="$1" oldsub="$2" newsub="$3" + repo="$4" # optional tree=$(toptree_for_commit $newsub) || exit $? if [ -n "$old" ]; then - squash_msg "$dir" "$oldsub" "$newsub" | + squash_msg "$dir" "$oldsub" "$newsub" "$repo" | git commit-tree "$tree" -p "$old" || exit $? else - squash_msg "$dir" "" "$newsub" | + squash_msg "$dir" "" "$newsub" "$repo" | git commit-tree "$tree" || exit $? fi }@@ -517,6 +526,16 @@ ensure_valid_ref_format() die "'$1' does not look like a ref" } +get_repository_url() +{ + repo=$1 + repo_url=$(git config --get remote.$repo.url) + if [ -z "$repo_url" ]; then + repo_url=$repo + fi + echo $repo_url +} + cmd_add() { if [ -e "$dir" ]; then@@ -548,19 +567,18 @@ cmd_add() cmd_add_repository() { echo "git fetch" "$@" - repository=$1 + repo=$1 refspec=$2 git fetch "$@" || exit $? revs=FETCH_HEAD - set -- $revs + set -- $revs $repo cmd_add_commit "$@" } cmd_add_commit() { - revs=$(git rev-parse $default --revs-only "$@") || exit $? - set -- $revs - rev="$1" + rev=$(git rev-parse $default --revs-only "$1") || exit $? + repo="$2" # optional debug "Adding $dir as '$rev'..." git read-tree --prefix="$dir" $rev || exit $?@@ -575,12 +593,12 @@ cmd_add_commit() fi if [ -n "$squash" ]; then - rev=$(new_squash_commit "" "" "$rev") || exit $? + rev=$(new_squash_commit "" "" "$rev" "$repo") || exit $? commit=$(add_squashed_msg "$rev" "$dir" | git commit-tree $tree $headp -p "$rev") || exit $? else revp=$(peel_committish "$rev") && - commit=$(add_msg "$dir" "$headrev" "$rev" | + commit=$(add_msg "$dir" "$headrev" "$rev" "$repo" | git commit-tree $tree $headp -p "$revp") || exit $? fi git reset "$commit" || exit $?@@ -609,7 +627,8 @@ cmd_split() else unrevs="$(find_existing_splits "$dir" "$revs")" fi - +e + rev="$1" # We can't restrict rev-list to only $dir here, because some of our # parents have the $dir contents the root, and those won't match. # (and rev-list --follow doesn't seem to solve this)@@ -683,15 +702,20 @@ cmd_split() cmd_merge() { - revs=$(git rev-parse $default --revs-only "$@") || exit $? + revs=$(git rev-parse $default --revs-only "$1") || exit $? ensure_clean - set -- $revs if [ $# -ne 1 ]; then die "You must provide exactly one revision. Got: '$revs'" fi + do_merge "$@" +} + +do_merge() +{ rev="$1" - + repo="$2" # optional + if [ -n "$squash" ]; then first_split="$(find_latest_squash "$dir")" if [ -z "$first_split" ]; then@@ -704,7 +728,7 @@ cmd_merge() say "Subtree is already at commit $rev." exit 0 fi - new=$(new_squash_commit "$old" "$sub" "$rev") || exit $? + new=$(new_squash_commit "$old" "$sub" "$rev" "$repo") || exit $? debug "New squash commit: $new" rev="$new" fi@@ -730,12 +754,13 @@ cmd_pull() if [ $# -ne 2 ]; then die "You must provide <repository> <ref>" fi + repo=$1 ensure_clean ensure_valid_ref_format "$2" git fetch "$@" || exit $? revs=FETCH_HEAD - set -- $revs - cmd_merge "$@" + set -- $revs $repo + do_merge "$@" } cmd_push()
Quoted 21 lines · David A. Greene
Quoted 4 lines · Mathias Nyman
For recalling where a subtree came from; git-subtree operations 'add' and 'pull', when called with the <repository> parameter add this to the commit message:
git-subtree-repo: <repo_url>I am sorry it tooks a couple of months to respond. I am finally coming up for air at work.
What is the future intent of this? I've toyed with the idea of adding something like this either as commit message metadata or in .gitconfig but every time I get ready to pull the trigger, I question what it will be used for.
Having been using git-subtree in anger for a couple of years now, I frequently pull subtree updates from multiple sources, so noting a particular repository is not only mostly meaningless, it may actually be misleading in that a quick perusal of the logs may lead one to think commits were draw from fewer places than they actually were.
Quoted 6 lines
I don't think it would be a good idea, for example, to have git-subtree use this information to auto-guess from where to pull future commits. Again, I think that would be misleading behavior.
-David
I don't have future features in mind which would build upon this.
For me this would be very helpful for identifying where to pull in updates from; I'm specifically thinking of the use case where git-subtree is used for managing third party dependencies. In particular when you want to bump versions, it would be convenient to have the history in the history :). So, having git-subtree automatically document that in the commit message seemed like a good idea to me.
:Mathias
Quoted 197 lines
Quoted 197 lines
Other operations that don't have the <repository> information, like 'merge' and 'add' without <repository>, are unchanged. Users with such a workflow will continue to be on their own with the --message parameter, if they'd like to record where the subtree came from.
Signed-off-by Mathias Nyman <[email protected]>Based-on-patch-by Nicola Paolucci <[email protected]>--- contrib/subtree/git-subtree.sh | 73 ++++++++++++++++++++++++++++-------------- 1 file changed, 49 insertions(+), 24 deletions(-)contrib/subtree/git-subtree.sh +49
-24@@ -335,18 +335,21 @@ add_msg() dir="$1" latest_old="$2" latest_new="$3" + repo="$4" # optional if [ -n "$message" ]; then commit_message="$message" else commit_message="Add '$dir/' from commit '$latest_new'" fi - cat <<-EOF - $commit_message - - git-subtree-dir: $dir - git-subtree-mainline: $latest_old - git-subtree-split: $latest_new - EOF + echo $commit_message + echo + echo git-subtree-dir: $dir + echo git-subtree-mainline: $latest_old + echo git-subtree-split: $latest_new + if [ -n "$repo" ]; then + repo_url=$(get_repository_url "$repo") + echo "git-subtree-repo: $repo_url" + fi } add_squashed_msg()@@ -382,8 +385,9 @@ squash_msg() dir="$1" oldsub="$2" newsub="$3" + repo="$4" # optional newsub_short=$(git rev-parse --short "$newsub") - + if [ -n "$oldsub" ]; then oldsub_short=$(git rev-parse --short "$oldsub") echo "Squashed '$dir/' changes from $oldsub_short..$newsub_short"@@ -397,6 +401,10 @@ squash_msg() echo echo "git-subtree-dir: $dir" echo "git-subtree-split: $newsub" + if [ -n "$repo" ]; then + repo_url=$(get_repository_url "$repo") + echo "git-subtree-repo: $repo_url" + fi } toptree_for_commit()@@ -440,12 +448,13 @@ new_squash_commit() old="$1" oldsub="$2" newsub="$3" + repo="$4" # optional tree=$(toptree_for_commit $newsub) || exit $? if [ -n "$old" ]; then - squash_msg "$dir" "$oldsub" "$newsub" | + squash_msg "$dir" "$oldsub" "$newsub" "$repo" | git commit-tree "$tree" -p "$old" || exit $? else - squash_msg "$dir" "" "$newsub" | + squash_msg "$dir" "" "$newsub" "$repo" | git commit-tree "$tree" || exit $? fi }@@ -517,6 +526,16 @@ ensure_valid_ref_format() die "'$1' does not look like a ref" } +get_repository_url() +{ + repo=$1 + repo_url=$(git config --get remote.$repo.url) + if [ -z "$repo_url" ]; then + repo_url=$repo + fi + echo $repo_url +} + cmd_add() { if [ -e "$dir" ]; then@@ -548,19 +567,18 @@ cmd_add() cmd_add_repository() { echo "git fetch" "$@" - repository=$1 + repo=$1 refspec=$2 git fetch "$@" || exit $? revs=FETCH_HEAD - set -- $revs + set -- $revs $repo cmd_add_commit "$@" } cmd_add_commit() { - revs=$(git rev-parse $default --revs-only "$@") || exit $? - set -- $revs - rev="$1" + rev=$(git rev-parse $default --revs-only "$1") || exit $? + repo="$2" # optional debug "Adding $dir as '$rev'..." git read-tree --prefix="$dir" $rev || exit $?@@ -575,12 +593,12 @@ cmd_add_commit() fi if [ -n "$squash" ]; then - rev=$(new_squash_commit "" "" "$rev") || exit $? + rev=$(new_squash_commit "" "" "$rev" "$repo") || exit $? commit=$(add_squashed_msg "$rev" "$dir" | git commit-tree $tree $headp -p "$rev") || exit $? else revp=$(peel_committish "$rev") && - commit=$(add_msg "$dir" "$headrev" "$rev" | + commit=$(add_msg "$dir" "$headrev" "$rev" "$repo" | git commit-tree $tree $headp -p "$revp") || exit $? fi git reset "$commit" || exit $?@@ -609,7 +627,8 @@ cmd_split() else unrevs="$(find_existing_splits "$dir" "$revs")" fi - +e + rev="$1" # We can't restrict rev-list to only $dir here, because some of our # parents have the $dir contents the root, and those won't match. # (and rev-list --follow doesn't seem to solve this)@@ -683,15 +702,20 @@ cmd_split() cmd_merge() { - revs=$(git rev-parse $default --revs-only "$@") || exit $? + revs=$(git rev-parse $default --revs-only "$1") || exit $? ensure_clean - set -- $revs if [ $# -ne 1 ]; then die "You must provide exactly one revision. Got: '$revs'" fi + do_merge "$@" +} + +do_merge() +{ rev="$1" - + repo="$2" # optional + if [ -n "$squash" ]; then first_split="$(find_latest_squash "$dir")" if [ -z "$first_split" ]; then@@ -704,7 +728,7 @@ cmd_merge() say "Subtree is already at commit $rev." exit 0 fi - new=$(new_squash_commit "$old" "$sub" "$rev") || exit $? + new=$(new_squash_commit "$old" "$sub" "$rev" "$repo") || exit $? debug "New squash commit: $new" rev="$new" fi@@ -730,12 +754,13 @@ cmd_pull() if [ $# -ne 2 ]; then die "You must provide <repository> <ref>" fi + repo=$1 ensure_clean ensure_valid_ref_format "$2" git fetch "$@" || exit $? revs=FETCH_HEAD - set -- $revs - cmd_merge "$@" + set -- $revs $repo + do_merge "$@" } cmd_push()