From 0ca71b3737cbb26fbf037aa15b3f58735785e6e3 Mon Sep 17 00:00:00 2001 From: Avery Pennarun Date: Fri, 24 Apr 2009 14:13:34 -0400 Subject: [PATCH 001/291] basic options parsing and whatnot. --- .gitignore | 1 + git-subtree | 1 + git-subtree.sh | 123 +++++++++++++++++++++++++++++++++++++++++++++++++ shellopts.sh | 1 + 4 files changed, 126 insertions(+) create mode 100644 .gitignore create mode 120000 git-subtree create mode 100755 git-subtree.sh create mode 100644 shellopts.sh diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000..b25c15b81f --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*~ diff --git a/git-subtree b/git-subtree new file mode 120000 index 0000000000..7d7539894e --- /dev/null +++ b/git-subtree @@ -0,0 +1 @@ +git-subtree.sh \ No newline at end of file diff --git a/git-subtree.sh b/git-subtree.sh new file mode 100755 index 0000000000..5e5b27f8ad --- /dev/null +++ b/git-subtree.sh @@ -0,0 +1,123 @@ +#!/bin/bash +# +# git-subtree.sh: split/join git repositories in subdirectories of this one +# +# Copyright (c) 2009 Avery Pennarun +# +OPTS_SPEC="\ +git subtree split -- +git subtree merge + +git subtree does foo and bar! +-- +h,help show the help +q quiet +v verbose +" +eval $(echo "$OPTS_SPEC" | git rev-parse --parseopt -- "$@" || echo exit $?) +. git-sh-setup +require_work_tree + +quiet= +command= + +debug() +{ + if [ -z "$quiet" ]; then + echo "$@" >&2 + fi +} + +#echo "Options: $*" + +while [ $# -gt 0 ]; do + opt="$1" + shift + case "$opt" in + -q) quiet=1 ;; + --) break ;; + esac +done + +command="$1" +shift +case "$command" in + split|merge) ;; + *) die "Unknown command '$command'" ;; +esac + +revs=$(git rev-parse --default HEAD --revs-only "$@") || exit $? +dirs="$(git rev-parse --sq --no-revs --no-flags "$@")" || exit $? + +#echo "dirs is {$dirs}" +eval $(echo set -- $dirs) +if [ "$#" -ne 1 ]; then + die "Must provide exactly one subtree dir (got $#)" +fi +dir="$1" + +debug "command: {$command}" +debug "quiet: {$quiet}" +debug "revs: {$revs}" +debug "dir: {$dir}" + +cache_setup() +{ + cachedir="$GIT_DIR/subtree-cache/$dir" + rm -rf "$cachedir" || die "Can't delete old cachedir: $cachedir" + mkdir -p "$cachedir" || die "Can't create new cachedir: $cachedir" + debug "Using cachedir: $cachedir" >&2 + echo "$cachedir" +} + +cache_get() +{ + for oldrev in $*; do + if [ -r "$cachedir/$oldrev" ]; then + read newrev <"$cachedir/$oldrev" + echo $newrev + fi + done +} + +cache_set() +{ + oldrev="$1" + newrev="$2" + if [ -e "$cachedir/$oldrev" ]; then + die "cache for $oldrev already exists!" + fi + echo "$newrev" >"$cachedir/$oldrev" +} + +cmd_split() +{ + debug "Splitting $dir..." + cache_setup || exit $? + + git rev-list --reverse --parents $revs -- "$dir" | + while read rev parents; do + newparents=$(cache_get $parents) + echo "rev: $rev / $newparents" + + git ls-tree $rev -- "$dir" | + while read mode type tree name; do + p="" + for parent in $newparents; do + p="$p -p $parent" + done + newrev=$(echo synthetic | git commit-tree $tree $p) \ + || die "Can't create new commit for $rev / $tree" + cache_set $rev $newrev + done + done + + exit 0 +} + +cmd_merge() +{ + die "merge command not implemented yet" +} + +"cmd_$command" diff --git a/shellopts.sh b/shellopts.sh new file mode 100644 index 0000000000..42644cd019 --- /dev/null +++ b/shellopts.sh @@ -0,0 +1 @@ +export PATH=$PWD:$PATH From 2573354e9b1619e92b8847d098555a0b6997c231 Mon Sep 17 00:00:00 2001 From: Avery Pennarun Date: Fri, 24 Apr 2009 14:24:38 -0400 Subject: [PATCH 002/291] 'git subtree split' now basically works. --- git-subtree.sh | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/git-subtree.sh b/git-subtree.sh index 5e5b27f8ad..c59759baa6 100755 --- a/git-subtree.sh +++ b/git-subtree.sh @@ -28,6 +28,16 @@ debug() fi } +assert() +{ + if "$@"; then + : + else + die "assertion failed: " "$@" + fi +} + + #echo "Options: $*" while [ $# -gt 0 ]; do @@ -63,7 +73,7 @@ debug "dir: {$dir}" cache_setup() { - cachedir="$GIT_DIR/subtree-cache/$dir" + cachedir="$GIT_DIR/subtree-cache/$$" rm -rf "$cachedir" || die "Can't delete old cachedir: $cachedir" mkdir -p "$cachedir" || die "Can't create new cachedir: $cachedir" debug "Using cachedir: $cachedir" >&2 @@ -98,19 +108,23 @@ cmd_split() git rev-list --reverse --parents $revs -- "$dir" | while read rev parents; do newparents=$(cache_get $parents) - echo "rev: $rev / $newparents" + debug + debug "Processing commit: $rev / $newparents" git ls-tree $rev -- "$dir" | while read mode type tree name; do + assert [ "$name" = "$dir" ] + debug " tree is: $tree" p="" for parent in $newparents; do p="$p -p $parent" done newrev=$(echo synthetic | git commit-tree $tree $p) \ || die "Can't create new commit for $rev / $tree" + echo " newrev is: $newrev" cache_set $rev $newrev - done - done + done || exit $? + done || exit $? exit 0 } From fd9500eef2eba7e8f66f984c924a11282daaa870 Mon Sep 17 00:00:00 2001 From: Avery Pennarun Date: Fri, 24 Apr 2009 14:45:02 -0400 Subject: [PATCH 003/291] We now copy the other stuff about a commit (changelog, author, etc). --- git-subtree.sh | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/git-subtree.sh b/git-subtree.sh index c59759baa6..256946b0de 100755 --- a/git-subtree.sh +++ b/git-subtree.sh @@ -77,7 +77,6 @@ cache_setup() rm -rf "$cachedir" || die "Can't delete old cachedir: $cachedir" mkdir -p "$cachedir" || die "Can't create new cachedir: $cachedir" debug "Using cachedir: $cachedir" >&2 - echo "$cachedir" } cache_get() @@ -100,6 +99,24 @@ cache_set() echo "$newrev" >"$cachedir/$oldrev" } +copy_commit() +{ + # We're doing to set some environment vars here, so + # do it in a subshell to get rid of them safely later + git log -1 --pretty=format:'%an%n%ae%n%ad%n%cn%n%ce%n%cd%n%s%n%n%b' "$1" | + ( + read GIT_AUTHOR_NAME + read GIT_AUTHOR_EMAIL + read GIT_AUTHOR_DATE + read GIT_COMMITTER_NAME + read GIT_COMMITTER_EMAIL + read GIT_COMMITTER_DATE + export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL GIT_AUTHOR_DATE + export GIT_COMMITTER_NAME GIT_COMMITTER_EMAIL GIT_COMMITTER_DATE + git commit-tree "$2" $3 # reads the rest of stdin + ) || die "Can't copy commit $1" +} + cmd_split() { debug "Splitting $dir..." @@ -119,9 +136,9 @@ cmd_split() for parent in $newparents; do p="$p -p $parent" done - newrev=$(echo synthetic | git commit-tree $tree $p) \ - || die "Can't create new commit for $rev / $tree" - echo " newrev is: $newrev" + + newrev=$(copy_commit $rev $tree "$p") || exit $? + debug " newrev is: $newrev" cache_set $rev $newrev done || exit $? done || exit $? From e25a6bf837ba378b0a8264e580c61069951dce66 Mon Sep 17 00:00:00 2001 From: Avery Pennarun Date: Fri, 24 Apr 2009 14:52:27 -0400 Subject: [PATCH 004/291] Print out the newly created commitid at the end, for use in other scripts. --- git-subtree.sh | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/git-subtree.sh b/git-subtree.sh index 256946b0de..5f8b0f6c59 100755 --- a/git-subtree.sh +++ b/git-subtree.sh @@ -93,7 +93,7 @@ cache_set() { oldrev="$1" newrev="$2" - if [ -e "$cachedir/$oldrev" ]; then + if [ "$oldrev" != "latest" -a -e "$cachedir/$oldrev" ]; then die "cache for $oldrev already exists!" fi echo "$newrev" >"$cachedir/$oldrev" @@ -140,9 +140,14 @@ cmd_split() newrev=$(copy_commit $rev $tree "$p") || exit $? debug " newrev is: $newrev" cache_set $rev $newrev + cache_set latest $newrev done || exit $? done || exit $? - + latest=$(cache_get latest) + if [ -z "$latest" ]; then + die "No new revisions were found" + fi + echo $latest exit 0 } From b77172f8140d830a9160306c8ee10ceed413ba23 Mon Sep 17 00:00:00 2001 From: Avery Pennarun Date: Fri, 24 Apr 2009 15:48:41 -0400 Subject: [PATCH 005/291] Add a new --rejoin option. The idea is to join the new split branch back into this one, so future splits can append themselves to the old split branch. We mark the split branch's history in our merge commit, so we can pull it back out later. --- git-subtree.sh | 53 +++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 44 insertions(+), 9 deletions(-) diff --git a/git-subtree.sh b/git-subtree.sh index 5f8b0f6c59..a31b0b2f6a 100755 --- a/git-subtree.sh +++ b/git-subtree.sh @@ -2,10 +2,10 @@ # # git-subtree.sh: split/join git repositories in subdirectories of this one # -# Copyright (c) 2009 Avery Pennarun +# Copyright (C) 2009 Avery Pennarun # OPTS_SPEC="\ -git subtree split -- +git subtree split [--rejoin] [--onto rev] -- git subtree merge git subtree does foo and bar! @@ -13,6 +13,8 @@ git subtree does foo and bar! h,help show the help q quiet v verbose +onto= existing subtree revision to connect, if any +rejoin merge the new branch back into HEAD " eval $(echo "$OPTS_SPEC" | git rev-parse --parseopt -- "$@" || echo exit $?) . git-sh-setup @@ -20,6 +22,8 @@ require_work_tree quiet= command= +onto= +rejoin= debug() { @@ -42,9 +46,12 @@ assert() while [ $# -gt 0 ]; do opt="$1" + debug "option: $1" shift case "$opt" in -q) quiet=1 ;; + --onto) onto="$1"; shift ;; + --rejoin) rejoin=1 ;; --) break ;; esac done @@ -93,7 +100,9 @@ cache_set() { oldrev="$1" newrev="$2" - if [ "$oldrev" != "latest" -a -e "$cachedir/$oldrev" ]; then + if [ "$oldrev" != "latest_old" \ + -a "$oldrev" != "latest_new" \ + -a -e "$cachedir/$oldrev" ]; then die "cache for $oldrev already exists!" fi echo "$newrev" >"$cachedir/$oldrev" @@ -111,12 +120,29 @@ copy_commit() read GIT_COMMITTER_NAME read GIT_COMMITTER_EMAIL read GIT_COMMITTER_DATE - export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL GIT_AUTHOR_DATE - export GIT_COMMITTER_NAME GIT_COMMITTER_EMAIL GIT_COMMITTER_DATE + export GIT_AUTHOR_NAME \ + GIT_AUTHOR_EMAIL \ + GIT_AUTHOR_DATE \ + GIT_COMMITTER_NAME \ + GIT_COMMITTER_EMAIL \ + GIT_COMMITTER_DATE git commit-tree "$2" $3 # reads the rest of stdin ) || die "Can't copy commit $1" } +merge_msg() +{ + dir="$1" + latest_old="$2" + latest_new="$3" + cat <<-EOF + Split changes from '$dir/' into commit '$latest_new' + + git-subtree-dir: $dir + git-subtree-includes: $latest_old + EOF +} + cmd_split() { debug "Splitting $dir..." @@ -140,14 +166,23 @@ cmd_split() newrev=$(copy_commit $rev $tree "$p") || exit $? debug " newrev is: $newrev" cache_set $rev $newrev - cache_set latest $newrev + cache_set latest_new $newrev + cache_set latest_old $rev done || exit $? done || exit $? - latest=$(cache_get latest) - if [ -z "$latest" ]; then + latest_new=$(cache_get latest_new) + if [ -z "$latest_new" ]; then die "No new revisions were found" fi - echo $latest + + if [ -n "$rejoin" ]; then + debug "Merging split branch into HEAD..." + latest_old=$(cache_get latest_old) + git merge -s ours \ + -m "$(merge_msg $dir $latest_old $latest_new)" \ + $latest_new + fi + echo $latest_new exit 0 } From 8b4a77f2a16d730f7261d66991107ab404b3b4ac Mon Sep 17 00:00:00 2001 From: Avery Pennarun Date: Fri, 24 Apr 2009 16:48:08 -0400 Subject: [PATCH 006/291] Use information about prior splits to make sure merges work right. --- git-subtree.sh | 40 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/git-subtree.sh b/git-subtree.sh index a31b0b2f6a..af1d332e24 100755 --- a/git-subtree.sh +++ b/git-subtree.sh @@ -46,7 +46,6 @@ assert() while [ $# -gt 0 ]; do opt="$1" - debug "option: $1" shift case "$opt" in -q) quiet=1 ;; @@ -108,6 +107,30 @@ cache_set() echo "$newrev" >"$cachedir/$oldrev" } +find_existing_splits() +{ + debug "Looking for prior splits..." + dir="$1" + revs="$2" + git log --grep="^git-subtree-dir: $dir\$" \ + --pretty=format:'%s%n%n%b%nEND' "$revs" | + while read a b junk; do + case "$a" in + git-subtree-mainline:) main="$b" ;; + git-subtree-split:) sub="$b" ;; + *) + if [ -n "$main" -a -n "$sub" ]; then + debug " Prior: $main -> $sub" + cache_set $main $sub + echo "^$main^ ^$sub^" + main= + sub= + fi + ;; + esac + done +} + copy_commit() { # We're doing to set some environment vars here, so @@ -136,10 +159,11 @@ merge_msg() latest_old="$2" latest_new="$3" cat <<-EOF - Split changes from '$dir/' into commit '$latest_new' + Split '$dir/' into commit '$latest_new' git-subtree-dir: $dir - git-subtree-includes: $latest_old + git-subtree-mainline: $latest_old + git-subtree-split: $latest_new EOF } @@ -148,12 +172,20 @@ cmd_split() debug "Splitting $dir..." cache_setup || exit $? - git rev-list --reverse --parents $revs -- "$dir" | + unrevs="$(find_existing_splits "$dir" "$revs")" + + git rev-list --reverse --parents $revs $unrevs -- "$dir" | while read rev parents; do + exists=$(cache_get $rev) newparents=$(cache_get $parents) debug debug "Processing commit: $rev / $newparents" + if [ -n "$exists" ]; then + debug " prior: $exists" + continue + fi + git ls-tree $rev -- "$dir" | while read mode type tree name; do assert [ "$name" = "$dir" ] From 33ff583ad7a52edb5ed9d869109e04c846d6209d Mon Sep 17 00:00:00 2001 From: Avery Pennarun Date: Fri, 24 Apr 2009 17:05:14 -0400 Subject: [PATCH 007/291] Added a --onto option, but it's so complicated I can't tell if it works. --- git-subtree.sh | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/git-subtree.sh b/git-subtree.sh index af1d332e24..7e1707ae2a 100755 --- a/git-subtree.sh +++ b/git-subtree.sh @@ -13,7 +13,7 @@ git subtree does foo and bar! h,help show the help q quiet v verbose -onto= existing subtree revision to connect, if any +onto= existing subtree revision to search for parent rejoin merge the new branch back into HEAD " eval $(echo "$OPTS_SPEC" | git rev-parse --parseopt -- "$@" || echo exit $?) @@ -172,6 +172,16 @@ cmd_split() debug "Splitting $dir..." cache_setup || exit $? + if [ -n "$onto" ]; then + echo "Reading history for $onto..." + git rev-list $onto | + while read rev; do + # the 'onto' history is already just the subdir, so + # any parent we find there can be used verbatim + cache_set $rev $rev + done + fi + unrevs="$(find_existing_splits "$dir" "$revs")" git rev-list --reverse --parents $revs $unrevs -- "$dir" | From 2c71b7c46d1ff887fb276a9d42346678a2948a00 Mon Sep 17 00:00:00 2001 From: Avery Pennarun Date: Fri, 24 Apr 2009 17:42:33 -0400 Subject: [PATCH 008/291] Hmm... can't actually filter rev-list on the subdir name. Otherwise we can't keep track of parent relationships. Argh. This change makes it "work", but we get a bunch of empty commits. --- git-subtree.sh | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/git-subtree.sh b/git-subtree.sh index 7e1707ae2a..1e1237f520 100755 --- a/git-subtree.sh +++ b/git-subtree.sh @@ -173,28 +173,31 @@ cmd_split() cache_setup || exit $? if [ -n "$onto" ]; then - echo "Reading history for $onto..." + echo "Reading history for --onto=$onto..." git rev-list $onto | while read rev; do # the 'onto' history is already just the subdir, so # any parent we find there can be used verbatim + debug " cache: $rev" cache_set $rev $rev done fi unrevs="$(find_existing_splits "$dir" "$revs")" - git rev-list --reverse --parents $revs $unrevs -- "$dir" | + debug "git rev-list --reverse $revs $unrevs" + git rev-list --reverse --parents $revs $unrevsx | while read rev parents; do - exists=$(cache_get $rev) - newparents=$(cache_get $parents) debug - debug "Processing commit: $rev / $newparents" - + debug "Processing commit: $rev" + exists=$(cache_get $rev) if [ -n "$exists" ]; then debug " prior: $exists" continue fi + debug " parents: $parents" + newparents=$(cache_get $parents) + debug " newparents: $newparents" git ls-tree $rev -- "$dir" | while read mode type tree name; do From 768d6d10051cbf2d0261b9cf671b1f969fb77a61 Mon Sep 17 00:00:00 2001 From: Avery Pennarun Date: Fri, 24 Apr 2009 17:53:10 -0400 Subject: [PATCH 009/291] Skip over empty commits. But we still need to get rid of unnecessary merge commits somehow... --- git-subtree.sh | 55 ++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 42 insertions(+), 13 deletions(-) diff --git a/git-subtree.sh b/git-subtree.sh index 1e1237f520..7ae71886f4 100755 --- a/git-subtree.sh +++ b/git-subtree.sh @@ -167,6 +167,32 @@ merge_msg() EOF } +tree_for_commit() +{ + git ls-tree "$1" -- "$dir" | + while read mode type tree name; do + assert [ "$name" = "$dir" ] + echo $tree + break + done +} + +tree_changed() +{ + tree=$1 + shift + if [ $# -ne 1 ]; then + return 0 # weird parents, consider it changed + else + ptree=$(tree_for_commit $1) + if [ "$ptree" != "$tree" ]; then + return 0 # changed + else + return 1 # not changed + fi + fi +} + cmd_split() { debug "Splitting $dir..." @@ -199,21 +225,24 @@ cmd_split() newparents=$(cache_get $parents) debug " newparents: $newparents" - git ls-tree $rev -- "$dir" | - while read mode type tree name; do - assert [ "$name" = "$dir" ] - debug " tree is: $tree" - p="" - for parent in $newparents; do - p="$p -p $parent" - done + tree=$(tree_for_commit $rev) + debug " tree is: $tree" + [ -z $tree ] && continue + + p="" + for parent in $newparents; do + p="$p -p $parent" + done + if tree_changed $tree $parents; then newrev=$(copy_commit $rev $tree "$p") || exit $? - debug " newrev is: $newrev" - cache_set $rev $newrev - cache_set latest_new $newrev - cache_set latest_old $rev - done || exit $? + else + newrev="$newparents" + fi + debug " newrev is: $newrev" + cache_set $rev $newrev + cache_set latest_new $newrev + cache_set latest_old $rev done || exit $? latest_new=$(cache_get latest_new) if [ -z "$latest_new" ]; then From 847e868167eb0e8a270004cbccec4ae36db06626 Mon Sep 17 00:00:00 2001 From: Avery Pennarun Date: Fri, 24 Apr 2009 21:35:50 -0400 Subject: [PATCH 010/291] Quick test script for generating reasonably complex merge scenarios. --- git-subtree.sh | 5 +-- test.sh | 96 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 99 insertions(+), 2 deletions(-) create mode 100755 test.sh diff --git a/git-subtree.sh b/git-subtree.sh index 7ae71886f4..ffffb5ed88 100755 --- a/git-subtree.sh +++ b/git-subtree.sh @@ -149,6 +149,7 @@ copy_commit() GIT_COMMITTER_NAME \ GIT_COMMITTER_EMAIL \ GIT_COMMITTER_DATE + (echo -n '*'; cat ) | # FIXME git commit-tree "$2" $3 # reads the rest of stdin ) || die "Can't copy commit $1" } @@ -199,7 +200,7 @@ cmd_split() cache_setup || exit $? if [ -n "$onto" ]; then - echo "Reading history for --onto=$onto..." + debug "Reading history for --onto=$onto..." git rev-list $onto | while read rev; do # the 'onto' history is already just the subdir, so @@ -254,7 +255,7 @@ cmd_split() latest_old=$(cache_get latest_old) git merge -s ours \ -m "$(merge_msg $dir $latest_old $latest_new)" \ - $latest_new + $latest_new >&2 fi echo $latest_new exit 0 diff --git a/test.sh b/test.sh new file mode 100755 index 0000000000..8a9d92f703 --- /dev/null +++ b/test.sh @@ -0,0 +1,96 @@ +#!/bin/bash -x +. shellopts.sh +set -e + +rm -rf mainline subproj +mkdir mainline subproj + +cd subproj +git init + +touch sub1 +git add sub1 +git commit -m 'sub-1' +git branch sub1 +git branch -m master subproj + +touch sub2 +git add sub2 +git commit -m 'sub-2' +git branch sub2 + +touch sub3 +git add sub3 +git commit -m 'sub-3' +git branch sub3 + +cd ../mainline +git init +touch main1 +git add main1 +git commit -m 'main-1' +git branch -m master mainline + +git fetch ../subproj sub1 +git branch sub1 FETCH_HEAD +git read-tree --prefix=subdir FETCH_HEAD +git checkout subdir +git commit -m 'initial-subdir-merge' + +git merge -m 'merge -s -ours' -s ours FETCH_HEAD + +touch subdir/main-sub3 +git add subdir/main-sub3 +git commit -m 'main-sub3' + +touch main-2 +git add main-2 +git commit -m 'main-2 boring' + +touch subdir/main-sub4 +git add subdir/main-sub4 +git commit -m 'main-sub4' + +git fetch ../subproj sub2 +git branch sub2 FETCH_HEAD +git merge -s subtree FETCH_HEAD +git branch pre-split + +split1=$(git subtree split --onto FETCH_HEAD subdir --rejoin) +echo "split1={$split1}" +git branch split1 "$split1" + +touch subdir/main-sub5 +git add subdir/main-sub5 +git commit -m 'main-sub5' + +cd ../subproj +git fetch ../mainline split1 +git branch split1 FETCH_HEAD +git merge FETCH_HEAD + +touch sub6 +git add sub6 +git commit -m 'sub6' + +cd ../mainline +split2=$(git subtree split subdir --rejoin) +git branch split2 "$split2" + +touch subdir/main-sub7 +git add subdir/main-sub7 +git commit -m 'main-sub7' + +split3=$(git subtree split subdir --rejoin) +git branch split3 "$split3" + +cd ../subproj +git fetch ../mainline split3 +git branch split3 FETCH_HEAD +git merge FETCH_HEAD +git branch subproj-merge-split3 + +cd ../mainline +git fetch ../subproj subproj-merge-split3 +git branch subproj-merge-split3 FETCH_HEAD +git merge subproj-merge-split3 From 210d083904914dd4668e032870f92ff0d5d441cc Mon Sep 17 00:00:00 2001 From: Avery Pennarun Date: Fri, 24 Apr 2009 21:49:19 -0400 Subject: [PATCH 011/291] Prune out some extra merge commits by comparing their parents correctly. --- git-subtree.sh | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/git-subtree.sh b/git-subtree.sh index ffffb5ed88..e6d8ce8817 100755 --- a/git-subtree.sh +++ b/git-subtree.sh @@ -168,9 +168,17 @@ merge_msg() EOF } -tree_for_commit() +toptree_for_commit() { - git ls-tree "$1" -- "$dir" | + commit="$1" + git log -1 --pretty=format:'%T' "$commit" -- || exit $? +} + +subtree_for_commit() +{ + commit="$1" + dir="$2" + git ls-tree "$commit" -- "$dir" | while read mode type tree name; do assert [ "$name" = "$dir" ] echo $tree @@ -185,7 +193,7 @@ tree_changed() if [ $# -ne 1 ]; then return 0 # weird parents, consider it changed else - ptree=$(tree_for_commit $1) + ptree=$(toptree_for_commit $1) if [ "$ptree" != "$tree" ]; then return 0 # changed else @@ -226,7 +234,7 @@ cmd_split() newparents=$(cache_get $parents) debug " newparents: $newparents" - tree=$(tree_for_commit $rev) + tree=$(subtree_for_commit $rev "$dir") debug " tree is: $tree" [ -z $tree ] && continue @@ -235,7 +243,7 @@ cmd_split() p="$p -p $parent" done - if tree_changed $tree $parents; then + if tree_changed $tree $newparents; then newrev=$(copy_commit $rev $tree "$p") || exit $? else newrev="$newparents" From d691265880abea4428783beb858683be56f3b340 Mon Sep 17 00:00:00 2001 From: Avery Pennarun Date: Fri, 24 Apr 2009 22:05:30 -0400 Subject: [PATCH 012/291] Even more aggressive commit trimming. Now we cut out a commit if any of its parents had the same tree; just use that parent in its place. This makes the history look nice, but I don't think it's quite right... --- git-subtree.sh | 34 ++++++++++++++++++++++++---------- test.sh | 2 +- 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/git-subtree.sh b/git-subtree.sh index e6d8ce8817..03107e2251 100755 --- a/git-subtree.sh +++ b/git-subtree.sh @@ -202,6 +202,29 @@ tree_changed() fi } +copy_or_skip() +{ + rev="$1" + tree="$2" + newparents="$3" + assert [ -n "$tree" ] + + p="" + for parent in $newparents; do + ptree=$(toptree_for_commit $parent) || exit $? + if [ "$ptree" = "$tree" ]; then + # any identical parent means this commit is unnecessary + echo $parent + return 0 + elif [ -n "$ptree" ]; then + # an existing, non-identical parent is important + p="$p -p $parent" + fi + done + + copy_commit $rev $tree "$p" || exit $? +} + cmd_split() { debug "Splitting $dir..." @@ -238,16 +261,7 @@ cmd_split() debug " tree is: $tree" [ -z $tree ] && continue - p="" - for parent in $newparents; do - p="$p -p $parent" - done - - if tree_changed $tree $newparents; then - newrev=$(copy_commit $rev $tree "$p") || exit $? - else - newrev="$newparents" - fi + newrev=$(copy_or_skip "$rev" "$tree" "$newparents") || exit $? debug " newrev is: $newrev" cache_set $rev $newrev cache_set latest_new $newrev diff --git a/test.sh b/test.sh index 8a9d92f703..a8ed0dbc7d 100755 --- a/test.sh +++ b/test.sh @@ -93,4 +93,4 @@ git branch subproj-merge-split3 cd ../mainline git fetch ../subproj subproj-merge-split3 git branch subproj-merge-split3 FETCH_HEAD -git merge subproj-merge-split3 +git merge -s subtree subproj-merge-split3 From 96db2c0448c2f6040c098d73570a96413338c662 Mon Sep 17 00:00:00 2001 From: Avery Pennarun Date: Fri, 24 Apr 2009 22:36:06 -0400 Subject: [PATCH 013/291] Okay, that was a little too aggressive. Now we only prune out a commit if it has exactly one remaining parent and that parent's tree is identical to ours. But I also changed the test to create the initial "-s ours" merge in one step instead of two, and that merge can be eliminated since one of its parents doesn't affect the subdir at all, and is thus deleted. --- git-subtree.sh | 46 ++++++++++++++++++++++++++++++++-------------- test.sh | 5 ++++- 2 files changed, 36 insertions(+), 15 deletions(-) diff --git a/git-subtree.sh b/git-subtree.sh index 03107e2251..d42cc1a164 100755 --- a/git-subtree.sh +++ b/git-subtree.sh @@ -4,17 +4,21 @@ # # Copyright (C) 2009 Avery Pennarun # +if [ $# -eq 0 ]; then + set -- -h +fi OPTS_SPEC="\ -git subtree split [--rejoin] [--onto rev] -- +git subtree split [options...] -- git subtree merge git subtree does foo and bar! -- -h,help show the help -q quiet -v verbose -onto= existing subtree revision to search for parent -rejoin merge the new branch back into HEAD +h,help show the help +q quiet +v verbose +onto= try connecting new tree to an existing one +rejoin merge the new branch back into HEAD +ignore-joins ignore prior --rejoin commits " eval $(echo "$OPTS_SPEC" | git rev-parse --parseopt -- "$@" || echo exit $?) . git-sh-setup @@ -24,6 +28,7 @@ quiet= command= onto= rejoin= +ignore_joins= debug() { @@ -50,7 +55,11 @@ while [ $# -gt 0 ]; do case "$opt" in -q) quiet=1 ;; --onto) onto="$1"; shift ;; + --no-onto) onto= ;; --rejoin) rejoin=1 ;; + --no-rejoin) rejoin= ;; + --ignore-joins) ignore_joins=1 ;; + --no-ignore-joins) ignore_joins= ;; --) break ;; esac done @@ -209,20 +218,25 @@ copy_or_skip() newparents="$3" assert [ -n "$tree" ] - p="" + identical= + p= for parent in $newparents; do ptree=$(toptree_for_commit $parent) || exit $? if [ "$ptree" = "$tree" ]; then - # any identical parent means this commit is unnecessary - echo $parent - return 0 - elif [ -n "$ptree" ]; then - # an existing, non-identical parent is important + # an identical parent could be used in place of this rev. + identical="$parent" + fi + if [ -n "$ptree" ]; then + parentmatch="$parentmatch$parent" p="$p -p $parent" fi done - copy_commit $rev $tree "$p" || exit $? + if [ -n "$identical" -a "$parentmatch" = "$identical" ]; then + echo $identical + else + copy_commit $rev $tree "$p" || exit $? + fi } cmd_split() @@ -241,7 +255,11 @@ cmd_split() done fi - unrevs="$(find_existing_splits "$dir" "$revs")" + if [ -n "$ignore_joins" ]; then + unrevs= + else + unrevs="$(find_existing_splits "$dir" "$revs")" + fi debug "git rev-list --reverse $revs $unrevs" git rev-list --reverse --parents $revs $unrevsx | diff --git a/test.sh b/test.sh index a8ed0dbc7d..39c4382f0d 100755 --- a/test.sh +++ b/test.sh @@ -35,7 +35,10 @@ git fetch ../subproj sub1 git branch sub1 FETCH_HEAD git read-tree --prefix=subdir FETCH_HEAD git checkout subdir -git commit -m 'initial-subdir-merge' +tree=$(git write-tree) +com=$(echo initial-subdir-merge | git commit-tree $tree -p HEAD -p FETCH_HEAD) +git reset $com +#git commit -m 'initial-subdir-merge' git merge -m 'merge -s -ours' -s ours FETCH_HEAD From 9a8821ff33d5abc9d2603dd91c04872016d40982 Mon Sep 17 00:00:00 2001 From: Avery Pennarun Date: Fri, 24 Apr 2009 22:57:14 -0400 Subject: [PATCH 014/291] Pass the path using the --prefix option instead of on the command line. I like this better. It's more like git-read-tree and some other commands. --- git-subtree.sh | 28 ++++++++++++++++------------ test.sh | 6 +++--- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/git-subtree.sh b/git-subtree.sh index d42cc1a164..0c7b755cf1 100755 --- a/git-subtree.sh +++ b/git-subtree.sh @@ -8,14 +8,12 @@ if [ $# -eq 0 ]; then set -- -h fi OPTS_SPEC="\ -git subtree split [options...] -- +git subtree split [options...] <--prefix=prefix> -- git subtree merge - -git subtree does foo and bar! -- h,help show the help q quiet -v verbose +prefix= the name of the subdir to split out onto= try connecting new tree to an existing one rejoin merge the new branch back into HEAD ignore-joins ignore prior --rejoin commits @@ -54,6 +52,8 @@ while [ $# -gt 0 ]; do shift case "$opt" in -q) quiet=1 ;; + --prefix) prefix="$1"; shift ;; + --no-prefix) prefix= ;; --onto) onto="$1"; shift ;; --no-onto) onto= ;; --rejoin) rejoin=1 ;; @@ -72,14 +72,16 @@ case "$command" in esac revs=$(git rev-parse --default HEAD --revs-only "$@") || exit $? -dirs="$(git rev-parse --sq --no-revs --no-flags "$@")" || exit $? -#echo "dirs is {$dirs}" -eval $(echo set -- $dirs) -if [ "$#" -ne 1 ]; then - die "Must provide exactly one subtree dir (got $#)" +if [ -z "$prefix" ]; then + die "You must provide the --prefix option." +fi +dir="$prefix" + +dirs="$(git rev-parse --no-revs --no-flags "$@")" || exit $? +if [ -n "$dirs" ]; then + die "Error: Use --prefix instead of bare filenames." fi -dir="$1" debug "command: {$command}" debug "quiet: {$quiet}" @@ -261,8 +263,10 @@ cmd_split() unrevs="$(find_existing_splits "$dir" "$revs")" fi - debug "git rev-list --reverse $revs $unrevs" - git rev-list --reverse --parents $revs $unrevsx | + # We can't restrict rev-list to only "$dir" here, because that leaves out + # critical information about commit parents. + debug "git rev-list --reverse --parents $revs $unrevs" + git rev-list --reverse --parents $revs $unrevs | while read rev parents; do debug debug "Processing commit: $rev" diff --git a/test.sh b/test.sh index 39c4382f0d..dac9b3559a 100755 --- a/test.sh +++ b/test.sh @@ -59,7 +59,7 @@ git branch sub2 FETCH_HEAD git merge -s subtree FETCH_HEAD git branch pre-split -split1=$(git subtree split --onto FETCH_HEAD subdir --rejoin) +split1=$(git subtree split --prefix subdir --onto FETCH_HEAD --rejoin) echo "split1={$split1}" git branch split1 "$split1" @@ -77,14 +77,14 @@ git add sub6 git commit -m 'sub6' cd ../mainline -split2=$(git subtree split subdir --rejoin) +split2=$(git subtree split --prefix subdir --rejoin) git branch split2 "$split2" touch subdir/main-sub7 git add subdir/main-sub7 git commit -m 'main-sub7' -split3=$(git subtree split subdir --rejoin) +split3=$(git subtree split --prefix subdir --rejoin) git branch split3 "$split3" cd ../subproj From eb7b590c8c63994051545bf1fe1f650f5dc4aedb Mon Sep 17 00:00:00 2001 From: Avery Pennarun Date: Fri, 24 Apr 2009 23:28:30 -0400 Subject: [PATCH 015/291] Add a new 'git subtree add' command for adding subtrees from a given rev. --- git-subtree.sh | 56 +++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 53 insertions(+), 3 deletions(-) diff --git a/git-subtree.sh b/git-subtree.sh index 0c7b755cf1..2dc99e82cd 100755 --- a/git-subtree.sh +++ b/git-subtree.sh @@ -8,7 +8,8 @@ if [ $# -eq 0 ]; then set -- -h fi OPTS_SPEC="\ -git subtree split [options...] <--prefix=prefix> -- +git subtree add <--prefix=prefix +git subtree split [options...] <--prefix=prefix> git subtree merge -- h,help show the help @@ -67,11 +68,12 @@ done command="$1" shift case "$command" in - split|merge) ;; + add|merge) default= ;; + split) default="--default HEAD" ;; *) die "Unknown command '$command'" ;; esac -revs=$(git rev-parse --default HEAD --revs-only "$@") || exit $? +revs=$(git rev-parse $default --revs-only "$@") || exit $? if [ -z "$prefix" ]; then die "You must provide the --prefix option." @@ -87,6 +89,7 @@ debug "command: {$command}" debug "quiet: {$quiet}" debug "revs: {$revs}" debug "dir: {$dir}" +debug cache_setup() { @@ -165,6 +168,20 @@ copy_commit() ) || die "Can't copy commit $1" } +add_msg() +{ + dir="$1" + latest_old="$2" + latest_new="$3" + cat <<-EOF + Add '$dir/' from commit '$latest_new' + + git-subtree-dir: $dir + git-subtree-mainline: $latest_old + git-subtree-split: $latest_new + EOF +} + merge_msg() { dir="$1" @@ -241,6 +258,39 @@ copy_or_skip() fi } +cmd_add() +{ + if [ -e "$dir" ]; then + die "'$dir' already exists. Cannot add." + fi + if ! git diff-index HEAD --exit-code --quiet; then + die "Working tree has modifications. Cannot add." + fi + if ! git diff-index --cached HEAD --exit-code --quiet; then + die "Index has modifications. Cannot add." + fi + set -- $revs + if [ $# -ne 1 ]; then + die "You must provide exactly one revision. Got: '$revs'" + fi + rev="$1" + + debug "Adding $dir as '$rev'..." + git read-tree --prefix="$dir" $rev || exit $? + git checkout "$dir" || exit $? + tree=$(git write-tree) || exit $? + + headrev=$(git rev-parse HEAD) || exit $? + if [ -n "$headrev" -a "$headrev" != "$rev" ]; then + headp="-p $headrev" + else + headp= + fi + commit=$(add_msg "$dir" "$headrev" "$rev" | + git commit-tree $tree $headp -p "$rev") || exit $? + git reset "$commit" || exit $? +} + cmd_split() { debug "Splitting $dir..." From 13648af5eecd0880a64b6ea4b14f485f53daa2f1 Mon Sep 17 00:00:00 2001 From: Avery Pennarun Date: Fri, 24 Apr 2009 23:41:19 -0400 Subject: [PATCH 016/291] Add 'git subtree merge' and 'git subtree pull'. These are simple shortcuts for 'git merge -s subtree' and 'git pull -s subtree', but it makes sense to have it all in one command. --- git-subtree.sh | 55 ++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 40 insertions(+), 15 deletions(-) diff --git a/git-subtree.sh b/git-subtree.sh index 2dc99e82cd..f2a1c6aae4 100755 --- a/git-subtree.sh +++ b/git-subtree.sh @@ -8,13 +8,15 @@ if [ $# -eq 0 ]; then set -- -h fi OPTS_SPEC="\ -git subtree add <--prefix=prefix -git subtree split [options...] <--prefix=prefix> -git subtree merge +git subtree add --prefix= +git subtree split [options...] --prefix= +git subtree merge --prefix= +git subtree pull --prefix= -- h,help show the help q quiet prefix= the name of the subdir to split out + options for 'split' onto= try connecting new tree to an existing one rejoin merge the new branch back into HEAD ignore-joins ignore prior --rejoin commits @@ -68,27 +70,29 @@ done command="$1" shift case "$command" in - add|merge) default= ;; + add|merge|pull) default= ;; split) default="--default HEAD" ;; *) die "Unknown command '$command'" ;; esac -revs=$(git rev-parse $default --revs-only "$@") || exit $? - if [ -z "$prefix" ]; then die "You must provide the --prefix option." fi dir="$prefix" -dirs="$(git rev-parse --no-revs --no-flags "$@")" || exit $? -if [ -n "$dirs" ]; then - die "Error: Use --prefix instead of bare filenames." +if [ "$command" != "pull" ]; then + revs=$(git rev-parse $default --revs-only "$@") || exit $? + dirs="$(git rev-parse --no-revs --no-flags "$@")" || exit $? + if [ -n "$dirs" ]; then + die "Error: Use --prefix instead of bare filenames." + fi fi debug "command: {$command}" debug "quiet: {$quiet}" debug "revs: {$revs}" debug "dir: {$dir}" +debug "opts: {$*}" debug cache_setup() @@ -258,17 +262,23 @@ copy_or_skip() fi } -cmd_add() +ensure_clean() { - if [ -e "$dir" ]; then - die "'$dir' already exists. Cannot add." - fi if ! git diff-index HEAD --exit-code --quiet; then die "Working tree has modifications. Cannot add." fi if ! git diff-index --cached HEAD --exit-code --quiet; then die "Index has modifications. Cannot add." fi +} + +cmd_add() +{ + if [ -e "$dir" ]; then + die "'$dir' already exists. Cannot add." + fi + ensure_clean + set -- $revs if [ $# -ne 1 ]; then die "You must provide exactly one revision. Got: '$revs'" @@ -357,7 +367,22 @@ cmd_split() cmd_merge() { - die "merge command not implemented yet" + ensure_clean + + set -- $revs + if [ $# -ne 1 ]; then + die "You must provide exactly one revision. Got: '$revs'" + fi + rev="$1" + + git merge -s subtree $rev } -"cmd_$command" +cmd_pull() +{ + ensure_clean + set -x + git pull -s subtree "$@" +} + +"cmd_$command" "$@" From b9de53532c3e7aa6b01aa188e0f0f17a266c099d Mon Sep 17 00:00:00 2001 From: Avery Pennarun Date: Sat, 25 Apr 2009 00:06:45 -0400 Subject: [PATCH 017/291] Handle it successfully if a given parent commit has no parents. --- git-subtree.sh | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/git-subtree.sh b/git-subtree.sh index f2a1c6aae4..aeafadac95 100755 --- a/git-subtree.sh +++ b/git-subtree.sh @@ -125,6 +125,16 @@ cache_set() echo "$newrev" >"$cachedir/$oldrev" } +# if a commit doesn't have a parent, this might not work. But we only want +# to remove the parent from the rev-list, and since it doesn't exist, it won't +# be there anyway, so do nothing in that case. +try_remove_previous() +{ + if git rev-parse "$1^" >/dev/null 2>&1; then + echo "^$1^" + fi +} + find_existing_splits() { debug "Looking for prior splits..." @@ -140,7 +150,8 @@ find_existing_splits() if [ -n "$main" -a -n "$sub" ]; then debug " Prior: $main -> $sub" cache_set $main $sub - echo "^$main^ ^$sub^" + try_remove_previous "$main" + try_remove_previous "$sub" main= sub= fi From a13a299996725a979f5a7d6bd878b0237de0f26d Mon Sep 17 00:00:00 2001 From: Avery Pennarun Date: Sat, 25 Apr 2009 00:07:04 -0400 Subject: [PATCH 018/291] Change test.sh to test the new add, merge, and pull commands. --- test.sh | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/test.sh b/test.sh index dac9b3559a..16fb8f217e 100755 --- a/test.sh +++ b/test.sh @@ -33,13 +33,9 @@ git branch -m master mainline git fetch ../subproj sub1 git branch sub1 FETCH_HEAD -git read-tree --prefix=subdir FETCH_HEAD -git checkout subdir -tree=$(git write-tree) -com=$(echo initial-subdir-merge | git commit-tree $tree -p HEAD -p FETCH_HEAD) -git reset $com -#git commit -m 'initial-subdir-merge' +git subtree add --prefix=subdir FETCH_HEAD +# this shouldn't actually do anything, since FETCH_HEAD is already a parent git merge -m 'merge -s -ours' -s ours FETCH_HEAD touch subdir/main-sub3 @@ -56,7 +52,7 @@ git commit -m 'main-sub4' git fetch ../subproj sub2 git branch sub2 FETCH_HEAD -git merge -s subtree FETCH_HEAD +git subtree merge --prefix=subdir FETCH_HEAD git branch pre-split split1=$(git subtree split --prefix subdir --onto FETCH_HEAD --rejoin) @@ -96,4 +92,4 @@ git branch subproj-merge-split3 cd ../mainline git fetch ../subproj subproj-merge-split3 git branch subproj-merge-split3 FETCH_HEAD -git merge -s subtree subproj-merge-split3 +git subtree pull --prefix=subdir ../subproj subproj-merge-split3 From 8c384754d8db80f74d3916100772171753bee4f9 Mon Sep 17 00:00:00 2001 From: Avery Pennarun Date: Sun, 26 Apr 2009 08:53:14 -0400 Subject: [PATCH 019/291] todo list --- todo | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 todo diff --git a/todo b/todo new file mode 100644 index 0000000000..b5b8e257aa --- /dev/null +++ b/todo @@ -0,0 +1,8 @@ + + delete tempdir + --annotate-sometimes: only annotate if the patch also changes files + outside the subdir? + 'git subtree rejoin' option to do the same as --rejoin, eg. after a + rebase + "-s subtree" should be given an explicit subtree option? + \ No newline at end of file From d0eb1b1417b855b262b5ad31d025840ea6e52094 Mon Sep 17 00:00:00 2001 From: Avery Pennarun Date: Sun, 26 Apr 2009 08:59:12 -0400 Subject: [PATCH 020/291] Add --annotate option, and create recognizable file content during tests. --- git-subtree.sh | 6 ++++- test.sh | 67 ++++++++++++++++++++++++++++---------------------- 2 files changed, 42 insertions(+), 31 deletions(-) diff --git a/git-subtree.sh b/git-subtree.sh index aeafadac95..e54651c336 100755 --- a/git-subtree.sh +++ b/git-subtree.sh @@ -17,6 +17,7 @@ h,help show the help q quiet prefix= the name of the subdir to split out options for 'split' +annotate= add a prefix to commit message of new commits onto= try connecting new tree to an existing one rejoin merge the new branch back into HEAD ignore-joins ignore prior --rejoin commits @@ -30,6 +31,7 @@ command= onto= rejoin= ignore_joins= +annotate= debug() { @@ -55,6 +57,8 @@ while [ $# -gt 0 ]; do shift case "$opt" in -q) quiet=1 ;; + --annotate) annotate="$1"; shift ;; + --no-annotate) annotate= ;; --prefix) prefix="$1"; shift ;; --no-prefix) prefix= ;; --onto) onto="$1"; shift ;; @@ -178,7 +182,7 @@ copy_commit() GIT_COMMITTER_NAME \ GIT_COMMITTER_EMAIL \ GIT_COMMITTER_DATE - (echo -n '*'; cat ) | # FIXME + (echo -n "$annotate"; cat ) | git commit-tree "$2" $3 # reads the rest of stdin ) || die "Can't copy commit $1" } diff --git a/test.sh b/test.sh index 16fb8f217e..85ed7ce549 100755 --- a/test.sh +++ b/test.sh @@ -1,4 +1,11 @@ #!/bin/bash -x +create() +{ + for d in 1 2 3 4 5 6 7 8 9 10; do + echo "$1" + done >"$1" +} + . shellopts.sh set -e @@ -8,27 +15,27 @@ mkdir mainline subproj cd subproj git init -touch sub1 +create sub1 git add sub1 -git commit -m 'sub-1' +git commit -m 'sub1' git branch sub1 git branch -m master subproj -touch sub2 +create sub2 git add sub2 -git commit -m 'sub-2' +git commit -m 'sub2' git branch sub2 -touch sub3 +create sub3 git add sub3 -git commit -m 'sub-3' +git commit -m 'sub3' git branch sub3 cd ../mainline git init -touch main1 -git add main1 -git commit -m 'main-1' +create main4 +git add main4 +git commit -m 'main4' git branch -m master mainline git fetch ../subproj sub1 @@ -38,49 +45,49 @@ git subtree add --prefix=subdir FETCH_HEAD # this shouldn't actually do anything, since FETCH_HEAD is already a parent git merge -m 'merge -s -ours' -s ours FETCH_HEAD -touch subdir/main-sub3 -git add subdir/main-sub3 -git commit -m 'main-sub3' +create subdir/main-sub5 +git add subdir/main-sub5 +git commit -m 'main-sub5' -touch main-2 -git add main-2 -git commit -m 'main-2 boring' +create main6 +git add main6 +git commit -m 'main6 boring' -touch subdir/main-sub4 -git add subdir/main-sub4 -git commit -m 'main-sub4' +create subdir/main-sub7 +git add subdir/main-sub7 +git commit -m 'main-sub7' git fetch ../subproj sub2 git branch sub2 FETCH_HEAD git subtree merge --prefix=subdir FETCH_HEAD git branch pre-split -split1=$(git subtree split --prefix subdir --onto FETCH_HEAD --rejoin) +split1=$(git subtree split --annotate='*' --prefix subdir --onto FETCH_HEAD --rejoin) echo "split1={$split1}" git branch split1 "$split1" -touch subdir/main-sub5 -git add subdir/main-sub5 -git commit -m 'main-sub5' +create subdir/main-sub8 +git add subdir/main-sub8 +git commit -m 'main-sub8' cd ../subproj git fetch ../mainline split1 git branch split1 FETCH_HEAD git merge FETCH_HEAD -touch sub6 -git add sub6 -git commit -m 'sub6' +create sub9 +git add sub9 +git commit -m 'sub9' cd ../mainline -split2=$(git subtree split --prefix subdir --rejoin) +split2=$(git subtree split --annotate='*' --prefix subdir --rejoin) git branch split2 "$split2" -touch subdir/main-sub7 -git add subdir/main-sub7 -git commit -m 'main-sub7' +create subdir/main-sub10 +git add subdir/main-sub10 +git commit -m 'main-sub10' -split3=$(git subtree split --prefix subdir --rejoin) +split3=$(git subtree split --annotate='*' --prefix subdir --rejoin) git branch split3 "$split3" cd ../subproj From 86de04c6eb9ffcb4ed11f1f18bcc62f868cfb743 Mon Sep 17 00:00:00 2001 From: Avery Pennarun Date: Sun, 26 Apr 2009 09:55:59 -0400 Subject: [PATCH 021/291] Typo when searching for existing splits. --- git-subtree.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git-subtree.sh b/git-subtree.sh index e54651c336..8b797dfc23 100755 --- a/git-subtree.sh +++ b/git-subtree.sh @@ -145,7 +145,7 @@ find_existing_splits() dir="$1" revs="$2" git log --grep="^git-subtree-dir: $dir\$" \ - --pretty=format:'%s%n%n%b%nEND' "$revs" | + --pretty=format:'%s%n%n%b%nEND' $revs | while read a b junk; do case "$a" in git-subtree-mainline:) main="$b" ;; From 1f73862f3b63bbc9f0a8a8a12dd58e1a39a3355f Mon Sep 17 00:00:00 2001 From: Avery Pennarun Date: Sun, 26 Apr 2009 15:54:42 -0400 Subject: [PATCH 022/291] Clarify why we can't do 'git rev-list' with a path. --- git-subtree.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/git-subtree.sh b/git-subtree.sh index 8b797dfc23..19ac2ef1c1 100755 --- a/git-subtree.sh +++ b/git-subtree.sh @@ -338,9 +338,9 @@ cmd_split() unrevs="$(find_existing_splits "$dir" "$revs")" fi - # We can't restrict rev-list to only "$dir" here, because that leaves out - # critical information about commit parents. - debug "git rev-list --reverse --parents $revs $unrevs" + # 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) git rev-list --reverse --parents $revs $unrevs | while read rev parents; do debug From 0ad3dd8534215648e381663979ea99db855578b6 Mon Sep 17 00:00:00 2001 From: Avery Pennarun Date: Sun, 26 Apr 2009 15:55:56 -0400 Subject: [PATCH 023/291] Add a 'create' helper function in test.sh. --- test.sh | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/test.sh b/test.sh index 85ed7ce549..276f40d1da 100755 --- a/test.sh +++ b/test.sh @@ -1,14 +1,14 @@ #!/bin/bash -x -create() -{ - for d in 1 2 3 4 5 6 7 8 9 10; do - echo "$1" - done >"$1" -} - . shellopts.sh set -e +create() +{ + echo "$1" >"$1" + git add "$1" +} + + rm -rf mainline subproj mkdir mainline subproj @@ -16,25 +16,21 @@ cd subproj git init create sub1 -git add sub1 git commit -m 'sub1' git branch sub1 git branch -m master subproj create sub2 -git add sub2 git commit -m 'sub2' git branch sub2 create sub3 -git add sub3 git commit -m 'sub3' git branch sub3 cd ../mainline git init create main4 -git add main4 git commit -m 'main4' git branch -m master mainline @@ -46,15 +42,12 @@ git subtree add --prefix=subdir FETCH_HEAD git merge -m 'merge -s -ours' -s ours FETCH_HEAD create subdir/main-sub5 -git add subdir/main-sub5 git commit -m 'main-sub5' create main6 -git add main6 git commit -m 'main6 boring' create subdir/main-sub7 -git add subdir/main-sub7 git commit -m 'main-sub7' git fetch ../subproj sub2 @@ -67,7 +60,6 @@ echo "split1={$split1}" git branch split1 "$split1" create subdir/main-sub8 -git add subdir/main-sub8 git commit -m 'main-sub8' cd ../subproj @@ -76,7 +68,6 @@ git branch split1 FETCH_HEAD git merge FETCH_HEAD create sub9 -git add sub9 git commit -m 'sub9' cd ../mainline @@ -84,7 +75,6 @@ split2=$(git subtree split --annotate='*' --prefix subdir --rejoin) git branch split2 "$split2" create subdir/main-sub10 -git add subdir/main-sub10 git commit -m 'main-sub10' split3=$(git subtree split --annotate='*' --prefix subdir --rejoin) From 1490e1546a380814fdd68dc3776023e58da60d48 Mon Sep 17 00:00:00 2001 From: Avery Pennarun Date: Sun, 26 Apr 2009 16:28:56 -0400 Subject: [PATCH 024/291] Add some basic assertions to test.sh. --- test.sh | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 72 insertions(+), 1 deletion(-) diff --git a/test.sh b/test.sh index 276f40d1da..4f2b674e5d 100755 --- a/test.sh +++ b/test.sh @@ -1,4 +1,4 @@ -#!/bin/bash -x +#!/bin/bash . shellopts.sh set -e @@ -8,6 +8,50 @@ create() git add "$1" } +check() +{ + echo + echo "check:" "$@" + if "$@"; then + echo ok + return 0 + else + echo FAILED + exit 1 + fi +} + +check_equal() +{ + echo + echo "check a:" "$1" + echo " b:" "$2" + if [ "$1" = "$2" ]; then + return 0 + else + echo FAILED + exit 1 + fi +} + +fixnl() +{ + t="" + while read x; do + t="$t$x " + done + echo $t +} + +multiline() +{ + while read x; do + set -- $x + for d in "$@"; do + echo "$d" + done + done +} rm -rf mainline subproj mkdir mainline subproj @@ -19,6 +63,7 @@ create sub1 git commit -m 'sub1' git branch sub1 git branch -m master subproj +check true create sub2 git commit -m 'sub2' @@ -86,7 +131,33 @@ git branch split3 FETCH_HEAD git merge FETCH_HEAD git branch subproj-merge-split3 +chkm="main4 main6" +chkms="main-sub10 main-sub5 main-sub7 main-sub8" +chkms_sub=$(echo $chkms | multiline | sed 's,^,subdir/,' | fixnl) +chks="sub1 sub2 sub3 sub9" +chks_sub=$(echo $chks | multiline | sed 's,^,subdir/,' | fixnl) + +# make sure exactly the right set of files ends up in the subproj +subfiles=$(git ls-files | fixnl) +check_equal "$subfiles" "$chkms $chks" + +# make sure the subproj history *only* contains commits that affect the subdir. +allchanges=$(git log --name-only --pretty=format:'' | sort | fixnl) +check_equal "$allchanges" "$chkms $chks" + cd ../mainline git fetch ../subproj subproj-merge-split3 git branch subproj-merge-split3 FETCH_HEAD git subtree pull --prefix=subdir ../subproj subproj-merge-split3 + +# make sure exactly the right set of files ends up in the mainline +mainfiles=$(git ls-files | fixnl) +check_equal "$mainfiles" "$chkm $chkms_sub $chks_sub" + +# make sure each filename changed exactly once in the entire history. +# 'main-sub??' and '/subdir/main-sub??' both change, because those are the +# changes that were split into their own history. And 'subdir/sub??' never +# change, since they were *only* changed in the subtree branch. +allchanges=$(git log --name-only --pretty=format:'' | sort | fixnl) +check_equal "$allchanges" "$chkm $chkms $chks $chkms_sub" + From a046c7b124de17c4f8aa8f1c3ee7fa5745dde30e Mon Sep 17 00:00:00 2001 From: Avery Pennarun Date: Sun, 26 Apr 2009 16:33:38 -0400 Subject: [PATCH 025/291] test.sh tweak --- test.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test.sh b/test.sh index 4f2b674e5d..ef1c70e1e6 100755 --- a/test.sh +++ b/test.sh @@ -100,7 +100,8 @@ git branch sub2 FETCH_HEAD git subtree merge --prefix=subdir FETCH_HEAD git branch pre-split -split1=$(git subtree split --annotate='*' --prefix subdir --onto FETCH_HEAD --rejoin) +split1=$(git subtree split --annotate='*' \ + --prefix subdir --onto FETCH_HEAD --rejoin) echo "split1={$split1}" git branch split1 "$split1" @@ -161,3 +162,5 @@ check_equal "$mainfiles" "$chkm $chkms_sub $chks_sub" allchanges=$(git log --name-only --pretty=format:'' | sort | fixnl) check_equal "$allchanges" "$chkm $chkms $chks $chkms_sub" +echo +echo 'ok' From a64f3a7286c4e554b38cd3f7dc8c722aab97cf98 Mon Sep 17 00:00:00 2001 From: Avery Pennarun Date: Sun, 26 Apr 2009 16:53:57 -0400 Subject: [PATCH 026/291] Trim some extra merge commits that don't need to go into the split tree. ...and update test.sh to test for this. --- git-subtree.sh | 19 ++++++++++++++++--- test.sh | 37 ++++++++++++++++++++++--------------- 2 files changed, 38 insertions(+), 18 deletions(-) diff --git a/git-subtree.sh b/git-subtree.sh index 19ac2ef1c1..ffd3e0b865 100755 --- a/git-subtree.sh +++ b/git-subtree.sh @@ -168,6 +168,7 @@ copy_commit() { # We're doing to set some environment vars here, so # do it in a subshell to get rid of them safely later + debug copy_commit "{$1}" "{$2}" "{$3}" git log -1 --pretty=format:'%an%n%ae%n%ad%n%cn%n%ce%n%cd%n%s%n%n%b' "$1" | ( read GIT_AUTHOR_NAME @@ -258,19 +259,31 @@ copy_or_skip() identical= p= + gotparents= for parent in $newparents; do ptree=$(toptree_for_commit $parent) || exit $? + [ -z "$ptree" ] && continue if [ "$ptree" = "$tree" ]; then # an identical parent could be used in place of this rev. identical="$parent" fi - if [ -n "$ptree" ]; then - parentmatch="$parentmatch$parent" + + # sometimes both old parents map to the same newparent; + # eliminate duplicates + is_new=1 + for gp in $gotparents; do + if [ "$gp" = "$parent" ]; then + is_new= + break + fi + done + if [ -n "$is_new" ]; then + gotparents="$gotparents $parent" p="$p -p $parent" fi done - if [ -n "$identical" -a "$parentmatch" = "$identical" ]; then + if [ -n "$identical" -a "$gotparents" = " $identical" ]; then echo $identical else copy_commit $rev $tree "$p" || exit $? diff --git a/test.sh b/test.sh index ef1c70e1e6..44d5da3f20 100755 --- a/test.sh +++ b/test.sh @@ -24,8 +24,8 @@ check() check_equal() { echo - echo "check a:" "$1" - echo " b:" "$2" + echo "check a:" "{$1}" + echo " b:" "{$2}" if [ "$1" = "$2" ]; then return 0 else @@ -100,17 +100,17 @@ git branch sub2 FETCH_HEAD git subtree merge --prefix=subdir FETCH_HEAD git branch pre-split -split1=$(git subtree split --annotate='*' \ +spl1=$(git subtree split --annotate='*' \ --prefix subdir --onto FETCH_HEAD --rejoin) -echo "split1={$split1}" -git branch split1 "$split1" +echo "spl1={$spl1}" +git branch spl1 "$spl1" create subdir/main-sub8 git commit -m 'main-sub8' cd ../subproj -git fetch ../mainline split1 -git branch split1 FETCH_HEAD +git fetch ../mainline spl1 +git branch spl1 FETCH_HEAD git merge FETCH_HEAD create sub9 @@ -123,14 +123,14 @@ git branch split2 "$split2" create subdir/main-sub10 git commit -m 'main-sub10' -split3=$(git subtree split --annotate='*' --prefix subdir --rejoin) -git branch split3 "$split3" +spl3=$(git subtree split --annotate='*' --prefix subdir --rejoin) +git branch spl3 "$spl3" cd ../subproj -git fetch ../mainline split3 -git branch split3 FETCH_HEAD +git fetch ../mainline spl3 +git branch spl3 FETCH_HEAD git merge FETCH_HEAD -git branch subproj-merge-split3 +git branch subproj-merge-spl3 chkm="main4 main6" chkms="main-sub10 main-sub5 main-sub7 main-sub8" @@ -147,9 +147,9 @@ allchanges=$(git log --name-only --pretty=format:'' | sort | fixnl) check_equal "$allchanges" "$chkms $chks" cd ../mainline -git fetch ../subproj subproj-merge-split3 -git branch subproj-merge-split3 FETCH_HEAD -git subtree pull --prefix=subdir ../subproj subproj-merge-split3 +git fetch ../subproj subproj-merge-spl3 +git branch subproj-merge-spl3 FETCH_HEAD +git subtree pull --prefix=subdir ../subproj subproj-merge-spl3 # make sure exactly the right set of files ends up in the mainline mainfiles=$(git ls-files | fixnl) @@ -162,5 +162,12 @@ check_equal "$mainfiles" "$chkm $chkms_sub $chks_sub" allchanges=$(git log --name-only --pretty=format:'' | sort | fixnl) check_equal "$allchanges" "$chkm $chkms $chks $chkms_sub" +# make sure the --rejoin commits never make it into subproj +check_equal "$(git log --pretty=format:'%s' HEAD^2 | grep -i split)" "" + +# make sure no 'git subtree' tagged commits make it into subproj. (They're +# meaningless to subproj since one side of the merge refers to the mainline) +check_equal "$(git log --pretty=format:'%s%n%b' HEAD^2 | grep 'git-subtree.*:')" "" + echo echo 'ok' From 49cf82288aac5f0dcb152e2d75cd340e48d9e760 Mon Sep 17 00:00:00 2001 From: Avery Pennarun Date: Sun, 26 Apr 2009 17:07:16 -0400 Subject: [PATCH 027/291] Only copy a commit if it has at least one nonidentical parent. This is a simplification of the previous logic. I don't *think* it'll break anything. Results in far fewer useless merge commmits when playing with gitweb in the git project: git subtree split --prefix=gitweb --annotate='(split) ' 0a8f4f0^^..f2e7330 --onto=1130ef3 ...and it doesn't *seem* to eliminate anything important. --- git-subtree.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/git-subtree.sh b/git-subtree.sh index ffd3e0b865..90e22ad8be 100755 --- a/git-subtree.sh +++ b/git-subtree.sh @@ -258,6 +258,7 @@ copy_or_skip() assert [ -n "$tree" ] identical= + nonidentical= p= gotparents= for parent in $newparents; do @@ -266,6 +267,8 @@ copy_or_skip() if [ "$ptree" = "$tree" ]; then # an identical parent could be used in place of this rev. identical="$parent" + else + nonidentical="$parent" fi # sometimes both old parents map to the same newparent; @@ -283,7 +286,7 @@ copy_or_skip() fi done - if [ -n "$identical" -a "$gotparents" = " $identical" ]; then + if [ -n "$identical" -a -z "$nonidentical" ]; then echo $identical else copy_commit $rev $tree "$p" || exit $? From fa16ab36ad014bcc03acc4313bb0918fb241b54d Mon Sep 17 00:00:00 2001 From: Avery Pennarun Date: Sun, 26 Apr 2009 17:43:53 -0400 Subject: [PATCH 028/291] test.sh: make sure no commit changes more than one file at a time. --- test.sh | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/test.sh b/test.sh index 44d5da3f20..4e00b536d7 100755 --- a/test.sh +++ b/test.sh @@ -169,5 +169,39 @@ check_equal "$(git log --pretty=format:'%s' HEAD^2 | grep -i split)" "" # meaningless to subproj since one side of the merge refers to the mainline) check_equal "$(git log --pretty=format:'%s%n%b' HEAD^2 | grep 'git-subtree.*:')" "" +# make sure no patch changes more than one file. The original set of commits +# changed only one file each. A multi-file change would imply that we pruned +# commits too aggressively. +joincommits() +{ + echo "hello world" + commit= + all= + while read x y; do + echo "{$x}" >&2 + if [ -z "$x" ]; then + continue + elif [ "$x" = "commit:" ]; then + if [ -n "$commit" ]; then + echo "$commit $all" + all= + fi + commit="$y" + else + all="$all $y" + fi + done + echo "$commit $all" +} +x=0 +git log --pretty=format:'commit: %H' | joincommits | +( while read commit a b; do + echo "Verifying commit $commit" + check_equal "$b" "" + x=$(($x + 1)) + done + check_equal $x 23 +) || exit 1 + echo echo 'ok' From 795e730e71e8a068ce0cb0790512dab0f1922369 Mon Sep 17 00:00:00 2001 From: Avery Pennarun Date: Sun, 26 Apr 2009 17:44:18 -0400 Subject: [PATCH 029/291] Simplify merges even more aggressively. If any one of the parents is the same as the current one, then clearly the other parent branch isn't important, so throw it away entirely. Can't remember why I didn't do this before, but if I rediscover it, it definitely needs a unit test. --- git-subtree.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git-subtree.sh b/git-subtree.sh index 90e22ad8be..e2e47f82ac 100755 --- a/git-subtree.sh +++ b/git-subtree.sh @@ -286,7 +286,7 @@ copy_or_skip() fi done - if [ -n "$identical" -a -z "$nonidentical" ]; then + if [ -n "$identical" ]; then echo $identical else copy_commit $rev $tree "$p" || exit $? From 34a82bda7766f000ef646130ed3f6af58ca23aa2 Mon Sep 17 00:00:00 2001 From: Avery Pennarun Date: Sun, 26 Apr 2009 18:05:49 -0400 Subject: [PATCH 030/291] test.sh: oops, never intended to count the raw number of commits. Just needed to make sure the count was non-zero. --- test.sh | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/test.sh b/test.sh index 4e00b536d7..38dff7a41a 100755 --- a/test.sh +++ b/test.sh @@ -174,7 +174,6 @@ check_equal "$(git log --pretty=format:'%s%n%b' HEAD^2 | grep 'git-subtree.*:')" # commits too aggressively. joincommits() { - echo "hello world" commit= all= while read x y; do @@ -193,14 +192,14 @@ joincommits() done echo "$commit $all" } -x=0 +x= git log --pretty=format:'commit: %H' | joincommits | ( while read commit a b; do echo "Verifying commit $commit" check_equal "$b" "" - x=$(($x + 1)) + x=1 done - check_equal $x 23 + check_equal "$x" 1 ) || exit 1 echo From 942dce5578c8eb03fdc7f9109c8418d499e931ff Mon Sep 17 00:00:00 2001 From: Avery Pennarun Date: Sun, 26 Apr 2009 18:06:08 -0400 Subject: [PATCH 031/291] debug messages are off by default; use -d to enable. Instead of debug messages, we print a progress counter to stderr. --- git-subtree.sh | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/git-subtree.sh b/git-subtree.sh index e2e47f82ac..39c377c173 100755 --- a/git-subtree.sh +++ b/git-subtree.sh @@ -15,6 +15,7 @@ git subtree pull --prefix= -- h,help show the help q quiet +d show debug messages prefix= the name of the subdir to split out options for 'split' annotate= add a prefix to commit message of new commits @@ -27,6 +28,7 @@ eval $(echo "$OPTS_SPEC" | git rev-parse --parseopt -- "$@" || echo exit $?) require_work_tree quiet= +debug= command= onto= rejoin= @@ -34,6 +36,13 @@ ignore_joins= annotate= debug() +{ + if [ -n "$debug" ]; then + echo "$@" >&2 + fi +} + +say() { if [ -z "$quiet" ]; then echo "$@" >&2 @@ -57,6 +66,7 @@ while [ $# -gt 0 ]; do shift case "$opt" in -q) quiet=1 ;; + -d) debug=1 ;; --annotate) annotate="$1"; shift ;; --no-annotate) annotate= ;; --prefix) prefix="$1"; shift ;; @@ -357,15 +367,21 @@ cmd_split() # 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) - git rev-list --reverse --parents $revs $unrevs | + grl='git rev-list --reverse --parents $revs $unrevs' + revmax=$(eval "$grl" | wc -l) + revcount=0 + createcount=0 + eval "$grl" | while read rev parents; do - debug + revcount=$(($revcount + 1)) + say -n "$revcount/$revmax ($createcount) " debug "Processing commit: $rev" exists=$(cache_get $rev) if [ -n "$exists" ]; then debug " prior: $exists" continue fi + createcount=$(($createcount + 1)) debug " parents: $parents" newparents=$(cache_get $parents) debug " newparents: $newparents" From ea28d674423aa580bfdbe24991ffcf796f2dd3dc Mon Sep 17 00:00:00 2001 From: Avery Pennarun Date: Thu, 30 Apr 2009 21:57:32 -0400 Subject: [PATCH 032/291] Abort if --rejoin fails. Thanks to Eduardo Kienetz for noticing this. --- git-subtree.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git-subtree.sh b/git-subtree.sh index 39c377c173..692792b864 100755 --- a/git-subtree.sh +++ b/git-subtree.sh @@ -406,7 +406,7 @@ cmd_split() latest_old=$(cache_get latest_old) git merge -s ours \ -m "$(merge_msg $dir $latest_old $latest_new)" \ - $latest_new >&2 + $latest_new >&2 || exit $? fi echo $latest_new exit 0 From 7b7ba4bb3792572bd6c22c95082e064754de47be Mon Sep 17 00:00:00 2001 From: Avery Pennarun Date: Sun, 24 May 2009 15:28:54 -0400 Subject: [PATCH 033/291] More to-do items based on feedback --- todo | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/todo b/todo index b5b8e257aa..97142fa4e2 100644 --- a/todo +++ b/todo @@ -1,8 +1,20 @@ + + write proper docs (asciidoc format for git compatibility) delete tempdir + --annotate-sometimes: only annotate if the patch also changes files outside the subdir? + 'git subtree rejoin' option to do the same as --rejoin, eg. after a rebase + "-s subtree" should be given an explicit subtree option? - \ No newline at end of file + + --prefix doesn't force the subtree correctly in merge/pull + + add a 'push' subcommand to parallel 'pull' + + add a --squash option so we don't merge histories but can still split + + add to-submodule and from-submodule commands From f96bc79019083cdc41cf7f699979f9b5e250d160 Mon Sep 17 00:00:00 2001 From: Avery Pennarun Date: Sat, 30 May 2009 00:47:59 -0400 Subject: [PATCH 034/291] typo in comment --- git-subtree.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git-subtree.sh b/git-subtree.sh index 692792b864..825dd1dcad 100755 --- a/git-subtree.sh +++ b/git-subtree.sh @@ -176,7 +176,7 @@ find_existing_splits() copy_commit() { - # We're doing to set some environment vars here, so + # We're going to set some environment vars here, so # do it in a subshell to get rid of them safely later debug copy_commit "{$1}" "{$2}" "{$3}" git log -1 --pretty=format:'%an%n%ae%n%ad%n%cn%n%ce%n%cd%n%s%n%n%b' "$1" | From 43a3951243ebcfb8ef4c47259ecb2d0dfaadbce4 Mon Sep 17 00:00:00 2001 From: Avery Pennarun Date: Sat, 30 May 2009 01:05:43 -0400 Subject: [PATCH 035/291] New --branch option to split command. This is just a handy way to create a new branch from the newly-split subtree. --- git-subtree.sh | 26 ++++++++++++++++++++++++-- todo | 10 +++++----- 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/git-subtree.sh b/git-subtree.sh index 825dd1dcad..f6bdef3001 100755 --- a/git-subtree.sh +++ b/git-subtree.sh @@ -19,15 +19,17 @@ d show debug messages prefix= the name of the subdir to split out options for 'split' annotate= add a prefix to commit message of new commits +b,branch= create a new branch from the split subtree +ignore-joins ignore prior --rejoin commits onto= try connecting new tree to an existing one rejoin merge the new branch back into HEAD -ignore-joins ignore prior --rejoin commits " eval $(echo "$OPTS_SPEC" | git rev-parse --parseopt -- "$@" || echo exit $?) . git-sh-setup require_work_tree quiet= +branch= debug= command= onto= @@ -69,6 +71,7 @@ while [ $# -gt 0 ]; do -d) debug=1 ;; --annotate) annotate="$1"; shift ;; --no-annotate) annotate= ;; + -b) branch="$1"; shift ;; --prefix) prefix="$1"; shift ;; --no-prefix) prefix= ;; --onto) onto="$1"; shift ;; @@ -78,6 +81,7 @@ while [ $# -gt 0 ]; do --ignore-joins) ignore_joins=1 ;; --no-ignore-joins) ignore_joins= ;; --) break ;; + *) die "Unexpected option: $opt" ;; esac done @@ -139,12 +143,21 @@ cache_set() echo "$newrev" >"$cachedir/$oldrev" } +rev_exists() +{ + if git rev-parse "$1" >/dev/null 2>&1; then + return 0 + else + return 1 + fi +} + # if a commit doesn't have a parent, this might not work. But we only want # to remove the parent from the rev-list, and since it doesn't exist, it won't # be there anyway, so do nothing in that case. try_remove_previous() { - if git rev-parse "$1^" >/dev/null 2>&1; then + if rev_exists "$1^"; then echo "^$1^" fi } @@ -344,6 +357,10 @@ cmd_add() cmd_split() { + if [ -n "$branch" ] && rev_exists "refs/heads/$branch"; then + die "Branch '$branch' already exists." + fi + debug "Splitting $dir..." cache_setup || exit $? @@ -408,6 +425,11 @@ cmd_split() -m "$(merge_msg $dir $latest_old $latest_new)" \ $latest_new >&2 || exit $? fi + if [ -n "$branch" ]; then + git update-ref -m 'subtree split' "refs/heads/$branch" \ + $latest_new "" || exit $? + say "Created branch '$branch'" + fi echo $latest_new exit 0 } diff --git a/todo b/todo index 97142fa4e2..f23a6d4ff2 100644 --- a/todo +++ b/todo @@ -3,17 +3,17 @@ delete tempdir - --annotate-sometimes: only annotate if the patch also changes files - outside the subdir? - 'git subtree rejoin' option to do the same as --rejoin, eg. after a rebase + --prefix doesn't force the subtree correctly in merge/pull: "-s subtree" should be given an explicit subtree option? - - --prefix doesn't force the subtree correctly in merge/pull + There doesn't seem to be a way to do this. We'd have to + patch git-merge-subtree. Ugh. add a 'push' subcommand to parallel 'pull' + + add a 'log' subcommand to see what's new in a subtree? add a --squash option so we don't merge histories but can still split From f4f29557e7e02c318931395c1cd4fd1ba090fdfd Mon Sep 17 00:00:00 2001 From: Avery Pennarun Date: Sat, 30 May 2009 01:10:14 -0400 Subject: [PATCH 036/291] slightly rearrange help message for split. --- git-subtree.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/git-subtree.sh b/git-subtree.sh index f6bdef3001..ea0294fb79 100755 --- a/git-subtree.sh +++ b/git-subtree.sh @@ -8,10 +8,10 @@ if [ $# -eq 0 ]; then set -- -h fi OPTS_SPEC="\ -git subtree add --prefix= -git subtree split [options...] --prefix= +git subtree add --prefix= git subtree merge --prefix= git subtree pull --prefix= +git subtree split --prefix= -- h,help show the help q quiet From 8e79043c47d69032a86e5587a69289304dd5ca23 Mon Sep 17 00:00:00 2001 From: Avery Pennarun Date: Sat, 30 May 2009 00:48:07 -0400 Subject: [PATCH 037/291] FIXME help for --squash option --- git-subtree.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/git-subtree.sh b/git-subtree.sh index ea0294fb79..65b6348fe4 100755 --- a/git-subtree.sh +++ b/git-subtree.sh @@ -23,6 +23,8 @@ b,branch= create a new branch from the split subtree ignore-joins ignore prior --rejoin commits onto= try connecting new tree to an existing one rejoin merge the new branch back into HEAD + options for 'merge' and 'pull' +squash merge subtree changes as a single commit " eval $(echo "$OPTS_SPEC" | git rev-parse --parseopt -- "$@" || echo exit $?) . git-sh-setup @@ -36,6 +38,7 @@ onto= rejoin= ignore_joins= annotate= +squash= debug() { @@ -80,6 +83,8 @@ while [ $# -gt 0 ]; do --no-rejoin) rejoin= ;; --ignore-joins) ignore_joins=1 ;; --no-ignore-joins) ignore_joins= ;; + --squash) squash=1 ;; + --no-squash) squash= ;; --) break ;; *) die "Unexpected option: $opt" ;; esac From 7ee9eef340170da6d13b9a0ab5a8d23950523b0d Mon Sep 17 00:00:00 2001 From: Avery Pennarun Date: Sat, 30 May 2009 01:28:20 -0400 Subject: [PATCH 038/291] merge_msg() is really more like rejoin_msg(). --- git-subtree.sh | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/git-subtree.sh b/git-subtree.sh index 65b6348fe4..d82e03e6fd 100755 --- a/git-subtree.sh +++ b/git-subtree.sh @@ -178,15 +178,15 @@ find_existing_splits() case "$a" in git-subtree-mainline:) main="$b" ;; git-subtree-split:) sub="$b" ;; - *) + END) if [ -n "$main" -a -n "$sub" ]; then debug " Prior: $main -> $sub" cache_set $main $sub try_remove_previous "$main" try_remove_previous "$sub" - main= - sub= fi + main= + sub= ;; esac done @@ -230,7 +230,7 @@ add_msg() EOF } -merge_msg() +rejoin_msg() { dir="$1" latest_old="$2" @@ -410,6 +410,9 @@ cmd_split() tree=$(subtree_for_commit $rev "$dir") debug " tree is: $tree" + + # ugly. is there no better way to tell if this is a subtree + # vs. a mainline commit? Does it matter? [ -z $tree ] && continue newrev=$(copy_or_skip "$rev" "$tree" "$newparents") || exit $? @@ -427,7 +430,7 @@ cmd_split() debug "Merging split branch into HEAD..." latest_old=$(cache_get latest_old) git merge -s ours \ - -m "$(merge_msg $dir $latest_old $latest_new)" \ + -m "$(rejoin_msg $dir $latest_old $latest_new)" \ $latest_new >&2 || exit $? fi if [ -n "$branch" ]; then From 1cc2cfff91c61bb56236914da7be7b15584951df Mon Sep 17 00:00:00 2001 From: Avery Pennarun Date: Sat, 30 May 2009 03:18:27 -0400 Subject: [PATCH 039/291] Basic "subtree merge --squash" support. Instead of merging in the history of the entire subproject, just squash it all into one commit, but try to at least track which commits we used so that we can do future merges correctly. Bonus feature: we can actually switch branches of the subproject this way, just by "squash merging" back and forth from one tag to another. --- git-subtree.sh | 78 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 77 insertions(+), 1 deletion(-) diff --git a/git-subtree.sh b/git-subtree.sh index d82e03e6fd..863e28bb74 100755 --- a/git-subtree.sh +++ b/git-subtree.sh @@ -167,15 +167,46 @@ try_remove_previous() fi } +find_latest_squash() +{ + debug "Looking for latest squash..." + dir="$1" + git log --grep="^git-subtree-dir: $dir\$" \ + --pretty=format:'START %H%n%s%n%n%b%nEND%n' HEAD | + while read a b junk; do + case "$a" in + START) sq="$b" ;; + git-subtree-mainline:) main="$b" ;; + git-subtree-split:) sub="$b" ;; + END) + if [ -n "$sub" ]; then + if [ -n "$main" ]; then + # a rejoin commit? + # Pretend its sub was a squash. + sq="$sub" + fi + debug "Squash found: $sq $sub" + echo "$sq" "$sub" + break + fi + sq= + main= + sub= + ;; + esac + done +} + find_existing_splits() { debug "Looking for prior splits..." dir="$1" revs="$2" git log --grep="^git-subtree-dir: $dir\$" \ - --pretty=format:'%s%n%n%b%nEND' $revs | + --pretty=format:'%s%n%n%b%nEND%n' $revs | while read a b junk; do case "$a" in + START) main="$b" ;; git-subtree-mainline:) main="$b" ;; git-subtree-split:) sub="$b" ;; END) @@ -244,6 +275,28 @@ rejoin_msg() EOF } +squash_msg() +{ + dir="$1" + oldsub="$2" + newsub="$3" + oldsub_short=$(git rev-parse --short "$oldsub") + newsub_short=$(git rev-parse --short "$newsub") + cat <<-EOF + Squashed '$dir/' changes from $oldsub_short..$newsub_short + + EOF + + git log --pretty=tformat:'%h %s' "$oldsub..$newsub" + git log --pretty=tformat:'REVERT: %h %s' "$newsub..$oldsub" + + cat <<-EOF + + git-subtree-dir: $dir + git-subtree-split: $newsub + EOF +} + toptree_for_commit() { commit="$1" @@ -278,6 +331,16 @@ tree_changed() fi } +new_squash_commit() +{ + old="$1" + oldsub="$2" + newsub="$3" + tree=$(toptree_for_commit $newsub) || exit $? + squash_msg "$dir" "$oldsub" "$newsub" | + git commit-tree "$tree" -p "$old" || exit $? +} + copy_or_skip() { rev="$1" @@ -452,6 +515,19 @@ cmd_merge() fi rev="$1" + if [ -n "$squash" ]; then + first_split="$(find_latest_squash "$dir")" + if [ -z "$first_split" ]; then + die "Can't squash-merge: '$dir' was never added." + fi + set $first_split + old=$1 + sub=$2 + new=$(new_squash_commit "$old" "$sub" "$rev") || exit $? + debug "New squash commit: $new" + rev="$new" + fi + git merge -s subtree $rev } From eb4fb91094cf5e20bf7570da3fadb50e444284bc Mon Sep 17 00:00:00 2001 From: Avery Pennarun Date: Sat, 30 May 2009 03:33:17 -0400 Subject: [PATCH 040/291] Don't squash-merge if the old and new commits are the same. --- git-subtree.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/git-subtree.sh b/git-subtree.sh index 863e28bb74..f7fe111178 100755 --- a/git-subtree.sh +++ b/git-subtree.sh @@ -523,6 +523,10 @@ cmd_merge() set $first_split old=$1 sub=$2 + if [ "$sub" = "$rev" ]; then + say "Subtree is already at commit $rev." + exit 0 + fi new=$(new_squash_commit "$old" "$sub" "$rev") || exit $? debug "New squash commit: $new" rev="$new" From 1a8c36dc5fdd8c439c65f18a91ad211050201fc8 Mon Sep 17 00:00:00 2001 From: Avery Pennarun Date: Sat, 30 May 2009 03:33:39 -0400 Subject: [PATCH 041/291] Fix splitting after using a squash merge. --- git-subtree.sh | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/git-subtree.sh b/git-subtree.sh index f7fe111178..1fff10e854 100755 --- a/git-subtree.sh +++ b/git-subtree.sh @@ -203,13 +203,17 @@ find_existing_splits() dir="$1" revs="$2" git log --grep="^git-subtree-dir: $dir\$" \ - --pretty=format:'%s%n%n%b%nEND%n' $revs | + --pretty=format:'START %H%n%s%n%n%b%nEND%n' $revs | while read a b junk; do case "$a" in - START) main="$b" ;; + START) main="$b"; sq="$b" ;; git-subtree-mainline:) main="$b" ;; git-subtree-split:) sub="$b" ;; END) + if [ -z "$main" -a -n "$sub" ]; then + # squash commits refer to a subtree + cache_set "$sq" "$sub" + fi if [ -n "$main" -a -n "$sub" ]; then debug " Prior: $main -> $sub" cache_set $main $sub From d713e2d87a5003da02d95a4ac5be28a1e9fdc3ce Mon Sep 17 00:00:00 2001 From: Avery Pennarun Date: Sat, 30 May 2009 04:11:43 -0400 Subject: [PATCH 042/291] Make --squash work with the 'add' command too. --- git-subtree.sh | 57 ++++++++++++++++++++++++++++++++++---------------- todo | 7 +++++-- 2 files changed, 44 insertions(+), 20 deletions(-) diff --git a/git-subtree.sh b/git-subtree.sh index 1fff10e854..962d5ff509 100755 --- a/git-subtree.sh +++ b/git-subtree.sh @@ -23,7 +23,7 @@ b,branch= create a new branch from the split subtree ignore-joins ignore prior --rejoin commits onto= try connecting new tree to an existing one rejoin merge the new branch back into HEAD - options for 'merge' and 'pull' + options for 'add', 'merge', and 'pull' squash merge subtree changes as a single commit " eval $(echo "$OPTS_SPEC" | git rev-parse --parseopt -- "$@" || echo exit $?) @@ -169,11 +169,16 @@ try_remove_previous() find_latest_squash() { - debug "Looking for latest squash..." + debug "Looking for latest squash ($dir)..." dir="$1" + sq= + main= + sub= git log --grep="^git-subtree-dir: $dir\$" \ --pretty=format:'START %H%n%s%n%n%b%nEND%n' HEAD | while read a b junk; do + debug "$a $b $junk" + debug "{{$sq/$main/$sub}}" case "$a" in START) sq="$b" ;; git-subtree-mainline:) main="$b" ;; @@ -202,6 +207,8 @@ find_existing_splits() debug "Looking for prior splits..." dir="$1" revs="$2" + main= + sub= git log --grep="^git-subtree-dir: $dir\$" \ --pretty=format:'START %H%n%s%n%n%b%nEND%n' $revs | while read a b junk; do @@ -284,21 +291,21 @@ squash_msg() dir="$1" oldsub="$2" newsub="$3" - oldsub_short=$(git rev-parse --short "$oldsub") newsub_short=$(git rev-parse --short "$newsub") - cat <<-EOF - Squashed '$dir/' changes from $oldsub_short..$newsub_short - EOF + if [ -n "$oldsub" ]; then + oldsub_short=$(git rev-parse --short "$oldsub") + echo "Squashed '$dir/' changes from $oldsub_short..$newsub_short" + echo + git log --pretty=tformat:'%h %s' "$oldsub..$newsub" + git log --pretty=tformat:'REVERT: %h %s' "$newsub..$oldsub" + else + echo "Squashed '$dir/' content from commit $newsub_short" + fi - git log --pretty=tformat:'%h %s' "$oldsub..$newsub" - git log --pretty=tformat:'REVERT: %h %s' "$newsub..$oldsub" - - cat <<-EOF - - git-subtree-dir: $dir - git-subtree-split: $newsub - EOF + echo + echo "git-subtree-dir: $dir" + echo "git-subtree-split: $newsub" } toptree_for_commit() @@ -341,8 +348,13 @@ new_squash_commit() oldsub="$2" newsub="$3" tree=$(toptree_for_commit $newsub) || exit $? - squash_msg "$dir" "$oldsub" "$newsub" | - git commit-tree "$tree" -p "$old" || exit $? + if [ -n "$old" ]; then + squash_msg "$dir" "$oldsub" "$newsub" | + git commit-tree "$tree" -p "$old" || exit $? + else + squash_msg "$dir" "" "$newsub" | + git commit-tree "$tree" || exit $? + fi } copy_or_skip() @@ -422,9 +434,18 @@ cmd_add() else headp= fi - commit=$(add_msg "$dir" "$headrev" "$rev" | - git commit-tree $tree $headp -p "$rev") || exit $? + + if [ -n "$squash" ]; then + rev=$(new_squash_commit "" "" "$rev") || exit $? + commit=$(echo "Merge commit '$rev' as '$dir'" | + git commit-tree $tree $headp -p "$rev") || exit $? + else + commit=$(add_msg "$dir" "$headrev" "$rev" | + git commit-tree $tree $headp -p "$rev") || exit $? + fi git reset "$commit" || exit $? + + say "Added dir '$dir'" } cmd_split() diff --git a/todo b/todo index f23a6d4ff2..a15a378da5 100644 --- a/todo +++ b/todo @@ -10,11 +10,14 @@ "-s subtree" should be given an explicit subtree option? There doesn't seem to be a way to do this. We'd have to patch git-merge-subtree. Ugh. + (but we could avoid this problem by generating squashes with + exactly the right subtree structure, rather than using + subtree merge...) add a 'push' subcommand to parallel 'pull' add a 'log' subcommand to see what's new in a subtree? - add a --squash option so we don't merge histories but can still split - add to-submodule and from-submodule commands + + automated tests for --squash stuff From e75d1da38a7091c15ebd3c80539e4aab20faf5b7 Mon Sep 17 00:00:00 2001 From: Avery Pennarun Date: Sat, 30 May 2009 14:05:33 -0400 Subject: [PATCH 043/291] Add basic git-subtree manpage in asciidoc format. --- .gitignore | 2 + Makefile | 18 ++++ asciidoc.conf | 91 ++++++++++++++++++ git-subtree.txt | 233 +++++++++++++++++++++++++++++++++++++++++++++ manpage-base.xsl | 35 +++++++ manpage-normal.xsl | 13 +++ 6 files changed, 392 insertions(+) create mode 100644 Makefile create mode 100644 asciidoc.conf create mode 100644 git-subtree.txt create mode 100644 manpage-base.xsl create mode 100644 manpage-normal.xsl diff --git a/.gitignore b/.gitignore index b25c15b81f..e358b18b78 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ *~ +git-subtree.xml +git-subtree.1 diff --git a/Makefile b/Makefile new file mode 100644 index 0000000000..bc163dd390 --- /dev/null +++ b/Makefile @@ -0,0 +1,18 @@ +default: + @echo "git-subtree doesn't need to be built." + @echo + @echo "Try: make doc" + @false + +doc: git-subtree.1 + +%.1: %.xml + xmlto -m manpage-normal.xsl man $^ + +%.xml: %.txt + asciidoc -b docbook -d manpage -f asciidoc.conf \ + -agit_version=1.6.3 $^ + +clean: + rm -f *~ *.xml *.html *.1 + rm -rf subproj mainline diff --git a/asciidoc.conf b/asciidoc.conf new file mode 100644 index 0000000000..dc76e7f073 --- /dev/null +++ b/asciidoc.conf @@ -0,0 +1,91 @@ +## linkgit: macro +# +# Usage: linkgit:command[manpage-section] +# +# Note, {0} is the manpage section, while {target} is the command. +# +# Show GIT link as: (
); if section is defined, else just show +# the command. + +[macros] +(?su)[\\]?(?Plinkgit):(?P\S*?)\[(?P.*?)\]= + +[attributes] +asterisk=* +plus=+ +caret=^ +startsb=[ +endsb=] +tilde=~ + +ifdef::backend-docbook[] +[linkgit-inlinemacro] +{0%{target}} +{0#} +{0#{target}{0}} +{0#} +endif::backend-docbook[] + +ifdef::backend-docbook[] +ifndef::git-asciidoc-no-roff[] +# "unbreak" docbook-xsl v1.68 for manpages. v1.69 works with or without this. +# v1.72 breaks with this because it replaces dots not in roff requests. +[listingblock] +{title} + +ifdef::doctype-manpage[] + .ft C +endif::doctype-manpage[] +| +ifdef::doctype-manpage[] + .ft +endif::doctype-manpage[] + +{title#} +endif::git-asciidoc-no-roff[] + +ifdef::git-asciidoc-no-roff[] +ifdef::doctype-manpage[] +# The following two small workarounds insert a simple paragraph after screen +[listingblock] +{title} + +| + +{title#} + +[verseblock] +{title} +{title%} +{title#} +| + +{title#} +{title%} +endif::doctype-manpage[] +endif::git-asciidoc-no-roff[] +endif::backend-docbook[] + +ifdef::doctype-manpage[] +ifdef::backend-docbook[] +[header] +template::[header-declarations] + + +{mantitle} +{manvolnum} +Git +{git_version} +Git Manual + + + {manname} + {manpurpose} + +endif::backend-docbook[] +endif::doctype-manpage[] + +ifdef::backend-xhtml11[] +[linkgit-inlinemacro] +{target}{0?({0})} +endif::backend-xhtml11[] diff --git a/git-subtree.txt b/git-subtree.txt new file mode 100644 index 0000000000..d10630180d --- /dev/null +++ b/git-subtree.txt @@ -0,0 +1,233 @@ +git-subtree(1) +============== + +NAME +---- +git-subtree - add, merge, and split subprojects stored in subtrees + + +SYNOPSIS +-------- +[verse] +'git subtree' add --prefix= +'git subtree' merge --prefix= +'git subtree' pull --prefix= +'git subtree' split --prefix= + + +DESCRIPTION +----------- +git subtree allows you to include an subproject in your +own repository as a subdirectory, optionally including the +subproject's entire history. For example, you could +include the source code for a library as a subdirectory of your +application. + +You can also extract the entire history of a subdirectory from +your project and make it into a standalone project. For +example, if a library you made for one application ends up being +useful elsewhere, you can extract its entire history and publish +that as its own git repository, without accidentally +intermingling the history of your application project. + +Most importantly, you can alternate back and forth between these +two operations. If the standalone library gets updated, you can +automatically merge the changes into your project; if you +update the library inside your project, you can "split" the +changes back out again and merge them back into the library +project. + +Unlike the 'git submodule' command, git subtree doesn't produce +any special constructions (like .gitmodule files or gitlinks) in +your repository, and doesn't require end-users of your +repository to do anything special or to understand how subtrees +work. A subtree is just another subdirectory and can be +committed to, branched, and merged along with your project in +any way you want. + +In order to keep your commit messages clean, we recommend that +people split their commits between the subtrees and the main +project as much as possible. That is, if you make a change that +affects both the library and the main application, commit it in +two pieces. That way, when you split the library commits out +later, their descriptions will still make sense. But if this +isn't important to you, it's not *necessary*. git subtree will +simply leave out the non-library-related parts of the commit +when it splits it out into the subproject later. + + +COMMANDS +-------- +add:: + Create the subtree by importing its contents + from the given commit. A new commit is created + automatically, joining the imported project's history + with your own. With '--squash', imports only a single + commit from the subproject, rather than its entire + history. + +merge:: + Merge recent changes up to into the + subtree. As with normal 'git merge', this doesn't + remove your own local changes; it just merges those + changes into the latest . With '--squash', + creates only one commit that contains all the changes, + rather than merging in the entire history. + + If you use '--squash', the merge direction doesn't + always have to be forward; you can use this command to + go back in time from v2.5 to v2.4, for example. If your + merge introduces a conflict, you can resolve it in the + usual ways. + +pull:: + Exactly like 'merge', but parallels 'git pull' in that + it fetches the given commit from the specified remote + repository. + +split:: + Extract a new, synthetic project history from the + history of the subtree. The new history + includes only the commits (including merges) that + affected , and each of those commits now has the + contents of at the root of the project instead + of in a subdirectory. Thus, the newly created history + is suitable for export as a separate git repository. + + After splitting successfully, a single commit id is + printed to stdout. This corresponds to the HEAD of the + newly created tree, which you can manipulate however you + want. + + Repeated splits of exactly the same history are + guaranteed to be identical (ie. to produce the same + commit ids). Because of this, if you add new commits + and then re-split, the new commits will be attached as + commits on top of the history you generated last time, + so 'git merge' and friends will work as expected. + + Note that if you use '--squash' when you merge, you + should usually not just '--rejoin' when you split. + + +OPTIONS +------- +-q:: +--quiet:: + Suppress unnecessary output messages on stderr. + +-d:: +--debug:: + Produce even more unnecessary output messages on stderr. + +--prefix=:: + Specify the path in the repository to the subtree you + want to manipulate. This option is currently mandatory + for all commands. + + +OPTIONS FOR add, merge, AND pull +-------------------------------- +--squash:: + Instead of merging the entire history from the subtree + project, produce only a single commit that contains all + the differences you want to merge, and then merge that + new commit into your project. + + Using this option helps to reduce log clutter. People + rarely want to see every change that happened between + v1.0 and v1.1 of the library they're using, since none of the + interim versions were ever included in their application. + + Using '--squash' also helps avoid problems when the same + subproject is included multiple times in the same + project, or is removed and then re-added. In such a + case, it doesn't make sense to combine the histories + anyway, since it's unclear which part of the history + belongs to which subtree. + + Furthermore, with '--squash', you can switch back and + forth between different versions of a subtree, rather + than strictly forward. 'git subtree merge --squash' + always adjusts the subtree to match the exactly + specified commit, even if getting to that commit would + require undoing some changes that were added earlier. + + Whether or not you use '--squash', changes made in your + local repository remain intact and can be later split + and send upstream to the subproject. + + +OPTIONS FOR split +----------------- +--annotate=:: + When generating synthetic history, add as a + prefix to each commit message. Since we're creating new + commits with the same commit message, but possibly + different content, from the original commits, this can help + to differentiate them and avoid confusion. + + Whenever you split, you need to use the same + , or else you don't have a guarantee that + the new re-created history will be identical to the old + one. That will prevent merging from working correctly. + git subtree tries to make it work anyway, particularly + if you use --rejoin, but it may not always be effective. + +-b :: +--branch=:: + After generating the synthetic history, create a new + branch called that contains the new history. + This is suitable for immediate pushing upstream. + must not already exist. + +--ignore-joins:: + If you use '--rejoin', git subtree attempts to optimize + its history reconstruction to generate only the new + commits since the last '--rejoin'. '--ignore-join' + disables this behaviour, forcing it to regenerate the + entire history. In a large project, this can take a + long time. + +--onto=:: + If your subtree was originally imported using something + other than git subtree, its history may not match what + git subtree is expecting. In that case, you can specify + the commit id that corresponds to the first + revision of the subproject's history that was imported + into your project, and git subtree will attempt to build + its history from there. + + If you used 'git subtree add', you should never need + this option. + +--rejoin:: + After splitting, merge the newly created synthetic + history back into your main project. That way, future + splits can search only the part of history that has + been added since the most recent --rejoin. + + If your split commits end up merged into the upstream + subproject, and then you want to get the latest upstream + version, this will allow git's merge algorithm to more + intelligently avoid conflicts (since it knows these + synthetic commits are already part of the upstream + repository). + + Unfortunately, using this option results in 'git log' + showing an extra copy of every new commit that was + created (the original, and the synthetic one). + + If you do all your merges with '--squash', don't use + '--rejoin' when you split, because you don't want the + subproject's history to be part of your project anyway. + + +AUTHOR +------ +Written by Avery Pennarun + + +GIT +--- +Part of the linkgit:git[1] suite diff --git a/manpage-base.xsl b/manpage-base.xsl new file mode 100644 index 0000000000..a264fa6160 --- /dev/null +++ b/manpage-base.xsl @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + sp + + + + + + + + br + + + diff --git a/manpage-normal.xsl b/manpage-normal.xsl new file mode 100644 index 0000000000..a48f5b11f3 --- /dev/null +++ b/manpage-normal.xsl @@ -0,0 +1,13 @@ + + + + + + +\ +. + + From dd07906252a3983fdec396ea6c58de12548713e1 Mon Sep 17 00:00:00 2001 From: Avery Pennarun Date: Sat, 30 May 2009 14:24:31 -0400 Subject: [PATCH 044/291] man page: add an EXAMPLES section. --- git-subtree.txt | 62 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/git-subtree.txt b/git-subtree.txt index d10630180d..649cc30989 100644 --- a/git-subtree.txt +++ b/git-subtree.txt @@ -223,6 +223,68 @@ OPTIONS FOR split subproject's history to be part of your project anyway. +EXAMPLES +-------- +Let's use the repository for the git source code as an example. +First, get your own copy of the git.git repository: + + $ git clone git://git.kernel.org/pub/scm/git/git.git test-git + $ cd test-git + +gitweb (commit 1130ef3) was merged into git as of commit +0a8f4f0, after which it was no longer maintained separately. +But imagine it had been maintained separately, and we wanted to +extract git's changes to gitweb since that time, to share with +the upstream. You could do this: + + $ git subtree split --prefix=gitweb --annotate='(split) ' \ + 0a8f4f0^.. --onto=1130ef3 --rejoin \ + --branch gitweb-latest + $ gitk gitweb-latest + $ git push git@github.com:whatever/gitweb gitweb-latest:master + +(We use '0a8f4f0^..' because that means "all the changes from +0a8f4f0 to the current version, including 0a8f4f0 itself.") + +If gitweb had originally been merged using 'git subtree add' (or +a previous split had already been done with --rejoin specified) +then you can do all your splits without having to remember any +weird commit ids: + + $ git subtree split --prefix=gitweb --annotate='(split) ' --rejoin \ + --branch gitweb-latest2 + +And you can merge changes back in from the upstream project just +as easily: + + $ git subtree pull --prefix=gitweb \ + git@github.com:whatever/gitweb gitweb-latest:master + +Or, using '--squash', you can actually rewind to an earlier +version of gitweb: + + $ git subtree merge --prefix=gitweb --squash gitweb-latest~10 + +Then make some changes: + + $ date >gitweb/myfile + $ git add gitweb/myfile + $ git commit -m 'created myfile' + +And fast forward again: + + $ git subtree merge --prefix=gitweb --squash gitweb-latest + +And notice that your change is still intact: + + $ ls -l gitweb/myfile + +And you can split it out and look at your changes versus +the standard gitweb: + + git log gitweb-latest..$(git subtree split --prefix=gitweb) + + AUTHOR ------ Written by Avery Pennarun From c8a98d4f8730d85a6f693d5dbcd4c1309d97f7c8 Mon Sep 17 00:00:00 2001 From: Avery Pennarun Date: Mon, 15 Jun 2009 14:12:40 -0400 Subject: [PATCH 045/291] update todo --- todo | 3 +++ 1 file changed, 3 insertions(+) diff --git a/todo b/todo index a15a378da5..88a4359916 100644 --- a/todo +++ b/todo @@ -21,3 +21,6 @@ add to-submodule and from-submodule commands automated tests for --squash stuff + + test.sh fails in msysgit? + sort error - see Thell's email From 6aa76263eed68ffed7405687f407e66deec30b02 Mon Sep 17 00:00:00 2001 From: Avery Pennarun Date: Thu, 2 Jul 2009 12:39:48 -0400 Subject: [PATCH 046/291] Some todo items reported by pmccurdy --- todo | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/todo b/todo index 88a4359916..1a9d64408d 100644 --- a/todo +++ b/todo @@ -1,5 +1,3 @@ - - write proper docs (asciidoc format for git compatibility) delete tempdir @@ -24,3 +22,24 @@ test.sh fails in msysgit? sort error - see Thell's email + + "add" command non-obviously requires a commitid; would be easier if + it had a "pull" sort of mode instead + + "pull" and "merge" commands should fail if you've never merged + that --prefix before + + docs should provide an example of "add" + + note that the initial split doesn't *have* to have a commitid + specified... that's just an optimization + + if you try to add (or maybe merge?) with an invalid commitid, you + get a misleading "prefix must end with /" message from + one of the other git tools that git-subtree calls. Should + detect this situation and print the *real* problem. + + In fact, the prefix should *not* end with slash, and we + should detect (and fix) it if it does. Otherwise the + log message looks weird. + From 76a7356f56655dbcbbc9d472e0cdc85c6ed3759f Mon Sep 17 00:00:00 2001 From: Avery Pennarun Date: Tue, 7 Jul 2009 17:41:38 -0400 Subject: [PATCH 047/291] todo --- todo | 2 ++ 1 file changed, 2 insertions(+) diff --git a/todo b/todo index 1a9d64408d..01d552979a 100644 --- a/todo +++ b/todo @@ -43,3 +43,5 @@ should detect (and fix) it if it does. Otherwise the log message looks weird. + totally weird behavior in 'git subtree add' if --prefix matches + a branch name From b64a7aa26c72fcae7b6e1decd88ed706c185cda7 Mon Sep 17 00:00:00 2001 From: Avery Pennarun Date: Wed, 8 Jul 2009 20:17:31 -0400 Subject: [PATCH 048/291] Docs: when pushing to github, the repo path needs to end in .git Reported by Thell Fowler. --- git-subtree.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/git-subtree.txt b/git-subtree.txt index 649cc30989..e7ce2d3654 100644 --- a/git-subtree.txt +++ b/git-subtree.txt @@ -241,7 +241,7 @@ the upstream. You could do this: 0a8f4f0^.. --onto=1130ef3 --rejoin \ --branch gitweb-latest $ gitk gitweb-latest - $ git push git@github.com:whatever/gitweb gitweb-latest:master + $ git push git@github.com:whatever/gitweb.git gitweb-latest:master (We use '0a8f4f0^..' because that means "all the changes from 0a8f4f0 to the current version, including 0a8f4f0 itself.") @@ -258,7 +258,7 @@ And you can merge changes back in from the upstream project just as easily: $ git subtree pull --prefix=gitweb \ - git@github.com:whatever/gitweb gitweb-latest:master + git@github.com:whatever/gitweb.git gitweb-latest:master Or, using '--squash', you can actually rewind to an earlier version of gitweb: From 5d1a5da411a8ec90cd7a7819bfc74440e3f2545c Mon Sep 17 00:00:00 2001 From: Avery Pennarun Date: Fri, 10 Jul 2009 15:14:33 -0400 Subject: [PATCH 049/291] todo --- todo | 3 +++ 1 file changed, 3 insertions(+) diff --git a/todo b/todo index 01d552979a..e67f713ad4 100644 --- a/todo +++ b/todo @@ -45,3 +45,6 @@ totally weird behavior in 'git subtree add' if --prefix matches a branch name + + "pull --squash" should do fetch-synthesize-merge, but instead just + does "pull" directly, which doesn't work at all. From 344f58abe599cba53a056c0a707c9a99e2cd13a8 Mon Sep 17 00:00:00 2001 From: Avery Pennarun Date: Thu, 16 Jul 2009 14:31:50 -0400 Subject: [PATCH 050/291] todo^ --- todo | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/todo b/todo index e67f713ad4..155c4be155 100644 --- a/todo +++ b/todo @@ -48,3 +48,8 @@ "pull --squash" should do fetch-synthesize-merge, but instead just does "pull" directly, which doesn't work at all. + + make a 'force-update' that does what 'add' does even if the subtree + already exists. That way we can help people who imported + subtrees "incorrectly" (eg. by just copying in the files) in + the past. From 0af6aa46751aa6c1ec393155b938601ce0b5f7ae Mon Sep 17 00:00:00 2001 From: Avery Pennarun Date: Sat, 1 Aug 2009 01:19:48 -0400 Subject: [PATCH 051/291] todo --- todo | 2 ++ 1 file changed, 2 insertions(+) diff --git a/todo b/todo index 155c4be155..b59713064b 100644 --- a/todo +++ b/todo @@ -53,3 +53,5 @@ already exists. That way we can help people who imported subtrees "incorrectly" (eg. by just copying in the files) in the past. + + guess --prefix automatically if possible based on pwd From ef7596677c181c649436fe97356dd31c1cb4a13e Mon Sep 17 00:00:00 2001 From: Avery Pennarun Date: Sun, 2 Aug 2009 17:48:20 -0400 Subject: [PATCH 052/291] todo: idea for a 'git subtree grafts' command --- todo | 3 +++ 1 file changed, 3 insertions(+) diff --git a/todo b/todo index b59713064b..3040b9f171 100644 --- a/todo +++ b/todo @@ -55,3 +55,6 @@ the past. guess --prefix automatically if possible based on pwd + + make a 'git subtree grafts' that automatically expands --squash'd + commits so you can see the full history if you want it. From e1a5b9d3e708d6be1a4c5220dc492da9f2694411 Mon Sep 17 00:00:00 2001 From: Amiel Martin Date: Wed, 12 Aug 2009 15:24:50 -0700 Subject: [PATCH 053/291] fixed order of assertion in tests --- test.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test.sh b/test.sh index 38dff7a41a..4229f840ac 100755 --- a/test.sh +++ b/test.sh @@ -160,7 +160,7 @@ check_equal "$mainfiles" "$chkm $chkms_sub $chks_sub" # changes that were split into their own history. And 'subdir/sub??' never # change, since they were *only* changed in the subtree branch. allchanges=$(git log --name-only --pretty=format:'' | sort | fixnl) -check_equal "$allchanges" "$chkm $chkms $chks $chkms_sub" +check_equal "$allchanges" "$chkms $chkm $chks $chkms_sub" # make sure the --rejoin commits never make it into subproj check_equal "$(git log --pretty=format:'%s' HEAD^2 | grep -i split)" "" From 558e7a57e20fe68aee05f74f8005b7a39795ac15 Mon Sep 17 00:00:00 2001 From: Amiel Martin Date: Wed, 12 Aug 2009 15:38:00 -0700 Subject: [PATCH 054/291] sort assertion to make it more generic --- test.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test.sh b/test.sh index 4229f840ac..8283fadaad 100755 --- a/test.sh +++ b/test.sh @@ -160,7 +160,7 @@ check_equal "$mainfiles" "$chkm $chkms_sub $chks_sub" # changes that were split into their own history. And 'subdir/sub??' never # change, since they were *only* changed in the subtree branch. allchanges=$(git log --name-only --pretty=format:'' | sort | fixnl) -check_equal "$allchanges" "$chkms $chkm $chks $chkms_sub" +check_equal "$allchanges" "$(echo $chkms $chkm $chks $chkms_sub | multiline | sort | fixnl)" # make sure the --rejoin commits never make it into subproj check_equal "$(git log --pretty=format:'%s' HEAD^2 | grep -i split)" "" From 2987e6add32f3367be8cc196ecac9195a213e415 Mon Sep 17 00:00:00 2001 From: kTln2 Date: Thu, 20 Aug 2009 13:30:45 +0200 Subject: [PATCH 055/291] Add explicit path of git installation by 'git --exec-path'. As pointed out by documentation, the correct use of 'git-sh-setup' is using $(git --exec-path) to avoid problems with not standard installations. Signed-off-by: gianluca.pacchiella --- git-subtree.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git-subtree.sh b/git-subtree.sh index 962d5ff509..c5c0201448 100755 --- a/git-subtree.sh +++ b/git-subtree.sh @@ -27,7 +27,7 @@ rejoin merge the new branch back into HEAD squash merge subtree changes as a single commit " eval $(echo "$OPTS_SPEC" | git rev-parse --parseopt -- "$@" || echo exit $?) -. git-sh-setup +. $(git --exec-path)/git-sh-setup require_work_tree quiet= From 33aaa697a2386a02002f9fb8439d11243f12e1c7 Mon Sep 17 00:00:00 2001 From: Avery Pennarun Date: Wed, 26 Aug 2009 10:41:03 -0400 Subject: [PATCH 056/291] Improve patch to use git --exec-path: add to PATH instead. If you (like me) are using a modified git straight out of its source directory (ie. without installing), then --exec-path isn't actually correct. Add it to the PATH instead, so if it is correct, it'll work, but if it's not, we fall back to the previous behaviour. --- git-subtree.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/git-subtree.sh b/git-subtree.sh index c5c0201448..f7d2fe408d 100755 --- a/git-subtree.sh +++ b/git-subtree.sh @@ -27,7 +27,8 @@ rejoin merge the new branch back into HEAD squash merge subtree changes as a single commit " eval $(echo "$OPTS_SPEC" | git rev-parse --parseopt -- "$@" || echo exit $?) -. $(git --exec-path)/git-sh-setup +PATH=$(git --exec-path):$PATH +. git-sh-setup require_work_tree quiet= From 227f78114752eee2e8ae3368089716d73d32dd8b Mon Sep 17 00:00:00 2001 From: Avery Pennarun Date: Wed, 26 Aug 2009 10:43:43 -0400 Subject: [PATCH 057/291] Fix behaviour if you have a branch named the same as your --prefix We were trying to 'git checkout $prefix', which is ambiguous if $prefix names a directory *and* a branch. Do 'git checkout -- $prefix' instead. The main place this appeared was in 'git subtree add'. Reported by several people. --- git-subtree.sh | 2 +- test.sh | 1 + todo | 6 ------ 3 files changed, 2 insertions(+), 7 deletions(-) diff --git a/git-subtree.sh b/git-subtree.sh index f7d2fe408d..b7c741cfd4 100755 --- a/git-subtree.sh +++ b/git-subtree.sh @@ -426,7 +426,7 @@ cmd_add() debug "Adding $dir as '$rev'..." git read-tree --prefix="$dir" $rev || exit $? - git checkout "$dir" || exit $? + git checkout -- "$dir" || exit $? tree=$(git write-tree) || exit $? headrev=$(git rev-parse HEAD) || exit $? diff --git a/test.sh b/test.sh index 8283fadaad..bed7f27906 100755 --- a/test.sh +++ b/test.sh @@ -78,6 +78,7 @@ git init create main4 git commit -m 'main4' git branch -m master mainline +git branch subdir git fetch ../subproj sub1 git branch sub1 FETCH_HEAD diff --git a/todo b/todo index 3040b9f171..5e72b2e510 100644 --- a/todo +++ b/todo @@ -20,9 +20,6 @@ automated tests for --squash stuff - test.sh fails in msysgit? - sort error - see Thell's email - "add" command non-obviously requires a commitid; would be easier if it had a "pull" sort of mode instead @@ -43,9 +40,6 @@ should detect (and fix) it if it does. Otherwise the log message looks weird. - totally weird behavior in 'git subtree add' if --prefix matches - a branch name - "pull --squash" should do fetch-synthesize-merge, but instead just does "pull" directly, which doesn't work at all. From 8ac5eca1eaa88bd5b998e91531937404bc6425c4 Mon Sep 17 00:00:00 2001 From: Pelle Wessman Date: Wed, 30 Sep 2009 14:29:42 +0200 Subject: [PATCH 058/291] Check that the type of the tree really is a tree and not a commit as it seems to sometimes become when eg. a submodule has existed in the same position previously. --- git-subtree.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/git-subtree.sh b/git-subtree.sh index b7c741cfd4..454ce7ef22 100755 --- a/git-subtree.sh +++ b/git-subtree.sh @@ -322,6 +322,7 @@ subtree_for_commit() git ls-tree "$commit" -- "$dir" | while read mode type tree name; do assert [ "$name" = "$dir" ] + assert [ "$type" = "tree" ] echo $tree break done From add00a3229ba4ada0cb47a447fdc483658df78e9 Mon Sep 17 00:00:00 2001 From: Avery Pennarun Date: Fri, 2 Oct 2009 11:51:25 -0400 Subject: [PATCH 059/291] Add a README that says to email me instead of using github mail. What's with this new generation who hates email so much? --- README | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 README diff --git a/README b/README new file mode 100644 index 0000000000..c686b4a69b --- /dev/null +++ b/README @@ -0,0 +1,8 @@ + +Please read git-subtree.txt for documentation. + +Please don't contact me using github mail; it's slow, ugly, and worst of +all, redundant. Email me instead at apenwarr@gmail.com and I'll be happy to +help. + +Avery From 6f2012cdc021f6b47ed19bc7fe64159ce9eeda8a Mon Sep 17 00:00:00 2001 From: Avery Pennarun Date: Fri, 2 Oct 2009 15:22:15 -0400 Subject: [PATCH 060/291] If someone provides a --prefix that ends with slash, strip the slash. Prefixes that differ only in the trailing slash should be considered identical. Also update the test to check that this works. --- git-subtree.sh | 6 +++--- test.sh | 4 ++-- todo | 4 ---- 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/git-subtree.sh b/git-subtree.sh index 454ce7ef22..0949fefe20 100755 --- a/git-subtree.sh +++ b/git-subtree.sh @@ -102,7 +102,7 @@ esac if [ -z "$prefix" ]; then die "You must provide the --prefix option." fi -dir="$prefix" +dir="$(dirname "$prefix/.")" if [ "$command" != "pull" ]; then revs=$(git rev-parse $default --revs-only "$@") || exit $? @@ -175,7 +175,7 @@ find_latest_squash() sq= main= sub= - git log --grep="^git-subtree-dir: $dir\$" \ + git log --grep="^git-subtree-dir: $dir/*\$" \ --pretty=format:'START %H%n%s%n%n%b%nEND%n' HEAD | while read a b junk; do debug "$a $b $junk" @@ -210,7 +210,7 @@ find_existing_splits() revs="$2" main= sub= - git log --grep="^git-subtree-dir: $dir\$" \ + git log --grep="^git-subtree-dir: $dir/*\$" \ --pretty=format:'START %H%n%s%n%n%b%nEND%n' $revs | while read a b junk; do case "$a" in diff --git a/test.sh b/test.sh index bed7f27906..12b0456574 100755 --- a/test.sh +++ b/test.sh @@ -82,7 +82,7 @@ git branch subdir git fetch ../subproj sub1 git branch sub1 FETCH_HEAD -git subtree add --prefix=subdir FETCH_HEAD +git subtree add --prefix=subdir/ FETCH_HEAD # this shouldn't actually do anything, since FETCH_HEAD is already a parent git merge -m 'merge -s -ours' -s ours FETCH_HEAD @@ -118,7 +118,7 @@ create sub9 git commit -m 'sub9' cd ../mainline -split2=$(git subtree split --annotate='*' --prefix subdir --rejoin) +split2=$(git subtree split --annotate='*' --prefix subdir/ --rejoin) git branch split2 "$split2" create subdir/main-sub10 diff --git a/todo b/todo index 5e72b2e510..7e44b0024f 100644 --- a/todo +++ b/todo @@ -36,10 +36,6 @@ one of the other git tools that git-subtree calls. Should detect this situation and print the *real* problem. - In fact, the prefix should *not* end with slash, and we - should detect (and fix) it if it does. Otherwise the - log message looks weird. - "pull --squash" should do fetch-synthesize-merge, but instead just does "pull" directly, which doesn't work at all. From 2275f7077d5ea2bb9201599dec0dd8f2a5de2e40 Mon Sep 17 00:00:00 2001 From: Avery Pennarun Date: Fri, 2 Oct 2009 16:09:09 -0400 Subject: [PATCH 061/291] Fix a minor problem in identifying squashes vs. normal splits. This didn't seem to have any noticeable side effects other than suspicious-looking log messages when you used -d. --- git-subtree.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/git-subtree.sh b/git-subtree.sh index 0949fefe20..cccc3400fd 100755 --- a/git-subtree.sh +++ b/git-subtree.sh @@ -214,12 +214,14 @@ find_existing_splits() --pretty=format:'START %H%n%s%n%n%b%nEND%n' $revs | while read a b junk; do case "$a" in - START) main="$b"; sq="$b" ;; + START) sq="$b" ;; git-subtree-mainline:) main="$b" ;; git-subtree-split:) sub="$b" ;; END) + debug " Main is: '$main'" if [ -z "$main" -a -n "$sub" ]; then # squash commits refer to a subtree + debug " Squash: $sq from $sub" cache_set "$sq" "$sub" fi if [ -n "$main" -a -n "$sub" ]; then From e31d1e2f30c943473de7a23bbbcd2dcea698e312 Mon Sep 17 00:00:00 2001 From: Avery Pennarun Date: Fri, 2 Oct 2009 18:23:54 -0400 Subject: [PATCH 062/291] cmd_pull didn't support --squash correctly. We should implement it as git fetch ... git subtree merge ... But we were instead just calling git pull -s subtree ... because 'git subtree merge' used to be just an alias for 'git merge -s subtree', but it no longer is. --- git-subtree.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/git-subtree.sh b/git-subtree.sh index cccc3400fd..8baa376fe5 100755 --- a/git-subtree.sh +++ b/git-subtree.sh @@ -567,8 +567,9 @@ cmd_merge() cmd_pull() { ensure_clean - set -x - git pull -s subtree "$@" + git fetch "$@" || exit $? + revs=FETCH_HEAD + cmd_merge } "cmd_$command" "$@" From c567d9e59fceb93d7334a1414d0a2a9d6f4913de Mon Sep 17 00:00:00 2001 From: Avery Pennarun Date: Wed, 4 Nov 2009 14:50:33 -0500 Subject: [PATCH 063/291] Add some tips for how to install. --- INSTALL | 13 +++++++++++++ Makefile | 1 + 2 files changed, 14 insertions(+) create mode 100644 INSTALL diff --git a/INSTALL b/INSTALL new file mode 100644 index 0000000000..5966dde46c --- /dev/null +++ b/INSTALL @@ -0,0 +1,13 @@ + +HOW TO INSTALL git-subtree +========================== + +Copy the file 'git-subtree.sh' to /usr/local/bin/git-subtree. + +That will make a 'git subtree' (note: space instead of dash) command +available. See the file git-subtree.txt for more. + +You can also install the man page by doing: + + make doc + cp git-subtree.1 /usr/share/man/man1/ diff --git a/Makefile b/Makefile index bc163dd390..3e97c6246f 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,6 @@ default: @echo "git-subtree doesn't need to be built." + @echo "Just copy it somewhere on your PATH, like /usr/local/bin." @echo @echo "Try: make doc" @false From d8b2c0da177ddfc2bc8d1e47278aa1c240d63034 Mon Sep 17 00:00:00 2001 From: Avery Pennarun Date: Sun, 15 Nov 2009 12:13:08 -0500 Subject: [PATCH 064/291] Oops, forgot a COPYING file. It's GPLv2. Thanks to Ben Walton for pointing this out. --- COPYING | 339 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 339 insertions(+) create mode 100644 COPYING diff --git a/COPYING b/COPYING new file mode 100644 index 0000000000..d511905c16 --- /dev/null +++ b/COPYING @@ -0,0 +1,339 @@ + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Lesser General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + , 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. From 0d31de303f9e8e28cc1649dbf41c1cc635bae2d8 Mon Sep 17 00:00:00 2001 From: Ben Walton Date: Fri, 13 Nov 2009 20:29:39 -0500 Subject: [PATCH 065/291] add installation support to Makefile Signed-off-by: Ben Walton --- Makefile | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/Makefile b/Makefile index 3e97c6246f..faefffded5 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,13 @@ +prefix ?= /usr/local +mandir ?= $(prefix)/share/man +gitdir ?= $(shell git --exec-path) + +# this should be set to a 'standard' bsd-type install program +INSTALL ?= install +INSTALL_DATA = $(INSTALL) -c -m 0644 +INSTALL_EXE = $(INSTALL) -c -m 0755 +INSTALL_DIR = $(INSTALL) -c -d -m 0755 + default: @echo "git-subtree doesn't need to be built." @echo "Just copy it somewhere on your PATH, like /usr/local/bin." @@ -5,6 +15,16 @@ default: @echo "Try: make doc" @false +install: install-exe install-doc + +install-exe: git-subtree.sh + $(INSTALL_DIR) $(DESTDIR)/$(gitdir) + $(INSTALL_EXE) $< $(DESTDIR)/$(gitdir)/git-subtree + +install-doc: git-subtree.1 + $(INSTALL_DIR) $(DESTDIR)/$(mandir)/man1/ + $(INSTALL_DATA) $< $(DESTDIR)/$(mandir)/man1/ + doc: git-subtree.1 %.1: %.xml From d20ac24c2fe860dba99b40d76fe371a323e9918d Mon Sep 17 00:00:00 2001 From: Ben Walton Date: Fri, 13 Nov 2009 20:29:40 -0500 Subject: [PATCH 066/291] make git version dynamic when building documentation Signed-off-by: Ben Walton --- Makefile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index faefffded5..9b204bdcae 100644 --- a/Makefile +++ b/Makefile @@ -2,6 +2,8 @@ prefix ?= /usr/local mandir ?= $(prefix)/share/man gitdir ?= $(shell git --exec-path) +gitver ?= $(word 3,$(shell git --version)) + # this should be set to a 'standard' bsd-type install program INSTALL ?= install INSTALL_DATA = $(INSTALL) -c -m 0644 @@ -32,7 +34,7 @@ doc: git-subtree.1 %.xml: %.txt asciidoc -b docbook -d manpage -f asciidoc.conf \ - -agit_version=1.6.3 $^ + -agit_version=$(gitver) $^ clean: rm -f *~ *.xml *.html *.1 From d344532afd3d99c9cdd6d7cfc46bd92ff7def4e8 Mon Sep 17 00:00:00 2001 From: Avery Pennarun Date: Fri, 20 Nov 2009 19:43:47 -0500 Subject: [PATCH 067/291] Weird, I forgot to have 'make test' call test.sh. --- Makefile | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Makefile b/Makefile index 9b204bdcae..91e0cc08ea 100644 --- a/Makefile +++ b/Makefile @@ -15,6 +15,7 @@ default: @echo "Just copy it somewhere on your PATH, like /usr/local/bin." @echo @echo "Try: make doc" + @echo " or: make test" @false install: install-exe install-doc @@ -35,6 +36,9 @@ doc: git-subtree.1 %.xml: %.txt asciidoc -b docbook -d manpage -f asciidoc.conf \ -agit_version=$(gitver) $^ + +test: + ./test.sh clean: rm -f *~ *.xml *.html *.1 From 6da401386ea37f1bda3f6717d7c77fb0e5c351b2 Mon Sep 17 00:00:00 2001 From: Jakub Suder Date: Wed, 6 Jan 2010 23:11:43 +0100 Subject: [PATCH 068/291] added -p alias for --prefix --- git-subtree.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/git-subtree.sh b/git-subtree.sh index 8baa376fe5..28fb8e81fb 100755 --- a/git-subtree.sh +++ b/git-subtree.sh @@ -16,7 +16,7 @@ git subtree split --prefix= h,help show the help q quiet d show debug messages -prefix= the name of the subdir to split out +p,prefix= the name of the subdir to split out options for 'split' annotate= add a prefix to commit message of new commits b,branch= create a new branch from the split subtree @@ -76,7 +76,7 @@ while [ $# -gt 0 ]; do --annotate) annotate="$1"; shift ;; --no-annotate) annotate= ;; -b) branch="$1"; shift ;; - --prefix) prefix="$1"; shift ;; + -p) prefix="$1"; shift ;; --no-prefix) prefix= ;; --onto) onto="$1"; shift ;; --no-onto) onto= ;; From 2da0969a794eac50401fd25ea072224d4378a5fe Mon Sep 17 00:00:00 2001 From: Jakub Suder Date: Sat, 9 Jan 2010 19:55:35 +0100 Subject: [PATCH 069/291] added -m/--message option for setting merge commit message --- git-subtree.sh | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/git-subtree.sh b/git-subtree.sh index 28fb8e81fb..96118735b2 100755 --- a/git-subtree.sh +++ b/git-subtree.sh @@ -17,6 +17,7 @@ h,help show the help q quiet d show debug messages p,prefix= the name of the subdir to split out +m,message= use the given message as the commit message for the merge commit options for 'split' annotate= add a prefix to commit message of new commits b,branch= create a new branch from the split subtree @@ -40,6 +41,7 @@ rejoin= ignore_joins= annotate= squash= +message= debug() { @@ -77,6 +79,7 @@ while [ $# -gt 0 ]; do --no-annotate) annotate= ;; -b) branch="$1"; shift ;; -p) prefix="$1"; shift ;; + -m) message="$1"; shift ;; --no-prefix) prefix= ;; --onto) onto="$1"; shift ;; --no-onto) onto= ;; @@ -266,8 +269,13 @@ add_msg() dir="$1" latest_old="$2" latest_new="$3" + if [ -n "$message" ]; then + commit_message="$message" + else + commit_message="Add '$dir/' from commit '$latest_new'" + fi cat <<-EOF - Add '$dir/' from commit '$latest_new' + $commit_message git-subtree-dir: $dir git-subtree-mainline: $latest_old @@ -275,13 +283,27 @@ add_msg() EOF } +add_squashed_msg() +{ + if [ -n "$message" ]; then + echo "$message" + else + echo "Merge commit '$1' as '$2'" + fi +} + rejoin_msg() { dir="$1" latest_old="$2" latest_new="$3" + if [ -n "$message" ]; then + commit_message="$message" + else + commit_message="Split '$dir/' into commit '$latest_new'" + fi cat <<-EOF - Split '$dir/' into commit '$latest_new' + $message git-subtree-dir: $dir git-subtree-mainline: $latest_old @@ -441,7 +463,7 @@ cmd_add() if [ -n "$squash" ]; then rev=$(new_squash_commit "" "" "$rev") || exit $? - commit=$(echo "Merge commit '$rev' as '$dir'" | + commit=$(add_squashed_msg "$rev" "$dir" | git commit-tree $tree $headp -p "$rev") || exit $? else commit=$(add_msg "$dir" "$headrev" "$rev" | @@ -561,7 +583,7 @@ cmd_merge() rev="$new" fi - git merge -s subtree $rev + git merge -s subtree --message="$message" $rev } cmd_pull() From 0a562948ae1fe7130f4e9a29ce4107311ab93b91 Mon Sep 17 00:00:00 2001 From: Jakub Suder Date: Sat, 9 Jan 2010 19:56:05 +0100 Subject: [PATCH 070/291] allow using --branch with existing branches if it makes sense --- git-subtree.sh | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/git-subtree.sh b/git-subtree.sh index 96118735b2..09992e39d5 100755 --- a/git-subtree.sh +++ b/git-subtree.sh @@ -161,6 +161,20 @@ rev_exists() fi } +rev_is_descendant_of_branch() +{ + newrev="$1" + branch="$2" + branch_hash=$(git rev-parse $branch) + match=$(git rev-list $newrev | grep $branch_hash) + + if [ -n "$match" ]; then + return 0 + else + return 1 + fi +} + # if a commit doesn't have a parent, this might not work. But we only want # to remove the parent from the rev-list, and since it doesn't exist, it won't # be there anyway, so do nothing in that case. @@ -476,10 +490,6 @@ cmd_add() cmd_split() { - if [ -n "$branch" ] && rev_exists "refs/heads/$branch"; then - die "Branch '$branch' already exists." - fi - debug "Splitting $dir..." cache_setup || exit $? @@ -510,7 +520,8 @@ cmd_split() eval "$grl" | while read rev parents; do revcount=$(($revcount + 1)) - say -n "$revcount/$revmax ($createcount) " + say -n "$revcount/$revmax ($createcount) +" debug "Processing commit: $rev" exists=$(cache_get $rev) if [ -n "$exists" ]; then @@ -548,9 +559,16 @@ cmd_split() $latest_new >&2 || exit $? fi if [ -n "$branch" ]; then - git update-ref -m 'subtree split' "refs/heads/$branch" \ - $latest_new "" || exit $? - say "Created branch '$branch'" + if rev_exists "refs/heads/$branch"; then + if ! rev_is_descendant_of_branch $latest_new $branch; then + die "Branch '$branch' is not an ancestor of commit '$latest_new'." + fi + action='Updated' + else + action='Created' + fi + git update-ref -m 'subtree split' "refs/heads/$branch" $latest_new || exit $? + say "$action branch '$branch'" fi echo $latest_new exit 0 From da949cc554304bf9dc2b20ffcd470fb6b8a35576 Mon Sep 17 00:00:00 2001 From: Jakub Suder Date: Sat, 9 Jan 2010 23:01:39 +0100 Subject: [PATCH 071/291] fix for subtree split not finding proper base for new commits --- git-subtree.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/git-subtree.sh b/git-subtree.sh index 09992e39d5..cdf7b0992b 100755 --- a/git-subtree.sh +++ b/git-subtree.sh @@ -538,7 +538,10 @@ cmd_split() # ugly. is there no better way to tell if this is a subtree # vs. a mainline commit? Does it matter? - [ -z $tree ] && continue + if [ -z $tree ]; then + cache_set $rev $rev + continue + fi newrev=$(copy_or_skip "$rev" "$tree" "$newparents") || exit $? debug " newrev is: $newrev" From 6e25f79f353a1c1f454ae0c44aa45ff3ab44551c Mon Sep 17 00:00:00 2001 From: Jakub Suder Date: Tue, 12 Jan 2010 22:38:21 +0100 Subject: [PATCH 072/291] changed alias for --prefix from -p to -P --- git-subtree.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/git-subtree.sh b/git-subtree.sh index cdf7b0992b..0a5cafa77f 100755 --- a/git-subtree.sh +++ b/git-subtree.sh @@ -16,7 +16,7 @@ git subtree split --prefix= h,help show the help q quiet d show debug messages -p,prefix= the name of the subdir to split out +P,prefix= the name of the subdir to split out m,message= use the given message as the commit message for the merge commit options for 'split' annotate= add a prefix to commit message of new commits @@ -78,7 +78,7 @@ while [ $# -gt 0 ]; do --annotate) annotate="$1"; shift ;; --no-annotate) annotate= ;; -b) branch="$1"; shift ;; - -p) prefix="$1"; shift ;; + -P) prefix="$1"; shift ;; -m) message="$1"; shift ;; --no-prefix) prefix= ;; --onto) onto="$1"; shift ;; From 12629161a89511847ec5703ca457ee373deb33cb Mon Sep 17 00:00:00 2001 From: Jakub Suder Date: Tue, 12 Jan 2010 22:38:34 +0100 Subject: [PATCH 073/291] fixed bug in commit message for split --- git-subtree.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git-subtree.sh b/git-subtree.sh index 0a5cafa77f..48bc570390 100755 --- a/git-subtree.sh +++ b/git-subtree.sh @@ -317,7 +317,7 @@ rejoin_msg() commit_message="Split '$dir/' into commit '$latest_new'" fi cat <<-EOF - $message + $commit_message git-subtree-dir: $dir git-subtree-mainline: $latest_old From 13ea2b5e0786e70780f91637fb82ca18dd03a730 Mon Sep 17 00:00:00 2001 From: Jakub Suder Date: Tue, 12 Jan 2010 23:04:25 +0100 Subject: [PATCH 074/291] added tests for recent changes --- test.sh | 106 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 104 insertions(+), 2 deletions(-) diff --git a/test.sh b/test.sh index 12b0456574..cfe3a3c258 100755 --- a/test.sh +++ b/test.sh @@ -53,6 +53,16 @@ multiline() done } +undo() +{ + git reset --hard HEAD~ +} + +last_commit_message() +{ + git log --format=%s -1 +} + rm -rf mainline subproj mkdir mainline subproj @@ -82,7 +92,24 @@ git branch subdir git fetch ../subproj sub1 git branch sub1 FETCH_HEAD + +# check if --message works for add +git subtree add --prefix=subdir --message="Added subproject" sub1 +check_equal "$(last_commit_message)" "Added subproject" +undo + +# check if --message works as -m and --prefix as -P +git subtree add -P subdir -m "Added subproject using git subtree" sub1 +check_equal "$(last_commit_message)" "Added subproject using git subtree" +undo + +# check if --message works with squash too +git subtree add -P subdir -m "Added subproject with squash" --squash sub1 +check_equal "$(last_commit_message)" "Added subproject with squash" +undo + git subtree add --prefix=subdir/ FETCH_HEAD +check_equal "$(last_commit_message)" "Add 'subdir/' from commit '$(git rev-parse sub1)'" # this shouldn't actually do anything, since FETCH_HEAD is already a parent git merge -m 'merge -s -ours' -s ours FETCH_HEAD @@ -98,13 +125,44 @@ git commit -m 'main-sub7' git fetch ../subproj sub2 git branch sub2 FETCH_HEAD + +# check if --message works for merge +git subtree merge --prefix=subdir -m "Merged changes from subproject" sub2 +check_equal "$(last_commit_message)" "Merged changes from subproject" +undo + +# check if --message for merge works with squash too +git subtree merge --prefix subdir -m "Merged changes from subproject using squash" --squash sub2 +check_equal "$(last_commit_message)" "Merged changes from subproject using squash" +undo + git subtree merge --prefix=subdir FETCH_HEAD git branch pre-split +check_equal "$(last_commit_message)" "Merge commit '$(git rev-parse sub2)' into mainline" -spl1=$(git subtree split --annotate='*' \ - --prefix subdir --onto FETCH_HEAD --rejoin) +# check if --message works for split+rejoin +spl1=$(git subtree split --annotate='*' --prefix subdir --onto FETCH_HEAD --message "Split & rejoin" --rejoin) echo "spl1={$spl1}" git branch spl1 "$spl1" +check_equal "$(last_commit_message)" "Split & rejoin" +undo + +# check split with --branch +git subtree split --annotate='*' --prefix subdir --onto FETCH_HEAD --branch splitbr1 +check_equal "$(git rev-parse splitbr1)" "$spl1" + +# check split with --branch for an existing branch +git branch splitbr2 sub1 +git subtree split --annotate='*' --prefix subdir --onto FETCH_HEAD --branch splitbr2 +check_equal "$(git rev-parse splitbr2)" "$spl1" + +# check split with --branch for an incompatible branch +result=$(git subtree split --prefix subdir --onto FETCH_HEAD --branch subdir || echo "caught error") +check_equal "$result" "caught error" + + +git subtree split --annotate='*' --prefix subdir --onto FETCH_HEAD --rejoin +check_equal "$(last_commit_message)" "Split 'subdir/' into commit '$spl1'" create subdir/main-sub8 git commit -m 'main-sub8' @@ -170,6 +228,50 @@ check_equal "$(git log --pretty=format:'%s' HEAD^2 | grep -i split)" "" # meaningless to subproj since one side of the merge refers to the mainline) check_equal "$(git log --pretty=format:'%s%n%b' HEAD^2 | grep 'git-subtree.*:')" "" + +# check if split can find proper base without --onto +# prepare second pair of repositories +mkdir test2 +cd test2 + +mkdir main +cd main +git init +create main1 +git commit -m "main1" + +cd .. +mkdir sub +cd sub +git init +create sub2 +git commit -m "sub2" + +cd ../main +git fetch ../sub master +git branch sub2 FETCH_HEAD +git subtree add --prefix subdir sub2 + +cd ../sub +create sub3 +git commit -m "sub3" + +cd ../main +git fetch ../sub master +git branch sub3 FETCH_HEAD +git subtree merge --prefix subdir sub3 + +create subdir/main-sub4 +git commit -m "main-sub4" +git subtree split --prefix subdir --branch mainsub4 + +# at this point, the new commit's parent should be sub3 +# if it's not, something went wrong (the "newparent" of "master~" commit should have been sub3, +# but it wasn't, because it's cache was not set to itself) +check_equal "$(git log --format=%P -1 mainsub4)" "$(git rev-parse sub3)" + + + # make sure no patch changes more than one file. The original set of commits # changed only one file each. A multi-file change would imply that we pruned # commits too aggressively. From 4a6ea5ce301c9844722bfdb9291bd9cb7797d9ed Mon Sep 17 00:00:00 2001 From: Jakub Suder Date: Tue, 12 Jan 2010 23:04:56 +0100 Subject: [PATCH 075/291] added temporary test dirs to gitignore --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index e358b18b78..7e77c9d022 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ *~ git-subtree.xml git-subtree.1 +mainline +subproj From 6bd910a82155ae3def5cf38acb27d36a192c449e Mon Sep 17 00:00:00 2001 From: Jakub Suder Date: Tue, 12 Jan 2010 23:34:52 +0100 Subject: [PATCH 076/291] improved rev_is_descendant_of_branch() function --- git-subtree.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/git-subtree.sh b/git-subtree.sh index 48bc570390..66ce251eaa 100755 --- a/git-subtree.sh +++ b/git-subtree.sh @@ -166,9 +166,9 @@ rev_is_descendant_of_branch() newrev="$1" branch="$2" branch_hash=$(git rev-parse $branch) - match=$(git rev-list $newrev | grep $branch_hash) + match=$(git rev-list -1 $branch_hash ^$newrev) - if [ -n "$match" ]; then + if [ -z "$match" ]; then return 0 else return 1 From e1ce417d0cb4bfe719efa07417c690b1ce0326e9 Mon Sep 17 00:00:00 2001 From: Arlen Cuss Date: Tue, 19 Jan 2010 12:51:19 -0700 Subject: [PATCH 077/291] Fix refspecs in given example for git subtree pull. (Updated slightly by apenwarr) --- git-subtree.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git-subtree.txt b/git-subtree.txt index e7ce2d3654..9b2d48e334 100644 --- a/git-subtree.txt +++ b/git-subtree.txt @@ -258,7 +258,7 @@ And you can merge changes back in from the upstream project just as easily: $ git subtree pull --prefix=gitweb \ - git@github.com:whatever/gitweb.git gitweb-latest:master + git@github.com:whatever/gitweb.git master Or, using '--squash', you can actually rewind to an earlier version of gitweb: From e2d0a4502f115ee63b8ff96661cfcc8aad075822 Mon Sep 17 00:00:00 2001 From: Avery Pennarun Date: Tue, 2 Feb 2010 10:30:11 -0500 Subject: [PATCH 078/291] Jakub's changes broke the progress message slightly. We really need that ^M (\r), not a ^J (\n) if we want the status message to overwrite itself nicely. --- git-subtree.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/git-subtree.sh b/git-subtree.sh index 66ce251eaa..11cda9ea82 100755 --- a/git-subtree.sh +++ b/git-subtree.sh @@ -520,8 +520,7 @@ cmd_split() eval "$grl" | while read rev parents; do revcount=$(($revcount + 1)) - say -n "$revcount/$revmax ($createcount) -" + say -n "$revcount/$revmax ($createcount) " debug "Processing commit: $rev" exists=$(cache_get $rev) if [ -n "$exists" ]; then From 37668a13edbc8bd8f8ac5ecbd5bf839a4171c09b Mon Sep 17 00:00:00 2001 From: Win Treese Date: Fri, 5 Feb 2010 19:48:11 -0500 Subject: [PATCH 079/291] git-subtree.txt: add another example. --- git-subtree.txt | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/git-subtree.txt b/git-subtree.txt index 9b2d48e334..2200aaeaf2 100644 --- a/git-subtree.txt +++ b/git-subtree.txt @@ -223,8 +223,8 @@ OPTIONS FOR split subproject's history to be part of your project anyway. -EXAMPLES --------- +EXAMPLE 1 +--------- Let's use the repository for the git source code as an example. First, get your own copy of the git.git repository: @@ -284,6 +284,23 @@ the standard gitweb: git log gitweb-latest..$(git subtree split --prefix=gitweb) +EXAMPLE 2 +--------- +Suppose you have a source directory with many files and +subdirectories, and you want to extract the lib directory to its own +git project. Here's a short way to do it: + +First, make the new repository wherever you want: + + git init --bare + +Back in your original directory: + git subtree split --prefix=lib --annotate="(split)" -b split + +Then push the new branch onto the new empty repository: + git push split:master + + AUTHOR ------ From 349a70d5cf127222c8a089f116070614ebd18732 Mon Sep 17 00:00:00 2001 From: Avery Pennarun Date: Sat, 6 Feb 2010 15:05:17 -0500 Subject: [PATCH 080/291] Make tests pass with recent git (1.7.0 and up). It seems that in older versions, --message="" was interpreted as "use the default commit message" instead of "use an empty commit message", and git-subtree was depending on this behaviour. Now we don't, so tests pass again. --- git-subtree.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/git-subtree.sh b/git-subtree.sh index 11cda9ea82..009c0db9bc 100755 --- a/git-subtree.sh +++ b/git-subtree.sh @@ -603,7 +603,11 @@ cmd_merge() rev="$new" fi - git merge -s subtree --message="$message" $rev + if [ -n "$message" ]; then + git merge -s subtree --message="$message" $rev + else + git merge -s subtree $rev + fi } cmd_pull() From ec54f0d9adb50baa14eae44a1b8c410f794d32de Mon Sep 17 00:00:00 2001 From: Win Treese Date: Fri, 5 Feb 2010 22:02:43 -0500 Subject: [PATCH 081/291] Make sure that exists when splitting. And test cases for that check, as well as for an error if no prefix is specified at all. --- git-subtree.sh | 5 +++++ test.sh | 8 ++++++++ 2 files changed, 13 insertions(+) diff --git a/git-subtree.sh b/git-subtree.sh index 009c0db9bc..52d4c0aeb1 100755 --- a/git-subtree.sh +++ b/git-subtree.sh @@ -105,6 +105,11 @@ esac if [ -z "$prefix" ]; then die "You must provide the --prefix option." fi + +if [ "$command" = "split" -a """"! -e "$prefix" ]; then + die "$prefix does not exist." +fi + dir="$(dirname "$prefix/.")" if [ "$command" != "pull" ]; then diff --git a/test.sh b/test.sh index cfe3a3c258..d0a2c86c24 100755 --- a/test.sh +++ b/test.sh @@ -140,6 +140,14 @@ git subtree merge --prefix=subdir FETCH_HEAD git branch pre-split check_equal "$(last_commit_message)" "Merge commit '$(git rev-parse sub2)' into mainline" +# Check that prefix argument is required for split (exits with warning and exit status = 1) +! result=$(git subtree split 2>&1) +check_equal "You must provide the --prefix option." "$result" + +# Check that the exists for a split. +! result=$(git subtree split --prefix=non-existent-directory 2>&1) +check_equal "non-existent-directory does not exist." "$result" + # check if --message works for split+rejoin spl1=$(git subtree split --annotate='*' --prefix subdir --onto FETCH_HEAD --message "Split & rejoin" --rejoin) echo "spl1={$spl1}" From 77ba30585213ee8e2be21841ba38786fd5bb26a5 Mon Sep 17 00:00:00 2001 From: Avery Pennarun Date: Mon, 8 Feb 2010 15:00:42 -0500 Subject: [PATCH 082/291] Improve checking for existence of the --prefix directory. For add, the prefix must *not* already exist. For all the other commands, it *must* already exist. --- git-subtree.sh | 9 ++++++--- test.sh | 15 +++++++++++++++ 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/git-subtree.sh b/git-subtree.sh index 52d4c0aeb1..e76b45c2dd 100755 --- a/git-subtree.sh +++ b/git-subtree.sh @@ -106,9 +106,12 @@ if [ -z "$prefix" ]; then die "You must provide the --prefix option." fi -if [ "$command" = "split" -a """"! -e "$prefix" ]; then - die "$prefix does not exist." -fi +case "$command" in + add) [ -e "$prefix" ] && + die "prefix '$prefix' already exists." ;; + *) [ -e "$prefix" ] || + die "'$prefix' does not exist; use 'git subtree add'" ;; +esac dir="$(dirname "$prefix/.")" diff --git a/test.sh b/test.sh index d0a2c86c24..1446cfeed8 100755 --- a/test.sh +++ b/test.sh @@ -21,6 +21,19 @@ check() fi } +check_not() +{ + echo + echo "check: NOT " "$@" + if "$@"; then + echo FAILED + exit 1 + else + echo ok + return 0 + fi +} + check_equal() { echo @@ -94,6 +107,8 @@ git fetch ../subproj sub1 git branch sub1 FETCH_HEAD # check if --message works for add +check_not git subtree merge --prefix=subdir sub1 +check_not git subtree pull --prefix=subdir ../subproj sub1 git subtree add --prefix=subdir --message="Added subproject" sub1 check_equal "$(last_commit_message)" "Added subproject" undo From 00889c8ca7017d7b9d07d47843e3a3e245a1de26 Mon Sep 17 00:00:00 2001 From: Avery Pennarun Date: Mon, 8 Feb 2010 19:42:15 -0500 Subject: [PATCH 083/291] Oops. Apparently I didn't run 'make test' after most recent change. Thanks to Dan Sabath for pointing that out. --- test.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test.sh b/test.sh index 1446cfeed8..c6ecde20bd 100755 --- a/test.sh +++ b/test.sh @@ -161,7 +161,8 @@ check_equal "You must provide the --prefix option." "$result" # Check that the exists for a split. ! result=$(git subtree split --prefix=non-existent-directory 2>&1) -check_equal "non-existent-directory does not exist." "$result" +check_equal "'non-existent-directory' does not exist; use 'git subtree add'" \ + "$result" # check if --message works for split+rejoin spl1=$(git subtree split --annotate='*' --prefix subdir --onto FETCH_HEAD --message "Split & rejoin" --rejoin) From 6fe986307d983704d3c6b3540f91fa301ff48549 Mon Sep 17 00:00:00 2001 From: Avery Pennarun Date: Mon, 8 Feb 2010 19:44:41 -0500 Subject: [PATCH 084/291] Some recent tests accidentally depended on very new versions of git. The "--format" option is too new. Use "--pretty=format:" (which means the same thing) instead. Now it works again on git 1.6.0 (at least). --- test.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test.sh b/test.sh index c6ecde20bd..8c1f1ea6bd 100755 --- a/test.sh +++ b/test.sh @@ -73,7 +73,7 @@ undo() last_commit_message() { - git log --format=%s -1 + git log --pretty=format:%s -1 } rm -rf mainline subproj @@ -292,7 +292,7 @@ git subtree split --prefix subdir --branch mainsub4 # at this point, the new commit's parent should be sub3 # if it's not, something went wrong (the "newparent" of "master~" commit should have been sub3, # but it wasn't, because it's cache was not set to itself) -check_equal "$(git log --format=%P -1 mainsub4)" "$(git rev-parse sub3)" +check_equal "$(git log --pretty=format:%P -1 mainsub4)" "$(git rev-parse sub3)" From c6ca48d4dc5b93a7576d2afa66b057f8c8a20718 Mon Sep 17 00:00:00 2001 From: Dan Sabath Date: Mon, 8 Feb 2010 20:31:51 -0500 Subject: [PATCH 085/291] docs: add simple 'add' case to clarify setup. This patch adds a simple use case for adding a library to an existing repository. Signed-off-by: Dan Sabath --- git-subtree.txt | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/git-subtree.txt b/git-subtree.txt index 2200aaeaf2..cde5a7e73e 100644 --- a/git-subtree.txt +++ b/git-subtree.txt @@ -225,7 +225,31 @@ OPTIONS FOR split EXAMPLE 1 --------- -Let's use the repository for the git source code as an example. +Let's assume that you have a local repository that you would like +to add an external vendor library to. In this case we will add the +git-subtree repository as a subdirectory of your already existing +git-extensions repository in ~/git-extensions/. + +First we need to fetch the remote objects + $ cd ~/git-extensions + $ git fetch git://github.com/apenwarr/git-subtree.git master + +'master' needs to be a valid remote ref and can be a different branch +name + +Now we add the vendor library with + $ git subtree add --prefix=git-subtree --squash FETCH_HEAD + +You can omit the --squash flag, but doing so will increase the number +of commits that are incldued in your local repository. + +We now have ~/git-extensions/git-subtree directory with the git-subtree +subdirectory containing code from the master branch of +git://github.com/apenwarr/git-subtree.git + +EXAMPLE 2 +--------- +Let's use the repository for the git source code as an example. First, get your own copy of the git.git repository: $ git clone git://git.kernel.org/pub/scm/git/git.git test-git @@ -284,7 +308,7 @@ the standard gitweb: git log gitweb-latest..$(git subtree split --prefix=gitweb) -EXAMPLE 2 +EXAMPLE 3 --------- Suppose you have a source directory with many files and subdirectories, and you want to extract the lib directory to its own From ae3301876cfea3b7260fbe0840635d508968a047 Mon Sep 17 00:00:00 2001 From: Dan Sabath Date: Mon, 8 Feb 2010 17:43:09 -0800 Subject: [PATCH 086/291] Docs: cleaning up example textual redundancy Signed-off-by: Dan Sabath --- git-subtree.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/git-subtree.txt b/git-subtree.txt index cde5a7e73e..c455f6912b 100644 --- a/git-subtree.txt +++ b/git-subtree.txt @@ -243,9 +243,9 @@ Now we add the vendor library with You can omit the --squash flag, but doing so will increase the number of commits that are incldued in your local repository. -We now have ~/git-extensions/git-subtree directory with the git-subtree -subdirectory containing code from the master branch of -git://github.com/apenwarr/git-subtree.git +We now have a ~/git-extensions/git-subtree directory containing code +from the master branch of git://github.com/apenwarr/git-subtree.git +in our git-extensions repository. EXAMPLE 2 --------- From c00d1d11688dc02f066196ed18783effdb7767ab Mon Sep 17 00:00:00 2001 From: Wayne Walter Date: Sat, 13 Feb 2010 14:32:21 -0500 Subject: [PATCH 087/291] Added new 'push' command and 2-parameter form of 'add'. Now you can do: git subtree add --prefix=whatever git://wherever branchname to add a new branch, instead of rather weirdly having to do 'git fetch' first. You can also split and push in one step: git subtree push --prefix=whatever git://wherever newbranch (Somewhat cleaned up by apenwarr.) --- INSTALL | 11 +++++++++- git-subtree.sh | 58 +++++++++++++++++++++++++++++++++++++++++-------- git-subtree.txt | 24 +++++++++++++------- install.sh | 2 ++ 4 files changed, 77 insertions(+), 18 deletions(-) create mode 100644 install.sh diff --git a/INSTALL b/INSTALL index 5966dde46c..81ac702ad2 100644 --- a/INSTALL +++ b/INSTALL @@ -2,7 +2,16 @@ HOW TO INSTALL git-subtree ========================== -Copy the file 'git-subtree.sh' to /usr/local/bin/git-subtree. +You simply need to copy the file 'git-subtree.sh' to where +the rest of the git scripts are stored. + +From the Git bash window just run: + +install.sh + +Or if you have the full Cygwin installed, you can use make: + +make install That will make a 'git subtree' (note: space instead of dash) command available. See the file git-subtree.txt for more. diff --git a/git-subtree.sh b/git-subtree.sh index e76b45c2dd..501c6dc2f1 100755 --- a/git-subtree.sh +++ b/git-subtree.sh @@ -11,6 +11,7 @@ OPTS_SPEC="\ git subtree add --prefix= git subtree merge --prefix= git subtree pull --prefix= +git subtree push --prefix= git subtree split --prefix= -- h,help show the help @@ -24,7 +25,7 @@ b,branch= create a new branch from the split subtree ignore-joins ignore prior --rejoin commits onto= try connecting new tree to an existing one rejoin merge the new branch back into HEAD - options for 'add', 'merge', and 'pull' + options for 'add', 'merge', 'pull' and 'push' squash merge subtree changes as a single commit " eval $(echo "$OPTS_SPEC" | git rev-parse --parseopt -- "$@" || echo exit $?) @@ -98,7 +99,7 @@ command="$1" shift case "$command" in add|merge|pull) default= ;; - split) default="--default HEAD" ;; + split|push) default="--default HEAD" ;; *) die "Unknown command '$command'" ;; esac @@ -115,7 +116,7 @@ esac dir="$(dirname "$prefix/.")" -if [ "$command" != "pull" ]; then +if [ "$command" != "pull" -a "$command" != "add" -a "$command" != "push" ]; then revs=$(git rev-parse $default --revs-only "$@") || exit $? dirs="$(git rev-parse --no-revs --no-flags "$@")" || exit $? if [ -n "$dirs" ]; then @@ -450,10 +451,10 @@ copy_or_skip() ensure_clean() { - if ! git diff-index HEAD --exit-code --quiet; then + if ! git diff-index HEAD --exit-code --quiet 2>&1; then die "Working tree has modifications. Cannot add." fi - if ! git diff-index --cached HEAD --exit-code --quiet; then + if ! git diff-index --cached HEAD --exit-code --quiet 2>&1; then die "Index has modifications. Cannot add." fi } @@ -463,12 +464,34 @@ cmd_add() if [ -e "$dir" ]; then die "'$dir' already exists. Cannot add." fi + ensure_clean - set -- $revs - if [ $# -ne 1 ]; then - die "You must provide exactly one revision. Got: '$revs'" + if [ $# -eq 1 ]; then + "cmd_add_commit" "$@" + elif [ $# -eq 2 ]; then + "cmd_add_repository" "$@" + else + say "error: parameters were '$@'" + die "Provide either a refspec or a repository and refspec." fi +} + +cmd_add_repository() +{ + echo "git fetch" "$@" + repository=$1 + refspec=$2 + git fetch "$@" || exit $? + revs=FETCH_HEAD + set -- $revs + cmd_add_commit "$@" +} + +cmd_add_commit() +{ + revs=$(git rev-parse $default --revs-only "$@") || exit $? + set -- $revs rev="$1" debug "Adding $dir as '$rev'..." @@ -586,6 +609,7 @@ cmd_split() cmd_merge() { + revs=$(git rev-parse $default --revs-only "$@") || exit $? ensure_clean set -- $revs @@ -623,7 +647,23 @@ cmd_pull() ensure_clean git fetch "$@" || exit $? revs=FETCH_HEAD - cmd_merge + set -- $revs + cmd_merge "$@" +} + +cmd_push() +{ + if [ $# -ne 2 ]; then + die "You must provide " + fi + if [ -e "$dir" ]; then + repository=$1 + refspec=$2 + echo "git push using: " $repository $refspec + git push $repository $(git subtree split --prefix=$prefix):refs/heads/$refspec + else + die "'$dir' must already exist. Try 'git subtree add'." + fi } "cmd_$command" "$@" diff --git a/git-subtree.txt b/git-subtree.txt index c455f6912b..4f715c640b 100644 --- a/git-subtree.txt +++ b/git-subtree.txt @@ -9,10 +9,12 @@ git-subtree - add, merge, and split subprojects stored in subtrees SYNOPSIS -------- [verse] -'git subtree' add --prefix= -'git subtree' merge --prefix= +'git subtree' add --prefix= 'git subtree' pull --prefix= -'git subtree' split --prefix= +'git subtree' push --prefix= +'git subtree' add --prefix= +'git subtree' merge --prefix= +'git subtree' split --prefix= DESCRIPTION @@ -60,11 +62,11 @@ COMMANDS -------- add:: Create the subtree by importing its contents - from the given commit. A new commit is created - automatically, joining the imported project's history - with your own. With '--squash', imports only a single - commit from the subproject, rather than its entire - history. + from the given or and remote . + A new commit is created automatically, joining the imported + project's history with your own. With '--squash', imports + only a single commit from the subproject, rather than its + entire history. merge:: Merge recent changes up to into the @@ -84,6 +86,12 @@ pull:: Exactly like 'merge', but parallels 'git pull' in that it fetches the given commit from the specified remote repository. + +push:: + Does a 'split' (see above) using the supplied + and then does a 'git push' to push the result to the + repository and refspec. This can be used to push your + subtree to different branches of the remote repository. split:: Extract a new, synthetic project history from the diff --git a/install.sh b/install.sh new file mode 100644 index 0000000000..1f87a62434 --- /dev/null +++ b/install.sh @@ -0,0 +1,2 @@ +# copy Git to where the rest of the Git scripts are found. +cp git-subtree.sh "$(git --exec-path)"/git-subtree \ No newline at end of file From 448e71e2637e0d7546fb0a2b386e74bc7aa93be8 Mon Sep 17 00:00:00 2001 From: Pelle Wessman Date: Fri, 7 May 2010 21:21:25 +0200 Subject: [PATCH 088/291] Use 'git merge -Xsubtree' when git version >= 1.7.0. It's possible to specify the subdir of a subtree since Git 1.7.0 - adding support for that functionality to make the merge more stable. Also checking for git version - now only uses the new subtree subdir option when on at least 1.7. --- git-subtree.sh | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/git-subtree.sh b/git-subtree.sh index 501c6dc2f1..b7c350107e 100755 --- a/git-subtree.sh +++ b/git-subtree.sh @@ -634,11 +634,20 @@ cmd_merge() debug "New squash commit: $new" rev="$new" fi - - if [ -n "$message" ]; then - git merge -s subtree --message="$message" $rev + + version=$(git version) + if [ "$version" \< "git version 1.7" ]; then + if [ -n "$message" ]; then + git merge -s subtree --message="$message" $rev + else + git merge -s subtree $rev + fi else - git merge -s subtree $rev + if [ -n "$message" ]; then + git merge -Xsubtree="$prefix" --message="$message" $rev + else + git merge -Xsubtree="$prefix" $rev + fi fi } From 39f5fff0d53bcc68f5c698150d2d3b35eececc27 Mon Sep 17 00:00:00 2001 From: Pelle Wessman Date: Thu, 20 May 2010 22:40:09 +0200 Subject: [PATCH 089/291] Fixed regression with splitting out new subtree A folder in a repository that wasn't initially imported as a subtree could no longer be splitted into an entirely new subtree with no parent. A fix and a new test to fix that regression is added here. --- git-subtree.sh | 5 ++++- test.sh | 9 +++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/git-subtree.sh b/git-subtree.sh index b7c350107e..a86cfd8b9f 100755 --- a/git-subtree.sh +++ b/git-subtree.sh @@ -253,6 +253,7 @@ find_existing_splits() if [ -n "$main" -a -n "$sub" ]; then debug " Prior: $main -> $sub" cache_set $main $sub + cache_set $sub $sub try_remove_previous "$main" try_remove_previous "$sub" fi @@ -569,7 +570,9 @@ cmd_split() # ugly. is there no better way to tell if this is a subtree # vs. a mainline commit? Does it matter? if [ -z $tree ]; then - cache_set $rev $rev + if [ -n "$newparents" ]; then + cache_set $rev $rev + fi continue fi diff --git a/test.sh b/test.sh index 8c1f1ea6bd..45237c3374 100755 --- a/test.sh +++ b/test.sh @@ -294,6 +294,15 @@ git subtree split --prefix subdir --branch mainsub4 # but it wasn't, because it's cache was not set to itself) check_equal "$(git log --pretty=format:%P -1 mainsub4)" "$(git rev-parse sub3)" +mkdir subdir2 +create subdir2/main-sub5 +git commit -m "main-sub5" +git subtree split --prefix subdir2 --branch mainsub5 + +# also test that we still can split out an entirely new subtree +# if the parent of the first commit in the tree isn't empty, +# then the new subtree has accidently been attached to something +check_equal "$(git log --pretty=format:%P -1 mainsub5)" "" # make sure no patch changes more than one file. The original set of commits From 9c632ea29ccd58a9967690c2670edec31dc468cd Mon Sep 17 00:00:00 2001 From: Avery Pennarun Date: Thu, 24 Jun 2010 01:53:05 -0400 Subject: [PATCH 090/291] (Hopefully) fix PATH setting for msysgit. Reported by Evan Shaw. The problem is that $(git --exec-path) includes a 'git' binary which is incompatible with the one in /usr/bin; if you run it, it gives you an error about libiconv2.dll. You might think we could just add $(git --exec-path) at the *end* of PATH, but then if there are multiple versions of git installed, we could end up with the wrong one; earlier versions used to put git-sh-setup in /usr/bin, so we'd pick up that one before the new one. So now we just set PATH back to its original value right after running git-sh-setup, and we should be okay. --- git-subtree.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/git-subtree.sh b/git-subtree.sh index 501c6dc2f1..935dfca7f3 100755 --- a/git-subtree.sh +++ b/git-subtree.sh @@ -29,8 +29,12 @@ rejoin merge the new branch back into HEAD squash merge subtree changes as a single commit " eval $(echo "$OPTS_SPEC" | git rev-parse --parseopt -- "$@" || echo exit $?) + +OPATH=$PATH PATH=$(git --exec-path):$PATH . git-sh-setup +PATH=$OPATH # apparently needed for some versions of msysgit + require_work_tree quiet= From df2302d77449832eb4167999d747aef57e4bd1fc Mon Sep 17 00:00:00 2001 From: Avery Pennarun Date: Thu, 24 Jun 2010 16:57:58 -0400 Subject: [PATCH 091/291] Another fix for PATH and msysgit. Evan Shaw tells me the previous fix didn't work. Let's use this one instead, which he says does work. This fix is kind of wrong because it will run the "correct" git-sh-setup *after* the one in /usr/bin, if there is one, which could be weird if you have multiple versions of git installed. But it works on my Linux and his msysgit, so it's obviously better than what we had before. --- git-subtree.sh | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/git-subtree.sh b/git-subtree.sh index a15d91ffb1..781eef3783 100755 --- a/git-subtree.sh +++ b/git-subtree.sh @@ -30,10 +30,8 @@ squash merge subtree changes as a single commit " eval $(echo "$OPTS_SPEC" | git rev-parse --parseopt -- "$@" || echo exit $?) -OPATH=$PATH -PATH=$(git --exec-path):$PATH +PATH=$PATH:$(git --exec-path) . git-sh-setup -PATH=$OPATH # apparently needed for some versions of msysgit require_work_tree From 242b20dc0ae51719c32776fb5996c5d6cb463928 Mon Sep 17 00:00:00 2001 From: Bryan Larsen Date: Wed, 21 Jul 2010 12:58:05 -0400 Subject: [PATCH 092/291] docs: simplify example 1 The documentation was written prior to Wayne Walter's 2-parameter add. Using 2-parameter add in example 1 makes the example much simpler. --- git-subtree.txt | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/git-subtree.txt b/git-subtree.txt index 4f715c640b..dbcba31346 100644 --- a/git-subtree.txt +++ b/git-subtree.txt @@ -236,18 +236,14 @@ EXAMPLE 1 Let's assume that you have a local repository that you would like to add an external vendor library to. In this case we will add the git-subtree repository as a subdirectory of your already existing -git-extensions repository in ~/git-extensions/. +git-extensions repository in ~/git-extensions/: -First we need to fetch the remote objects - $ cd ~/git-extensions - $ git fetch git://github.com/apenwarr/git-subtree.git master + $ git subtree add --prefix=git-subtree --squash \ + git://github.com/apenwarr/git-subtree.git master 'master' needs to be a valid remote ref and can be a different branch name -Now we add the vendor library with - $ git subtree add --prefix=git-subtree --squash FETCH_HEAD - You can omit the --squash flag, but doing so will increase the number of commits that are incldued in your local repository. From 7f74d65b12ecb5142442c276da805b42e3023a9d Mon Sep 17 00:00:00 2001 From: Avery Pennarun Date: Thu, 12 Aug 2010 11:15:57 -0400 Subject: [PATCH 093/291] Fix typo: an -> a Thanks to Vanuan on github. --- git-subtree.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git-subtree.txt b/git-subtree.txt index dbcba31346..a30293d607 100644 --- a/git-subtree.txt +++ b/git-subtree.txt @@ -19,7 +19,7 @@ SYNOPSIS DESCRIPTION ----------- -git subtree allows you to include an subproject in your +git subtree allows you to include a subproject in your own repository as a subdirectory, optionally including the subproject's entire history. For example, you could include the source code for a library as a subdirectory of your From 11f1511e7650a78709d0d7198bb150cd5392d9d1 Mon Sep 17 00:00:00 2001 From: Cole Stanfield Date: Mon, 13 Sep 2010 13:16:57 -0600 Subject: [PATCH 094/291] Fixing eval syntax error. --- git-subtree.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git-subtree.sh b/git-subtree.sh index 781eef3783..ce94d363dc 100755 --- a/git-subtree.sh +++ b/git-subtree.sh @@ -28,7 +28,7 @@ rejoin merge the new branch back into HEAD options for 'add', 'merge', 'pull' and 'push' squash merge subtree changes as a single commit " -eval $(echo "$OPTS_SPEC" | git rev-parse --parseopt -- "$@" || echo exit $?) +eval "$(echo "$OPTS_SPEC" | git rev-parse --parseopt -- "$@" || echo exit $?)" PATH=$PATH:$(git --exec-path) . git-sh-setup From 7f86ff0fe292a5061757f3ceaffdd992c5feaa9f Mon Sep 17 00:00:00 2001 From: John Yani Date: Thu, 12 Aug 2010 19:54:55 +0300 Subject: [PATCH 095/291] docs: Description, synopsys, options and examples changes. Description: Made the difference from submodules and the subtree merge strategy clearer. Synopsys and options: Synchronize with 'git subtree -h' output. I hope, properly. Examples: Added example descriptions in captions. Small fixes. Signed-off-by: John Yani --- git-subtree.txt | 110 ++++++++++++++++++++++++++++++------------------ 1 file changed, 68 insertions(+), 42 deletions(-) diff --git a/git-subtree.txt b/git-subtree.txt index a30293d607..18a9af501f 100644 --- a/git-subtree.txt +++ b/git-subtree.txt @@ -3,50 +3,55 @@ git-subtree(1) NAME ---- -git-subtree - add, merge, and split subprojects stored in subtrees +git-subtree - Merge subtrees together and split repository into subtrees SYNOPSIS -------- [verse] -'git subtree' add --prefix= -'git subtree' pull --prefix= -'git subtree' push --prefix= -'git subtree' add --prefix= -'git subtree' merge --prefix= -'git subtree' split --prefix= - +'git subtree' add -P |--prefix= +'git subtree' pull -P |--prefix= +'git subtree' push -P |--prefix= +'git subtree' merge -P |--prefix= +'git subtree' split -P |--prefix= [OPTIONS] [] + DESCRIPTION ----------- -git subtree allows you to include a subproject in your -own repository as a subdirectory, optionally including the -subproject's entire history. For example, you could -include the source code for a library as a subdirectory of your -application. +Subtrees allow subprojects to be included within a subdirectory +of the main project, optionally including the subproject's +entire history. -You can also extract the entire history of a subdirectory from -your project and make it into a standalone project. For -example, if a library you made for one application ends up being -useful elsewhere, you can extract its entire history and publish -that as its own git repository, without accidentally -intermingling the history of your application project. +For example, you could include the source code for a library +as a subdirectory of your application. -Most importantly, you can alternate back and forth between these -two operations. If the standalone library gets updated, you can +Subtrees are not to be confused with submodules, which are meant for +the same task. Unlike submodules, subtrees do not need any special +constructions (like .gitmodule files or gitlinks) be present in +your repository, and do not force end-users of your +repository to do anything special or to understand how subtrees +work. A subtree is just a subdirectory that can be +committed to, branched, and merged along with your project in +any way you want. + +They are neither not to be confused with using the subtree merge +strategy. The main difference is that, besides merging +of the other project as a subdirectory, you can also extract the +entire history of a subdirectory from your project and make it +into a standalone project. Unlike the subtree merge strategy +you can alternate back and forth between these +two operations. If the standalone library gets updated, you can automatically merge the changes into your project; if you update the library inside your project, you can "split" the changes back out again and merge them back into the library project. -Unlike the 'git submodule' command, git subtree doesn't produce -any special constructions (like .gitmodule files or gitlinks) in -your repository, and doesn't require end-users of your -repository to do anything special or to understand how subtrees -work. A subtree is just another subdirectory and can be -committed to, branched, and merged along with your project in -any way you want. +For example, if a library you made for one application ends up being +useful elsewhere, you can extract its entire history and publish +that as its own git repository, without accidentally +intermingling the history of your application project. +[TIP] In order to keep your commit messages clean, we recommend that people split their commits between the subtrees and the main project as much as possible. That is, if you make a change that @@ -128,20 +133,29 @@ OPTIONS --debug:: Produce even more unnecessary output messages on stderr. +-P :: --prefix=:: Specify the path in the repository to the subtree you - want to manipulate. This option is currently mandatory + want to manipulate. This option is mandatory for all commands. +-m :: +--message=:: + This option is only valid for add, merge and pull (unsure). + Specify as the commit message for the merge commit. -OPTIONS FOR add, merge, AND pull --------------------------------- + +OPTIONS FOR add, merge, push, pull +---------------------------------- --squash:: + This option is only valid for add, merge, push and pull + commands. + Instead of merging the entire history from the subtree project, produce only a single commit that contains all the differences you want to merge, and then merge that new commit into your project. - + Using this option helps to reduce log clutter. People rarely want to see every change that happened between v1.0 and v1.1 of the library they're using, since none of the @@ -169,6 +183,8 @@ OPTIONS FOR add, merge, AND pull OPTIONS FOR split ----------------- --annotate=:: + This option is only valid for the split command. + When generating synthetic history, add as a prefix to each commit message. Since we're creating new commits with the same commit message, but possibly @@ -184,12 +200,16 @@ OPTIONS FOR split -b :: --branch=:: + This option is only valid for the split command. + After generating the synthetic history, create a new branch called that contains the new history. This is suitable for immediate pushing upstream. must not already exist. --ignore-joins:: + This option is only valid for the split command. + If you use '--rejoin', git subtree attempts to optimize its history reconstruction to generate only the new commits since the last '--rejoin'. '--ignore-join' @@ -198,6 +218,8 @@ OPTIONS FOR split long time. --onto=:: + This option is only valid for the split command. + If your subtree was originally imported using something other than git subtree, its history may not match what git subtree is expecting. In that case, you can specify @@ -210,6 +232,8 @@ OPTIONS FOR split this option. --rejoin:: + This option is only valid for the split command. + After splitting, merge the newly created synthetic history back into your main project. That way, future splits can search only the part of history that has @@ -231,8 +255,8 @@ OPTIONS FOR split subproject's history to be part of your project anyway. -EXAMPLE 1 ---------- +EXAMPLE 1. Add command +---------------------- Let's assume that you have a local repository that you would like to add an external vendor library to. In this case we will add the git-subtree repository as a subdirectory of your already existing @@ -251,8 +275,8 @@ We now have a ~/git-extensions/git-subtree directory containing code from the master branch of git://github.com/apenwarr/git-subtree.git in our git-extensions repository. -EXAMPLE 2 ---------- +EXAMPLE 2. Extract a subtree using commit, merge and pull +--------------------------------------------------------- Let's use the repository for the git source code as an example. First, get your own copy of the git.git repository: @@ -312,22 +336,24 @@ the standard gitweb: git log gitweb-latest..$(git subtree split --prefix=gitweb) -EXAMPLE 3 ---------- +EXAMPLE 3. Extract a subtree using branch +----------------------------------------- Suppose you have a source directory with many files and subdirectories, and you want to extract the lib directory to its own git project. Here's a short way to do it: First, make the new repository wherever you want: - - git init --bare + + $ + $ git init --bare Back in your original directory: - git subtree split --prefix=lib --annotate="(split)" -b split + + $ git subtree split --prefix=lib --annotate="(split)" -b split Then push the new branch onto the new empty repository: - git push split:master + $ git push split:master AUTHOR From 9a40fcc2014cc4a85eca71f81ff4c86d49b7a9e2 Mon Sep 17 00:00:00 2001 From: Avery Pennarun Date: Thu, 21 Oct 2010 12:28:18 -0700 Subject: [PATCH 096/291] Fix a few typos/grammar-o's in the preceding commit. --- git-subtree.txt | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/git-subtree.txt b/git-subtree.txt index 18a9af501f..0c44fda011 100644 --- a/git-subtree.txt +++ b/git-subtree.txt @@ -9,11 +9,11 @@ git-subtree - Merge subtrees together and split repository into subtrees SYNOPSIS -------- [verse] -'git subtree' add -P |--prefix= -'git subtree' pull -P |--prefix= -'git subtree' push -P |--prefix= -'git subtree' merge -P |--prefix= -'git subtree' split -P |--prefix= [OPTIONS] [] +'git subtree' add -P +'git subtree' pull -P +'git subtree' push -P +'git subtree' merge -P +'git subtree' split -P [OPTIONS] [] DESCRIPTION @@ -34,9 +34,9 @@ work. A subtree is just a subdirectory that can be committed to, branched, and merged along with your project in any way you want. -They are neither not to be confused with using the subtree merge +They are also not to be confused with using the subtree merge strategy. The main difference is that, besides merging -of the other project as a subdirectory, you can also extract the +the other project as a subdirectory, you can also extract the entire history of a subdirectory from your project and make it into a standalone project. Unlike the subtree merge strategy you can alternate back and forth between these From 6f4f84fa2a03f441826f323c291ca6566acd0d3a Mon Sep 17 00:00:00 2001 From: Jesse Greenwald Date: Tue, 9 Nov 2010 08:34:49 -0600 Subject: [PATCH 097/291] Split cmd now processes commits in topo order. Added the "--topo-order" option to git rev-list. Without this, it seems that the revision list is coming back in reverse order but it is sorted chronologically. This does not gurantee that parent commits are handled before child commits. --- git-subtree.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git-subtree.sh b/git-subtree.sh index ce94d363dc..390c0fc574 100755 --- a/git-subtree.sh +++ b/git-subtree.sh @@ -547,7 +547,7 @@ cmd_split() # 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) - grl='git rev-list --reverse --parents $revs $unrevs' + grl='git rev-list --topo-order --reverse --parents $revs $unrevs' revmax=$(eval "$grl" | wc -l) revcount=0 createcount=0 From 915b9894abe94169e60a14e4dc671f6bd15131f3 Mon Sep 17 00:00:00 2001 From: Jesse Greenwald Date: Tue, 9 Nov 2010 22:18:36 -0600 Subject: [PATCH 098/291] Added check to order of processed commits. With debug messages enabled, "incorrect order" will be output whenever a commit is processed before its parents have been processed. This can be determined by checking to see if a parent isn't mapped to a new commit, but it has been processed. --- git-subtree.sh | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/git-subtree.sh b/git-subtree.sh index 390c0fc574..cf50de150c 100755 --- a/git-subtree.sh +++ b/git-subtree.sh @@ -138,6 +138,7 @@ cache_setup() cachedir="$GIT_DIR/subtree-cache/$$" rm -rf "$cachedir" || die "Can't delete old cachedir: $cachedir" mkdir -p "$cachedir" || die "Can't create new cachedir: $cachedir" + mkdir -p "$cachedir/notree" || die "Can't create new cachedir: $cachedir/notree" debug "Using cachedir: $cachedir" >&2 } @@ -151,6 +152,30 @@ cache_get() done } +cache_miss() +{ + for oldrev in $*; do + if [ ! -r "$cachedir/$oldrev" ]; then + echo $oldrev + fi + done +} + +check_parents() +{ + missed=$(cache_miss $*) + for miss in $missed; do + if [ ! -r "$cachedir/notree/$miss" ]; then + debug " incorrect order: $miss" + fi + done +} + +set_notree() +{ + echo "1" > "$cachedir/notree/$1" +} + cache_set() { oldrev="$1" @@ -568,10 +593,13 @@ cmd_split() tree=$(subtree_for_commit $rev "$dir") debug " tree is: $tree" + + check_parents $parents # ugly. is there no better way to tell if this is a subtree # vs. a mainline commit? Does it matter? if [ -z $tree ]; then + set_notree $rev if [ -n "$newparents" ]; then cache_set $rev $rev fi From 856bea1f71db30339539b0c917d6d7dc32729d0f Mon Sep 17 00:00:00 2001 From: Avery Pennarun Date: Mon, 28 Feb 2011 16:49:42 -0800 Subject: [PATCH 099/291] It's also okay if an expected tree object is actually a commit. ...that happens with submodules sometimes, so don't panic. Reported by Sum-Wai Low. --- git-subtree.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git-subtree.sh b/git-subtree.sh index cf50de150c..fa4e3e3661 100755 --- a/git-subtree.sh +++ b/git-subtree.sh @@ -397,7 +397,7 @@ subtree_for_commit() git ls-tree "$commit" -- "$dir" | while read mode type tree name; do assert [ "$name" = "$dir" ] - assert [ "$type" = "tree" ] + assert [ "$type" = "tree" -o "$type" = "commit" ] echo $tree break done From 2793ee6ba6da57d97e9c313741041f7eb2e88974 Mon Sep 17 00:00:00 2001 From: Avery Pennarun Date: Mon, 28 Feb 2011 20:48:50 -0800 Subject: [PATCH 100/291] Skip commit objects that should be trees, rather than copying them. An improvement on the previous patch, based on more reports from Sum-Wai Low. --- git-subtree.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/git-subtree.sh b/git-subtree.sh index fa4e3e3661..920c664bb7 100755 --- a/git-subtree.sh +++ b/git-subtree.sh @@ -398,6 +398,7 @@ subtree_for_commit() while read mode type tree name; do assert [ "$name" = "$dir" ] assert [ "$type" = "tree" -o "$type" = "commit" ] + [ "$type" = "commit" ] && continue # ignore submodules echo $tree break done From 9153f19f6d340b97c7d581d44884b6318e627155 Mon Sep 17 00:00:00 2001 From: "David A. Greene" Date: Sun, 29 Jan 2012 15:57:36 -0600 Subject: [PATCH 101/291] Move Tests Into Subdirectory Move the git-subtree tests into a "t" subdir to reflect how testing works at the top level. Signed-off-by: David A. Greene --- test.sh => t/test.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename test.sh => t/test.sh (100%) diff --git a/test.sh b/t/test.sh similarity index 100% rename from test.sh rename to t/test.sh From 9e2a55a276df9647d0f79c0695e23e5164835c0d Mon Sep 17 00:00:00 2001 From: "David A. Greene" Date: Sun, 29 Jan 2012 16:09:15 -0600 Subject: [PATCH 102/291] Rename Test Rename the subtree test file to conform with git project conventions. Signed-off-by: David A. Greene --- t/{test.sh => t7900-subtree.sh} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename t/{test.sh => t7900-subtree.sh} (100%) diff --git a/t/test.sh b/t/t7900-subtree.sh similarity index 100% rename from t/test.sh rename to t/t7900-subtree.sh From d3a04e06c77d57978bb5230361c64946232cc346 Mon Sep 17 00:00:00 2001 From: "David A. Greene" Date: Sun, 29 Jan 2012 16:09:58 -0600 Subject: [PATCH 103/291] Use Test Harness Clean up the git-subtree tests to conform the git project conventions and use the existing test harness. Signed-off-by: David A. Greene --- t/t7900-subtree.sh | 572 +++++++++++++++++++++++++++++---------------- 1 file changed, 368 insertions(+), 204 deletions(-) diff --git a/t/t7900-subtree.sh b/t/t7900-subtree.sh index 45237c3374..585f8d5751 100755 --- a/t/t7900-subtree.sh +++ b/t/t7900-subtree.sh @@ -1,6 +1,14 @@ -#!/bin/bash -. shellopts.sh -set -e +#!/bin/sh +# +# Copyright (c) 2012 Avery Pennaraum +# +test_description='Basic porcelain support for subtrees + +This test verifies the basic operation of the merge, pull, add +and split subcommands of git subtree. +' + +. ./test-lib.sh create() { @@ -8,42 +16,16 @@ create() git add "$1" } -check() -{ - echo - echo "check:" "$@" - if "$@"; then - echo ok - return 0 - else - echo FAILED - exit 1 - fi -} - -check_not() -{ - echo - echo "check: NOT " "$@" - if "$@"; then - echo FAILED - exit 1 - else - echo ok - return 0 - fi -} check_equal() { - echo - echo "check a:" "{$1}" - echo " b:" "{$2}" + test_debug 'echo' + test_debug "echo \"check a:\" \"{$1}\"" + test_debug "echo \" b:\" \"{$2}\"" if [ "$1" = "$2" ]; then return 0 else - echo FAILED - exit 1 + return 1 fi } @@ -76,144 +58,257 @@ last_commit_message() git log --pretty=format:%s -1 } -rm -rf mainline subproj -mkdir mainline subproj +# 1 +test_expect_success 'init subproj' ' + test_create_repo subproj +' +# To the subproject! cd subproj -git init -create sub1 -git commit -m 'sub1' -git branch sub1 -git branch -m master subproj -check true +# 2 +test_expect_success 'add sub1' ' + create sub1 && + git commit -m "sub1" && + git branch sub1 && + git branch -m master subproj +' -create sub2 -git commit -m 'sub2' -git branch sub2 +# 3 +test_expect_success 'add sub2' ' + create sub2 && + git commit -m "sub2" && + git branch sub2 +' -create sub3 -git commit -m 'sub3' -git branch sub3 +# 4 +test_expect_success 'add sub3' ' + create sub3 && + git commit -m "sub3" && + git branch sub3 +' -cd ../mainline -git init -create main4 -git commit -m 'main4' -git branch -m master mainline -git branch subdir +# Back to mainline +cd .. -git fetch ../subproj sub1 -git branch sub1 FETCH_HEAD +# 5 +test_expect_success 'add main4' ' + create main4 && + git commit -m "main4" && + git branch -m master mainline && + git branch subdir +' -# check if --message works for add -check_not git subtree merge --prefix=subdir sub1 -check_not git subtree pull --prefix=subdir ../subproj sub1 -git subtree add --prefix=subdir --message="Added subproject" sub1 -check_equal "$(last_commit_message)" "Added subproject" -undo +# 6 +test_expect_success 'fetch subproj history' ' + git fetch ./subproj sub1 && + git branch sub1 FETCH_HEAD +' -# check if --message works as -m and --prefix as -P -git subtree add -P subdir -m "Added subproject using git subtree" sub1 -check_equal "$(last_commit_message)" "Added subproject using git subtree" -undo +# 7 +test_expect_success 'no subtree exists in main tree' ' + test_must_fail git subtree merge --prefix=subdir sub1 +' -# check if --message works with squash too -git subtree add -P subdir -m "Added subproject with squash" --squash sub1 -check_equal "$(last_commit_message)" "Added subproject with squash" -undo +# 8 +test_expect_success 'no pull from non-existant subtree' ' + test_must_fail git subtree pull --prefix=subdir ./subproj sub1 +' -git subtree add --prefix=subdir/ FETCH_HEAD -check_equal "$(last_commit_message)" "Add 'subdir/' from commit '$(git rev-parse sub1)'" +# 9 +test_expect_success 'check if --message works for add' ' + git subtree add --prefix=subdir --message="Added subproject" sub1 && + check_equal ''"$(last_commit_message)"'' "Added subproject" && + undo +' +# 10 +test_expect_success 'check if --message works as -m and --prefix as -P' ' + git subtree add -P subdir -m "Added subproject using git subtree" sub1 && + check_equal ''"$(last_commit_message)"'' "Added subproject using git subtree" && + undo +' + +# 11 +test_expect_success 'check if --message works with squash too' ' + git subtree add -P subdir -m "Added subproject with squash" --squash sub1 && + check_equal ''"$(last_commit_message)"'' "Added subproject with squash" && + undo +' + +# 12 +test_expect_success 'add subproj to mainline' ' + git subtree add --prefix=subdir/ FETCH_HEAD && + check_equal ''"$(last_commit_message)"'' "Add '"'subdir/'"' from commit '"'"'''"$(git rev-parse sub1)"'''"'"'" +' + +# 13 # this shouldn't actually do anything, since FETCH_HEAD is already a parent -git merge -m 'merge -s -ours' -s ours FETCH_HEAD +test_expect_success 'merge fetched subproj' ' + git merge -m "merge -s -ours" -s ours FETCH_HEAD +' -create subdir/main-sub5 -git commit -m 'main-sub5' +# 14 +test_expect_success 'add main-sub5' ' + create subdir/main-sub5 && + git commit -m "main-sub5" +' -create main6 -git commit -m 'main6 boring' +# 15 +test_expect_success 'add main6' ' + create main6 && + git commit -m "main6 boring" +' -create subdir/main-sub7 -git commit -m 'main-sub7' +# 16 +test_expect_success 'add main-sub7' ' + create subdir/main-sub7 && + git commit -m "main-sub7" +' -git fetch ../subproj sub2 -git branch sub2 FETCH_HEAD +# 17 +test_expect_success 'fetch new subproj history' ' + git fetch ./subproj sub2 && + git branch sub2 FETCH_HEAD +' -# check if --message works for merge -git subtree merge --prefix=subdir -m "Merged changes from subproject" sub2 -check_equal "$(last_commit_message)" "Merged changes from subproject" -undo +# 18 +test_expect_success 'check if --message works for merge' ' + git subtree merge --prefix=subdir -m "Merged changes from subproject" sub2 && + check_equal ''"$(last_commit_message)"'' "Merged changes from subproject" && + undo +' -# check if --message for merge works with squash too -git subtree merge --prefix subdir -m "Merged changes from subproject using squash" --squash sub2 -check_equal "$(last_commit_message)" "Merged changes from subproject using squash" -undo +# 19 +test_expect_success 'check if --message for merge works with squash too' ' + git subtree merge --prefix subdir -m "Merged changes from subproject using squash" --squash sub2 && + check_equal ''"$(last_commit_message)"'' "Merged changes from subproject using squash" && + undo +' -git subtree merge --prefix=subdir FETCH_HEAD -git branch pre-split -check_equal "$(last_commit_message)" "Merge commit '$(git rev-parse sub2)' into mainline" +# 20 +test_expect_success 'merge new subproj history into subdir' ' + git subtree merge --prefix=subdir FETCH_HEAD && + git branch pre-split && + check_equal ''"$(last_commit_message)"'' "Merge commit '"'"'"$(git rev-parse sub2)"'"'"' into mainline" +' -# Check that prefix argument is required for split (exits with warning and exit status = 1) -! result=$(git subtree split 2>&1) -check_equal "You must provide the --prefix option." "$result" +# 21 +test_expect_success 'Check that prefix argument is required for split' ' + echo "You must provide the --prefix option." > expected && + test_must_fail git subtree split > actual 2>&1 && + test_debug "echo -n expected: " && + test_debug "cat expected" && + test_debug "echo -n actual: " && + test_debug "cat actual" && + test_cmp expected actual && + rm -f expected actual +' -# Check that the exists for a split. -! result=$(git subtree split --prefix=non-existent-directory 2>&1) -check_equal "'non-existent-directory' does not exist; use 'git subtree add'" \ - "$result" +# 22 +test_expect_success 'Check that the exists for a split' ' + echo "'"'"'non-existent-directory'"'"'" does not exist\; use "'"'"'git subtree add'"'"'" > expected && + test_must_fail git subtree split --prefix=non-existent-directory > actual 2>&1 && + test_debug "echo -n expected: " && + test_debug "cat expected" && + test_debug "echo -n actual: " && + test_debug "cat actual" && + test_cmp expected actual +# rm -f expected actual +' -# check if --message works for split+rejoin -spl1=$(git subtree split --annotate='*' --prefix subdir --onto FETCH_HEAD --message "Split & rejoin" --rejoin) -echo "spl1={$spl1}" -git branch spl1 "$spl1" -check_equal "$(last_commit_message)" "Split & rejoin" -undo +# 23 +test_expect_success 'check if --message works for split+rejoin' ' + spl1=''"$(git subtree split --annotate='"'*'"' --prefix subdir --onto FETCH_HEAD --message "Split & rejoin" --rejoin)"'' && + git branch spl1 "$spl1" && + check_equal ''"$(last_commit_message)"'' "Split & rejoin" && + undo +' -# check split with --branch -git subtree split --annotate='*' --prefix subdir --onto FETCH_HEAD --branch splitbr1 -check_equal "$(git rev-parse splitbr1)" "$spl1" +# 24 +test_expect_success 'check split with --branch' ' + spl1=$(git subtree split --annotate='"'*'"' --prefix subdir --onto FETCH_HEAD --message "Split & rejoin" --rejoin) && + undo && + git subtree split --annotate='"'*'"' --prefix subdir --onto FETCH_HEAD --branch splitbr1 && + check_equal ''"$(git rev-parse splitbr1)"'' "$spl1" +' -# check split with --branch for an existing branch -git branch splitbr2 sub1 -git subtree split --annotate='*' --prefix subdir --onto FETCH_HEAD --branch splitbr2 -check_equal "$(git rev-parse splitbr2)" "$spl1" +# 25 +test_expect_success 'check split with --branch for an existing branch' ' + spl1=''"$(git subtree split --annotate='"'*'"' --prefix subdir --onto FETCH_HEAD --message "Split & rejoin" --rejoin)"'' && + undo && + git branch splitbr2 sub1 && + git subtree split --annotate='"'*'"' --prefix subdir --onto FETCH_HEAD --branch splitbr2 && + check_equal ''"$(git rev-parse splitbr2)"'' "$spl1" +' -# check split with --branch for an incompatible branch -result=$(git subtree split --prefix subdir --onto FETCH_HEAD --branch subdir || echo "caught error") -check_equal "$result" "caught error" +# 26 +test_expect_success 'check split with --branch for an incompatible branch' ' + test_must_fail git subtree split --prefix subdir --onto FETCH_HEAD --branch subdir +' -git subtree split --annotate='*' --prefix subdir --onto FETCH_HEAD --rejoin -check_equal "$(last_commit_message)" "Split 'subdir/' into commit '$spl1'" +# 27 +test_expect_success 'check split+rejoin' ' + spl1=''"$(git subtree split --annotate='"'*'"' --prefix subdir --onto FETCH_HEAD --message "Split & rejoin" --rejoin)"'' && + undo && + git subtree split --annotate='"'*'"' --prefix subdir --onto FETCH_HEAD --rejoin && + check_equal ''"$(last_commit_message)"'' "Split '"'"'subdir/'"'"' into commit '"'"'"$spl1"'"'"'" +' -create subdir/main-sub8 -git commit -m 'main-sub8' +# 28 +test_expect_success 'add main-sub8' ' + create subdir/main-sub8 && + git commit -m "main-sub8" +' -cd ../subproj -git fetch ../mainline spl1 -git branch spl1 FETCH_HEAD -git merge FETCH_HEAD +# To the subproject! +cd ./subproj -create sub9 -git commit -m 'sub9' +# 29 +test_expect_success 'merge split into subproj' ' + git fetch .. spl1 && + git branch spl1 FETCH_HEAD && + git merge FETCH_HEAD +' -cd ../mainline -split2=$(git subtree split --annotate='*' --prefix subdir/ --rejoin) -git branch split2 "$split2" +# 30 +test_expect_success 'add sub9' ' + create sub9 && + git commit -m "sub9" +' -create subdir/main-sub10 -git commit -m 'main-sub10' +# Back to mainline +cd .. -spl3=$(git subtree split --annotate='*' --prefix subdir --rejoin) -git branch spl3 "$spl3" +# 31 +test_expect_success 'split for sub8' ' + split2=''"$(git subtree split --annotate='"'*'"' --prefix subdir/ --rejoin)"'' + git branch split2 "$split2" +' -cd ../subproj -git fetch ../mainline spl3 -git branch spl3 FETCH_HEAD -git merge FETCH_HEAD -git branch subproj-merge-spl3 +# 32 +test_expect_success 'add main-sub10' ' + create subdir/main-sub10 && + git commit -m "main-sub10" +' + +# 33 +test_expect_success 'split for sub10' ' + spl3=''"$(git subtree split --annotate='"'*'"' --prefix subdir --rejoin)"'' && + git branch spl3 "$spl3" +' + +# To the subproject! +cd ./subproj + +# 34 +test_expect_success 'merge split into subproj' ' + git fetch .. spl3 && + git branch spl3 FETCH_HEAD && + git merge FETCH_HEAD && + git branch subproj-merge-spl3 +' chkm="main4 main6" chkms="main-sub10 main-sub5 main-sub7 main-sub8" @@ -221,89 +316,150 @@ chkms_sub=$(echo $chkms | multiline | sed 's,^,subdir/,' | fixnl) chks="sub1 sub2 sub3 sub9" chks_sub=$(echo $chks | multiline | sed 's,^,subdir/,' | fixnl) -# make sure exactly the right set of files ends up in the subproj -subfiles=$(git ls-files | fixnl) -check_equal "$subfiles" "$chkms $chks" +# 35 +test_expect_success 'make sure exactly the right set of files ends up in the subproj' ' + subfiles=''"$(git ls-files | fixnl)"'' && + check_equal "$subfiles" "$chkms $chks" +' -# make sure the subproj history *only* contains commits that affect the subdir. -allchanges=$(git log --name-only --pretty=format:'' | sort | fixnl) -check_equal "$allchanges" "$chkms $chks" +# 36 +test_expect_success 'make sure the subproj history *only* contains commits that affect the subdir' ' + allchanges=''"$(git log --name-only --pretty=format:'"''"' | sort | fixnl)"'' && + check_equal "$allchanges" "$chkms $chks" +' -cd ../mainline -git fetch ../subproj subproj-merge-spl3 -git branch subproj-merge-spl3 FETCH_HEAD -git subtree pull --prefix=subdir ../subproj subproj-merge-spl3 +# Back to mainline +cd .. -# make sure exactly the right set of files ends up in the mainline -mainfiles=$(git ls-files | fixnl) -check_equal "$mainfiles" "$chkm $chkms_sub $chks_sub" +# 37 +test_expect_success 'pull from subproj' ' + git fetch ./subproj subproj-merge-spl3 && + git branch subproj-merge-spl3 FETCH_HEAD && + git subtree pull --prefix=subdir ./subproj subproj-merge-spl3 +' -# make sure each filename changed exactly once in the entire history. -# 'main-sub??' and '/subdir/main-sub??' both change, because those are the -# changes that were split into their own history. And 'subdir/sub??' never -# change, since they were *only* changed in the subtree branch. -allchanges=$(git log --name-only --pretty=format:'' | sort | fixnl) -check_equal "$allchanges" "$(echo $chkms $chkm $chks $chkms_sub | multiline | sort | fixnl)" +# 38 +test_expect_success 'make sure exactly the right set of files ends up in the mainline' ' + mainfiles=''"$(git ls-files | fixnl)"'' && + check_equal "$mainfiles" "$chkm $chkms_sub $chks_sub" +' -# make sure the --rejoin commits never make it into subproj -check_equal "$(git log --pretty=format:'%s' HEAD^2 | grep -i split)" "" +# 39 +test_expect_success 'make sure each filename changed exactly once in the entire history' ' + # main-sub?? and /subdir/main-sub?? both change, because those are the + # changes that were split into their own history. And subdir/sub?? never + # change, since they were *only* changed in the subtree branch. + allchanges=''"$(git log --name-only --pretty=format:'"''"' | sort | fixnl)"'' && + check_equal "$allchanges" ''"$(echo $chkms $chkm $chks $chkms_sub | multiline | sort | fixnl)"'' +' -# make sure no 'git subtree' tagged commits make it into subproj. (They're -# meaningless to subproj since one side of the merge refers to the mainline) -check_equal "$(git log --pretty=format:'%s%n%b' HEAD^2 | grep 'git-subtree.*:')" "" +# 40 +test_expect_success 'make sure the --rejoin commits never make it into subproj' ' + check_equal ''"$(git log --pretty=format:'"'%s'"' HEAD^2 | grep -i split)"'' "" +' +# 41 +test_expect_success 'make sure no "git subtree" tagged commits make it into subproj' ' + # They are meaningless to subproj since one side of the merge refers to the mainline + check_equal ''"$(git log --pretty=format:'"'%s%n%b'"' HEAD^2 | grep "git-subtree.*:")"'' "" +' -# check if split can find proper base without --onto # prepare second pair of repositories mkdir test2 cd test2 -mkdir main +# 42 +test_expect_success 'init main' ' + test_create_repo main +' + cd main -git init -create main1 -git commit -m "main1" + +# 43 +test_expect_success 'add main1' ' + create main1 && + git commit -m "main1" +' cd .. -mkdir sub + +# 44 +test_expect_success 'init sub' ' + test_create_repo sub +' + cd sub -git init -create sub2 -git commit -m "sub2" + +# 45 +test_expect_success 'add sub2' ' + create sub2 && + git commit -m "sub2" +' cd ../main -git fetch ../sub master -git branch sub2 FETCH_HEAD -git subtree add --prefix subdir sub2 + +# check if split can find proper base without --onto + +# 46 +test_expect_success 'add sub as subdir in main' ' + git fetch ../sub master && + git branch sub2 FETCH_HEAD && + git subtree add --prefix subdir sub2 +' cd ../sub -create sub3 -git commit -m "sub3" + +# 47 +test_expect_success 'add sub3' ' + create sub3 && + git commit -m "sub3" +' cd ../main -git fetch ../sub master -git branch sub3 FETCH_HEAD -git subtree merge --prefix subdir sub3 -create subdir/main-sub4 -git commit -m "main-sub4" -git subtree split --prefix subdir --branch mainsub4 +# 48 +test_expect_success 'merge from sub' ' + git fetch ../sub master && + git branch sub3 FETCH_HEAD && + git subtree merge --prefix subdir sub3 +' -# at this point, the new commit's parent should be sub3 -# if it's not, something went wrong (the "newparent" of "master~" commit should have been sub3, -# but it wasn't, because it's cache was not set to itself) -check_equal "$(git log --pretty=format:%P -1 mainsub4)" "$(git rev-parse sub3)" +# 49 +test_expect_success 'add main-sub4' ' + create subdir/main-sub4 && + git commit -m "main-sub4" +' -mkdir subdir2 -create subdir2/main-sub5 -git commit -m "main-sub5" -git subtree split --prefix subdir2 --branch mainsub5 +# 50 +test_expect_success 'split for main-sub4 without --onto' ' + git subtree split --prefix subdir --branch mainsub4 +' -# also test that we still can split out an entirely new subtree -# if the parent of the first commit in the tree isn't empty, -# then the new subtree has accidently been attached to something -check_equal "$(git log --pretty=format:%P -1 mainsub5)" "" +# at this point, the new commit parent should be sub3 if it is not, +# something went wrong (the "newparent" of "master~" commit should +# have been sub3, but it was not, because its cache was not set to +# itself) +# 51 +test_expect_success 'check that the commit parent is sub3' ' + check_equal ''"$(git log --pretty=format:%P -1 mainsub4)"'' ''"$(git rev-parse sub3)"'' +' + +# 52 +test_expect_success 'add main-sub5' ' + mkdir subdir2 && + create subdir2/main-sub5 && + git commit -m "main-sub5" +' + +# 53 +test_expect_success 'split for main-sub5 without --onto' ' + # also test that we still can split out an entirely new subtree + # if the parent of the first commit in the tree is not empty, + # then the new subtree has accidently been attached to something + git subtree split --prefix subdir2 --branch mainsub5 && + check_equal ''"$(git log --pretty=format:%P -1 mainsub5)"'' "" +' # make sure no patch changes more than one file. The original set of commits # changed only one file each. A multi-file change would imply that we pruned @@ -313,7 +469,7 @@ joincommits() commit= all= while read x y; do - echo "{$x}" >&2 + #echo "{$x}" >&2 if [ -z "$x" ]; then continue elif [ "$x" = "commit:" ]; then @@ -328,15 +484,23 @@ joincommits() done echo "$commit $all" } -x= -git log --pretty=format:'commit: %H' | joincommits | -( while read commit a b; do - echo "Verifying commit $commit" - check_equal "$b" "" - x=1 - done - check_equal "$x" 1 -) || exit 1 -echo -echo 'ok' +# 54 +test_expect_success 'verify one file change per commit' ' + x= && + list=''"$(git log --pretty=format:'"'commit: %H'"' | joincommits)"'' && +# test_debug "echo HERE" && +# test_debug "echo ''"$list"''" && + (git log --pretty=format:'"'commit: %H'"' | joincommits | + ( while read commit a b; do + test_debug "echo Verifying commit "''"$commit"'' + test_debug "echo a: "''"$a"'' + test_debug "echo b: "''"$b"'' + check_equal "$b" "" + x=1 + done + check_equal "$x" 1 + )) +' + +test_done From e5b06629de847663aaf0f7daae8de81338da3901 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sun, 19 Feb 2012 14:32:25 -0800 Subject: [PATCH 104/291] xdiff: remove XDL_PATCH_* macros These are not used anywhere in our codebase, and the bit assignment definition is merely confusing. Signed-off-by: Junio C Hamano --- xdiff/xdiff.h | 5 ----- 1 file changed, 5 deletions(-) diff --git a/xdiff/xdiff.h b/xdiff/xdiff.h index 00d36c3ac7..70c8b87ff2 100644 --- a/xdiff/xdiff.h +++ b/xdiff/xdiff.h @@ -36,11 +36,6 @@ extern "C" { #define XDF_HISTOGRAM_DIFF (1 << 6) #define XDF_WHITESPACE_FLAGS (XDF_IGNORE_WHITESPACE | XDF_IGNORE_WHITESPACE_CHANGE | XDF_IGNORE_WHITESPACE_AT_EOL) -#define XDL_PATCH_NORMAL '-' -#define XDL_PATCH_REVERSE '+' -#define XDL_PATCH_MODEMASK ((1 << 8) - 1) -#define XDL_PATCH_IGNOREBSPACE (1 << 8) - #define XDL_EMIT_FUNCNAMES (1 << 0) #define XDL_EMIT_COMMON (1 << 1) #define XDL_EMIT_FUNCCONTEXT (1 << 2) From 307ab20b333d9b4c818b1ff912e86944d1a3fdc1 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sun, 19 Feb 2012 15:36:55 -0800 Subject: [PATCH 105/291] xdiff: PATIENCE/HISTOGRAM are not independent option bits Because the default Myers, patience and histogram algorithms cannot be in effect at the same time, XDL_PATIENCE_DIFF and XDL_HISTOGRAM_DIFF are not independent bits. Instead of wasting one bit per algorithm, define a few macros to access the few bits they occupy and update the code that access them. Signed-off-by: Junio C Hamano --- diff.c | 4 ++-- diff.h | 2 ++ merge-recursive.c | 4 ++-- xdiff/xdiff.h | 5 ++++- xdiff/xdiffi.c | 4 ++-- xdiff/xhistogram.c | 2 +- xdiff/xpatience.c | 2 +- xdiff/xprepare.c | 21 ++++++++++----------- 8 files changed, 24 insertions(+), 20 deletions(-) diff --git a/diff.c b/diff.c index 374ecf3b48..52cda7a0da 100644 --- a/diff.c +++ b/diff.c @@ -3400,9 +3400,9 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac) else if (!strcmp(arg, "--ignore-space-at-eol")) DIFF_XDL_SET(options, IGNORE_WHITESPACE_AT_EOL); else if (!strcmp(arg, "--patience")) - DIFF_XDL_SET(options, PATIENCE_DIFF); + options->xdl_opts = DIFF_WITH_ALG(options, PATIENCE_DIFF); else if (!strcmp(arg, "--histogram")) - DIFF_XDL_SET(options, HISTOGRAM_DIFF); + options->xdl_opts = DIFF_WITH_ALG(options, HISTOGRAM_DIFF); /* flags options */ else if (!strcmp(arg, "--binary")) { diff --git a/diff.h b/diff.h index 0c51724493..e688a48d10 100644 --- a/diff.h +++ b/diff.h @@ -88,6 +88,8 @@ typedef struct strbuf *(*diff_prefix_fn_t)(struct diff_options *opt, void *data) #define DIFF_XDL_SET(opts, flag) ((opts)->xdl_opts |= XDF_##flag) #define DIFF_XDL_CLR(opts, flag) ((opts)->xdl_opts &= ~XDF_##flag) +#define DIFF_WITH_ALG(opts, flag) (((opts)->xdl_opts & ~XDF_DIFF_ALGORITHM_MASK) | XDF_##flag) + enum diff_words_type { DIFF_WORDS_NONE = 0, DIFF_WORDS_PORCELAIN, diff --git a/merge-recursive.c b/merge-recursive.c index cc664c39b6..1d574fee8b 100644 --- a/merge-recursive.c +++ b/merge-recursive.c @@ -2069,9 +2069,9 @@ int parse_merge_opt(struct merge_options *o, const char *s) else if (!prefixcmp(s, "subtree=")) o->subtree_shift = s + strlen("subtree="); else if (!strcmp(s, "patience")) - o->xdl_opts |= XDF_PATIENCE_DIFF; + o->xdl_opts = DIFF_WITH_ALG(o, PATIENCE_DIFF); else if (!strcmp(s, "histogram")) - o->xdl_opts |= XDF_HISTOGRAM_DIFF; + o->xdl_opts = DIFF_WITH_ALG(o, HISTOGRAM_DIFF); else if (!strcmp(s, "ignore-space-change")) o->xdl_opts |= XDF_IGNORE_WHITESPACE_CHANGE; else if (!strcmp(s, "ignore-all-space")) diff --git a/xdiff/xdiff.h b/xdiff/xdiff.h index 70c8b87ff2..09215afe6e 100644 --- a/xdiff/xdiff.h +++ b/xdiff/xdiff.h @@ -32,9 +32,12 @@ extern "C" { #define XDF_IGNORE_WHITESPACE (1 << 2) #define XDF_IGNORE_WHITESPACE_CHANGE (1 << 3) #define XDF_IGNORE_WHITESPACE_AT_EOL (1 << 4) +#define XDF_WHITESPACE_FLAGS (XDF_IGNORE_WHITESPACE | XDF_IGNORE_WHITESPACE_CHANGE | XDF_IGNORE_WHITESPACE_AT_EOL) + #define XDF_PATIENCE_DIFF (1 << 5) #define XDF_HISTOGRAM_DIFF (1 << 6) -#define XDF_WHITESPACE_FLAGS (XDF_IGNORE_WHITESPACE | XDF_IGNORE_WHITESPACE_CHANGE | XDF_IGNORE_WHITESPACE_AT_EOL) +#define XDF_DIFF_ALGORITHM_MASK (XDF_PATIENCE_DIFF | XDF_HISTOGRAM_DIFF) +#define XDF_DIFF_ALG(x) ((x) & XDF_DIFF_ALGORITHM_MASK) #define XDL_EMIT_FUNCNAMES (1 << 0) #define XDL_EMIT_COMMON (1 << 1) diff --git a/xdiff/xdiffi.c b/xdiff/xdiffi.c index 75a3922750..bc889e8789 100644 --- a/xdiff/xdiffi.c +++ b/xdiff/xdiffi.c @@ -328,10 +328,10 @@ int xdl_do_diff(mmfile_t *mf1, mmfile_t *mf2, xpparam_t const *xpp, xdalgoenv_t xenv; diffdata_t dd1, dd2; - if (xpp->flags & XDF_PATIENCE_DIFF) + if (XDF_DIFF_ALG(xpp->flags) == XDF_PATIENCE_DIFF) return xdl_do_patience_diff(mf1, mf2, xpp, xe); - if (xpp->flags & XDF_HISTOGRAM_DIFF) + if (XDF_DIFF_ALG(xpp->flags) == XDF_HISTOGRAM_DIFF) return xdl_do_histogram_diff(mf1, mf2, xpp, xe); if (xdl_prepare_env(mf1, mf2, xpp, xe) < 0) { diff --git a/xdiff/xhistogram.c b/xdiff/xhistogram.c index 18f6f997c3..bf99787c3e 100644 --- a/xdiff/xhistogram.c +++ b/xdiff/xhistogram.c @@ -252,7 +252,7 @@ static int fall_back_to_classic_diff(struct histindex *index, int line1, int count1, int line2, int count2) { xpparam_t xpp; - xpp.flags = index->xpp->flags & ~XDF_HISTOGRAM_DIFF; + xpp.flags = index->xpp->flags & ~XDF_DIFF_ALGORITHM_MASK; return xdl_fall_back_diff(index->env, &xpp, line1, count1, line2, count2); diff --git a/xdiff/xpatience.c b/xdiff/xpatience.c index fdd7d0263f..04e1a1ab2a 100644 --- a/xdiff/xpatience.c +++ b/xdiff/xpatience.c @@ -288,7 +288,7 @@ static int fall_back_to_classic_diff(struct hashmap *map, int line1, int count1, int line2, int count2) { xpparam_t xpp; - xpp.flags = map->xpp->flags & ~XDF_PATIENCE_DIFF; + xpp.flags = map->xpp->flags & ~XDF_DIFF_ALGORITHM_MASK; return xdl_fall_back_diff(map->env, &xpp, line1, count1, line2, count2); diff --git a/xdiff/xprepare.c b/xdiff/xprepare.c index e419f4f726..63a22c630e 100644 --- a/xdiff/xprepare.c +++ b/xdiff/xprepare.c @@ -181,7 +181,7 @@ static int xdl_prepare_ctx(unsigned int pass, mmfile_t *mf, long narec, xpparam_ if (!(recs = (xrecord_t **) xdl_malloc(narec * sizeof(xrecord_t *)))) goto abort; - if (xpp->flags & XDF_HISTOGRAM_DIFF) + if (XDF_DIFF_ALG(xpp->flags) == XDF_HISTOGRAM_DIFF) hbits = hsize = 0; else { hbits = xdl_hashbits((unsigned int) narec); @@ -209,8 +209,8 @@ static int xdl_prepare_ctx(unsigned int pass, mmfile_t *mf, long narec, xpparam_ crec->ha = hav; recs[nrec++] = crec; - if (!(xpp->flags & XDF_HISTOGRAM_DIFF) && - xdl_classify_record(pass, cf, rhash, hbits, crec) < 0) + if ((XDF_DIFF_ALG(xpp->flags) != XDF_HISTOGRAM_DIFF) && + xdl_classify_record(pass, cf, rhash, hbits, crec) < 0) goto abort; } } @@ -273,16 +273,15 @@ int xdl_prepare_env(mmfile_t *mf1, mmfile_t *mf2, xpparam_t const *xpp, * (nrecs) will be updated correctly anyway by * xdl_prepare_ctx(). */ - sample = xpp->flags & XDF_HISTOGRAM_DIFF ? XDL_GUESS_NLINES2 : XDL_GUESS_NLINES1; + sample = (XDF_DIFF_ALG(xpp->flags) == XDF_HISTOGRAM_DIFF + ? XDL_GUESS_NLINES2 : XDL_GUESS_NLINES1); enl1 = xdl_guess_lines(mf1, sample) + 1; enl2 = xdl_guess_lines(mf2, sample) + 1; - if (!(xpp->flags & XDF_HISTOGRAM_DIFF) && - xdl_init_classifier(&cf, enl1 + enl2 + 1, xpp->flags) < 0) { - + if (XDF_DIFF_ALG(xpp->flags) != XDF_HISTOGRAM_DIFF && + xdl_init_classifier(&cf, enl1 + enl2 + 1, xpp->flags) < 0) return -1; - } if (xdl_prepare_ctx(1, mf1, enl1, xpp, &cf, &xe->xdf1) < 0) { @@ -296,9 +295,9 @@ int xdl_prepare_env(mmfile_t *mf1, mmfile_t *mf2, xpparam_t const *xpp, return -1; } - if (!(xpp->flags & XDF_PATIENCE_DIFF) && - !(xpp->flags & XDF_HISTOGRAM_DIFF) && - xdl_optimize_ctxs(&cf, &xe->xdf1, &xe->xdf2) < 0) { + if ((XDF_DIFF_ALG(xpp->flags) != XDF_PATIENCE_DIFF) && + (XDF_DIFF_ALG(xpp->flags) != XDF_HISTOGRAM_DIFF) && + xdl_optimize_ctxs(&cf, &xe->xdf1, &xe->xdf2) < 0) { xdl_free_ctx(&xe->xdf2); xdl_free_ctx(&xe->xdf1); From 47a02ff2ca821c52268197dd5fa46cd60a2e94bc Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Wed, 7 Mar 2012 17:54:15 +0700 Subject: [PATCH 106/291] streaming: make streaming-write-entry to be more reusable MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The static function in entry.c takes a cache entry and streams its blob contents to a file in the working tree. Refactor the logic to a new API function stream_blob_to_fd() that takes an object name and an open file descriptor, so that it can be reused by other callers. Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano --- entry.c | 53 +++++---------------------------------------------- streaming.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++ streaming.h | 2 ++ 3 files changed, 62 insertions(+), 48 deletions(-) diff --git a/entry.c b/entry.c index 852fea1395..17a6bccec6 100644 --- a/entry.c +++ b/entry.c @@ -120,58 +120,15 @@ static int streaming_write_entry(struct cache_entry *ce, char *path, const struct checkout *state, int to_tempfile, int *fstat_done, struct stat *statbuf) { - struct git_istream *st; - enum object_type type; - unsigned long sz; int result = -1; - ssize_t kept = 0; - int fd = -1; - - st = open_istream(ce->sha1, &type, &sz, filter); - if (!st) - return -1; - if (type != OBJ_BLOB) - goto close_and_exit; + int fd; fd = open_output_fd(path, ce, to_tempfile); - if (fd < 0) - goto close_and_exit; - - for (;;) { - char buf[1024 * 16]; - ssize_t wrote, holeto; - ssize_t readlen = read_istream(st, buf, sizeof(buf)); - - if (!readlen) - break; - if (sizeof(buf) == readlen) { - for (holeto = 0; holeto < readlen; holeto++) - if (buf[holeto]) - break; - if (readlen == holeto) { - kept += holeto; - continue; - } - } - - if (kept && lseek(fd, kept, SEEK_CUR) == (off_t) -1) - goto close_and_exit; - else - kept = 0; - wrote = write_in_full(fd, buf, readlen); - - if (wrote != readlen) - goto close_and_exit; - } - if (kept && (lseek(fd, kept - 1, SEEK_CUR) == (off_t) -1 || - write(fd, "", 1) != 1)) - goto close_and_exit; - *fstat_done = fstat_output(fd, state, statbuf); - -close_and_exit: - close_istream(st); - if (0 <= fd) + if (0 <= fd) { + result = stream_blob_to_fd(fd, ce->sha1, filter, 1); + *fstat_done = fstat_output(fd, state, statbuf); result = close(fd); + } if (result && 0 <= fd) unlink(path); return result; diff --git a/streaming.c b/streaming.c index 71072e1b1d..7e7ee2be6f 100644 --- a/streaming.c +++ b/streaming.c @@ -489,3 +489,58 @@ static open_method_decl(incore) return st->u.incore.buf ? 0 : -1; } + + +/**************************************************************** + * Users of streaming interface + ****************************************************************/ + +int stream_blob_to_fd(int fd, unsigned const char *sha1, struct stream_filter *filter, + int can_seek) +{ + struct git_istream *st; + enum object_type type; + unsigned long sz; + ssize_t kept = 0; + int result = -1; + + st = open_istream(sha1, &type, &sz, filter); + if (!st) + return result; + if (type != OBJ_BLOB) + goto close_and_exit; + for (;;) { + char buf[1024 * 16]; + ssize_t wrote, holeto; + ssize_t readlen = read_istream(st, buf, sizeof(buf)); + + if (!readlen) + break; + if (can_seek && sizeof(buf) == readlen) { + for (holeto = 0; holeto < readlen; holeto++) + if (buf[holeto]) + break; + if (readlen == holeto) { + kept += holeto; + continue; + } + } + + if (kept && lseek(fd, kept, SEEK_CUR) == (off_t) -1) + goto close_and_exit; + else + kept = 0; + wrote = write_in_full(fd, buf, readlen); + + if (wrote != readlen) + goto close_and_exit; + } + if (kept && (lseek(fd, kept - 1, SEEK_CUR) == (off_t) -1 || + write(fd, "", 1) != 1)) + goto close_and_exit; + result = 0; + + close_and_exit: + close_istream(st); + return result; +} diff --git a/streaming.h b/streaming.h index 589e857b8c..3e827709c8 100644 --- a/streaming.h +++ b/streaming.h @@ -12,4 +12,6 @@ extern struct git_istream *open_istream(const unsigned char *, enum object_type extern int close_istream(struct git_istream *); extern ssize_t read_istream(struct git_istream *, char *, size_t); +extern int stream_blob_to_fd(int fd, const unsigned char *, struct stream_filter *, int can_seek); + #endif /* STREAMING_H */ From d41489a6424308dc9a0409bc2f6845aa08bd4f7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Wed, 7 Mar 2012 17:54:16 +0700 Subject: [PATCH 107/291] Add more large blob test cases MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit New test cases list commands that should work when memory is limited. All memory allocation functions (*) learn to reject any allocation larger than $GIT_ALLOC_LIMIT if set. (*) Not exactly all. Some places do not use x* functions, but malloc/calloc directly, notably diff-delta. These code path should never be run on large blobs. Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano --- t/t1050-large.sh | 38 ++++++++++++++++++++++++++++++++++++-- wrapper.c | 27 ++++++++++++++++++++++++--- 2 files changed, 60 insertions(+), 5 deletions(-) diff --git a/t/t1050-large.sh b/t/t1050-large.sh index 29d6024b7f..ded66b3228 100755 --- a/t/t1050-large.sh +++ b/t/t1050-large.sh @@ -6,11 +6,15 @@ test_description='adding and checking out large blobs' . ./test-lib.sh test_expect_success setup ' - git config core.bigfilethreshold 200k && + # clone does not allow us to pass core.bigfilethreshold to + # new repos, so set core.bigfilethreshold globally + git config --global core.bigfilethreshold 200k && echo X | dd of=large1 bs=1k seek=2000 && echo X | dd of=large2 bs=1k seek=2000 && echo X | dd of=large3 bs=1k seek=2000 && - echo Y | dd of=huge bs=1k seek=2500 + echo Y | dd of=huge bs=1k seek=2500 && + GIT_ALLOC_LIMIT=1500 && + export GIT_ALLOC_LIMIT ' test_expect_success 'add a large file or two' ' @@ -100,4 +104,34 @@ test_expect_success 'packsize limit' ' ) ' +test_expect_success 'diff --raw' ' + git commit -q -m initial && + echo modified >>large1 && + git add large1 && + git commit -q -m modified && + git diff --raw HEAD^ +' + +test_expect_success 'hash-object' ' + git hash-object large1 +' + +test_expect_failure 'cat-file a large file' ' + git cat-file blob :large1 >/dev/null +' + +test_expect_failure 'cat-file a large file from a tag' ' + git tag -m largefile largefiletag :large1 && + git cat-file blob largefiletag >/dev/null +' + +test_expect_failure 'git-show a large file' ' + git show :large1 >/dev/null + +' + +test_expect_failure 'repack' ' + git repack -ad +' + test_done diff --git a/wrapper.c b/wrapper.c index 85f09df747..6ccd0595f4 100644 --- a/wrapper.c +++ b/wrapper.c @@ -9,6 +9,18 @@ static void do_nothing(size_t size) static void (*try_to_free_routine)(size_t size) = do_nothing; +static void memory_limit_check(size_t size) +{ + static int limit = -1; + if (limit == -1) { + const char *env = getenv("GIT_ALLOC_LIMIT"); + limit = env ? atoi(env) * 1024 : 0; + } + if (limit && size > limit) + die("attempting to allocate %"PRIuMAX" over limit %d", + (intmax_t)size, limit); +} + try_to_free_t set_try_to_free_routine(try_to_free_t routine) { try_to_free_t old = try_to_free_routine; @@ -32,7 +44,10 @@ char *xstrdup(const char *str) void *xmalloc(size_t size) { - void *ret = malloc(size); + void *ret; + + memory_limit_check(size); + ret = malloc(size); if (!ret && !size) ret = malloc(1); if (!ret) { @@ -79,7 +94,10 @@ char *xstrndup(const char *str, size_t len) void *xrealloc(void *ptr, size_t size) { - void *ret = realloc(ptr, size); + void *ret; + + memory_limit_check(size); + ret = realloc(ptr, size); if (!ret && !size) ret = realloc(ptr, 1); if (!ret) { @@ -95,7 +113,10 @@ void *xrealloc(void *ptr, size_t size) void *xcalloc(size_t nmemb, size_t size) { - void *ret = calloc(nmemb, size); + void *ret; + + memory_limit_check(size * nmemb); + ret = calloc(nmemb, size); if (!ret && (!nmemb || !size)) ret = calloc(1, 1); if (!ret) { From 00c8fd493afbd1620febf2b895fb2365f76d5875 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Wed, 7 Mar 2012 17:54:17 +0700 Subject: [PATCH 108/291] cat-file: use streaming API to print blobs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano --- builtin/cat-file.c | 25 +++++++++++++++++++++++++ t/t1050-large.sh | 4 ++-- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/builtin/cat-file.c b/builtin/cat-file.c index 8ed501f220..36a9104433 100644 --- a/builtin/cat-file.c +++ b/builtin/cat-file.c @@ -11,6 +11,7 @@ #include "parse-options.h" #include "diff.h" #include "userdiff.h" +#include "streaming.h" #define BATCH 1 #define BATCH_CHECK 2 @@ -127,6 +128,8 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name) return cmd_ls_tree(2, ls_args, NULL); } + if (type == OBJ_BLOB) + return stream_blob_to_fd(1, sha1, NULL, 0); buf = read_sha1_file(sha1, &type, &size); if (!buf) die("Cannot read object %s", obj_name); @@ -149,6 +152,28 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name) break; case 0: + if (type_from_string(exp_type) == OBJ_BLOB) { + unsigned char blob_sha1[20]; + if (sha1_object_info(sha1, NULL) == OBJ_TAG) { + enum object_type type; + unsigned long size; + char *buffer = read_sha1_file(sha1, &type, &size); + if (memcmp(buffer, "object ", 7) || + get_sha1_hex(buffer + 7, blob_sha1)) + die("%s not a valid tag", sha1_to_hex(sha1)); + free(buffer); + } else + hashcpy(blob_sha1, sha1); + + if (sha1_object_info(blob_sha1, NULL) == OBJ_BLOB) + return stream_blob_to_fd(1, blob_sha1, NULL, 0); + /* + * we attempted to dereference a tag to a blob + * and failed; there may be new dereference + * mechanisms this code is not aware of. + * fall-back to the usual case. + */ + } buf = read_object_with_reference(sha1, exp_type, &size, NULL); break; diff --git a/t/t1050-large.sh b/t/t1050-large.sh index ded66b3228..f662fefa67 100755 --- a/t/t1050-large.sh +++ b/t/t1050-large.sh @@ -116,11 +116,11 @@ test_expect_success 'hash-object' ' git hash-object large1 ' -test_expect_failure 'cat-file a large file' ' +test_expect_success 'cat-file a large file' ' git cat-file blob :large1 >/dev/null ' -test_expect_failure 'cat-file a large file from a tag' ' +test_expect_success 'cat-file a large file from a tag' ' git tag -m largefile largefiletag :large1 && git cat-file blob largefiletag >/dev/null ' From 090ea12671b2971b1c613f0a3d2657e8cdd35134 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Wed, 7 Mar 2012 17:54:18 +0700 Subject: [PATCH 109/291] parse_object: avoid putting whole blob in core MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Traditionally, all the callers of check_sha1_signature() first called read_sha1_file() to prepare the whole object data in core, and called this function. The function is used to revalidate what we read from the object database actually matches the object name we used to ask for the data from the object database. Update the API to allow callers to pass NULL as the object data, and have the function read and hash the object data using streaming API to recompute the object name, without having to hold everything in core at the same time. This is most useful in parse_object() that parses a blob object, because this caller does not have to keep the actual blob data around in memory after a "struct blob" is returned. Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano --- object.c | 11 +++++++++++ sha1_file.c | 42 ++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 51 insertions(+), 2 deletions(-) diff --git a/object.c b/object.c index 6b06297a5f..0498b18d45 100644 --- a/object.c +++ b/object.c @@ -198,6 +198,17 @@ struct object *parse_object(const unsigned char *sha1) if (obj && obj->parsed) return obj; + if ((obj && obj->type == OBJ_BLOB) || + (!obj && has_sha1_file(sha1) && + sha1_object_info(sha1, NULL) == OBJ_BLOB)) { + if (check_sha1_signature(repl, NULL, 0, NULL) < 0) { + error("sha1 mismatch %s\n", sha1_to_hex(repl)); + return NULL; + } + parse_blob_buffer(lookup_blob(sha1), NULL, 0); + return lookup_object(sha1); + } + buffer = read_sha1_file(sha1, &type, &size); if (buffer) { if (check_sha1_signature(repl, buffer, size, typename(type)) < 0) { diff --git a/sha1_file.c b/sha1_file.c index 4f06a0e450..ad314f08b9 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -19,6 +19,7 @@ #include "pack-revindex.h" #include "sha1-lookup.h" #include "bulk-checkin.h" +#include "streaming.h" #ifndef O_NOATIME #if defined(__linux__) && (defined(__i386__) || defined(__PPC__)) @@ -1146,10 +1147,47 @@ static const struct packed_git *has_packed_and_bad(const unsigned char *sha1) return NULL; } -int check_sha1_signature(const unsigned char *sha1, void *map, unsigned long size, const char *type) +/* + * With an in-core object data in "map", rehash it to make sure the + * object name actually matches "sha1" to detect object corruption. + * With "map" == NULL, try reading the object named with "sha1" using + * the streaming interface and rehash it to do the same. + */ +int check_sha1_signature(const unsigned char *sha1, void *map, + unsigned long size, const char *type) { unsigned char real_sha1[20]; - hash_sha1_file(map, size, type, real_sha1); + enum object_type obj_type; + struct git_istream *st; + git_SHA_CTX c; + char hdr[32]; + int hdrlen; + + if (map) { + hash_sha1_file(map, size, type, real_sha1); + return hashcmp(sha1, real_sha1) ? -1 : 0; + } + + st = open_istream(sha1, &obj_type, &size, NULL); + if (!st) + return -1; + + /* Generate the header */ + hdrlen = sprintf(hdr, "%s %lu", typename(obj_type), size) + 1; + + /* Sha1.. */ + git_SHA1_Init(&c); + git_SHA1_Update(&c, hdr, hdrlen); + for (;;) { + char buf[1024 * 16]; + ssize_t readlen = read_istream(st, buf, sizeof(buf)); + + if (!readlen) + break; + git_SHA1_Update(&c, buf, readlen); + } + git_SHA1_Final(real_sha1, &c); + close_istream(st); return hashcmp(sha1, real_sha1) ? -1 : 0; } From 74775a09b166fb85f5dce816548e337f11124c6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Wed, 7 Mar 2012 17:54:19 +0700 Subject: [PATCH 110/291] show: use streaming API for showing blobs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano --- builtin/log.c | 34 ++++++++++++++++++++-------------- t/t1050-large.sh | 2 +- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/builtin/log.c b/builtin/log.c index 7d1f6f88a0..d1702e7580 100644 --- a/builtin/log.c +++ b/builtin/log.c @@ -20,6 +20,7 @@ #include "string-list.h" #include "parse-options.h" #include "branch.h" +#include "streaming.h" /* Set a default date-time format for git log ("log.date" config variable) */ static const char *default_date_mode = NULL; @@ -381,8 +382,13 @@ static void show_tagger(char *buf, int len, struct rev_info *rev) strbuf_release(&out); } -static int show_object(const unsigned char *sha1, int show_tag_object, - struct rev_info *rev) +static int show_blob_object(const unsigned char *sha1, struct rev_info *rev) +{ + fflush(stdout); + return stream_blob_to_fd(1, sha1, NULL, 0); +} + +static int show_tag_object(const unsigned char *sha1, struct rev_info *rev) { unsigned long size; enum object_type type; @@ -392,16 +398,16 @@ static int show_object(const unsigned char *sha1, int show_tag_object, if (!buf) return error(_("Could not read object %s"), sha1_to_hex(sha1)); - if (show_tag_object) - while (offset < size && buf[offset] != '\n') { - int new_offset = offset + 1; - while (new_offset < size && buf[new_offset++] != '\n') - ; /* do nothing */ - if (!prefixcmp(buf + offset, "tagger ")) - show_tagger(buf + offset + 7, - new_offset - offset - 7, rev); - offset = new_offset; - } + assert(type == OBJ_TAG); + while (offset < size && buf[offset] != '\n') { + int new_offset = offset + 1; + while (new_offset < size && buf[new_offset++] != '\n') + ; /* do nothing */ + if (!prefixcmp(buf + offset, "tagger ")) + show_tagger(buf + offset + 7, + new_offset - offset - 7, rev); + offset = new_offset; + } if (offset < size) fwrite(buf + offset, size - offset, 1, stdout); @@ -459,7 +465,7 @@ int cmd_show(int argc, const char **argv, const char *prefix) const char *name = objects[i].name; switch (o->type) { case OBJ_BLOB: - ret = show_object(o->sha1, 0, NULL); + ret = show_blob_object(o->sha1, NULL); break; case OBJ_TAG: { struct tag *t = (struct tag *)o; @@ -470,7 +476,7 @@ int cmd_show(int argc, const char **argv, const char *prefix) diff_get_color_opt(&rev.diffopt, DIFF_COMMIT), t->tag, diff_get_color_opt(&rev.diffopt, DIFF_RESET)); - ret = show_object(o->sha1, 1, &rev); + ret = show_tag_object(o->sha1, &rev); rev.shown_one = 1; if (ret) break; diff --git a/t/t1050-large.sh b/t/t1050-large.sh index f662fefa67..dd1bb8422c 100755 --- a/t/t1050-large.sh +++ b/t/t1050-large.sh @@ -125,7 +125,7 @@ test_expect_success 'cat-file a large file from a tag' ' git cat-file blob largefiletag >/dev/null ' -test_expect_failure 'git-show a large file' ' +test_expect_success 'git-show a large file' ' git show :large1 >/dev/null ' From 6f7f3beb2d19ab772729fc599d4a92ebf9140c5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Wed, 7 Mar 2012 17:54:20 +0700 Subject: [PATCH 111/291] fsck: use streaming API for writing lost-found blobs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano --- builtin/fsck.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/builtin/fsck.c b/builtin/fsck.c index 67eb553c7d..a710227a64 100644 --- a/builtin/fsck.c +++ b/builtin/fsck.c @@ -12,6 +12,7 @@ #include "parse-options.h" #include "dir.h" #include "progress.h" +#include "streaming.h" #define REACHABLE 0x0001 #define SEEN 0x0002 @@ -238,13 +239,8 @@ static void check_unreachable_object(struct object *obj) if (!(f = fopen(filename, "w"))) die_errno("Could not open '%s'", filename); if (obj->type == OBJ_BLOB) { - enum object_type type; - unsigned long size; - char *buf = read_sha1_file(obj->sha1, - &type, &size); - if (buf && fwrite(buf, 1, size, f) != size) + if (stream_blob_to_fd(fileno(f), obj->sha1, NULL, 1)) die_errno("Could not write '%s'", filename); - free(buf); } else fprintf(f, "%s\n", sha1_to_hex(obj->sha1)); if (fclose(f)) From da591a7f4bbe1a208cc5f955523506eb857c45ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Wed, 7 Mar 2012 17:54:21 +0700 Subject: [PATCH 112/291] update-server-info: respect core.bigfilethreshold MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This command indirectly calls check_sha1_signature() (add_info_ref -> deref_tag -> parse_object -> ..) , which may put whole blob in memory if the blob's size is under core.bigfilethreshold. As config is not read, the threshold is always 512MB. Respect user settings here. Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano --- builtin/update-server-info.c | 1 + t/t1050-large.sh | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/builtin/update-server-info.c b/builtin/update-server-info.c index b90dce6358..0d63c4498c 100644 --- a/builtin/update-server-info.c +++ b/builtin/update-server-info.c @@ -15,6 +15,7 @@ int cmd_update_server_info(int argc, const char **argv, const char *prefix) OPT_END() }; + git_config(git_default_config, NULL); argc = parse_options(argc, argv, prefix, options, update_server_info_usage, 0); if (argc > 0) diff --git a/t/t1050-large.sh b/t/t1050-large.sh index dd1bb8422c..4d127f19b7 100755 --- a/t/t1050-large.sh +++ b/t/t1050-large.sh @@ -130,7 +130,7 @@ test_expect_success 'git-show a large file' ' ' -test_expect_failure 'repack' ' +test_expect_success 'repack' ' git repack -ad ' From 6fe53908f954b5683ca08d3745be1d76dd665483 Mon Sep 17 00:00:00 2001 From: Jared Hance Date: Wed, 7 Mar 2012 17:21:25 -0500 Subject: [PATCH 113/291] apply: do not leak patches and fragments In the while loop inside apply_patch, patch and fragments are dynamically allocated with a calloc. However, only unused patches are actually freed and the rest are left to leak. Since a list is actively built up consisting of the used patches, they can simply be iterated and freed at the end of the function. In addition, the text in fragments were not freed, primarily because they mostly point into a patch text that is freed as a whole. But there are some cases where new piece of memory is allocated and pointed by a fragment (namely, when handling a binary patch). Introduce a free_patch bitfield to mark each fragment if its text needs to be freed, and free patches, fragments and fragment text that need to be freed when we are done with the input. Signed-off-by: Jared Hance Signed-off-by: Junio C Hamano --- builtin/apply.c | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/builtin/apply.c b/builtin/apply.c index c24dc546d0..427c2634d7 100644 --- a/builtin/apply.c +++ b/builtin/apply.c @@ -152,8 +152,9 @@ struct fragment { unsigned long oldpos, oldlines; unsigned long newpos, newlines; const char *patch; + unsigned free_patch:1, + rejected:1; int size; - int rejected; int linenr; struct fragment *next; }; @@ -195,6 +196,24 @@ struct patch { struct patch *next; }; +static void free_patch(struct patch *patch) +{ + while (patch) { + struct patch *patch_next = patch->next; + struct fragment *fragment = patch->fragments; + + while (fragment) { + struct fragment *fragment_next = fragment->next; + if (fragment->patch != NULL && fragment->free_patch) + free((char *)fragment->patch); + free(fragment); + fragment = fragment_next; + } + free(patch); + patch = patch_next; + } +} + /* * A line in a file, len-bytes long (includes the terminating LF, * except for an incomplete line at the end if the file ends with @@ -1741,6 +1760,7 @@ static struct fragment *parse_binary_hunk(char **buf_p, frag = xcalloc(1, sizeof(*frag)); frag->patch = inflate_it(data, hunk_size, origlen); + frag->free_patch = 1; if (!frag->patch) goto corrupt; free(data); @@ -3686,7 +3706,6 @@ static int apply_patch(int fd, const char *filename, int options) struct patch *list = NULL, **listp = &list; int skipped_patch = 0; - /* FIXME - memory leak when using multiple patch files as inputs */ memset(&fn_table, 0, sizeof(struct string_list)); patch_input_file = filename; read_patch_file(&buf, fd); @@ -3711,8 +3730,7 @@ static int apply_patch(int fd, const char *filename, int options) listp = &patch->next; } else { - /* perhaps free it a bit better? */ - free(patch); + free_patch(patch); skipped_patch++; } offset += nr; @@ -3753,6 +3771,7 @@ static int apply_patch(int fd, const char *filename, int options) if (summary) summary_patch_list(list); + free_patch(list); strbuf_release(&buf); return 0; } From 4b340cfab9c7a18e39bc531d6a6ffaffdf95f62d Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sun, 11 Mar 2012 01:25:43 -0800 Subject: [PATCH 114/291] ident.c: add split_ident_line() to parse formatted ident line The commit formatting logic format_person_part() in pretty.c implements the logic to split an author/committer ident line into its parts, intermixed with logic to compute its output using these piece it computes. Separate the former out to a helper function split_ident_line() so that other codepath can use the same logic, and rewrite the function using the helper function. Signed-off-by: Junio C Hamano --- cache.h | 16 +++++++++++++ ident.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ pretty.c | 64 +++++++++++++++++----------------------------------- 3 files changed, 104 insertions(+), 44 deletions(-) diff --git a/cache.h b/cache.h index 3a8e1258e7..7c42ecaff8 100644 --- a/cache.h +++ b/cache.h @@ -928,6 +928,22 @@ extern const char *fmt_name(const char *name, const char *email); extern const char *git_editor(void); extern const char *git_pager(int stdout_is_tty); +struct ident_split { + const char *name_begin; + const char *name_end; + const char *mail_begin; + const char *mail_end; + const char *date_begin; + const char *date_end; + const char *tz_begin; + const char *tz_end; +}; +/* + * Signals an success with 0, but time part of the result may be NULL + * if the input lacks timestamp and zone + */ +extern int split_ident_line(struct ident_split *, const char *, int); + struct checkout { const char *base_dir; int base_dir_len; diff --git a/ident.c b/ident.c index f619619b82..87c697c2b0 100644 --- a/ident.c +++ b/ident.c @@ -220,6 +220,74 @@ static int copy(char *buf, size_t size, int offset, const char *src) return offset; } +/* + * Reverse of fmt_ident(); given an ident line, split the fields + * to allow the caller to parse it. + * Signal a success by returning 0, but date/tz fields of the result + * can still be NULL if the input line only has the name/email part + * (e.g. reading from a reflog entry). + */ +int split_ident_line(struct ident_split *split, const char *line, int len) +{ + const char *cp; + size_t span; + int status = -1; + + memset(split, 0, sizeof(*split)); + + split->name_begin = line; + for (cp = line; *cp && cp < line + len; cp++) + if (*cp == '<') { + split->mail_begin = cp + 1; + break; + } + if (!split->mail_begin) + return status; + + for (cp = split->mail_begin - 2; line < cp; cp--) + if (!isspace(*cp)) { + split->name_end = cp + 1; + break; + } + if (!split->name_end) + return status; + + for (cp = split->mail_begin; cp < line + len; cp++) + if (*cp == '>') { + split->mail_end = cp; + break; + } + if (!split->mail_end) + return status; + + for (cp = split->mail_end + 1; cp < line + len && isspace(*cp); cp++) + ; + if (line + len <= cp) + goto person_only; + split->date_begin = cp; + span = strspn(cp, "0123456789"); + if (!span) + goto person_only; + split->date_end = split->date_begin + span; + for (cp = split->date_end; cp < line + len && isspace(*cp); cp++) + ; + if (line + len <= cp || (*cp != '+' && *cp != '-')) + goto person_only; + split->tz_begin = cp; + span = strspn(cp + 1, "0123456789"); + if (!span) + goto person_only; + split->tz_end = split->tz_begin + 1 + span; + return 0; + +person_only: + split->date_begin = NULL; + split->date_end = NULL; + split->tz_begin = NULL; + split->tz_end = NULL; + return 0; +} + static const char *env_hint = "\n" "*** Please tell me who you are.\n" diff --git a/pretty.c b/pretty.c index 8688b8f2d4..f2dee308b8 100644 --- a/pretty.c +++ b/pretty.c @@ -531,41 +531,24 @@ static size_t format_person_part(struct strbuf *sb, char part, { /* currently all placeholders have same length */ const int placeholder_len = 2; - int start, end, tz = 0; + int tz; unsigned long date = 0; - char *ep; - const char *name_start, *name_end, *mail_start, *mail_end, *msg_end = msg+len; char person_name[1024]; char person_mail[1024]; + struct ident_split s; + const char *name_start, *name_end, *mail_start, *mail_end; - /* advance 'end' to point to email start delimiter */ - for (end = 0; end < len && msg[end] != '<'; end++) - ; /* do nothing */ - - /* - * When end points at the '<' that we found, it should have - * matching '>' later, which means 'end' must be strictly - * below len - 1. - */ - if (end >= len - 2) + if (split_ident_line(&s, msg, len) < 0) goto skip; - /* Seek for both name and email part */ - name_start = msg; - name_end = msg+end; - while (name_end > name_start && isspace(*(name_end-1))) - name_end--; - mail_start = msg+end+1; - mail_end = mail_start; - while (mail_end < msg_end && *mail_end != '>') - mail_end++; - if (mail_end == msg_end) - goto skip; - end = mail_end-msg; + name_start = s.name_begin; + name_end = s.name_end; + mail_start = s.mail_begin; + mail_end = s.mail_end; if (part == 'N' || part == 'E') { /* mailmap lookup */ - strlcpy(person_name, name_start, name_end-name_start+1); - strlcpy(person_mail, mail_start, mail_end-mail_start+1); + strlcpy(person_name, name_start, name_end - name_start + 1); + strlcpy(person_mail, mail_start, mail_end - mail_start + 1); mailmap_name(person_mail, sizeof(person_mail), person_name, sizeof(person_name)); name_start = person_name; name_end = name_start + strlen(person_name); @@ -581,28 +564,20 @@ static size_t format_person_part(struct strbuf *sb, char part, return placeholder_len; } - /* advance 'start' to point to date start delimiter */ - for (start = end + 1; start < len && isspace(msg[start]); start++) - ; /* do nothing */ - if (start >= len) - goto skip; - date = strtoul(msg + start, &ep, 10); - if (msg + start == ep) + if (!s.date_begin) goto skip; + date = strtoul(s.date_begin, NULL, 10); + if (part == 't') { /* date, UNIX timestamp */ - strbuf_add(sb, msg + start, ep - (msg + start)); + strbuf_add(sb, s.date_begin, s.date_end - s.date_begin); return placeholder_len; } /* parse tz */ - for (start = ep - msg + 1; start < len && isspace(msg[start]); start++) - ; /* do nothing */ - if (start + 1 < len) { - tz = strtoul(msg + start + 1, NULL, 10); - if (msg[start] == '-') - tz = -tz; - } + tz = strtoul(s.tz_begin + 1, NULL, 10); + if (*s.tz_begin == '-') + tz = -tz; switch (part) { case 'd': /* date */ @@ -621,8 +596,9 @@ static size_t format_person_part(struct strbuf *sb, char part, skip: /* - * bogus commit, 'sb' cannot be updated, but we still need to - * compute a valid return value. + * reading from either a bogus commit, or a reflog entry with + * %gn, %ge, etc.; 'sb' cannot be updated, but we still need + * to compute a valid return value. */ if (part == 'n' || part == 'e' || part == 't' || part == 'd' || part == 'D' || part == 'r' || part == 'i') From 04861982e553289c923b2f9ef829ef33206c9bc4 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sun, 11 Mar 2012 03:51:32 -0700 Subject: [PATCH 115/291] t7503: does pre-commit-hook learn authorship? When "--author" option is used to lie the authorship to "git commit" command, hooks should learn the author name and email just like when GIT_AUTHOR_NAME and GIT_AUTHOR_EMAIL environment variables are used to lie the authorship. Test this. Signed-off-by: Junio C Hamano --- t/t7503-pre-commit-hook.sh | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/t/t7503-pre-commit-hook.sh b/t/t7503-pre-commit-hook.sh index ee7f0cd459..aa294ea428 100755 --- a/t/t7503-pre-commit-hook.sh +++ b/t/t7503-pre-commit-hook.sh @@ -118,4 +118,22 @@ test_expect_success 'with failing hook requiring GIT_PREFIX' ' git checkout -- file ' +test_expect_failure 'check the author in hook' ' + write_script "$HOOK" <<-\EOF && + test "$GIT_AUTHOR_NAME" = "New Author" && + test "$GIT_AUTHOR_EMAIL" = "newauthor@example.com" + EOF + test_must_fail git commit --allow-empty -m "by a.u.thor" && + ( + GIT_AUTHOR_NAME="New Author" && + GIT_AUTHOR_EMAIL="newauthor@example.com" && + export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL && + git commit --allow-empty -m "by new.author via env" && + git show -s + ) && + git commit --author="New Author " \ + --allow-empty -m "by new.author via command line" && + git show -s +' + test_done From 7dfe8ad6006c105989e4e8cfb196aa4ecda3c21d Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sun, 11 Mar 2012 03:12:10 -0700 Subject: [PATCH 116/291] commit: pass author/committer info to hooks When lying the author name via GIT_AUTHOR_NAME environment variable to "git commit", the hooks run by the command saw it and could act on the name that will be recorded in the final commit. When the user uses the "--author" option from the command line, the command should give the same information to the hook, and back when "git command" was a scripted Porcelain, it did set the environment variable and hooks can learn the author name from it. However, when the command was reimplemented in C, the rewritten code was not very faithful to the original, and hooks stopped getting the authorship information given with "--author". Fix this by exporting the necessary environment variables. Signed-off-by: Junio C Hamano --- builtin/commit.c | 22 +++++++++++++++++++--- t/t7503-pre-commit-hook.sh | 2 +- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/builtin/commit.c b/builtin/commit.c index eae5a29aeb..57a60f9f4b 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -533,9 +533,20 @@ static int is_a_merge(const struct commit *current_head) static const char sign_off_header[] = "Signed-off-by: "; +static void export_one(const char *var, const char *s, const char *e, int hack) +{ + struct strbuf buf = STRBUF_INIT; + if (hack) + strbuf_addch(&buf, hack); + strbuf_addf(&buf, "%.*s", (int)(e - s), s); + setenv(var, buf.buf, 1); + strbuf_release(&buf); +} + static void determine_author_info(struct strbuf *author_ident) { char *name, *email, *date; + struct ident_split author; name = getenv("GIT_AUTHOR_NAME"); email = getenv("GIT_AUTHOR_EMAIL"); @@ -585,6 +596,11 @@ static void determine_author_info(struct strbuf *author_ident) date = force_date; strbuf_addstr(author_ident, fmt_ident(name, email, date, IDENT_ERROR_ON_NO_NAME)); + if (!split_ident_line(&author, author_ident->buf, author_ident->len)) { + export_one("GIT_AUTHOR_NAME", author.name_begin, author.name_end, 0); + export_one("GIT_AUTHOR_EMAIL", author.mail_begin, author.mail_end, 0); + export_one("GIT_AUTHOR_DATE", author.date_begin, author.tz_end, '@'); + } } static int ends_rfc2822_footer(struct strbuf *sb) @@ -652,6 +668,9 @@ static int prepare_to_commit(const char *index_file, const char *prefix, int ident_shown = 0; int clean_message_contents = (cleanup_mode != CLEANUP_NONE); + /* This checks and barfs if author is badly specified */ + determine_author_info(author_ident); + if (!no_verify && run_hook(index_file, "pre-commit", NULL)) return 0; @@ -771,9 +790,6 @@ static int prepare_to_commit(const char *index_file, const char *prefix, strbuf_release(&sb); - /* This checks and barfs if author is badly specified */ - determine_author_info(author_ident); - /* This checks if committer ident is explicitly given */ strbuf_addstr(&committer_ident, git_committer_info(0)); if (use_editor && include_status) { diff --git a/t/t7503-pre-commit-hook.sh b/t/t7503-pre-commit-hook.sh index aa294ea428..984889b39d 100755 --- a/t/t7503-pre-commit-hook.sh +++ b/t/t7503-pre-commit-hook.sh @@ -118,7 +118,7 @@ test_expect_success 'with failing hook requiring GIT_PREFIX' ' git checkout -- file ' -test_expect_failure 'check the author in hook' ' +test_expect_success 'check the author in hook' ' write_script "$HOOK" <<-\EOF && test "$GIT_AUTHOR_NAME" = "New Author" && test "$GIT_AUTHOR_EMAIL" = "newauthor@example.com" From fc5877a6231aca01b63ddfd507bc1180078c09e2 Mon Sep 17 00:00:00 2001 From: Jonathan Nieder Date: Mon, 12 Mar 2012 23:54:05 -0500 Subject: [PATCH 117/291] test: use test_i18ncmp when checking --stat output Ever since v1.7.9.2~13 (2012-02-01), git's diffstat-style summary line produced by "git apply --stat", "git diff --stat", and "git commit" varies by locale, producing test failures when GETTEXT_POISON is set. Signed-off-by: Jonathan Nieder Signed-off-by: Junio C Hamano --- t/t3300-funny-names.sh | 6 +++--- t/t3508-cherry-pick-many-commits.sh | 4 ++-- t/t3903-stash.sh | 4 ++-- t/t4012-diff-binary.sh | 4 ++-- t/t4049-diff-stat-count.sh | 2 +- t/t4100-apply-stat.sh | 4 ++-- t/t5150-request-pull.sh | 2 +- t/t7602-merge-octopus-many.sh | 6 +++--- 8 files changed, 16 insertions(+), 16 deletions(-) diff --git a/t/t3300-funny-names.sh b/t/t3300-funny-names.sh index 9f00ada5f7..644aa219e9 100755 --- a/t/t3300-funny-names.sh +++ b/t/t3300-funny-names.sh @@ -174,7 +174,7 @@ EOF test_expect_success TABS_IN_FILENAMES 'git diff-tree rename with-funny applied' \ 'git diff-index -M -p $t0 | git apply --stat | sed -e "s/|.*//" -e "s/ *\$//" >current && - test_cmp expected current' + test_i18ncmp expected current' test_expect_success TABS_IN_FILENAMES 'setup expect' ' cat > expected <<\EOF @@ -187,12 +187,12 @@ EOF test_expect_success TABS_IN_FILENAMES 'git diff-tree delete with-funny applied' \ 'git diff-index -p $t0 | git apply --stat | sed -e "s/|.*//" -e "s/ *\$//" >current && - test_cmp expected current' + test_i18ncmp expected current' test_expect_success TABS_IN_FILENAMES 'git apply non-git diff' \ 'git diff-index -p $t0 | sed -ne "/^[-+@]/p" | git apply --stat | sed -e "s/|.*//" -e "s/ *\$//" >current && - test_cmp expected current' + test_i18ncmp expected current' test_done diff --git a/t/t3508-cherry-pick-many-commits.sh b/t/t3508-cherry-pick-many-commits.sh index 1b3a344158..d909e6dbcf 100755 --- a/t/t3508-cherry-pick-many-commits.sh +++ b/t/t3508-cherry-pick-many-commits.sh @@ -55,7 +55,7 @@ test_expect_success 'cherry-pick first..fourth works' ' git diff --quiet HEAD other && sed -e "s/$_x05[0-9a-f][0-9a-f]/OBJID/" actual.fuzzy && - test_cmp expected actual.fuzzy && + test_i18ncmp expected actual.fuzzy && check_head_differs_from fourth ' @@ -82,7 +82,7 @@ test_expect_success 'cherry-pick --strategy resolve first..fourth works' ' git diff --quiet other && git diff --quiet HEAD other && sed -e "s/$_x05[0-9a-f][0-9a-f]/OBJID/" actual.fuzzy && - test_cmp expected actual.fuzzy && + test_i18ncmp expected actual.fuzzy && check_head_differs_from fourth ' diff --git a/t/t3903-stash.sh b/t/t3903-stash.sh index 663c60a12e..c69e4da182 100755 --- a/t/t3903-stash.sh +++ b/t/t3903-stash.sh @@ -447,7 +447,7 @@ test_expect_success 'stash show - stashes on stack, stash-like argument' ' 1 file changed, 1 insertion(+) EOF git stash show ${STASH_ID} >actual && - test_cmp expected actual + test_i18ncmp expected actual ' test_expect_success 'stash show -p - stashes on stack, stash-like argument' ' @@ -485,7 +485,7 @@ test_expect_success 'stash show - no stashes on stack, stash-like argument' ' 1 file changed, 1 insertion(+) EOF git stash show ${STASH_ID} >actual && - test_cmp expected actual + test_i18ncmp expected actual ' test_expect_success 'stash show -p - no stashes on stack, stash-like argument' ' diff --git a/t/t4012-diff-binary.sh b/t/t4012-diff-binary.sh index 2d9f9a0cf1..008cf10a0c 100755 --- a/t/t4012-diff-binary.sh +++ b/t/t4012-diff-binary.sh @@ -25,11 +25,11 @@ cat > expected <<\EOF EOF test_expect_success 'diff without --binary' \ 'git diff | git apply --stat --summary >current && - test_cmp expected current' + test_i18ncmp expected current' test_expect_success 'diff with --binary' \ 'git diff --binary | git apply --stat --summary >current && - test_cmp expected current' + test_i18ncmp expected current' # apply needs to be able to skip the binary material correctly # in order to report the line number of a corrupt patch. diff --git a/t/t4049-diff-stat-count.sh b/t/t4049-diff-stat-count.sh index a6d1887536..591ffbc075 100755 --- a/t/t4049-diff-stat-count.sh +++ b/t/t4049-diff-stat-count.sh @@ -19,7 +19,7 @@ test_expect_success setup ' 2 files changed, 2 insertions(+) EOF git diff --stat --stat-count=2 >actual && - test_cmp expect actual + test_i18ncmp expect actual ' test_done diff --git a/t/t4100-apply-stat.sh b/t/t4100-apply-stat.sh index 9b433de836..744b8e51be 100755 --- a/t/t4100-apply-stat.sh +++ b/t/t4100-apply-stat.sh @@ -17,13 +17,13 @@ do test_expect_success "$title" ' git apply --stat --summary \ <"$TEST_DIRECTORY/t4100/t-apply-$num.patch" >current && - test_cmp "$TEST_DIRECTORY"/t4100/t-apply-$num.expect current + test_i18ncmp "$TEST_DIRECTORY"/t4100/t-apply-$num.expect current ' test_expect_success "$title with recount" ' sed -e "$UNC" <"$TEST_DIRECTORY/t4100/t-apply-$num.patch" | git apply --recount --stat --summary >current && - test_cmp "$TEST_DIRECTORY"/t4100/t-apply-$num.expect current + test_i18ncmp "$TEST_DIRECTORY"/t4100/t-apply-$num.expect current ' done <<\EOF rename diff --git a/t/t5150-request-pull.sh b/t/t5150-request-pull.sh index 2af8947eeb..432f98c357 100755 --- a/t/t5150-request-pull.sh +++ b/t/t5150-request-pull.sh @@ -216,7 +216,7 @@ test_expect_success 'pull request format' ' git request-pull initial "$downstream_url" >../request ) && request.fuzzy && - test_cmp expect request.fuzzy + test_i18ncmp expect request.fuzzy ' diff --git a/t/t7602-merge-octopus-many.sh b/t/t7602-merge-octopus-many.sh index 5783ebf3ab..bce0bd37cb 100755 --- a/t/t7602-merge-octopus-many.sh +++ b/t/t7602-merge-octopus-many.sh @@ -66,7 +66,7 @@ EOF test_expect_success 'merge output uses pretty names' ' git reset --hard c1 && git merge c2 c3 c4 >actual && - test_cmp actual expected + test_i18ncmp expected actual ' cat >expected <<\EOF @@ -80,7 +80,7 @@ EOF test_expect_success 'merge up-to-date output uses pretty names' ' git merge c4 c5 >actual && - test_cmp actual expected + test_i18ncmp expected actual ' cat >expected <<\EOF @@ -97,7 +97,7 @@ EOF test_expect_success 'merge fast-forward output uses pretty names' ' git reset --hard c0 && git merge c1 c2 >actual && - test_cmp actual expected + test_i18ncmp expected actual ' test_done From e7a8ac3875ef2a6fe10af7f16d034a2b8f218af3 Mon Sep 17 00:00:00 2001 From: Jonathan Nieder Date: Mon, 12 Mar 2012 23:58:59 -0500 Subject: [PATCH 118/291] test: use numstat instead of diffstat in funny-names test This test script checks that git's plumbing commands quote filenames with special characters like space, tab, and double-quote appropriately in their input and output. Since commit v1.7.9.2~13 (Use correct grammar in diffstat summary line, 2012-02-01), the final "1 file changed, 1 insertion(+)" line from diffstats is translatable, meaning tests that rely on exact "git apply --stat" output have to be skipped when git is not configured to produce output in the C locale (for example, when GETTEXT_POISON is enabled). So: - Tweak the three "git apply --stat" tests that check "git apply"'s input parsing to use --numstat instead. --numstat output is more reliable, does not vary with locale, and is itself easier to parse. These tests are mainly about how "git apply" parses its input so this should not result in much loss of coverage. - Add a new "apply --stat" test to check the quoting in --stat output format. This wins back a little of the test coverage lost with the patch "test: use test_i18ncmp to check --stat output" when GETTEXT_POISON is enabled. Signed-off-by: Jonathan Nieder Signed-off-by: Junio C Hamano --- t/t3300-funny-names.sh | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/t/t3300-funny-names.sh b/t/t3300-funny-names.sh index 644aa219e9..9114893b13 100755 --- a/t/t3300-funny-names.sh +++ b/t/t3300-funny-names.sh @@ -171,28 +171,35 @@ cat >expected <<\EOF EOF ' -test_expect_success TABS_IN_FILENAMES 'git diff-tree rename with-funny applied' \ +test_expect_success TABS_IN_FILENAMES 'diffstat for rename with funny chars' \ 'git diff-index -M -p $t0 | git apply --stat | sed -e "s/|.*//" -e "s/ *\$//" >current && test_i18ncmp expected current' +test_expect_success TABS_IN_FILENAMES 'numstat for rename with funny chars' \ + 'cat >expected <<-\EOF && + 0 0 "tabs\t,\" (dq) and spaces" + EOF + git diff-index -M -p $t0 >diff && + git apply --numstat current && + test_cmp expected current' + test_expect_success TABS_IN_FILENAMES 'setup expect' ' cat > expected <<\EOF - no-funny - "tabs\t,\" (dq) and spaces" - 2 files changed, 3 insertions(+), 3 deletions(-) +0 3 no-funny +3 0 "tabs\t,\" (dq) and spaces" EOF ' -test_expect_success TABS_IN_FILENAMES 'git diff-tree delete with-funny applied' \ +test_expect_success TABS_IN_FILENAMES 'numstat without -M for funny rename' \ 'git diff-index -p $t0 | - git apply --stat | sed -e "s/|.*//" -e "s/ *\$//" >current && - test_i18ncmp expected current' + git apply --numstat >current && + test_cmp expected current' -test_expect_success TABS_IN_FILENAMES 'git apply non-git diff' \ +test_expect_success TABS_IN_FILENAMES 'numstat for non-git funny rename diff' \ 'git diff-index -p $t0 | sed -ne "/^[-+@]/p" | - git apply --stat | sed -e "s/|.*//" -e "s/ *\$//" >current && - test_i18ncmp expected current' + git apply --numstat >current && + test_cmp expected current' test_done From ef7db1933b6d4ae466a1b248a98c7ed9d1d65a41 Mon Sep 17 00:00:00 2001 From: Jonathan Nieder Date: Mon, 12 Mar 2012 23:59:52 -0500 Subject: [PATCH 119/291] test: modernize funny-names test style This is one of the early tests, so it uses a style that by modern standards can be hard to read. Tweak it to: - clearly declare what assertion each test is designed to check - mark tests that create state later tests will depend on with the word "setup" so people writing or running tests know the others can be skipped or reordered safely - put commands that populate a file with expected output inside the corresponding test stanza, so it is easier to see by eye where each test begins and ends - instead of pipelines, use commands that read and write a temporary file, so bugs causing commands to segfault or produce the wrong exit status can be caught. More cosmetic changes: - put the opening quote starting each test on the same line as the test_expect_* invocation, and indent the commands in each test with a single tab - end the test early if the underlying filesystem cannot accomodate the filenames we use, instead of marking all tests with the same TABS_IN_FILENAMES prerequisite. Signed-off-by: Jonathan Nieder Signed-off-by: Junio C Hamano --- t/t3300-funny-names.sh | 323 +++++++++++++++++++++-------------------- 1 file changed, 168 insertions(+), 155 deletions(-) diff --git a/t/t3300-funny-names.sh b/t/t3300-funny-names.sh index 9114893b13..c53c9f65eb 100755 --- a/t/t3300-funny-names.sh +++ b/t/t3300-funny-names.sh @@ -15,191 +15,204 @@ p0='no-funny' p1='tabs ," (dq) and spaces' p2='just space' -cat >"$p0" <<\EOF -1. A quick brown fox jumps over the lazy cat, oops dog. -2. A quick brown fox jumps over the lazy cat, oops dog. -3. A quick brown fox jumps over the lazy cat, oops dog. -EOF +test_expect_success 'setup' ' + cat >"$p0" <<-\EOF && + 1. A quick brown fox jumps over the lazy cat, oops dog. + 2. A quick brown fox jumps over the lazy cat, oops dog. + 3. A quick brown fox jumps over the lazy cat, oops dog. + EOF -cat 2>/dev/null >"$p1" "$p0" -echo 'Foo Bar Baz' >"$p2" + { cat "$p0" >"$p1" || :; } && + { echo "Foo Bar Baz" >"$p2" || :; } && -if test -f "$p1" && cmp "$p0" "$p1" + if test -f "$p1" && cmp "$p0" "$p1" + then + test_set_prereq TABS_IN_FILENAMES + fi +' + +if ! test_have_prereq TABS_IN_FILENAMES then - test_set_prereq TABS_IN_FILENAMES -else # since FAT/NTFS does not allow tabs in filenames, skip this test - say 'Your filesystem does not allow tabs in filenames' + skip_all='Your filesystem does not allow tabs in filenames' + test_done fi -test_expect_success TABS_IN_FILENAMES 'setup expect' " -echo 'just space -no-funny' >expected -" +test_expect_success 'setup: populate index and tree' ' + git update-index --add "$p0" "$p2" && + t0=$(git write-tree) +' -test_expect_success TABS_IN_FILENAMES 'git ls-files no-funny' \ - 'git update-index --add "$p0" "$p2" && +test_expect_success 'ls-files prints space in filename verbatim' ' + printf "%s\n" "just space" no-funny >expected && git ls-files >current && - test_cmp expected current' - -test_expect_success TABS_IN_FILENAMES 'setup expect' ' -t0=`git write-tree` && -echo "$t0" >t0 && - -cat > expected <<\EOF -just space -no-funny -"tabs\t,\" (dq) and spaces" -EOF + test_cmp expected current ' -test_expect_success TABS_IN_FILENAMES 'git ls-files with-funny' \ - 'git update-index --add "$p1" && +test_expect_success 'setup: add funny filename' ' + git update-index --add "$p1" && + t1=$(git write-tree) +' + +test_expect_success 'ls-files quotes funny filename' ' + cat >expected <<-\EOF && + just space + no-funny + "tabs\t,\" (dq) and spaces" + EOF git ls-files >current && - test_cmp expected current' - -test_expect_success TABS_IN_FILENAMES 'setup expect' " -echo 'just space -no-funny -tabs ,\" (dq) and spaces' >expected -" - -test_expect_success TABS_IN_FILENAMES 'git ls-files -z with-funny' \ - 'git ls-files -z | perl -pe y/\\000/\\012/ >current && - test_cmp expected current' - -test_expect_success TABS_IN_FILENAMES 'setup expect' ' -t1=`git write-tree` && -echo "$t1" >t1 && - -cat > expected <<\EOF -just space -no-funny -"tabs\t,\" (dq) and spaces" -EOF + test_cmp expected current ' -test_expect_success TABS_IN_FILENAMES 'git ls-tree with funny' \ - 'git ls-tree -r $t1 | sed -e "s/^[^ ]* //" >current && - test_cmp expected current' - -test_expect_success TABS_IN_FILENAMES 'setup expect' ' -cat > expected <<\EOF -A "tabs\t,\" (dq) and spaces" -EOF +test_expect_success 'ls-files -z does not quote funny filename' ' + cat >expected <<-\EOF && + just space + no-funny + tabs ," (dq) and spaces + EOF + git ls-files -z >ls-files.z && + perl -pe "y/\000/\012/" current && + test_cmp expected current ' -test_expect_success TABS_IN_FILENAMES 'git diff-index with-funny' \ - 'git diff-index --name-status $t0 >current && - test_cmp expected current' - -test_expect_success TABS_IN_FILENAMES 'git diff-tree with-funny' \ - 'git diff-tree --name-status $t0 $t1 >current && - test_cmp expected current' - -test_expect_success TABS_IN_FILENAMES 'setup expect' " -echo 'A -tabs ,\" (dq) and spaces' >expected -" - -test_expect_success TABS_IN_FILENAMES 'git diff-index -z with-funny' \ - 'git diff-index -z --name-status $t0 | perl -pe y/\\000/\\012/ >current && - test_cmp expected current' - -test_expect_success TABS_IN_FILENAMES 'git diff-tree -z with-funny' \ - 'git diff-tree -z --name-status $t0 $t1 | perl -pe y/\\000/\\012/ >current && - test_cmp expected current' - -test_expect_success TABS_IN_FILENAMES 'setup expect' ' -cat > expected <<\EOF -CNUM no-funny "tabs\t,\" (dq) and spaces" -EOF +test_expect_success 'ls-tree quotes funny filename' ' + cat >expected <<-\EOF && + just space + no-funny + "tabs\t,\" (dq) and spaces" + EOF + git ls-tree -r $t1 >ls-tree && + sed -e "s/^[^ ]* //" current && + test_cmp expected current ' -test_expect_success TABS_IN_FILENAMES 'git diff-tree -C with-funny' \ - 'git diff-tree -C --find-copies-harder --name-status \ - $t0 $t1 | sed -e 's/^C[0-9]*/CNUM/' >current && - test_cmp expected current' - -test_expect_success TABS_IN_FILENAMES 'setup expect' ' -cat > expected <<\EOF -RNUM no-funny "tabs\t,\" (dq) and spaces" -EOF +test_expect_success 'diff-index --name-status quotes funny filename' ' + cat >expected <<-\EOF && + A "tabs\t,\" (dq) and spaces" + EOF + git diff-index --name-status $t0 >current && + test_cmp expected current ' -test_expect_success TABS_IN_FILENAMES 'git diff-tree delete with-funny' \ - 'git update-index --force-remove "$p0" && - git diff-index -M --name-status \ - $t0 | sed -e 's/^R[0-9]*/RNUM/' >current && - test_cmp expected current' - -test_expect_success TABS_IN_FILENAMES 'setup expect' ' -cat > expected <<\EOF -diff --git a/no-funny "b/tabs\t,\" (dq) and spaces" -similarity index NUM% -rename from no-funny -rename to "tabs\t,\" (dq) and spaces" -EOF +test_expect_success 'diff-tree --name-status quotes funny filename' ' + cat >expected <<-\EOF && + A "tabs\t,\" (dq) and spaces" + EOF + git diff-tree --name-status $t0 $t1 >current && + test_cmp expected current ' -test_expect_success TABS_IN_FILENAMES 'git diff-tree delete with-funny' \ - 'git diff-index -M -p $t0 | - sed -e "s/index [0-9]*%/index NUM%/" >current && - test_cmp expected current' - -test_expect_success TABS_IN_FILENAMES 'setup expect' ' -chmod +x "$p1" && -cat > expected <<\EOF -diff --git a/no-funny "b/tabs\t,\" (dq) and spaces" -old mode 100644 -new mode 100755 -similarity index NUM% -rename from no-funny -rename to "tabs\t,\" (dq) and spaces" -EOF +test_expect_success 'diff-index -z does not quote funny filename' ' + cat >expected <<-\EOF && + A + tabs ," (dq) and spaces + EOF + git diff-index -z --name-status $t0 >diff-index.z && + perl -pe "y/\000/\012/" current && + test_cmp expected current ' -test_expect_success TABS_IN_FILENAMES 'git diff-tree delete with-funny' \ - 'git diff-index -M -p $t0 | - sed -e "s/index [0-9]*%/index NUM%/" >current && - test_cmp expected current' - -test_expect_success TABS_IN_FILENAMES 'setup expect' ' -cat >expected <<\EOF - "tabs\t,\" (dq) and spaces" - 1 file changed, 0 insertions(+), 0 deletions(-) -EOF +test_expect_success 'diff-tree -z does not quote funny filename' ' + cat >expected <<-\EOF && + A + tabs ," (dq) and spaces + EOF + git diff-tree -z --name-status $t0 $t1 >diff-tree.z && + perl -pe y/\\000/\\012/ current && + test_cmp expected current ' -test_expect_success TABS_IN_FILENAMES 'diffstat for rename with funny chars' \ - 'git diff-index -M -p $t0 | - git apply --stat | sed -e "s/|.*//" -e "s/ *\$//" >current && - test_i18ncmp expected current' +test_expect_success 'diff-tree --find-copies-harder quotes funny filename' ' + cat >expected <<-\EOF && + CNUM no-funny "tabs\t,\" (dq) and spaces" + EOF + git diff-tree -C --find-copies-harder --name-status $t0 $t1 >out && + sed -e "s/^C[0-9]*/CNUM/" current && + test_cmp expected current +' -test_expect_success TABS_IN_FILENAMES 'numstat for rename with funny chars' \ - 'cat >expected <<-\EOF && +test_expect_success 'setup: remove unfunny index entry' ' + git update-index --force-remove "$p0" +' + +test_expect_success 'diff-tree -M quotes funny filename' ' + cat >expected <<-\EOF && + RNUM no-funny "tabs\t,\" (dq) and spaces" + EOF + git diff-index -M --name-status $t0 >out && + sed -e "s/^R[0-9]*/RNUM/" current && + test_cmp expected current +' + +test_expect_success 'diff-index -M -p quotes funny filename' ' + cat >expected <<-\EOF && + diff --git a/no-funny "b/tabs\t,\" (dq) and spaces" + similarity index NUM% + rename from no-funny + rename to "tabs\t,\" (dq) and spaces" + EOF + git diff-index -M -p $t0 >diff && + sed -e "s/index [0-9]*%/index NUM%/" current && + test_cmp expected current +' + +test_expect_success 'setup: mode change' ' + chmod +x "$p1" +' + +test_expect_success 'diff-index -M -p with mode change quotes funny filename' ' + cat >expected <<-\EOF && + diff --git a/no-funny "b/tabs\t,\" (dq) and spaces" + old mode 100644 + new mode 100755 + similarity index NUM% + rename from no-funny + rename to "tabs\t,\" (dq) and spaces" + EOF + git diff-index -M -p $t0 >diff && + sed -e "s/index [0-9]*%/index NUM%/" current && + test_cmp expected current +' + +test_expect_success 'diffstat for rename quotes funny filename' ' + cat >expected <<-\EOF && + "tabs\t,\" (dq) and spaces" + 1 file changed, 0 insertions(+), 0 deletions(-) + EOF + git diff-index -M -p $t0 >diff && + git apply --stat diffstat && + sed -e "s/|.*//" -e "s/ *\$//" current && + test_i18ncmp expected current +' + +test_expect_success 'numstat for rename quotes funny filename' ' + cat >expected <<-\EOF && 0 0 "tabs\t,\" (dq) and spaces" EOF - git diff-index -M -p $t0 >diff && - git apply --numstat current && - test_cmp expected current' - -test_expect_success TABS_IN_FILENAMES 'setup expect' ' -cat > expected <<\EOF -0 3 no-funny -3 0 "tabs\t,\" (dq) and spaces" -EOF + git diff-index -M -p $t0 >diff && + git apply --numstat current && + test_cmp expected current ' -test_expect_success TABS_IN_FILENAMES 'numstat without -M for funny rename' \ - 'git diff-index -p $t0 | - git apply --numstat >current && - test_cmp expected current' +test_expect_success 'numstat without -M quotes funny filename' ' + cat >expected <<-\EOF && + 0 3 no-funny + 3 0 "tabs\t,\" (dq) and spaces" + EOF + git diff-index -p $t0 >diff && + git apply --numstat current && + test_cmp expected current +' -test_expect_success TABS_IN_FILENAMES 'numstat for non-git funny rename diff' \ - 'git diff-index -p $t0 | - sed -ne "/^[-+@]/p" | - git apply --numstat >current && - test_cmp expected current' +test_expect_success 'numstat for non-git rename diff quotes funny filename' ' + cat >expected <<-\EOF && + 0 3 no-funny + 3 0 "tabs\t,\" (dq) and spaces" + EOF + git diff-index -p $t0 >git-diff && + sed -ne "/^[-+@]/p" diff && + git apply --numstat current && + test_cmp expected current +' test_done From 2593633f5a7e1ddc02cd5f8256d02a53324e4cf6 Mon Sep 17 00:00:00 2001 From: Jonathan Nieder Date: Tue, 13 Mar 2012 00:00:36 -0500 Subject: [PATCH 120/291] test: test cherry-pick functionality and output separately Since v1.7.3-rc0~26^2~9 (revert: report success when using option --strategy, 2010-07-14), the cherry-pick-many-commits test checks the format of output written to the terminal during a cherry-pick sequence in addition to the functionality. There is no reason those have to be checked in the same test, though, and it has some downsides: - when progress output is broken, the test result does not convey whether the functionality was also broken or not - it is not immediately obvious when reading that these checks are meant to prevent regressions in details of the output format and are not just a roundabout way to check functional details like the number of commits produced - there is a temptation to include the same kind of output checking for every new cherry-pick test, which would make future changes to the output unnecessarily difficult Put the tests from v1.7.3-rc0~26^2~9 in separate assertions, following the principle "test one feature at a time". Signed-off-by: Jonathan Nieder Signed-off-by: Junio C Hamano --- t/t3508-cherry-pick-many-commits.sh | 32 +++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/t/t3508-cherry-pick-many-commits.sh b/t/t3508-cherry-pick-many-commits.sh index d909e6dbcf..75f7ff4f2f 100755 --- a/t/t3508-cherry-pick-many-commits.sh +++ b/t/t3508-cherry-pick-many-commits.sh @@ -35,6 +35,16 @@ test_expect_success setup ' ' test_expect_success 'cherry-pick first..fourth works' ' + git checkout -f master && + git reset --hard first && + test_tick && + git cherry-pick first..fourth && + git diff --quiet other && + git diff --quiet HEAD other && + check_head_differs_from fourth +' + +test_expect_success 'output to keep user entertained during multi-pick' ' cat <<-\EOF >expected && [master OBJID] second Author: A U Thor @@ -51,15 +61,22 @@ test_expect_success 'cherry-pick first..fourth works' ' git reset --hard first && test_tick && git cherry-pick first..fourth >actual && - git diff --quiet other && - git diff --quiet HEAD other && - sed -e "s/$_x05[0-9a-f][0-9a-f]/OBJID/" actual.fuzzy && - test_i18ncmp expected actual.fuzzy && - check_head_differs_from fourth + test_line_count -ge 3 actual.fuzzy && + test_i18ncmp expected actual.fuzzy ' test_expect_success 'cherry-pick --strategy resolve first..fourth works' ' + git checkout -f master && + git reset --hard first && + test_tick && + git cherry-pick --strategy resolve first..fourth && + git diff --quiet other && + git diff --quiet HEAD other && + check_head_differs_from fourth +' + +test_expect_success 'output during multi-pick indicates merge strategy' ' cat <<-\EOF >expected && Trying simple merge. [master OBJID] second @@ -79,11 +96,8 @@ test_expect_success 'cherry-pick --strategy resolve first..fourth works' ' git reset --hard first && test_tick && git cherry-pick --strategy resolve first..fourth >actual && - git diff --quiet other && - git diff --quiet HEAD other && sed -e "s/$_x05[0-9a-f][0-9a-f]/OBJID/" actual.fuzzy && - test_i18ncmp expected actual.fuzzy && - check_head_differs_from fourth + test_i18ncmp expected actual.fuzzy ' test_expect_success 'cherry-pick --ff first..fourth works' ' From 1145211456580530ab01ef713adae4812d5758b2 Mon Sep 17 00:00:00 2001 From: Jonathan Nieder Date: Tue, 13 Mar 2012 00:01:32 -0500 Subject: [PATCH 121/291] test: use --numstat instead of --stat in "git stash show" tests git's diff --stat output is intended for human consumption and since v1.7.9.2~13 (2012-02-01) varies by locale. Add a test checking that git stash show defaults to --stat and tweak the rest of the "stash show" tests that showed a diffstat to use numstat. This way, there are fewer tests to tweak if the diffstat format changes again. This also improves test coverage when running tests with git configured not to write its output in the C locale (e.g., via GETTEXT_POISON=Yes). Signed-off-by: Jonathan Nieder Signed-off-by: Junio C Hamano --- t/t3903-stash.sh | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/t/t3903-stash.sh b/t/t3903-stash.sh index c69e4da182..3addb804d5 100755 --- a/t/t3903-stash.sh +++ b/t/t3903-stash.sh @@ -432,7 +432,7 @@ test_expect_success 'stash branch - stashes on stack, stash-like argument' ' test $(git ls-files --modified | wc -l) -eq 1 ' -test_expect_success 'stash show - stashes on stack, stash-like argument' ' +test_expect_success 'stash show format defaults to --stat' ' git stash clear && test_when_finished "git reset --hard HEAD" && git reset --hard && @@ -450,6 +450,21 @@ test_expect_success 'stash show - stashes on stack, stash-like argument' ' test_i18ncmp expected actual ' +test_expect_success 'stash show - stashes on stack, stash-like argument' ' + git stash clear && + test_when_finished "git reset --hard HEAD" && + git reset --hard && + echo foo >> file && + git stash && + test_when_finished "git stash drop" && + echo bar >> file && + STASH_ID=$(git stash create) && + git reset --hard && + echo "1 0 file" >expected && + git stash show --numstat ${STASH_ID} >actual && + test_cmp expected actual +' + test_expect_success 'stash show -p - stashes on stack, stash-like argument' ' git stash clear && test_when_finished "git reset --hard HEAD" && @@ -480,12 +495,9 @@ test_expect_success 'stash show - no stashes on stack, stash-like argument' ' echo foo >> file && STASH_ID=$(git stash create) && git reset --hard && - cat >expected <<-EOF && - file | 1 + - 1 file changed, 1 insertion(+) - EOF - git stash show ${STASH_ID} >actual && - test_i18ncmp expected actual + echo "1 0 file" >expected && + git stash show --numstat ${STASH_ID} >actual && + test_cmp expected actual ' test_expect_success 'stash show -p - no stashes on stack, stash-like argument' ' From 2983c0e22a5b6a56b8f5d7bb2dd2a3a0e26ac005 Mon Sep 17 00:00:00 2001 From: Jonathan Nieder Date: Tue, 13 Mar 2012 00:02:19 -0500 Subject: [PATCH 122/291] test: use numstat instead of diffstat in binary-diff test git's --stat output is intended for humans and since v1.7.9.2~13 (2012-02-01) varies by locale. The tests in this script using "apply --stat" are meant to check two things: - how binary file changes are accounted for and printed in git's diffstat format - that "git apply" can parse the various forms of binary diff Split these two kinds of check into separate tests, and use --numstat instead of --stat in the latter. This way, we lose less test coverage when git is being run without writing its output in the C locale (for example because GETTEXT_POISON is enabled) and there are fewer tests to change if the --stat output needs to be tweaked again. While at it, use commands separated by && that read and write to temporary files in place of pipelines so segfaults and other failures in the upstream of the processing pipeline don't get hidden. Signed-off-by: Jonathan Nieder Signed-off-by: Junio C Hamano --- t/t4012-diff-binary.sh | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/t/t4012-diff-binary.sh b/t/t4012-diff-binary.sh index 008cf10a0c..ed24ddd88a 100755 --- a/t/t4012-diff-binary.sh +++ b/t/t4012-diff-binary.sh @@ -8,6 +8,13 @@ test_description='Binary diff and apply . ./test-lib.sh +cat >expect.binary-numstat <<\EOF +1 1 a +- - b +1 1 c +- - d +EOF + test_expect_success 'prepare repository' \ 'echo AIT >a && echo BIT >b && echo CIT >c && echo DIT >d && git update-index --add a b c d && @@ -23,13 +30,23 @@ cat > expected <<\EOF d | Bin 4 files changed, 2 insertions(+), 2 deletions(-) EOF -test_expect_success 'diff without --binary' \ - 'git diff | git apply --stat --summary >current && - test_i18ncmp expected current' +test_expect_success '"apply --stat" output for binary file change' ' + git diff >diff && + git apply --stat --summary current && + test_i18ncmp expected current +' -test_expect_success 'diff with --binary' \ - 'git diff --binary | git apply --stat --summary >current && - test_i18ncmp expected current' +test_expect_success 'apply --numstat notices binary file change' ' + git diff >diff && + git apply --numstat current && + test_cmp expect.binary-numstat current +' + +test_expect_success 'apply --numstat understands diff --binary format' ' + git diff --binary >diff && + git apply --numstat current && + test_cmp expect.binary-numstat current +' # apply needs to be able to skip the binary material correctly # in order to report the line number of a corrupt patch. From 6dd88832e77ad7c0c7f82522d3741b5b7bf62fbd Mon Sep 17 00:00:00 2001 From: Jonathan Nieder Date: Tue, 13 Mar 2012 00:05:54 -0500 Subject: [PATCH 123/291] diffstat summary line varies by locale: miscellany These changes are in the same spirit as the six patches that precede them, but they haven't been split into individually justifiable patches yet. Signed-off-by: Jonathan Nieder Signed-off-by: Junio C Hamano --- t/t4013-diff-various.sh | 7 +++- t/t4014-format-patch.sh | 9 ++--- t/t4016-diff-quote.sh | 41 +++++++++++++-------- t/t4030-diff-textconv.sh | 6 +++- t/t4031-diff-rewrite-binary.sh | 10 ++++-- t/t4043-diff-rename-binary.sh | 8 ++--- t/t4045-diff-relative.sh | 16 +++++++-- t/t4047-diff-dirstat.sh | 65 ++++++++++++++++------------------ 8 files changed, 97 insertions(+), 65 deletions(-) diff --git a/t/t4013-diff-various.sh b/t/t4013-diff-various.sh index 93a6f20871..e77c09c37e 100755 --- a/t/t4013-diff-various.sh +++ b/t/t4013-diff-various.sh @@ -128,7 +128,12 @@ do } >"$actual" && if test -f "$expect" then - test_cmp "$expect" "$actual" && + case $cmd in + *format-patch* | *-stat*) + test_i18ncmp "$expect" "$actual";; + *) + test_cmp "$expect" "$actual";; + esac && rm -f "$actual" else # this is to help developing new tests. diff --git a/t/t4014-format-patch.sh b/t/t4014-format-patch.sh index 7dfe716cf9..b473b6d6eb 100755 --- a/t/t4014-format-patch.sh +++ b/t/t4014-format-patch.sh @@ -518,11 +518,6 @@ test_expect_success 'shortlog of cover-letter wraps overly-long onelines' ' ' cat > expect << EOF ---- - file | 16 ++++++++++++++++ - 1 file changed, 16 insertions(+) - -diff --git a/file b/file index 40f36c6..2dc5c23 100644 --- a/file +++ b/file @@ -537,7 +532,9 @@ EOF test_expect_success 'format-patch respects -U' ' git format-patch -U4 -2 && - sed -e "1,/^\$/d" -e "/^+5/q" < 0001-This-is-an-excessively-long-subject-line-for-a-messa.patch > output && + sed -e "1,/^diff/d" -e "/^+5/q" \ + <0001-This-is-an-excessively-long-subject-line-for-a-messa.patch \ + >output && test_cmp expect output ' diff --git a/t/t4016-diff-quote.sh b/t/t4016-diff-quote.sh index ab0c2f0574..3ec71184ba 100755 --- a/t/t4016-diff-quote.sh +++ b/t/t4016-diff-quote.sh @@ -57,22 +57,33 @@ test_expect_success TABS_IN_FILENAMES 'git diff --summary -M HEAD' ' test_cmp expect actual ' -test_expect_success TABS_IN_FILENAMES 'setup expected files' ' -cat >expect <<\EOF - pathname.1 => "Rpathname\twith HT.0" | 0 - pathname.3 => "Rpathname\nwith LF.0" | 0 - "pathname\twith HT.3" => "Rpathname\nwith LF.1" | 0 - pathname.2 => Rpathname with SP.0 | 0 - "pathname\twith HT.2" => Rpathname with SP.1 | 0 - pathname.0 => Rpathname.0 | 0 - "pathname\twith HT.0" => Rpathname.1 | 0 - 7 files changed, 0 insertions(+), 0 deletions(-) -EOF -' - -test_expect_success TABS_IN_FILENAMES 'git diff --stat -M HEAD' ' - git diff --stat -M HEAD >actual && +test_expect_success TABS_IN_FILENAMES 'git diff --numstat -M HEAD' ' + cat >expect <<-\EOF && + 0 0 pathname.1 => "Rpathname\twith HT.0" + 0 0 pathname.3 => "Rpathname\nwith LF.0" + 0 0 "pathname\twith HT.3" => "Rpathname\nwith LF.1" + 0 0 pathname.2 => Rpathname with SP.0 + 0 0 "pathname\twith HT.2" => Rpathname with SP.1 + 0 0 pathname.0 => Rpathname.0 + 0 0 "pathname\twith HT.0" => Rpathname.1 + EOF + git diff --numstat -M HEAD >actual && test_cmp expect actual ' +test_expect_success TABS_IN_FILENAMES 'git diff --stat -M HEAD' ' + cat >expect <<-\EOF && + pathname.1 => "Rpathname\twith HT.0" | 0 + pathname.3 => "Rpathname\nwith LF.0" | 0 + "pathname\twith HT.3" => "Rpathname\nwith LF.1" | 0 + pathname.2 => Rpathname with SP.0 | 0 + "pathname\twith HT.2" => Rpathname with SP.1 | 0 + pathname.0 => Rpathname.0 | 0 + "pathname\twith HT.0" => Rpathname.1 | 0 + 7 files changed, 0 insertions(+), 0 deletions(-) + EOF + git diff --stat -M HEAD >actual && + test_i18ncmp expect actual +' + test_done diff --git a/t/t4030-diff-textconv.sh b/t/t4030-diff-textconv.sh index 4ac162cfcf..06b05df848 100755 --- a/t/t4030-diff-textconv.sh +++ b/t/t4030-diff-textconv.sh @@ -91,7 +91,11 @@ EOF test_expect_success 'diffstat does not run textconv' ' echo file diff=fail >.gitattributes && git diff --stat HEAD^ HEAD >actual && - test_cmp expect.stat actual + test_i18ncmp expect.stat actual && + + head -n1 expect.line1 && + head -n1 actual.line1 && + test_cmp expect.line1 actual.line1 ' # restore working setup echo file diff=foo >.gitattributes diff --git a/t/t4031-diff-rewrite-binary.sh b/t/t4031-diff-rewrite-binary.sh index 7d7470f21b..c8296fa4fc 100755 --- a/t/t4031-diff-rewrite-binary.sh +++ b/t/t4031-diff-rewrite-binary.sh @@ -44,10 +44,16 @@ test_expect_success 'rewrite diff can show binary patch' ' grep "GIT binary patch" diff ' -test_expect_success 'rewrite diff --stat shows binary changes' ' +test_expect_success 'rewrite diff --numstat shows binary changes' ' + git diff -B --numstat --summary >diff && + grep -e "- - " diff && + grep " rewrite file" diff +' + +test_expect_success 'diff --stat counts binary rewrite as 0 lines' ' git diff -B --stat --summary >diff && grep "Bin" diff && - grep "0 insertions.*0 deletions" diff && + test_i18ngrep "0 insertions.*0 deletions" diff && grep " rewrite file" diff ' diff --git a/t/t4043-diff-rename-binary.sh b/t/t4043-diff-rename-binary.sh index 06012811a1..2a2cf91352 100755 --- a/t/t4043-diff-rename-binary.sh +++ b/t/t4043-diff-rename-binary.sh @@ -23,9 +23,8 @@ test_expect_success 'move the files into a "sub" directory' ' ' cat > expected <<\EOF - bar => sub/bar | Bin 5 -> 5 bytes - foo => sub/foo | 0 - 2 files changed, 0 insertions(+), 0 deletions(-) +- - bar => sub/bar +0 0 foo => sub/foo diff --git a/bar b/sub/bar similarity index 100% @@ -38,7 +37,8 @@ rename to sub/foo EOF test_expect_success 'git show -C -C report renames' ' - git show -C -C --raw --binary --stat | tail -n 12 > current && + git show -C -C --raw --binary --numstat >patch-with-stat && + tail -n 11 patch-with-stat >current && test_cmp expected current ' diff --git a/t/t4045-diff-relative.sh b/t/t4045-diff-relative.sh index bd119be106..18fadcf06e 100755 --- a/t/t4045-diff-relative.sh +++ b/t/t4045-diff-relative.sh @@ -29,6 +29,18 @@ test_expect_success "-p $*" " " } +check_numstat() { +expect=$1; shift +cat >expected <expected && + git diff --numstat $* HEAD^ >actual && + test_cmp expected actual +" +} + check_stat() { expect=$1; shift cat >expected <expected <actual && - test_cmp expected actual + test_i18ncmp expected actual " } @@ -52,7 +64,7 @@ test_expect_success "--raw $*" " " } -for type in diff stat raw; do +for type in diff numstat stat raw; do check_$type file2 --relative=subdir/ check_$type file2 --relative=subdir check_$type dir/file2 --relative=sub diff --git a/t/t4047-diff-dirstat.sh b/t/t4047-diff-dirstat.sh index 29e80a58cd..ed7e093366 100755 --- a/t/t4047-diff-dirstat.sh +++ b/t/t4047-diff-dirstat.sh @@ -252,50 +252,47 @@ EOF ' cat <expect_diff_stat - changed/text | 2 +- - dst/copy/changed/text | 10 ++++++++++ - dst/copy/rearranged/text | 10 ++++++++++ - dst/copy/unchanged/text | 10 ++++++++++ - dst/move/changed/text | 10 ++++++++++ - dst/move/rearranged/text | 10 ++++++++++ - dst/move/unchanged/text | 10 ++++++++++ - rearranged/text | 2 +- - src/move/changed/text | 10 ---------- - src/move/rearranged/text | 10 ---------- - src/move/unchanged/text | 10 ---------- - 11 files changed, 62 insertions(+), 32 deletions(-) +1 1 changed/text +10 0 dst/copy/changed/text +10 0 dst/copy/rearranged/text +10 0 dst/copy/unchanged/text +10 0 dst/move/changed/text +10 0 dst/move/rearranged/text +10 0 dst/move/unchanged/text +1 1 rearranged/text +0 10 src/move/changed/text +0 10 src/move/rearranged/text +0 10 src/move/unchanged/text EOF cat <expect_diff_stat_M - changed/text | 2 +- - dst/copy/changed/text | 10 ++++++++++ - dst/copy/rearranged/text | 10 ++++++++++ - dst/copy/unchanged/text | 10 ++++++++++ - {src => dst}/move/changed/text | 2 +- - {src => dst}/move/rearranged/text | 2 +- - {src => dst}/move/unchanged/text | 0 - rearranged/text | 2 +- - 8 files changed, 34 insertions(+), 4 deletions(-) +1 1 changed/text +10 0 dst/copy/changed/text +10 0 dst/copy/rearranged/text +10 0 dst/copy/unchanged/text +1 1 {src => dst}/move/changed/text +1 1 {src => dst}/move/rearranged/text +0 0 {src => dst}/move/unchanged/text +1 1 rearranged/text EOF cat <expect_diff_stat_CC - changed/text | 2 +- - {src => dst}/copy/changed/text | 2 +- - {src => dst}/copy/rearranged/text | 2 +- - {src => dst}/copy/unchanged/text | 0 - {src => dst}/move/changed/text | 2 +- - {src => dst}/move/rearranged/text | 2 +- - {src => dst}/move/unchanged/text | 0 - rearranged/text | 2 +- - 8 files changed, 6 insertions(+), 6 deletions(-) +1 1 changed/text +1 1 {src => dst}/copy/changed/text +1 1 {src => dst}/copy/rearranged/text +0 0 {src => dst}/copy/unchanged/text +1 1 {src => dst}/move/changed/text +1 1 {src => dst}/move/rearranged/text +0 0 {src => dst}/move/unchanged/text +1 1 rearranged/text EOF -test_expect_success 'sanity check setup (--stat)' ' - git diff --stat HEAD^..HEAD >actual_diff_stat && +test_expect_success 'sanity check setup (--numstat)' ' + git diff --numstat HEAD^..HEAD >actual_diff_stat && test_cmp expect_diff_stat actual_diff_stat && - git diff --stat -M HEAD^..HEAD >actual_diff_stat_M && + git diff --numstat -M HEAD^..HEAD >actual_diff_stat_M && test_cmp expect_diff_stat_M actual_diff_stat_M && - git diff --stat -C -C HEAD^..HEAD >actual_diff_stat_CC && + git diff --numstat -C -C HEAD^..HEAD >actual_diff_stat_CC && test_cmp expect_diff_stat_CC actual_diff_stat_CC ' From 418a1435f19b8105de2ee94b54cc2962bc9b5f03 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Tue, 13 Mar 2012 10:00:00 -0700 Subject: [PATCH 124/291] fmt-merge-msg: show those involved in a merged series As we already walk the history of the branch that gets merged to come up with a short log, let's label it with names of the primary authors, so that the user who summarizes the merge can easily give credit to them in the log message. Also infer the names of "lieutents" to help integrators at higher level of the food-chain to give credit to them, by counting: * The committer of the 'tip' commit that is merged * The committer of merge commits that are merged Often the first one gives the owner of the history being pulled, but his last pull from his sublieutenants may have been a fast-forward, in which case the first one would not be. The latter rule will count the integrator of the history, so together it might be a reasonable heuristics. There are two special cases: - The "author" credit is omitted when the series is written solely by the same author who is making the merge. The name can be seen on the "Author" line of the "git log" output to view the log message anyway. - The "lieutenant" credit is omitted when there is only one key committer in the merged branch and it is the committer who is making the merge. Typically this applies to the case where the developer merges his own branch. Signed-off-by: Junio C Hamano --- builtin/fmt-merge-msg.c | 114 +++++++++++++++++++++++++++++++++++++-- t/t6200-fmt-merge-msg.sh | 27 ++++++++-- 2 files changed, 134 insertions(+), 7 deletions(-) diff --git a/builtin/fmt-merge-msg.c b/builtin/fmt-merge-msg.c index c81a7fef26..1bc6b8b8c3 100644 --- a/builtin/fmt-merge-msg.c +++ b/builtin/fmt-merge-msg.c @@ -27,6 +27,8 @@ int fmt_merge_msg_config(const char *key, const char *value, void *cb) merge_log_config = DEFAULT_MERGE_LOG_LEN; } else if (!strcmp(key, "merge.branchdesc")) { use_branch_desc = git_config_bool(key, value); + } else { + return git_default_config(key, value, cb); } return 0; } @@ -180,6 +182,101 @@ static void add_branch_desc(struct strbuf *out, const char *name) strbuf_release(&desc); } +#define util_as_integral(elem) ((intptr_t)((elem)->util)) + +static void record_person(int which, struct string_list *people, + struct commit *commit) +{ + char name_buf[MAX_GITNAME], *name, *name_end; + struct string_list_item *elem; + const char *field = (which == 'a') ? "\nauthor " : "\ncommitter "; + + name = strstr(commit->buffer, field); + if (!name) + return; + name += strlen(field); + name_end = strchrnul(name, '<'); + if (*name_end) + name_end--; + while (isspace(*name_end) && name <= name_end) + name_end--; + if (name_end < name || name + MAX_GITNAME <= name_end) + return; + memcpy(name_buf, name, name_end - name + 1); + name_buf[name_end - name + 1] = '\0'; + + elem = string_list_lookup(people, name_buf); + if (!elem) { + elem = string_list_insert(people, name_buf); + elem->util = (void *)0; + } + elem->util = (void*)(util_as_integral(elem) + 1); +} + +static int cmp_string_list_util_as_integral(const void *a_, const void *b_) +{ + const struct string_list_item *a = a_, *b = b_; + return util_as_integral(b) - util_as_integral(a); +} + +static void add_people_count(struct strbuf *out, struct string_list *people) +{ + if (people->nr == 1) + strbuf_addf(out, "%s", people->items[0].string); + else if (people->nr == 2) + strbuf_addf(out, "%s (%d) and %s (%d)", + people->items[0].string, + (int)util_as_integral(&people->items[0]), + people->items[1].string, + (int)util_as_integral(&people->items[1])); + else if (people->nr) + strbuf_addf(out, "%s (%d) and others", + people->items[0].string, + (int)util_as_integral(&people->items[0])); +} + +static void credit_people(struct strbuf *out, + struct string_list *them, + int kind) +{ + const char *label; + const char *me; + + if (kind == 'a') { + label = "\nBy "; + me = git_author_info(IDENT_NO_DATE); + } else { + label = "\nvia "; + me = git_committer_info(IDENT_NO_DATE); + } + + if (!them->nr || + (them->nr == 1 && + me && + (me = skip_prefix(me, them->items->string)) != NULL && + skip_prefix(me, " <"))) + return; + strbuf_addstr(out, label); + add_people_count(out, them); +} + +static void add_people_info(struct strbuf *out, + struct string_list *authors, + struct string_list *committers) +{ + if (authors->nr) + qsort(authors->items, + authors->nr, sizeof(authors->items[0]), + cmp_string_list_util_as_integral); + if (committers->nr) + qsort(committers->items, + committers->nr, sizeof(committers->items[0]), + cmp_string_list_util_as_integral); + + credit_people(out, authors, 'a'); + credit_people(out, committers, 'c'); +} + static void shortlog(const char *name, struct origin_data *origin_data, struct commit *head, @@ -190,6 +287,8 @@ static void shortlog(const char *name, struct commit *commit; struct object *branch; struct string_list subjects = STRING_LIST_INIT_DUP; + struct string_list authors = STRING_LIST_INIT_DUP; + struct string_list committers = STRING_LIST_INIT_DUP; int flags = UNINTERESTING | TREESAME | SEEN | SHOWN | ADDED; struct strbuf sb = STRBUF_INIT; const unsigned char *sha1 = origin_data->sha1; @@ -199,7 +298,6 @@ static void shortlog(const char *name, return; setup_revisions(0, NULL, rev, NULL); - rev->ignore_merges = 1; add_pending_object(rev, branch, name); add_pending_object(rev, &head->object, "^HEAD"); head->object.flags |= UNINTERESTING; @@ -208,10 +306,15 @@ static void shortlog(const char *name, while ((commit = get_revision(rev)) != NULL) { struct pretty_print_context ctx = {0}; - /* ignore merges */ - if (commit->parents && commit->parents->next) + if (commit->parents && commit->parents->next) { + /* do not list a merge but count committer */ + record_person('c', &committers, commit); continue; - + } + if (!count) + /* the 'tip' committer */ + record_person('c', &committers, commit); + record_person('a', &authors, commit); count++; if (subjects.nr > limit) continue; @@ -226,6 +329,7 @@ static void shortlog(const char *name, string_list_append(&subjects, strbuf_detach(&sb, NULL)); } + add_people_info(out, &authors, &committers); if (count > limit) strbuf_addf(out, "\n* %s: (%d commits)\n", name, count); else @@ -246,6 +350,8 @@ static void shortlog(const char *name, rev->commits = NULL; rev->pending.nr = 0; + string_list_clear(&authors, 0); + string_list_clear(&committers, 0); string_list_clear(&subjects, 0); } diff --git a/t/t6200-fmt-merge-msg.sh b/t/t6200-fmt-merge-msg.sh index 9a16806921..9b50f54cc2 100755 --- a/t/t6200-fmt-merge-msg.sh +++ b/t/t6200-fmt-merge-msg.sh @@ -35,15 +35,18 @@ test_expect_success setup ' echo "l3" >two && test_tick && - git commit -a -m "Left #3" && + GIT_COMMITTER_NAME="Another Committer" \ + GIT_AUTHOR_NAME="Another Author" git commit -a -m "Left #3" && echo "l4" >two && test_tick && - git commit -a -m "Left #4" && + GIT_COMMITTER_NAME="Another Committer" \ + GIT_AUTHOR_NAME="Another Author" git commit -a -m "Left #4" && echo "l5" >two && test_tick && - git commit -a -m "Left #5" && + GIT_COMMITTER_NAME="Another Committer" \ + GIT_AUTHOR_NAME="Another Author" git commit -a -m "Left #5" && git tag tag-l5 && git checkout right && @@ -99,6 +102,8 @@ test_expect_success '[merge] summary/log configuration' ' cat >expected <<-EOF && Merge branch ${apos}left${apos} + By Another Author (3) and A U Thor (2) + via Another Committer * left: Left #5 Left #4 @@ -144,6 +149,8 @@ test_expect_success 'merge.log=3 limits shortlog length' ' cat >expected <<-EOF && Merge branch ${apos}left${apos} + By Another Author (3) and A U Thor (2) + via Another Committer * left: (5 commits) Left #5 Left #4 @@ -159,6 +166,8 @@ test_expect_success 'merge.log=5 shows all 5 commits' ' cat >expected <<-EOF && Merge branch ${apos}left${apos} + By Another Author (3) and A U Thor (2) + via Another Committer * left: Left #5 Left #4 @@ -181,6 +190,8 @@ test_expect_success '--log=3 limits shortlog length' ' cat >expected <<-EOF && Merge branch ${apos}left${apos} + By Another Author (3) and A U Thor (2) + via Another Committer * left: (5 commits) Left #5 Left #4 @@ -196,6 +207,8 @@ test_expect_success '--log=5 shows all 5 commits' ' cat >expected <<-EOF && Merge branch ${apos}left${apos} + By Another Author (3) and A U Thor (2) + via Another Committer * left: Left #5 Left #4 @@ -225,6 +238,8 @@ test_expect_success 'fmt-merge-msg -m' ' cat >expected.log <<-EOF && Sync with left + By Another Author (3) and A U Thor (2) + via Another Committer * ${apos}left${apos} of $(pwd): Left #5 Left #4 @@ -256,6 +271,8 @@ test_expect_success 'setup: expected shortlog for two branches' ' cat >expected <<-EOF Merge branches ${apos}left${apos} and ${apos}right${apos} + By Another Author (3) and A U Thor (2) + via Another Committer * left: Left #5 Left #4 @@ -379,6 +396,8 @@ test_expect_success 'merge-msg two tags' ' Common #2 Common #1 + By Another Author (3) and A U Thor (2) + via Another Committer * tag ${apos}tag-l5${apos}: Left #5 Left #4 @@ -407,6 +426,8 @@ test_expect_success 'merge-msg tag and branch' ' Common #2 Common #1 + By Another Author (3) and A U Thor (2) + via Another Committer * left: Left #5 Left #4 From 62d39359af1a46de68b600c0dc73a98b78aa5523 Mon Sep 17 00:00:00 2001 From: Johannes Sixt Date: Wed, 14 Mar 2012 20:50:21 +0100 Subject: [PATCH 125/291] t4034: diff.*.wordregex should not be "sticky" in --word-diff The test case applies a custom wordRegex to one file in a diff, and expects that the default word splitting applies to the second file in the diff. But the custom wordRegex is also incorrectly used for the second file. Helped-by: Thomas Rast Signed-off-by: Johannes Sixt Signed-off-by: Junio C Hamano --- t/t4034-diff-words.sh | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/t/t4034-diff-words.sh b/t/t4034-diff-words.sh index 5c2012111c..310ace1b5d 100755 --- a/t/t4034-diff-words.sh +++ b/t/t4034-diff-words.sh @@ -3,6 +3,7 @@ test_description='word diff colors' . ./test-lib.sh +. "$TEST_DIRECTORY"/diff-lib.sh cat >pre.simple <<-\EOF h(4) @@ -293,6 +294,10 @@ test_expect_success '--word-diff=none' ' word_diff --word-diff=plain --word-diff=none ' +test_expect_success 'unset default driver' ' + test_unconfig diff.wordregex +' + test_language_driver bibtex test_language_driver cpp test_language_driver csharp @@ -348,4 +353,35 @@ test_expect_success 'word-diff with no newline at EOF' ' word_diff --word-diff=plain ' +test_expect_success 'setup history with two files' ' + echo "a b; c" >a.tex && + echo "a b; c" >z.txt && + git add a.tex z.txt && + git commit -minitial && + + # modify both + echo "a bx; c" >a.tex && + echo "a bx; c" >z.txt && + git commit -mmodified -a +' + +test_expect_failure 'wordRegex for the first file does not apply to the second' ' + echo "*.tex diff=tex" >.gitattributes && + git config diff.tex.wordRegex "[a-z]+|." && + cat >expect <<-\EOF && + diff --git a/a.tex b/a.tex + --- a/a.tex + +++ b/a.tex + @@ -1 +1 @@ + a [-b-]{+bx+}; c + diff --git a/z.txt b/z.txt + --- a/z.txt + +++ b/z.txt + @@ -1 +1 @@ + a [-b;-]{+bx;+} c + EOF + git diff --word-diff HEAD~ >actual && + compare_diff_patch expect actual +' + test_done From 77d1a520fb5b8ad8cc86228023f16a44b75c05d1 Mon Sep 17 00:00:00 2001 From: Thomas Rast Date: Wed, 14 Mar 2012 19:24:08 +0100 Subject: [PATCH 126/291] diff: refactor the word-diff setup from builtin_diff_cmd Quite a chunk of builtin_diff_cmd deals with word-diff setup, defaults and such. This makes the function a bit hard to read, but is also asymmetric because the corresponding teardown lives in free_diff_words_data already. Refactor into a new function init_diff_words_data. For simplicity, also shuffle around some functions it depends on. Signed-off-by: Thomas Rast Signed-off-by: Junio C Hamano --- diff.c | 119 ++++++++++++++++++++++++++++++--------------------------- 1 file changed, 63 insertions(+), 56 deletions(-) diff --git a/diff.c b/diff.c index 5388ded214..526f198059 100644 --- a/diff.c +++ b/diff.c @@ -987,6 +987,67 @@ static void diff_words_flush(struct emit_callback *ecbdata) diff_words_show(ecbdata->diff_words); } +static void diff_filespec_load_driver(struct diff_filespec *one) +{ + /* Use already-loaded driver */ + if (one->driver) + return; + + if (S_ISREG(one->mode)) + one->driver = userdiff_find_by_path(one->path); + + /* Fallback to default settings */ + if (!one->driver) + one->driver = userdiff_find_by_name("default"); +} + +static const char *userdiff_word_regex(struct diff_filespec *one) +{ + diff_filespec_load_driver(one); + return one->driver->word_regex; +} + +static void init_diff_words_data(struct emit_callback *ecbdata, + struct diff_options *o, + struct diff_filespec *one, + struct diff_filespec *two) +{ + int i; + + ecbdata->diff_words = + xcalloc(1, sizeof(struct diff_words_data)); + ecbdata->diff_words->type = o->word_diff; + ecbdata->diff_words->opt = o; + if (!o->word_regex) + o->word_regex = userdiff_word_regex(one); + if (!o->word_regex) + o->word_regex = userdiff_word_regex(two); + if (!o->word_regex) + o->word_regex = diff_word_regex_cfg; + if (o->word_regex) { + ecbdata->diff_words->word_regex = (regex_t *) + xmalloc(sizeof(regex_t)); + if (regcomp(ecbdata->diff_words->word_regex, + o->word_regex, + REG_EXTENDED | REG_NEWLINE)) + die ("Invalid regular expression: %s", + o->word_regex); + } + for (i = 0; i < ARRAY_SIZE(diff_words_styles); i++) { + if (o->word_diff == diff_words_styles[i].type) { + ecbdata->diff_words->style = + &diff_words_styles[i]; + break; + } + } + if (want_color(o->use_color)) { + struct diff_words_style *st = ecbdata->diff_words->style; + st->old.color = diff_get_color_opt(o, DIFF_FILE_OLD); + st->new.color = diff_get_color_opt(o, DIFF_FILE_NEW); + st->ctx.color = diff_get_color_opt(o, DIFF_PLAIN); + } +} + static void free_diff_words_data(struct emit_callback *ecbdata) { if (ecbdata->diff_words) { @@ -2016,20 +2077,6 @@ static void emit_binary_diff(FILE *file, mmfile_t *one, mmfile_t *two, char *pre emit_binary_diff_body(file, two, one, prefix); } -static void diff_filespec_load_driver(struct diff_filespec *one) -{ - /* Use already-loaded driver */ - if (one->driver) - return; - - if (S_ISREG(one->mode)) - one->driver = userdiff_find_by_path(one->path); - - /* Fallback to default settings */ - if (!one->driver) - one->driver = userdiff_find_by_name("default"); -} - int diff_filespec_is_binary(struct diff_filespec *one) { if (one->is_binary == -1) { @@ -2055,12 +2102,6 @@ static const struct userdiff_funcname *diff_funcname_pattern(struct diff_filespe return one->driver->funcname.pattern ? &one->driver->funcname : NULL; } -static const char *userdiff_word_regex(struct diff_filespec *one) -{ - diff_filespec_load_driver(one); - return one->driver->word_regex; -} - void diff_set_mnemonic_prefix(struct diff_options *options, const char *a, const char *b) { if (!options->a_prefix) @@ -2247,42 +2288,8 @@ static void builtin_diff(const char *name_a, xecfg.ctxlen = strtoul(diffopts + 10, NULL, 10); else if (!prefixcmp(diffopts, "-u")) xecfg.ctxlen = strtoul(diffopts + 2, NULL, 10); - if (o->word_diff) { - int i; - - ecbdata.diff_words = - xcalloc(1, sizeof(struct diff_words_data)); - ecbdata.diff_words->type = o->word_diff; - ecbdata.diff_words->opt = o; - if (!o->word_regex) - o->word_regex = userdiff_word_regex(one); - if (!o->word_regex) - o->word_regex = userdiff_word_regex(two); - if (!o->word_regex) - o->word_regex = diff_word_regex_cfg; - if (o->word_regex) { - ecbdata.diff_words->word_regex = (regex_t *) - xmalloc(sizeof(regex_t)); - if (regcomp(ecbdata.diff_words->word_regex, - o->word_regex, - REG_EXTENDED | REG_NEWLINE)) - die ("Invalid regular expression: %s", - o->word_regex); - } - for (i = 0; i < ARRAY_SIZE(diff_words_styles); i++) { - if (o->word_diff == diff_words_styles[i].type) { - ecbdata.diff_words->style = - &diff_words_styles[i]; - break; - } - } - if (want_color(o->use_color)) { - struct diff_words_style *st = ecbdata.diff_words->style; - st->old.color = diff_get_color_opt(o, DIFF_FILE_OLD); - st->new.color = diff_get_color_opt(o, DIFF_FILE_NEW); - st->ctx.color = diff_get_color_opt(o, DIFF_PLAIN); - } - } + if (o->word_diff) + init_diff_words_data(&ecbdata, o, one, two); xdi_diff_outf(&mf1, &mf2, fn_out_consume, &ecbdata, &xpp, &xecfg); if (o->word_diff) From 6440d3417c1d51a20014d4b6fc6c59bacfa87dab Mon Sep 17 00:00:00 2001 From: Thomas Rast Date: Wed, 14 Mar 2012 19:24:09 +0100 Subject: [PATCH 127/291] diff: tweak a _copy_ of diff_options with word-diff When using word diff, the code sets the word_regex from various defaults if it was not set already. The problem is that it does this on the original diff_options, which will also be used in subsequent diffs. This means that when the word_regex is not given on the command line, only the first diff for which a setting for word_regex (either from attributes or diff.wordRegex) ever takes effect. This value then propagates to the rest of the diff runs and in particular prevents further attribute lookups. Fix the problem of changing diff state once and for all, by working with a _copy_ of the diff_options. Noticed-by: Johannes Sixt Signed-off-by: Thomas Rast Signed-off-by: Junio C Hamano --- diff.c | 5 ++++- t/t4034-diff-words.sh | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/diff.c b/diff.c index 526f198059..349a61d588 100644 --- a/diff.c +++ b/diff.c @@ -1008,11 +1008,13 @@ static const char *userdiff_word_regex(struct diff_filespec *one) } static void init_diff_words_data(struct emit_callback *ecbdata, - struct diff_options *o, + struct diff_options *orig_opts, struct diff_filespec *one, struct diff_filespec *two) { int i; + struct diff_options *o = xmalloc(sizeof(struct diff_options)); + memcpy(o, orig_opts, sizeof(struct diff_options)); ecbdata->diff_words = xcalloc(1, sizeof(struct diff_words_data)); @@ -1052,6 +1054,7 @@ static void free_diff_words_data(struct emit_callback *ecbdata) { if (ecbdata->diff_words) { diff_words_flush(ecbdata); + free (ecbdata->diff_words->opt); free (ecbdata->diff_words->minus.text.ptr); free (ecbdata->diff_words->minus.orig); free (ecbdata->diff_words->plus.text.ptr); diff --git a/t/t4034-diff-words.sh b/t/t4034-diff-words.sh index 310ace1b5d..30d42cb3bf 100755 --- a/t/t4034-diff-words.sh +++ b/t/t4034-diff-words.sh @@ -365,7 +365,7 @@ test_expect_success 'setup history with two files' ' git commit -mmodified -a ' -test_expect_failure 'wordRegex for the first file does not apply to the second' ' +test_expect_success 'wordRegex for the first file does not apply to the second' ' echo "*.tex diff=tex" >.gitattributes && git config diff.tex.wordRegex "[a-z]+|." && cat >expect <<-\EOF && From 16e44810c9602bd7ed494f24c27eec193ff6a674 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Thu, 15 Mar 2012 12:08:00 +0100 Subject: [PATCH 128/291] t0303: immediately bail out w/o GIT_TEST_CREDENTIAL_HELPER MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit t0300-credential-helpers.sh requires GIT_TEST_CREDENTIAL_HELPER to be configured to do something sensible. If it is not set, prove will say: ./t0303-credential-external.sh .. skipped: (no reason given) which isn't very nice. Use skip_all="..." && test_done to bail out immediately and provide a nicer message. In case GIT_TEST_CREDENTIAL_HELPER is set, but the timeout tests are skipped, mention GIT_TEST_CREDENTIAL_HELPER_TIMEOUT. Signed-off-by: Zbigniew Jędrzejewski-Szmek Acked-by: Jeff King Signed-off-by: Junio C Hamano --- t/t0303-credential-external.sh | 39 ++++++++++++++-------------------- 1 file changed, 16 insertions(+), 23 deletions(-) diff --git a/t/t0303-credential-external.sh b/t/t0303-credential-external.sh index 267f4c8ba3..e771075255 100755 --- a/t/t0303-credential-external.sh +++ b/t/t0303-credential-external.sh @@ -4,36 +4,29 @@ test_description='external credential helper tests' . ./test-lib.sh . "$TEST_DIRECTORY"/lib-credential.sh -pre_test() { - test -z "$GIT_TEST_CREDENTIAL_HELPER_SETUP" || +if test -z "$GIT_TEST_CREDENTIAL_HELPER"; then + skip_all="used to test external credential helpers" + test_done +fi + +test -z "$GIT_TEST_CREDENTIAL_HELPER_SETUP" || eval "$GIT_TEST_CREDENTIAL_HELPER_SETUP" - # clean before the test in case there is cruft left - # over from a previous run that would impact results - helper_test_clean "$GIT_TEST_CREDENTIAL_HELPER" -} +# clean before the test in case there is cruft left +# over from a previous run that would impact results +helper_test_clean "$GIT_TEST_CREDENTIAL_HELPER" -post_test() { - # clean afterwards so that we are good citizens - # and don't leave cruft in the helper's storage, which - # might be long-term system storage - helper_test_clean "$GIT_TEST_CREDENTIAL_HELPER" -} - -if test -z "$GIT_TEST_CREDENTIAL_HELPER"; then - say "# skipping external helper tests (set GIT_TEST_CREDENTIAL_HELPER)" -else - pre_test - helper_test "$GIT_TEST_CREDENTIAL_HELPER" - post_test -fi +helper_test "$GIT_TEST_CREDENTIAL_HELPER" if test -z "$GIT_TEST_CREDENTIAL_HELPER_TIMEOUT"; then - say "# skipping external helper timeout tests" + say "# skipping timeout tests (GIT_TEST_CREDENTIAL_HELPER_TIMEOUT not set)" else - pre_test helper_test_timeout "$GIT_TEST_CREDENTIAL_HELPER_TIMEOUT" - post_test fi +# clean afterwards so that we are good citizens +# and don't leave cruft in the helper's storage, which +# might be long-term system storage +helper_test_clean "$GIT_TEST_CREDENTIAL_HELPER" + test_done From 6c556cb8e6a6ef14966bf7e78e5308a38028b54c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Thu, 15 Mar 2012 12:08:01 +0100 Subject: [PATCH 129/291] t0303: resurrect commit message as test documentation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The commit message which added those tests (861444f 't: add test harness for external credential helpers' 2011-12-10) provided nice documentation in the commit message. Let's make it more visible by putting it in the test description. The documentation is updated to reflect the fact that GIT_TEST_CREDENTIAL_HELPER must be set for GIT_TEST_CREDENTIAL_HELPER_TIMEOUT to be used and GIT_TEST_CREDENTIAL_HELPER_SETUP can be used. Based-on-commit-message-by: Jeff King Signed-off-by: Zbigniew Jędrzejewski-Szmek Acked-by: Jeff King Signed-off-by: Junio C Hamano --- t/t0303-credential-external.sh | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/t/t0303-credential-external.sh b/t/t0303-credential-external.sh index e771075255..f028fd1418 100755 --- a/t/t0303-credential-external.sh +++ b/t/t0303-credential-external.sh @@ -1,6 +1,34 @@ #!/bin/sh -test_description='external credential helper tests' +test_description='external credential helper tests + +This is a tool for authors of external helper tools to sanity-check +their helpers. If you have written the "git-credential-foo" helper, +you check it with: + + make GIT_TEST_CREDENTIAL_HELPER=foo t0303-credential-external.sh + +This assumes that your helper is capable of both storing and +retrieving credentials (some helpers may be read-only, and they will +fail these tests). + +Please note that the individual tests do not verify all of the +preconditions themselves, but rather build on each other. A failing +test means that tests later in the sequence can return false "OK" +results. + +If your helper supports time-based expiration with a configurable +timeout, you can test that feature with: + + make GIT_TEST_CREDENTIAL_HELPER=foo \ + GIT_TEST_CREDENTIAL_HELPER_TIMEOUT="foo --timeout=1" \ + t0303-credential-external.sh + +If your helper requires additional setup before the tests are started, +you can set GIT_TEST_CREDENTIAL_HELPER_SETUP to a sequence of shell +commands. +' + . ./test-lib.sh . "$TEST_DIRECTORY"/lib-credential.sh From c844a8035617a602015d74ce329ee88f9b003bf9 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Thu, 15 Mar 2012 15:58:54 +0100 Subject: [PATCH 130/291] remove_dir_recursively(): Add flag for skipping removal of toplevel dir Add the REMOVE_DIR_KEEP_TOPLEVEL flag to remove_dir_recursively() for deleting everything inside the given directory, but _not_ the given directory itself. Note that this does not pass the REMOVE_DIR_KEEP_NESTED_GIT flag, if set, to the recursive invocations of remove_dir_recursively(). It is likely to be a a bug that has been present since REMOVE_DIR_KEEP_NESTED_GIT was introduced (a0f4afb), but this commit keeps the same behaviour for now. Signed-off-by: Johan Herland Signed-off-by: Junio C Hamano --- dir.c | 14 ++++++++++---- dir.h | 1 + 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/dir.c b/dir.c index 0a78d00b54..2087d23b6b 100644 --- a/dir.c +++ b/dir.c @@ -1178,6 +1178,7 @@ int remove_dir_recursively(struct strbuf *path, int flag) struct dirent *e; int ret = 0, original_len = path->len, len; int only_empty = (flag & REMOVE_DIR_EMPTY_ONLY); + int keep_toplevel = (flag & REMOVE_DIR_KEEP_TOPLEVEL); unsigned char submodule_head[20]; if ((flag & REMOVE_DIR_KEEP_NESTED_GIT) && @@ -1185,9 +1186,14 @@ int remove_dir_recursively(struct strbuf *path, int flag) /* Do not descend and nuke a nested git work tree. */ return 0; + flag &= ~(REMOVE_DIR_KEEP_TOPLEVEL|REMOVE_DIR_KEEP_NESTED_GIT); dir = opendir(path->buf); - if (!dir) - return rmdir(path->buf); + if (!dir) { + if (!keep_toplevel) + return rmdir(path->buf); + else + return -1; + } if (path->buf[original_len - 1] != '/') strbuf_addch(path, '/'); @@ -1202,7 +1208,7 @@ int remove_dir_recursively(struct strbuf *path, int flag) if (lstat(path->buf, &st)) ; /* fall thru */ else if (S_ISDIR(st.st_mode)) { - if (!remove_dir_recursively(path, only_empty)) + if (!remove_dir_recursively(path, flag)) continue; /* happy */ } else if (!only_empty && !unlink(path->buf)) continue; /* happy, too */ @@ -1214,7 +1220,7 @@ int remove_dir_recursively(struct strbuf *path, int flag) closedir(dir); strbuf_setlen(path, original_len); - if (!ret) + if (!ret && !keep_toplevel) ret = rmdir(path->buf); return ret; } diff --git a/dir.h b/dir.h index dd6947e1d4..58b6fc7c86 100644 --- a/dir.h +++ b/dir.h @@ -102,6 +102,7 @@ extern void setup_standard_excludes(struct dir_struct *dir); #define REMOVE_DIR_EMPTY_ONLY 01 #define REMOVE_DIR_KEEP_NESTED_GIT 02 +#define REMOVE_DIR_KEEP_TOPLEVEL 04 extern int remove_dir_recursively(struct strbuf *path, int flag); /* tries to remove the path with empty directories along it, ignores ENOENT */ From 01bfec8e52dcfa2da47b54b3c89c3181ae09b9a9 Mon Sep 17 00:00:00 2001 From: Johan Herland Date: Mon, 12 Mar 2012 15:57:12 +0100 Subject: [PATCH 131/291] t3310: illustrate failure to "notes merge --commit" inside $GIT_DIR/ The 'git notes merge' command expected to be run from the working tree of the project being annotated, and did not anticipate getting run inside $GIT_DIR/. However, because we use $GIT_DIR/NOTES_MERGE_WORKTREE as a temporary working space for the user to work on resolving conflicts, it is not unreasonable for a user to run "git notes merge --commit" there. But the command fails to do so. Found-by: David Bremner Signed-off-by: Johan Herland Signed-off-by: Junio C Hamano --- t/t3310-notes-merge-manual-resolve.sh | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/t/t3310-notes-merge-manual-resolve.sh b/t/t3310-notes-merge-manual-resolve.sh index 4367197953..0c531c3795 100755 --- a/t/t3310-notes-merge-manual-resolve.sh +++ b/t/t3310-notes-merge-manual-resolve.sh @@ -553,4 +553,23 @@ test_expect_success 'resolve situation by aborting the notes merge' ' verify_notes z ' +cat >expect_notes < $(git rev-parse HEAD) && + echo "bar" >> $(git rev-parse HEAD) && + git notes merge --commit + ) && + git notes show HEAD > actual_notes && + test_cmp expect_notes actual_notes +' + test_done From a0be62c100897573ef1575ec0d5e8b215e9dcafe Mon Sep 17 00:00:00 2001 From: Johan Herland Date: Mon, 12 Mar 2012 15:57:13 +0100 Subject: [PATCH 132/291] notes-merge: use opendir/readdir instead of using read_directory() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit notes_merge_commit() only needs to list all entries (non-recursively) under a directory, which can be easily accomplished with opendir/readdir and would be more lightweight than read_directory(). read_directory() is designed to list paths inside a working directory. Using it outside of its scope may lead to undesired effects. Apparently, one of the undesired effects of read_directory() is that it doesn't deal with being given absolute paths. This creates problems for notes_merge_commit() when git_path() returns an absolute path, which happens when the current working directory is in a subdirectory of the .git directory. Originally-by: Nguyễn Thái Ngọc Duy Updated-by: Johan Herland Signed-off-by: Johan Herland Signed-off-by: Junio C Hamano --- notes-merge.c | 50 ++++++++++++++++----------- t/t3310-notes-merge-manual-resolve.sh | 2 +- 2 files changed, 31 insertions(+), 21 deletions(-) diff --git a/notes-merge.c b/notes-merge.c index fb0832f97d..3a16af2817 100644 --- a/notes-merge.c +++ b/notes-merge.c @@ -687,51 +687,60 @@ int notes_merge_commit(struct notes_merge_options *o, { /* * Iterate through files in .git/NOTES_MERGE_WORKTREE and add all - * found notes to 'partial_tree'. Write the updates notes tree to + * found notes to 'partial_tree'. Write the updated notes tree to * the DB, and commit the resulting tree object while reusing the * commit message and parents from 'partial_commit'. * Finally store the new commit object SHA1 into 'result_sha1'. */ - struct dir_struct dir; - char *path = xstrdup(git_path(NOTES_MERGE_WORKTREE "/")); - int path_len = strlen(path), i; + DIR *dir; + struct dirent *e; + struct strbuf path = STRBUF_INIT; char *msg = strstr(partial_commit->buffer, "\n\n"); struct strbuf sb_msg = STRBUF_INIT; + int baselen; + strbuf_addstr(&path, git_path(NOTES_MERGE_WORKTREE)); if (o->verbosity >= 3) - printf("Committing notes in notes merge worktree at %.*s\n", - path_len - 1, path); + printf("Committing notes in notes merge worktree at %s\n", + path.buf); if (!msg || msg[2] == '\0') die("partial notes commit has empty message"); msg += 2; - memset(&dir, 0, sizeof(dir)); - read_directory(&dir, path, path_len, NULL); - for (i = 0; i < dir.nr; i++) { - struct dir_entry *ent = dir.entries[i]; + dir = opendir(path.buf); + if (!dir) + die_errno("could not open %s", path.buf); + + strbuf_addch(&path, '/'); + baselen = path.len; + while ((e = readdir(dir)) != NULL) { struct stat st; - const char *relpath = ent->name + path_len; unsigned char obj_sha1[20], blob_sha1[20]; - if (ent->len - path_len != 40 || get_sha1_hex(relpath, obj_sha1)) { + if (is_dot_or_dotdot(e->d_name)) + continue; + + if (strlen(e->d_name) != 40 || get_sha1_hex(e->d_name, obj_sha1)) { if (o->verbosity >= 3) - printf("Skipping non-SHA1 entry '%s'\n", - ent->name); + printf("Skipping non-SHA1 entry '%s%s'\n", + path.buf, e->d_name); continue; } + strbuf_addstr(&path, e->d_name); /* write file as blob, and add to partial_tree */ - if (stat(ent->name, &st)) - die_errno("Failed to stat '%s'", ent->name); - if (index_path(blob_sha1, ent->name, &st, HASH_WRITE_OBJECT)) - die("Failed to write blob object from '%s'", ent->name); + if (stat(path.buf, &st)) + die_errno("Failed to stat '%s'", path.buf); + if (index_path(blob_sha1, path.buf, &st, HASH_WRITE_OBJECT)) + die("Failed to write blob object from '%s'", path.buf); if (add_note(partial_tree, obj_sha1, blob_sha1, NULL)) die("Failed to add resolved note '%s' to notes tree", - ent->name); + path.buf); if (o->verbosity >= 4) printf("Added resolved note for object %s: %s\n", sha1_to_hex(obj_sha1), sha1_to_hex(blob_sha1)); + strbuf_setlen(&path, baselen); } strbuf_attach(&sb_msg, msg, strlen(msg), strlen(msg) + 1); @@ -740,7 +749,8 @@ int notes_merge_commit(struct notes_merge_options *o, if (o->verbosity >= 4) printf("Finalized notes merge commit: %s\n", sha1_to_hex(result_sha1)); - free(path); + strbuf_release(&path); + closedir(dir); return 0; } diff --git a/t/t3310-notes-merge-manual-resolve.sh b/t/t3310-notes-merge-manual-resolve.sh index 0c531c3795..d6d6ac608b 100755 --- a/t/t3310-notes-merge-manual-resolve.sh +++ b/t/t3310-notes-merge-manual-resolve.sh @@ -558,7 +558,7 @@ foo bar EOF -test_expect_failure 'switch cwd before committing notes merge' ' +test_expect_success 'switch cwd before committing notes merge' ' git notes add -m foo HEAD && git notes --ref=other add -m bar HEAD && test_must_fail git notes merge refs/notes/other && From dabba590aa0e94a8deb6f0e827144697895bcfe8 Mon Sep 17 00:00:00 2001 From: Johan Herland Date: Thu, 15 Mar 2012 15:58:56 +0100 Subject: [PATCH 133/291] notes-merge: Don't remove .git/NOTES_MERGE_WORKTREE; it may be the user's cwd When a manual notes merge is committed or aborted, we need to remove the temporary worktree at .git/NOTES_MERGE_WORKTREE. However, removing the entire directory is not good if the user ran the 'git notes merge --commit/--abort' from within that directory. On Windows, the directory removal would simply fail, while on POSIX systems, users would suddenly find themselves in an invalid current directory. Therefore, instead of deleting the entire directory, we delete everything _within_ the directory, and leave the (empty) directory in place. This would cause a subsequent notes merge to abort, complaining about a previous - unfinished - notes merge (due to the presence of .git/NOTES_MERGE_WORKTREE), so we also need to adjust this check to only trigger when .git/NOTES_MERGE_WORKTREE is non-empty. Finally, adjust the t3310 manual notes merge testcases to correctly handle the existence of an empty .git/NOTES_MERGE_WORKTREE directory. Inspired-by: Junio C Hamano Signed-off-by: Johan Herland Signed-off-by: Junio C Hamano --- notes-merge.c | 13 +++++++++---- t/t3310-notes-merge-manual-resolve.sh | 8 ++++---- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/notes-merge.c b/notes-merge.c index 3a16af2817..74aa77ce4b 100644 --- a/notes-merge.c +++ b/notes-merge.c @@ -267,7 +267,8 @@ static void check_notes_merge_worktree(struct notes_merge_options *o) * Must establish NOTES_MERGE_WORKTREE. * Abort if NOTES_MERGE_WORKTREE already exists */ - if (file_exists(git_path(NOTES_MERGE_WORKTREE))) { + if (file_exists(git_path(NOTES_MERGE_WORKTREE)) && + !is_empty_dir(git_path(NOTES_MERGE_WORKTREE))) { if (advice_resolve_conflict) die("You have not concluded your previous " "notes merge (%s exists).\nPlease, use " @@ -756,14 +757,18 @@ int notes_merge_commit(struct notes_merge_options *o, int notes_merge_abort(struct notes_merge_options *o) { - /* Remove .git/NOTES_MERGE_WORKTREE directory and all files within */ + /* + * Remove all files within .git/NOTES_MERGE_WORKTREE. We do not remove + * the .git/NOTES_MERGE_WORKTREE directory itself, since it might be + * the current working directory of the user. + */ struct strbuf buf = STRBUF_INIT; int ret; strbuf_addstr(&buf, git_path(NOTES_MERGE_WORKTREE)); if (o->verbosity >= 3) - printf("Removing notes merge worktree at %s\n", buf.buf); - ret = remove_dir_recursively(&buf, 0); + printf("Removing notes merge worktree at %s/*\n", buf.buf); + ret = remove_dir_recursively(&buf, REMOVE_DIR_KEEP_TOPLEVEL); strbuf_release(&buf); return ret; } diff --git a/t/t3310-notes-merge-manual-resolve.sh b/t/t3310-notes-merge-manual-resolve.sh index d6d6ac608b..195bb97f85 100755 --- a/t/t3310-notes-merge-manual-resolve.sh +++ b/t/t3310-notes-merge-manual-resolve.sh @@ -324,7 +324,7 @@ y and z notes on 4th commit EOF git notes merge --commit && # No .git/NOTES_MERGE_* files left - test_must_fail ls .git/NOTES_MERGE_* >output 2>/dev/null && + test_might_fail ls .git/NOTES_MERGE_* >output 2>/dev/null && test_cmp /dev/null output && # Merge commit has pre-merge y and pre-merge z as parents test "$(git rev-parse refs/notes/m^1)" = "$(cat pre_merge_y)" && @@ -386,7 +386,7 @@ test_expect_success 'redo merge of z into m (== y) with default ("manual") resol test_expect_success 'abort notes merge' ' git notes merge --abort && # No .git/NOTES_MERGE_* files left - test_must_fail ls .git/NOTES_MERGE_* >output 2>/dev/null && + test_might_fail ls .git/NOTES_MERGE_* >output 2>/dev/null && test_cmp /dev/null output && # m has not moved (still == y) test "$(git rev-parse refs/notes/m)" = "$(cat pre_merge_y)" && @@ -453,7 +453,7 @@ EOF # Finalize merge git notes merge --commit && # No .git/NOTES_MERGE_* files left - test_must_fail ls .git/NOTES_MERGE_* >output 2>/dev/null && + test_might_fail ls .git/NOTES_MERGE_* >output 2>/dev/null && test_cmp /dev/null output && # Merge commit has pre-merge y and pre-merge z as parents test "$(git rev-parse refs/notes/m^1)" = "$(cat pre_merge_y)" && @@ -542,7 +542,7 @@ EOF test_expect_success 'resolve situation by aborting the notes merge' ' git notes merge --abort && # No .git/NOTES_MERGE_* files left - test_must_fail ls .git/NOTES_MERGE_* >output 2>/dev/null && + test_might_fail ls .git/NOTES_MERGE_* >output 2>/dev/null && test_cmp /dev/null output && # m has not moved (still == w) test "$(git rev-parse refs/notes/m)" = "$(git rev-parse refs/notes/w)" && From ae2f203ef7be7b33ff5ec61646c8662363eccd62 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Thu, 15 Mar 2012 01:04:12 -0700 Subject: [PATCH 134/291] clean: preserve nested git worktree in subdirectories remove_dir_recursively() has a check to avoid removing the directory it was asked to remove without recursing into it and report success when the directory is the top level of a working tree of a nested git repository, to protect such a repository from "clean -f" (without double -f). If a working tree of a nested git repository is in a subdirectory of a toplevel project, however, this protection did not apply by mistake; we forgot to pass the REMOVE_DIR_KEEP_NESTED_GIT down to the recursive removal codepath. This requires us to also teach the higher level not to remove the directory it is asked to remove, when the recursed invocation did not remove the directory it was asked to remove due to a nested git repository, as it is not an error to leave the parent directories of such a nested repository. Signed-off-by: Junio C Hamano --- dir.c | 27 +++++++++++++++++++++------ t/t7300-clean.sh | 27 ++++++++++++++++++++++----- 2 files changed, 43 insertions(+), 11 deletions(-) diff --git a/dir.c b/dir.c index 2087d23b6b..e98760c72d 100644 --- a/dir.c +++ b/dir.c @@ -1172,23 +1172,27 @@ int is_empty_dir(const char *path) return ret; } -int remove_dir_recursively(struct strbuf *path, int flag) +static int remove_dir_recurse(struct strbuf *path, int flag, int *kept_up) { DIR *dir; struct dirent *e; - int ret = 0, original_len = path->len, len; + int ret = 0, original_len = path->len, len, kept_down = 0; int only_empty = (flag & REMOVE_DIR_EMPTY_ONLY); int keep_toplevel = (flag & REMOVE_DIR_KEEP_TOPLEVEL); unsigned char submodule_head[20]; if ((flag & REMOVE_DIR_KEEP_NESTED_GIT) && - !resolve_gitlink_ref(path->buf, "HEAD", submodule_head)) + !resolve_gitlink_ref(path->buf, "HEAD", submodule_head)) { /* Do not descend and nuke a nested git work tree. */ + if (kept_up) + *kept_up = 1; return 0; + } - flag &= ~(REMOVE_DIR_KEEP_TOPLEVEL|REMOVE_DIR_KEEP_NESTED_GIT); + flag &= ~REMOVE_DIR_KEEP_TOPLEVEL; dir = opendir(path->buf); if (!dir) { + /* an empty dir could be removed even if it is unreadble */ if (!keep_toplevel) return rmdir(path->buf); else @@ -1208,7 +1212,7 @@ int remove_dir_recursively(struct strbuf *path, int flag) if (lstat(path->buf, &st)) ; /* fall thru */ else if (S_ISDIR(st.st_mode)) { - if (!remove_dir_recursively(path, flag)) + if (!remove_dir_recurse(path, flag, &kept_down)) continue; /* happy */ } else if (!only_empty && !unlink(path->buf)) continue; /* happy, too */ @@ -1220,11 +1224,22 @@ int remove_dir_recursively(struct strbuf *path, int flag) closedir(dir); strbuf_setlen(path, original_len); - if (!ret && !keep_toplevel) + if (!ret && !keep_toplevel && !kept_down) ret = rmdir(path->buf); + else if (kept_up) + /* + * report the uplevel that it is not an error that we + * did not rmdir() our directory. + */ + *kept_up = !ret; return ret; } +int remove_dir_recursively(struct strbuf *path, int flag) +{ + return remove_dir_recurse(path, flag, NULL); +} + void setup_standard_excludes(struct dir_struct *dir) { const char *path; diff --git a/t/t7300-clean.sh b/t/t7300-clean.sh index 800b5368a5..ccfb54de7a 100755 --- a/t/t7300-clean.sh +++ b/t/t7300-clean.sh @@ -399,8 +399,8 @@ test_expect_success SANITY 'removal failure' ' ' test_expect_success 'nested git work tree' ' - rm -fr foo bar && - mkdir foo bar && + rm -fr foo bar baz && + mkdir -p foo bar baz/boo && ( cd foo && git init && @@ -412,15 +412,24 @@ test_expect_success 'nested git work tree' ' cd bar && >goodbye.people ) && + ( + cd baz/boo && + git init && + >deeper.world + git add . && + git commit -a -m deeply.nested + ) && git clean -f -d && test -f foo/.git/index && test -f foo/hello.world && + test -f baz/boo/.git/index && + test -f baz/boo/deeper.world && ! test -d bar ' test_expect_success 'force removal of nested git work tree' ' - rm -fr foo bar && - mkdir foo bar && + rm -fr foo bar baz && + mkdir -p foo bar baz/boo && ( cd foo && git init && @@ -432,9 +441,17 @@ test_expect_success 'force removal of nested git work tree' ' cd bar && >goodbye.people ) && + ( + cd baz/boo && + git init && + >deeper.world + git add . && + git commit -a -m deeply.nested + ) && git clean -f -f -d && ! test -d foo && - ! test -d bar + ! test -d bar && + ! test -d baz ' test_expect_success 'git clean -e' ' From d50b2c73b6ffcdc9a55efa38542d02773df44407 Mon Sep 17 00:00:00 2001 From: David Aguilar Date: Fri, 16 Mar 2012 20:54:37 -0700 Subject: [PATCH 135/291] t7800: Test difftool passing arguments to diff git-difftool relies on the ability to forward unknown arguments to the git-diff command. Add a test to ensure that this works as advertised. Signed-off-by: David Aguilar Signed-off-by: Junio C Hamano --- t/t7800-difftool.sh | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/t/t7800-difftool.sh b/t/t7800-difftool.sh index 4fb4c9384a..2763d795f0 100755 --- a/t/t7800-difftool.sh +++ b/t/t7800-difftool.sh @@ -83,6 +83,17 @@ test_expect_success PERL 'difftool ignores bad --tool values' ' test "$diff" = "" ' +test_expect_success PERL 'difftool forwards arguments to diff' ' + >for-diff && + git add for-diff && + echo changes>for-diff && + git add for-diff && + diff=$(git difftool --cached --no-prompt -- for-diff) && + test "$diff" = "" && + git reset -- for-diff && + rm for-diff +' + test_expect_success PERL 'difftool honors --gui' ' git config merge.tool bogus-tool && git config diff.tool bogus-tool && From f25950f3475e263ed6c8f0797bb058ba6444f85e Mon Sep 17 00:00:00 2001 From: Christopher Tiwald Date: Tue, 20 Mar 2012 00:31:33 -0400 Subject: [PATCH 136/291] push: Provide situational hints for non-fast-forward errors Pushing a non-fast-forward update to a remote repository will result in an error, but the hint text doesn't provide the correct resolution in every case. Give better resolution advice in three push scenarios: 1) If you push your current branch and it triggers a non-fast-forward error, you should merge remote changes with 'git pull' before pushing again. 2) If you push to a shared repository others push to, and your local tracking branches are not kept up to date, the 'matching refs' default will generate non-fast-forward errors on outdated branches. If this is your workflow, the 'matching refs' default is not for you. Consider setting the 'push.default' configuration variable to 'current' or 'upstream' to ensure only your current branch is pushed. 3) If you explicitly specify a ref that is not your current branch or push matching branches with ':', you will generate a non-fast-forward error if any pushed branch tip is out of date. You should checkout the offending branch and merge remote changes before pushing again. Teach transport.c to recognize these scenarios and configure push.c to hint for them. If 'git push's default behavior changes or we discover more scenarios, extension is easy. Standardize on the advice API and add three new advice variables, 'pushNonFFCurrent', 'pushNonFFDefault', and 'pushNonFFMatching'. Setting any of these to 'false' will disable their affiliated advice. Setting 'pushNonFastForward' to false will disable all three, thus preserving the config option for users who already set it, but guaranteeing new users won't disable push advice accidentally. Based-on-patch-by: Junio C Hamano Signed-off-by: Christopher Tiwald Signed-off-by: Junio C Hamano --- Documentation/config.txt | 19 +++++++++++-- advice.c | 6 ++++ advice.h | 3 ++ builtin/push.c | 60 ++++++++++++++++++++++++++++++++++++---- cache.h | 8 ++++-- environment.c | 2 +- transport.c | 13 +++++++-- 7 files changed, 99 insertions(+), 12 deletions(-) diff --git a/Documentation/config.txt b/Documentation/config.txt index c081657be7..fb386abc51 100644 --- a/Documentation/config.txt +++ b/Documentation/config.txt @@ -138,8 +138,23 @@ advice.*:: + -- pushNonFastForward:: - Advice shown when linkgit:git-push[1] refuses - non-fast-forward refs. + Set this variable to 'false' if you want to disable + 'pushNonFFCurrent', 'pushNonFFDefault', and + 'pushNonFFMatching' simultaneously. + pushNonFFCurrent:: + Advice shown when linkgit:git-push[1] fails due to a + non-fast-forward update to the current branch. + pushNonFFDefault:: + Advice to set 'push.default' to 'upstream' or 'current' + when you ran linkgit:git-push[1] and pushed 'matching + refs' by default (i.e. you did not provide an explicit + refspec, and no 'push.default' configuration was set) + and it resulted in a non-fast-forward error. + pushNonFFMatching:: + Advice shown when you ran linkgit:git-push[1] and pushed + 'matching refs' explicitly (i.e. you used ':', or + specified a refspec that isn't your current branch) and + it resulted in a non-fast-forward error. statusHints:: Directions on how to stage/unstage/add shown in the output of linkgit:git-status[1] and the template shown diff --git a/advice.c b/advice.c index 01130e54e7..a492eea24f 100644 --- a/advice.c +++ b/advice.c @@ -1,6 +1,9 @@ #include "cache.h" int advice_push_nonfastforward = 1; +int advice_push_non_ff_current = 1; +int advice_push_non_ff_default = 1; +int advice_push_non_ff_matching = 1; int advice_status_hints = 1; int advice_commit_before_merge = 1; int advice_resolve_conflict = 1; @@ -12,6 +15,9 @@ static struct { int *preference; } advice_config[] = { { "pushnonfastforward", &advice_push_nonfastforward }, + { "pushnonffcurrent", &advice_push_non_ff_current }, + { "pushnonffdefault", &advice_push_non_ff_default }, + { "pushnonffmatching", &advice_push_non_ff_matching }, { "statushints", &advice_status_hints }, { "commitbeforemerge", &advice_commit_before_merge }, { "resolveconflict", &advice_resolve_conflict }, diff --git a/advice.h b/advice.h index 7bda45b83e..f3cdbbf29e 100644 --- a/advice.h +++ b/advice.h @@ -4,6 +4,9 @@ #include "git-compat-util.h" extern int advice_push_nonfastforward; +extern int advice_push_non_ff_current; +extern int advice_push_non_ff_default; +extern int advice_push_non_ff_matching; extern int advice_status_hints; extern int advice_commit_before_merge; extern int advice_resolve_conflict; diff --git a/builtin/push.c b/builtin/push.c index d315475f16..8a14e4bcc1 100644 --- a/builtin/push.c +++ b/builtin/push.c @@ -24,6 +24,7 @@ static int progress = -1; static const char **refspec; static int refspec_nr; static int refspec_alloc; +static int default_matching_used; static void add_refspec(const char *ref) { @@ -95,6 +96,9 @@ static void setup_default_push_refspecs(struct remote *remote) { switch (push_default) { default: + case PUSH_DEFAULT_UNSPECIFIED: + default_matching_used = 1; + /* fallthru */ case PUSH_DEFAULT_MATCHING: add_refspec(":"); break; @@ -114,6 +118,45 @@ static void setup_default_push_refspecs(struct remote *remote) } } +static const char message_advice_pull_before_push[] = + N_("Updates were rejected because the tip of your current branch is behind\n" + "its remote counterpart. Merge the remote changes (e.g. 'git pull')\n" + "before pushing again.\n" + "See the 'Note about fast-forwards' in 'git push --help' for details."); + +static const char message_advice_use_upstream[] = + N_("Updates were rejected because a pushed branch tip is behind its remote\n" + "counterpart. If you did not intend to push that branch, you may want to\n" + "specify branches to push or set the 'push.default' configuration\n" + "variable to 'current' or 'upstream' to push only the current branch."); + +static const char message_advice_checkout_pull_push[] = + N_("Updates were rejected because a pushed branch tip is behind its remote\n" + "counterpart. Check out this branch and merge the remote changes\n" + "(e.g. 'git pull') before pushing again.\n" + "See the 'Note about fast-forwards' in 'git push --help' for details."); + +static void advise_pull_before_push(void) +{ + if (!advice_push_non_ff_current || !advice_push_nonfastforward) + return; + advise(_(message_advice_pull_before_push)); +} + +static void advise_use_upstream(void) +{ + if (!advice_push_non_ff_default || !advice_push_nonfastforward) + return; + advise(_(message_advice_use_upstream)); +} + +static void advise_checkout_pull_push(void) +{ + if (!advice_push_non_ff_matching || !advice_push_nonfastforward) + return; + advise(_(message_advice_checkout_pull_push)); +} + static int push_with_options(struct transport *transport, int flags) { int err; @@ -135,14 +178,21 @@ static int push_with_options(struct transport *transport, int flags) error(_("failed to push some refs to '%s'"), transport->url); err |= transport_disconnect(transport); - if (!err) return 0; - if (nonfastforward && advice_push_nonfastforward) { - fprintf(stderr, _("To prevent you from losing history, non-fast-forward updates were rejected\n" - "Merge the remote changes (e.g. 'git pull') before pushing again. See the\n" - "'Note about fast-forwards' section of 'git push --help' for details.\n")); + switch (nonfastforward) { + default: + break; + case NON_FF_HEAD: + advise_pull_before_push(); + break; + case NON_FF_OTHER: + if (default_matching_used) + advise_use_upstream(); + else + advise_checkout_pull_push(); + break; } return 1; diff --git a/cache.h b/cache.h index e5e1aa4e15..427b600267 100644 --- a/cache.h +++ b/cache.h @@ -625,7 +625,8 @@ enum push_default_type { PUSH_DEFAULT_NOTHING = 0, PUSH_DEFAULT_MATCHING, PUSH_DEFAULT_UPSTREAM, - PUSH_DEFAULT_CURRENT + PUSH_DEFAULT_CURRENT, + PUSH_DEFAULT_UNSPECIFIED }; extern enum branch_track git_branch_track; @@ -1008,7 +1009,6 @@ struct ref { char *symref; unsigned int force:1, merge:1, - nonfastforward:1, deletion:1; enum { REF_STATUS_NONE = 0, @@ -1019,6 +1019,10 @@ struct ref { REF_STATUS_REMOTE_REJECT, REF_STATUS_EXPECTING_REPORT } status; + enum { + NON_FF_HEAD = 1, + NON_FF_OTHER + } nonfastforward; char *remote_status; struct ref *peer_ref; /* when renaming */ char name[FLEX_ARRAY]; /* more */ diff --git a/environment.c b/environment.c index c93b8f44df..d7e6c65763 100644 --- a/environment.c +++ b/environment.c @@ -52,7 +52,7 @@ enum safe_crlf safe_crlf = SAFE_CRLF_WARN; unsigned whitespace_rule_cfg = WS_DEFAULT_RULE; enum branch_track git_branch_track = BRANCH_TRACK_REMOTE; enum rebase_setup_type autorebase = AUTOREBASE_NEVER; -enum push_default_type push_default = PUSH_DEFAULT_MATCHING; +enum push_default_type push_default = PUSH_DEFAULT_UNSPECIFIED; #ifndef OBJECT_CREATION_MODE #define OBJECT_CREATION_MODE OBJECT_CREATION_USES_HARDLINKS #endif diff --git a/transport.c b/transport.c index 181f8f24d1..7864007c9c 100644 --- a/transport.c +++ b/transport.c @@ -721,6 +721,10 @@ void transport_print_push_status(const char *dest, struct ref *refs, { struct ref *ref; int n = 0; + unsigned char head_sha1[20]; + char *head; + + head = resolve_refdup("HEAD", head_sha1, 1, NULL); if (verbose) { for (ref = refs; ref; ref = ref->next) @@ -738,8 +742,13 @@ void transport_print_push_status(const char *dest, struct ref *refs, ref->status != REF_STATUS_UPTODATE && ref->status != REF_STATUS_OK) n += print_one_push_status(ref, dest, n, porcelain); - if (ref->status == REF_STATUS_REJECT_NONFASTFORWARD) - *nonfastforward = 1; + if (ref->status == REF_STATUS_REJECT_NONFASTFORWARD && + *nonfastforward != NON_FF_HEAD) { + if (!strcmp(head, ref->name)) + *nonfastforward = NON_FF_HEAD; + else + *nonfastforward = NON_FF_OTHER; + } } } From aea69a016f5bda67c359e43a3cbfabe923ad0f5a Mon Sep 17 00:00:00 2001 From: Lucian Poston Date: Tue, 20 Mar 2012 01:05:34 -0700 Subject: [PATCH 137/291] log --graph --stat: three-dash separator should come after graph lines Output from "git log --graph --stat -p" emits the three-dash separator line before the graph that shows ancestry lines. The separator should come after the ancestry lines just like all the other output. Signed-off-by: Lucian Poston Signed-off-by: Junio C Hamano --- log-tree.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/log-tree.c b/log-tree.c index 24c295ea1d..f962203ec5 100644 --- a/log-tree.c +++ b/log-tree.c @@ -570,14 +570,15 @@ int log_tree_diff_flush(struct rev_info *opt) opt->verbose_header && opt->commit_format != CMIT_FMT_ONELINE) { int pch = DIFF_FORMAT_DIFFSTAT | DIFF_FORMAT_PATCH; - if ((pch & opt->diffopt.output_format) == pch) - printf("---"); if (opt->diffopt.output_prefix) { struct strbuf *msg = NULL; msg = opt->diffopt.output_prefix(&opt->diffopt, opt->diffopt.output_prefix_data); fwrite(msg->buf, msg->len, 1, stdout); } + if ((pch & opt->diffopt.output_format) == pch) { + printf("---"); + } putchar('\n'); } } From b18e97ceb938362c0be62997ba333d4ad36226e4 Mon Sep 17 00:00:00 2001 From: Lucian Poston Date: Tue, 20 Mar 2012 01:05:34 -0700 Subject: [PATCH 138/291] log --graph: fix break in graph lines Output from "git log --graph --stat -p" broke the ancestry graph lines with a single empty line between the diffstat and the patch. Signed-off-by: Lucian Poston Signed-off-by: Junio C Hamano --- diff.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/diff.c b/diff.c index d922b77aef..7d5b7ecf14 100644 --- a/diff.c +++ b/diff.c @@ -4266,6 +4266,12 @@ void diff_flush(struct diff_options *options) if (output_format & DIFF_FORMAT_PATCH) { if (separator) { + if (options->output_prefix) { + struct strbuf *msg = NULL; + msg = options->output_prefix(options, + options->output_prefix_data); + fwrite(msg->buf, msg->len, 1, stdout); + } putc(options->line_termination, options->file); if (options->stat_sep) { /* attach patch instead of inline */ From e2c59667ed0a495998b911628de5389a0ee9a728 Mon Sep 17 00:00:00 2001 From: Lucian Poston Date: Tue, 20 Mar 2012 01:05:34 -0700 Subject: [PATCH 139/291] t4202: add test for "log --graph --stat -p" separator lines Add tests to make sure that the three-dash separator lines appear after the graph ancestry lines, and also the graph ancestry lines are not broken between the diffstat and the patch. Signed-off-by: Lucian Poston Signed-off-by: Junio C Hamano --- t/t4202-log.sh | 290 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 290 insertions(+) diff --git a/t/t4202-log.sh b/t/t4202-log.sh index 983e34bec6..19a0851e7a 100755 --- a/t/t4202-log.sh +++ b/t/t4202-log.sh @@ -516,4 +516,294 @@ test_expect_success 'show added path under "--follow -M"' ' ) ' +cat >expect <<\EOF +* commit COMMIT_OBJECT_NAME +|\ Merge: MERGE_PARENTS +| | Author: A U Thor +| | +| | Merge HEADS DESCRIPTION +| | +| * commit COMMIT_OBJECT_NAME +| | Author: A U Thor +| | +| | reach +| | --- +| | reach.t | 1 + +| | 1 file changed, 1 insertion(+) +| | +| | diff --git a/reach.t b/reach.t +| | new file mode 100644 +| | index 0000000..10c9591 +| | --- /dev/null +| | +++ b/reach.t +| | @@ -0,0 +1 @@ +| | +reach +| | +| \ +*-. \ commit COMMIT_OBJECT_NAME +|\ \ \ Merge: MERGE_PARENTS +| | | | Author: A U Thor +| | | | +| | | | Merge HEADS DESCRIPTION +| | | | +| | * | commit COMMIT_OBJECT_NAME +| | |/ Author: A U Thor +| | | +| | | octopus-b +| | | --- +| | | octopus-b.t | 1 + +| | | 1 file changed, 1 insertion(+) +| | | +| | | diff --git a/octopus-b.t b/octopus-b.t +| | | new file mode 100644 +| | | index 0000000..d5fcad0 +| | | --- /dev/null +| | | +++ b/octopus-b.t +| | | @@ -0,0 +1 @@ +| | | +octopus-b +| | | +| * | commit COMMIT_OBJECT_NAME +| |/ Author: A U Thor +| | +| | octopus-a +| | --- +| | octopus-a.t | 1 + +| | 1 file changed, 1 insertion(+) +| | +| | diff --git a/octopus-a.t b/octopus-a.t +| | new file mode 100644 +| | index 0000000..11ee015 +| | --- /dev/null +| | +++ b/octopus-a.t +| | @@ -0,0 +1 @@ +| | +octopus-a +| | +* | commit COMMIT_OBJECT_NAME +|/ Author: A U Thor +| +| seventh +| --- +| seventh.t | 1 + +| 1 file changed, 1 insertion(+) +| +| diff --git a/seventh.t b/seventh.t +| new file mode 100644 +| index 0000000..9744ffc +| --- /dev/null +| +++ b/seventh.t +| @@ -0,0 +1 @@ +| +seventh +| +* commit COMMIT_OBJECT_NAME +|\ Merge: MERGE_PARENTS +| | Author: A U Thor +| | +| | Merge branch 'tangle' +| | +| * commit COMMIT_OBJECT_NAME +| |\ Merge: MERGE_PARENTS +| | | Author: A U Thor +| | | +| | | Merge branch 'side' (early part) into tangle +| | | +| * | commit COMMIT_OBJECT_NAME +| |\ \ Merge: MERGE_PARENTS +| | | | Author: A U Thor +| | | | +| | | | Merge branch 'master' (early part) into tangle +| | | | +| * | | commit COMMIT_OBJECT_NAME +| | | | Author: A U Thor +| | | | +| | | | tangle-a +| | | | --- +| | | | tangle-a | 1 + +| | | | 1 file changed, 1 insertion(+) +| | | | +| | | | diff --git a/tangle-a b/tangle-a +| | | | new file mode 100644 +| | | | index 0000000..7898192 +| | | | --- /dev/null +| | | | +++ b/tangle-a +| | | | @@ -0,0 +1 @@ +| | | | +a +| | | | +* | | | commit COMMIT_OBJECT_NAME +|\ \ \ \ Merge: MERGE_PARENTS +| | | | | Author: A U Thor +| | | | | +| | | | | Merge branch 'side' +| | | | | +| * | | | commit COMMIT_OBJECT_NAME +| | |_|/ Author: A U Thor +| |/| | +| | | | side-2 +| | | | --- +| | | | 2 | 1 + +| | | | 1 file changed, 1 insertion(+) +| | | | +| | | | diff --git a/2 b/2 +| | | | new file mode 100644 +| | | | index 0000000..0cfbf08 +| | | | --- /dev/null +| | | | +++ b/2 +| | | | @@ -0,0 +1 @@ +| | | | +2 +| | | | +| * | | commit COMMIT_OBJECT_NAME +| | | | Author: A U Thor +| | | | +| | | | side-1 +| | | | --- +| | | | 1 | 1 + +| | | | 1 file changed, 1 insertion(+) +| | | | +| | | | diff --git a/1 b/1 +| | | | new file mode 100644 +| | | | index 0000000..d00491f +| | | | --- /dev/null +| | | | +++ b/1 +| | | | @@ -0,0 +1 @@ +| | | | +1 +| | | | +* | | | commit COMMIT_OBJECT_NAME +| | | | Author: A U Thor +| | | | +| | | | Second +| | | | --- +| | | | one | 1 + +| | | | 1 file changed, 1 insertion(+) +| | | | +| | | | diff --git a/one b/one +| | | | new file mode 100644 +| | | | index 0000000..9a33383 +| | | | --- /dev/null +| | | | +++ b/one +| | | | @@ -0,0 +1 @@ +| | | | +case +| | | | +* | | | commit COMMIT_OBJECT_NAME +| |_|/ Author: A U Thor +|/| | +| | | sixth +| | | --- +| | | a/two | 1 - +| | | 1 file changed, 1 deletion(-) +| | | +| | | diff --git a/a/two b/a/two +| | | deleted file mode 100644 +| | | index 9245af5..0000000 +| | | --- a/a/two +| | | +++ /dev/null +| | | @@ -1 +0,0 @@ +| | | -ni +| | | +* | | commit COMMIT_OBJECT_NAME +| | | Author: A U Thor +| | | +| | | fifth +| | | --- +| | | a/two | 1 + +| | | 1 file changed, 1 insertion(+) +| | | +| | | diff --git a/a/two b/a/two +| | | new file mode 100644 +| | | index 0000000..9245af5 +| | | --- /dev/null +| | | +++ b/a/two +| | | @@ -0,0 +1 @@ +| | | +ni +| | | +* | | commit COMMIT_OBJECT_NAME +|/ / Author: A U Thor +| | +| | fourth +| | --- +| | ein | 1 + +| | 1 file changed, 1 insertion(+) +| | +| | diff --git a/ein b/ein +| | new file mode 100644 +| | index 0000000..9d7e69f +| | --- /dev/null +| | +++ b/ein +| | @@ -0,0 +1 @@ +| | +ichi +| | +* | commit COMMIT_OBJECT_NAME +|/ Author: A U Thor +| +| third +| --- +| ichi | 1 + +| one | 1 - +| 2 files changed, 1 insertion(+), 1 deletion(-) +| +| diff --git a/ichi b/ichi +| new file mode 100644 +| index 0000000..9d7e69f +| --- /dev/null +| +++ b/ichi +| @@ -0,0 +1 @@ +| +ichi +| diff --git a/one b/one +| deleted file mode 100644 +| index 9d7e69f..0000000 +| --- a/one +| +++ /dev/null +| @@ -1 +0,0 @@ +| -ichi +| +* commit COMMIT_OBJECT_NAME +| Author: A U Thor +| +| second +| --- +| one | 2 +- +| 1 file changed, 1 insertion(+), 1 deletion(-) +| +| diff --git a/one b/one +| index 5626abf..9d7e69f 100644 +| --- a/one +| +++ b/one +| @@ -1 +1 @@ +| -one +| +ichi +| +* commit COMMIT_OBJECT_NAME + Author: A U Thor + + initial + --- + one | 1 + + 1 file changed, 1 insertion(+) + + diff --git a/one b/one + new file mode 100644 + index 0000000..5626abf + --- /dev/null + +++ b/one + @@ -0,0 +1 @@ + +one +EOF + +sanitize_output () { + sed -e 's/ *$//' \ + -e 's/commit [0-9a-f]*$/commit COMMIT_OBJECT_NAME/' \ + -e 's/Merge: [ 0-9a-f]*$/Merge: MERGE_PARENTS/' \ + -e 's/Merge tag.*/Merge HEADS DESCRIPTION/' \ + -e 's/Merge commit.*/Merge HEADS DESCRIPTION/' \ + -e 's/, 0 deletions(-)//' \ + -e 's/, 0 insertions(+)//' \ + -e 's/ 1 files changed, / 1 file changed, /' \ + -e 's/, 1 deletions(-)/, 1 deletion(-)/' \ + -e 's/, 1 insertions(+)/, 1 insertion(+)/' +} + +test_expect_success 'log --graph with diff and stats' ' + git log --graph --pretty=short --stat -p >actual && + sanitize_output >actual.sanitized Date: Fri, 16 Mar 2012 07:48:33 -0700 Subject: [PATCH 140/291] rebase -i: remind that the lines are top-to-bottom Nelson Benitez Leon opened a discussion with a patch with this in the note: Hi, I was using git rebase -i for some time now and never occured to me I could reorder the commit lines to affect the order the commits are applied, learnt that recently from a git tutorial. Nelson's patch was to stress the fact that the lines in the insn sheet can be re-ordered in a much more verbose way. Let's add a one-liner reminder and also remind that the lines in the insn sheet is read from top to bottom, unlike the "git log" output. Discussion-triggered-by: Nelson Benitez Leon Signed-off-by: Junio C Hamano --- git-rebase--interactive.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh index 5812222eb9..2b7eb6dda4 100644 --- a/git-rebase--interactive.sh +++ b/git-rebase--interactive.sh @@ -846,6 +846,8 @@ cat >> "$todo" << EOF # f, fixup = like "squash", but discard this commit's log message # x, exec = run command (the rest of the line) using shell # +# These lines can be re-ordered; they are executed from top to bottom. +# # If you remove a line here THAT COMMIT WILL BE LOST. # However, if you remove everything, the rebase will be aborted. # From cba595bd21fd0731e37898dbd6c5b55f65fd8aea Mon Sep 17 00:00:00 2001 From: Jeff King Date: Thu, 22 Mar 2012 14:53:24 -0400 Subject: [PATCH 141/291] drop casts from users EMPTY_TREE_SHA1_BIN This macro already evaluates to the correct type, as it casts the string literal to "unsigned char *" itself (and callers who want the literal can use the _LITERAL form). Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- builtin/diff.c | 2 +- merge-recursive.c | 2 +- sequencer.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/builtin/diff.c b/builtin/diff.c index 424c815f9b..9069dc41be 100644 --- a/builtin/diff.c +++ b/builtin/diff.c @@ -327,7 +327,7 @@ int cmd_diff(int argc, const char **argv, const char *prefix) add_head_to_pending(&rev); if (!rev.pending.nr) { struct tree *tree; - tree = lookup_tree((const unsigned char*)EMPTY_TREE_SHA1_BIN); + tree = lookup_tree(EMPTY_TREE_SHA1_BIN); add_pending_object(&rev, &tree->object, "HEAD"); } break; diff --git a/merge-recursive.c b/merge-recursive.c index 6479a60cd1..318d32e223 100644 --- a/merge-recursive.c +++ b/merge-recursive.c @@ -1914,7 +1914,7 @@ int merge_recursive(struct merge_options *o, /* if there is no common ancestor, use an empty tree */ struct tree *tree; - tree = lookup_tree((const unsigned char *)EMPTY_TREE_SHA1_BIN); + tree = lookup_tree(EMPTY_TREE_SHA1_BIN); merged_common_ancestors = make_virtual_commit(tree, "ancestor"); } diff --git a/sequencer.c b/sequencer.c index a37846a594..4307364b26 100644 --- a/sequencer.c +++ b/sequencer.c @@ -164,7 +164,7 @@ static void write_message(struct strbuf *msgbuf, const char *filename) static struct tree *empty_tree(void) { - return lookup_tree((const unsigned char *)EMPTY_TREE_SHA1_BIN); + return lookup_tree(EMPTY_TREE_SHA1_BIN); } static int error_dirty_index(struct replay_opts *opts) From f8582cad8d11cae15e73fe5213b6180ee4b9fcce Mon Sep 17 00:00:00 2001 From: Jeff King Date: Thu, 22 Mar 2012 14:53:39 -0400 Subject: [PATCH 142/291] make is_empty_blob_sha1 available everywhere The read-cache implementation defines this static function, but it is a generally useful concept in git. Let's give the empty blob the same treatment as the empty tree, providing both hex and binary forms of the sha1. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- cache.h | 13 +++++++++++++ read-cache.c | 10 ---------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/cache.h b/cache.h index e5e1aa4e15..5280574801 100644 --- a/cache.h +++ b/cache.h @@ -708,6 +708,19 @@ static inline void hashclr(unsigned char *hash) #define EMPTY_TREE_SHA1_BIN \ ((const unsigned char *) EMPTY_TREE_SHA1_BIN_LITERAL) +#define EMPTY_BLOB_SHA1_HEX \ + "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391" +#define EMPTY_BLOB_SHA1_BIN_LITERAL \ + "\xe6\x9d\xe2\x9b\xb2\xd1\xd6\x43\x4b\x8b" \ + "\x29\xae\x77\x5a\xd8\xc2\xe4\x8c\x53\x91" +#define EMPTY_BLOB_SHA1_BIN \ + ((const unsigned char *) EMPTY_BLOB_SHA1_BIN_LITERAL) + +static inline int is_empty_blob_sha1(const unsigned char *sha1) +{ + return !hashcmp(sha1, EMPTY_BLOB_SHA1_BIN); +} + int git_mkstemp(char *path, size_t n, const char *template); int git_mkstemps(char *path, size_t n, const char *template, int suffix_len); diff --git a/read-cache.c b/read-cache.c index 274e54b4f3..6c8f395836 100644 --- a/read-cache.c +++ b/read-cache.c @@ -157,16 +157,6 @@ static int ce_modified_check_fs(struct cache_entry *ce, struct stat *st) return 0; } -static int is_empty_blob_sha1(const unsigned char *sha1) -{ - static const unsigned char empty_blob_sha1[20] = { - 0xe6,0x9d,0xe2,0x9b,0xb2,0xd1,0xd6,0x43,0x4b,0x8b, - 0x29,0xae,0x77,0x5a,0xd8,0xc2,0xe4,0x8c,0x53,0x91 - }; - - return !hashcmp(sha1, empty_blob_sha1); -} - static int ce_match_stat_basic(struct cache_entry *ce, struct stat *st) { unsigned int changed = 0; From 90d43b07687fdc51d1f2fc14948df538dc45584b Mon Sep 17 00:00:00 2001 From: Jeff King Date: Thu, 22 Mar 2012 18:52:13 -0400 Subject: [PATCH 143/291] teach diffcore-rename to optionally ignore empty content Our rename detection is a heuristic, matching pairs of removed and added files with similar or identical content. It's unlikely to be wrong when there is actual content to compare, and we already take care not to do inexact rename detection when there is not enough content to produce good results. However, we always do exact rename detection, even when the blob is tiny or empty. It's easy to get false positives with an empty blob, simply because it is an obvious content to use as a boilerplate (e.g., when telling git that an empty directory is worth tracking via an empty .gitignore). This patch lets callers specify whether or not they are interested in using empty files as rename sources and destinations. The default is "yes", keeping the original behavior. It works by detecting the empty-blob sha1 for rename sources and destinations. One more flexible alternative would be to allow the caller to specify a minimum size for a blob to be "interesting" for rename detection. But that would catch small boilerplate files, not large ones (e.g., if you had the GPL COPYING file in many directories). A better alternative would be to allow a "-rename" gitattribute to allow boilerplate files to be marked as such. I'll leave the complexity of that solution until such time as somebody actually wants it. The complaints we've seen so far revolve around empty files, so let's start with the simple thing. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- diff.c | 5 +++++ diff.h | 2 +- diffcore-rename.c | 6 ++++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/diff.c b/diff.c index 377ec1ea4c..0b70aadc4f 100644 --- a/diff.c +++ b/diff.c @@ -3136,6 +3136,7 @@ void diff_setup(struct diff_options *options) options->rename_limit = -1; options->dirstat_permille = diff_dirstat_permille_default; options->context = 3; + DIFF_OPT_SET(options, RENAME_EMPTY); options->change = diff_change; options->add_remove = diff_addremove; @@ -3506,6 +3507,10 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac) } else if (!strcmp(arg, "--no-renames")) options->detect_rename = 0; + else if (!strcmp(arg, "--rename-empty")) + DIFF_OPT_SET(options, RENAME_EMPTY); + else if (!strcmp(arg, "--no-rename-empty")) + DIFF_OPT_CLR(options, RENAME_EMPTY); else if (!strcmp(arg, "--relative")) DIFF_OPT_SET(options, RELATIVE_NAME); else if (!prefixcmp(arg, "--relative=")) { diff --git a/diff.h b/diff.h index cb687436a0..dd48eca71d 100644 --- a/diff.h +++ b/diff.h @@ -60,7 +60,7 @@ typedef struct strbuf *(*diff_prefix_fn_t)(struct diff_options *opt, void *data) #define DIFF_OPT_SILENT_ON_REMOVE (1 << 5) #define DIFF_OPT_FIND_COPIES_HARDER (1 << 6) #define DIFF_OPT_FOLLOW_RENAMES (1 << 7) -/* (1 << 8) unused */ +#define DIFF_OPT_RENAME_EMPTY (1 << 8) /* (1 << 9) unused */ #define DIFF_OPT_HAS_CHANGES (1 << 10) #define DIFF_OPT_QUICK (1 << 11) diff --git a/diffcore-rename.c b/diffcore-rename.c index f639601c76..216a7a4bbc 100644 --- a/diffcore-rename.c +++ b/diffcore-rename.c @@ -512,9 +512,15 @@ void diffcore_rename(struct diff_options *options) else if (options->single_follow && strcmp(options->single_follow, p->two->path)) continue; /* not interested */ + else if (!DIFF_OPT_TST(options, RENAME_EMPTY) && + is_empty_blob_sha1(p->two->sha1)) + continue; else locate_rename_dst(p->two, 1); } + else if (!DIFF_OPT_TST(options, RENAME_EMPTY) && + is_empty_blob_sha1(p->one->sha1)) + continue; else if (!DIFF_PAIR_UNMERGED(p) && !DIFF_FILE_VALID(p->two)) { /* * If the source is a broken "delete", and From 4f7cb99ada26be5d86402a6e060f3ee16a672f16 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Thu, 22 Mar 2012 18:52:24 -0400 Subject: [PATCH 144/291] merge-recursive: don't detect renames of empty files Merge-recursive detects renames so that if one side modifies "foo" and the other side moves it to "bar", the modification is applied to "bar". However, our rename detection is based on content analysis, it can be wrong (i.e., two files were not intended as a rename, but just happen to have the same or similar content). This is quite rare if the files actually contain content, since two unrelated files are unlikely to have exactly the same content. However, empty files present a problem, in that there is nothing to analyze. An uninteresting placeholder file with zero bytes may or may not be related to a placeholder file with another name. The result is that adding content to an empty file may cause confusion if the other side of a merge removed it; your content may end up in another random placeholder file that was added. Let's err on the side of caution and not consider empty files as renames. This will cause a modify/delete conflict on the merge, which will let the user sort it out themselves. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- merge-recursive.c | 1 + t/t6022-merge-rename.sh | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/merge-recursive.c b/merge-recursive.c index 318d32e223..0fb174359a 100644 --- a/merge-recursive.c +++ b/merge-recursive.c @@ -485,6 +485,7 @@ static struct string_list *get_renames(struct merge_options *o, renames = xcalloc(1, sizeof(struct string_list)); diff_setup(&opts); DIFF_OPT_SET(&opts, RECURSIVE); + DIFF_OPT_CLR(&opts, RENAME_EMPTY); opts.detect_rename = DIFF_DETECT_RENAME; opts.rename_limit = o->merge_rename_limit >= 0 ? o->merge_rename_limit : o->diff_rename_limit >= 0 ? o->diff_rename_limit : diff --git a/t/t6022-merge-rename.sh b/t/t6022-merge-rename.sh index 9d8584e957..1104249182 100755 --- a/t/t6022-merge-rename.sh +++ b/t/t6022-merge-rename.sh @@ -884,4 +884,20 @@ test_expect_success 'no spurious "refusing to lose untracked" message' ' ! grep "refusing to lose untracked file" errors.txt ' +test_expect_success 'do not follow renames for empty files' ' + git checkout -f -b empty-base && + >empty1 && + git add empty1 && + git commit -m base && + echo content >empty1 && + git add empty1 && + git commit -m fill && + git checkout -b empty-topic HEAD^ && + git mv empty1 empty2 && + git commit -m rename && + test_must_fail git merge empty-base && + >expect && + test_cmp expect empty2 +' + test_done From e5e9b56528294e9455d22d1abb21ad32f098a1be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Scharfe?= Date: Sat, 24 Mar 2012 16:18:46 +0100 Subject: [PATCH 145/291] combine-diff: fix loop index underflow If both la and context are zero at the start of the loop, la wraps around and we end up reading from memory far away. Skip the loop in that case instead. Reported-by: Julia Lawall Signed-off-by: Rene Scharfe Signed-off-by: Junio C Hamano --- combine-diff.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/combine-diff.c b/combine-diff.c index 9445e86c2f..45221f84a5 100644 --- a/combine-diff.c +++ b/combine-diff.c @@ -414,7 +414,7 @@ static int make_hunks(struct sline *sline, unsigned long cnt, hunk_begin, j); la = (la + context < cnt + 1) ? (la + context) : cnt + 1; - while (j <= --la) { + while (la && j <= --la) { if (sline[la].flag & mark) { contin = 1; break; From e9e8c8090e579da5b5f6d2437ecf271568d127ff Mon Sep 17 00:00:00 2001 From: Stefano Lattarini Date: Mon, 26 Mar 2012 18:42:24 +0200 Subject: [PATCH 146/291] configure: move definitions of private m4 macros before AC_INIT invocation This way, no spurious comments nor whitespace will be propagated in the generated configure script. This change is a pure code movement (plus addition of a comment line). Signed-off-by: Stefano Lattarini Signed-off-by: Junio C Hamano --- configure.ac | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/configure.ac b/configure.ac index 72f7958824..0743a70ffe 100644 --- a/configure.ac +++ b/configure.ac @@ -1,18 +1,6 @@ # -*- Autoconf -*- # Process this file with autoconf to produce a configure script. -AC_PREREQ(2.59) -AC_INIT([git], [@@GIT_VERSION@@], [git@vger.kernel.org]) - -AC_CONFIG_SRCDIR([git.c]) - -config_file=config.mak.autogen -config_append=config.mak.append -config_in=config.mak.in - -echo "# ${config_append}. Generated by configure." > "${config_append}" - - ## Definitions of macros # GIT_CONF_APPEND_LINE(LINE) # -------------------------- @@ -137,6 +125,19 @@ if test -n "$1"; then fi ]) +## Configure body starts here. + +AC_PREREQ(2.59) +AC_INIT([git], [@@GIT_VERSION@@], [git@vger.kernel.org]) + +AC_CONFIG_SRCDIR([git.c]) + +config_file=config.mak.autogen +config_append=config.mak.append +config_in=config.mak.in + +echo "# ${config_append}. Generated by configure." > "${config_append}" + # Directories holding "saner" versions of common or POSIX binaries. AC_ARG_WITH([sane-tool-path], [AS_HELP_STRING( From 99cccefbe0927027e69ba7ba96317eba42cec3cb Mon Sep 17 00:00:00 2001 From: Stefano Lattarini Date: Mon, 26 Mar 2012 18:42:25 +0200 Subject: [PATCH 147/291] configure: avoid some code repetitions thanks to m4_{push,pop}def This change is just cosmetic, and should cause no semantic change, nor any change in the generated configure script. Signed-off-by: Stefano Lattarini Signed-off-by: Junio C Hamano --- configure.ac | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/configure.ac b/configure.ac index 0743a70ffe..e888601b1d 100644 --- a/configure.ac +++ b/configure.ac @@ -27,10 +27,11 @@ AC_DEFUN([GIT_ARG_SET_PATH], # Optional second argument allows setting NO_PROGRAM=YesPlease if # --without-PROGRAM is used. AC_DEFUN([GIT_CONF_APPEND_PATH], -[PROGRAM=m4_toupper($1); \ +[m4_pushdef([GIT_UC_PROGRAM], m4_toupper([$1]))dnl +PROGRAM=GIT_UC_PROGRAM; \ if test "$withval" = "no"; then \ if test -n "$2"; then \ - m4_toupper($1)_PATH=$withval; \ + GIT_UC_PROGRAM[]_PATH=$withval; \ AC_MSG_NOTICE([Disabling use of ${PROGRAM}]); \ GIT_CONF_APPEND_LINE(NO_${PROGRAM}=YesPlease); \ GIT_CONF_APPEND_LINE(${PROGRAM}_PATH=); \ @@ -41,12 +42,12 @@ else \ if test "$withval" = "yes"; then \ AC_MSG_WARN([You should provide path for --with-$1=PATH]); \ else \ - m4_toupper($1)_PATH=$withval; \ - AC_MSG_NOTICE([Setting m4_toupper($1)_PATH to $withval]); \ + GIT_UC_PROGRAM[]_PATH=$withval; \ + AC_MSG_NOTICE([Setting GIT_UC_PROGRAM[]_PATH to $withval]); \ GIT_CONF_APPEND_LINE(${PROGRAM}_PATH=$withval); \ fi; \ fi; \ -]) # GIT_CONF_APPEND_PATH +m4_popdef([GIT_UC_PROGRAM])]) # GIT_CONF_APPEND_PATH # # GIT_PARSE_WITH(PACKAGE) # ----------------------- @@ -55,18 +56,19 @@ fi; \ # * Set PACKAGEDIR=PATH for --with-PACKAGE=PATH # * Unset NO_PACKAGE for --with-PACKAGE without ARG AC_DEFUN([GIT_PARSE_WITH], -[PACKAGE=m4_toupper($1); \ +[m4_pushdef([GIT_UC_PACKAGE], m4_toupper([$1]))dnl +PACKAGE=GIT_UC_PACKAGE; \ if test "$withval" = "no"; then \ - m4_toupper(NO_$1)=YesPlease; \ + NO_[]GIT_UC_PACKAGE=YesPlease; \ elif test "$withval" = "yes"; then \ - m4_toupper(NO_$1)=; \ + NO_[]GIT_UC_PACKAGE=; \ else \ - m4_toupper(NO_$1)=; \ - m4_toupper($1)DIR=$withval; \ - AC_MSG_NOTICE([Setting m4_toupper($1)DIR to $withval]); \ + NO_[]GIT_UC_PACKAGE=; \ + GIT_UC_PACKAGE[]DIR=$withval; \ + AC_MSG_NOTICE([Setting GIT_UC_PACKAGE[]DIR to $withval]); \ GIT_CONF_APPEND_LINE(${PACKAGE}DIR=$withval); \ fi \ -])# GIT_PARSE_WITH +m4_popdef([GIT_UC_PACKAGE])]) # GIT_PARSE_WITH # # GIT_PARSE_WITH_SET_MAKE_VAR(WITHNAME, VAR, HELP_TEXT) # --------------------- From 5b2d131419817c5f5996da0e284e906400c083ef Mon Sep 17 00:00:00 2001 From: Stefano Lattarini Date: Mon, 26 Mar 2012 18:42:26 +0200 Subject: [PATCH 148/291] configure: be more idiomatic Lots of code in Git's configure.ac doesn't follow the typical formatting, idioms and best practices for Autoconf input files. Improve the situation. There are probably many more similar improvements to be done, but trying to clump all of them in a single change would make it unreviewable, so we content ourselves with a partial improvement. This change is just cosmetic, and should cause no semantic change. The most relevant of the changes introduced by this patch are: - Do not add trailing '\' characters for line continuation where they are not truly needed. - In several (but not all) macro calls, properly quote the arguments. - Few cosmetic changes in spacing and comments. Signed-off-by: Stefano Lattarini Signed-off-by: Junio C Hamano --- configure.ac | 176 +++++++++++++++++++++++++-------------------------- 1 file changed, 87 insertions(+), 89 deletions(-) diff --git a/configure.ac b/configure.ac index e888601b1d..e1255506a6 100644 --- a/configure.ac +++ b/configure.ac @@ -1,54 +1,55 @@ # -*- Autoconf -*- # Process this file with autoconf to produce a configure script. -## Definitions of macros +## Definitions of private macros. + # GIT_CONF_APPEND_LINE(LINE) # -------------------------- # Append LINE to file ${config_append} AC_DEFUN([GIT_CONF_APPEND_LINE], -[echo "$1" >> "${config_append}"])# GIT_CONF_APPEND_LINE -# + [echo "$1" >> "${config_append}"]) + # GIT_ARG_SET_PATH(PROGRAM) # ------------------------- # Provide --with-PROGRAM=PATH option to set PATH to PROGRAM # Optional second argument allows setting NO_PROGRAM=YesPlease if # --without-PROGRAM version used. AC_DEFUN([GIT_ARG_SET_PATH], -[AC_ARG_WITH([$1], - [AS_HELP_STRING([--with-$1=PATH], - [provide PATH to $1])], - [GIT_CONF_APPEND_PATH($1,$2)],[]) -])# GIT_ARG_SET_PATH -# + [AC_ARG_WITH([$1], + [AS_HELP_STRING([--with-$1=PATH], + [provide PATH to $1])], + [GIT_CONF_APPEND_PATH([$1], [$2])], + [])]) + # GIT_CONF_APPEND_PATH(PROGRAM) -# ------------------------------ +# ----------------------------- # Parse --with-PROGRAM=PATH option to set PROGRAM_PATH=PATH # Used by GIT_ARG_SET_PATH(PROGRAM) # Optional second argument allows setting NO_PROGRAM=YesPlease if # --without-PROGRAM is used. AC_DEFUN([GIT_CONF_APPEND_PATH], -[m4_pushdef([GIT_UC_PROGRAM], m4_toupper([$1]))dnl -PROGRAM=GIT_UC_PROGRAM; \ -if test "$withval" = "no"; then \ - if test -n "$2"; then \ - GIT_UC_PROGRAM[]_PATH=$withval; \ - AC_MSG_NOTICE([Disabling use of ${PROGRAM}]); \ - GIT_CONF_APPEND_LINE(NO_${PROGRAM}=YesPlease); \ - GIT_CONF_APPEND_LINE(${PROGRAM}_PATH=); \ - else \ - AC_MSG_ERROR([You cannot use git without $1]); \ - fi; \ -else \ - if test "$withval" = "yes"; then \ - AC_MSG_WARN([You should provide path for --with-$1=PATH]); \ - else \ - GIT_UC_PROGRAM[]_PATH=$withval; \ - AC_MSG_NOTICE([Setting GIT_UC_PROGRAM[]_PATH to $withval]); \ - GIT_CONF_APPEND_LINE(${PROGRAM}_PATH=$withval); \ - fi; \ -fi; \ -m4_popdef([GIT_UC_PROGRAM])]) # GIT_CONF_APPEND_PATH -# + [m4_pushdef([GIT_UC_PROGRAM], m4_toupper([$1]))dnl + PROGRAM=GIT_UC_PROGRAM + if test "$withval" = "no"; then + if test -n "$2"; then + GIT_UC_PROGRAM[]_PATH=$withval + AC_MSG_NOTICE([Disabling use of ${PROGRAM}]) + GIT_CONF_APPEND_LINE(NO_${PROGRAM}=YesPlease) + GIT_CONF_APPEND_LINE(${PROGRAM}_PATH=) + else + AC_MSG_ERROR([You cannot use git without $1]) + fi + else + if test "$withval" = "yes"; then + AC_MSG_WARN([You should provide path for --with-$1=PATH]) + else + GIT_UC_PROGRAM[]_PATH=$withval + AC_MSG_NOTICE([Setting GIT_UC_PROGRAM[]_PATH to $withval]) + GIT_CONF_APPEND_LINE(${PROGRAM}_PATH=$withval) + fi + fi + m4_popdef([GIT_UC_PROGRAM])]) + # GIT_PARSE_WITH(PACKAGE) # ----------------------- # For use in AC_ARG_WITH action-if-found, for packages default ON. @@ -56,22 +57,22 @@ m4_popdef([GIT_UC_PROGRAM])]) # GIT_CONF_APPEND_PATH # * Set PACKAGEDIR=PATH for --with-PACKAGE=PATH # * Unset NO_PACKAGE for --with-PACKAGE without ARG AC_DEFUN([GIT_PARSE_WITH], -[m4_pushdef([GIT_UC_PACKAGE], m4_toupper([$1]))dnl -PACKAGE=GIT_UC_PACKAGE; \ -if test "$withval" = "no"; then \ - NO_[]GIT_UC_PACKAGE=YesPlease; \ -elif test "$withval" = "yes"; then \ - NO_[]GIT_UC_PACKAGE=; \ -else \ - NO_[]GIT_UC_PACKAGE=; \ - GIT_UC_PACKAGE[]DIR=$withval; \ - AC_MSG_NOTICE([Setting GIT_UC_PACKAGE[]DIR to $withval]); \ - GIT_CONF_APPEND_LINE(${PACKAGE}DIR=$withval); \ -fi \ -m4_popdef([GIT_UC_PACKAGE])]) # GIT_PARSE_WITH -# + [m4_pushdef([GIT_UC_PACKAGE], m4_toupper([$1]))dnl + PACKAGE=GIT_UC_PACKAGE + if test "$withval" = "no"; then + NO_[]GIT_UC_PACKAGE=YesPlease + elif test "$withval" = "yes"; then + NO_[]GIT_UC_PACKAGE= + else + NO_[]GIT_UC_PACKAGE= + GIT_UC_PACKAGE[]DIR=$withval + AC_MSG_NOTICE([Setting GIT_UC_PACKAGE[]DIR to $withval]) + GIT_CONF_APPEND_LINE(${PACKAGE}DIR=$withval) + fi + m4_popdef([GIT_UC_PACKAGE])]) + # GIT_PARSE_WITH_SET_MAKE_VAR(WITHNAME, VAR, HELP_TEXT) -# --------------------- +# ----------------------------------------------------- # Set VAR to the value specied by --with-WITHNAME. # No verification of arguments is performed, but warnings are issued # if either 'yes' or 'no' is specified. @@ -80,33 +81,32 @@ m4_popdef([GIT_UC_PACKAGE])]) # GIT_PARSE_WITH AC_DEFUN([GIT_PARSE_WITH_SET_MAKE_VAR], [AC_ARG_WITH([$1], [AS_HELP_STRING([--with-$1=VALUE], $3)], - if test -n "$withval"; then \ - if test "$withval" = "yes" -o "$withval" = "no"; then \ + if test -n "$withval"; then + if test "$withval" = "yes" -o "$withval" = "no"; then AC_MSG_WARN([You likely do not want either 'yes' or 'no' as] - [a value for $1 ($2). Maybe you do...?]); \ - fi; \ - \ - AC_MSG_NOTICE([Setting $2 to $withval]); \ - GIT_CONF_APPEND_LINE($2=$withval); \ + [a value for $1 ($2). Maybe you do...?]) + fi + AC_MSG_NOTICE([Setting $2 to $withval]) + GIT_CONF_APPEND_LINE($2=$withval) fi)])# GIT_PARSE_WITH_SET_MAKE_VAR -dnl -dnl GIT_CHECK_FUNC(FUNCTION, IFTRUE, IFFALSE) -dnl ----------------------------------------- -dnl Similar to AC_CHECK_FUNC, but on systems that do not generate -dnl warnings for missing prototypes (e.g. FreeBSD when compiling without -dnl -Wall), it does not work. By looking for function definition in -dnl libraries, this problem can be worked around. +# +# GIT_CHECK_FUNC(FUNCTION, IFTRUE, IFFALSE) +# ----------------------------------------- +# Similar to AC_CHECK_FUNC, but on systems that do not generate +# warnings for missing prototypes (e.g. FreeBSD when compiling without +# -Wall), it does not work. By looking for function definition in +# libraries, this problem can be worked around. AC_DEFUN([GIT_CHECK_FUNC],[AC_CHECK_FUNC([$1],[ AC_SEARCH_LIBS([$1],, [$2],[$3]) ],[$3])]) -dnl -dnl GIT_STASH_FLAGS(BASEPATH_VAR) -dnl ----------------------------- -dnl Allow for easy stashing of LDFLAGS and CPPFLAGS before running -dnl tests that may want to take user settings into account. +# +# GIT_STASH_FLAGS(BASEPATH_VAR) +# ----------------------------- +# Allow for easy stashing of LDFLAGS and CPPFLAGS before running +# tests that may want to take user settings into account. AC_DEFUN([GIT_STASH_FLAGS],[ if test -n "$1"; then old_CPPFLAGS="$CPPFLAGS" @@ -164,14 +164,13 @@ AC_ARG_WITH([sane-tool-path], AC_ARG_WITH([lib], [AS_HELP_STRING([--with-lib=ARG], [ARG specifies alternative name for lib directory])], - [if test "$withval" = "no" || test "$withval" = "yes"; then \ - AC_MSG_WARN([You should provide name for --with-lib=ARG]); \ -else \ - lib=$withval; \ - AC_MSG_NOTICE([Setting lib to '$lib']); \ - GIT_CONF_APPEND_LINE(lib=$withval); \ -fi; \ -],[]) + [if test "$withval" = "no" || test "$withval" = "yes"; then + AC_MSG_WARN([You should provide name for --with-lib=ARG]) + else + lib=$withval + AC_MSG_NOTICE([Setting lib to '$lib']) + GIT_CONF_APPEND_LINE(lib=$withval) + fi]) if test -z "$lib"; then AC_MSG_NOTICE([Setting lib to 'lib' (the default)]) @@ -237,9 +236,9 @@ AC_MSG_NOTICE([CHECKS for site configuration]) # /foo/bar/include and /foo/bar/lib directories. AC_ARG_WITH(openssl, AS_HELP_STRING([--with-openssl],[use OpenSSL library (default is YES)]) -AS_HELP_STRING([], [ARG can be prefix for openssl library and headers]),\ -GIT_PARSE_WITH(openssl)) -# +AS_HELP_STRING([], [ARG can be prefix for openssl library and headers]), +GIT_PARSE_WITH([openssl])) + # Define USE_LIBPCRE if you have and want to use libpcre. git-grep will be # able to use Perl-compatible regular expressions. # @@ -249,17 +248,16 @@ GIT_PARSE_WITH(openssl)) AC_ARG_WITH(libpcre, AS_HELP_STRING([--with-libpcre],[support Perl-compatible regexes (default is NO)]) AS_HELP_STRING([], [ARG can be also prefix for libpcre library and headers]), -if test "$withval" = "no"; then \ - USE_LIBPCRE=; \ -elif test "$withval" = "yes"; then \ - USE_LIBPCRE=YesPlease; \ -else - USE_LIBPCRE=YesPlease; \ - LIBPCREDIR=$withval; \ - AC_MSG_NOTICE([Setting LIBPCREDIR to $withval]); \ - GIT_CONF_APPEND_LINE(LIBPCREDIR=$withval); \ -fi \ -) + if test "$withval" = "no"; then + USE_LIBPCRE= + elif test "$withval" = "yes"; then + USE_LIBPCRE=YesPlease + else + USE_LIBPCRE=YesPlease + LIBPCREDIR=$withval + AC_MSG_NOTICE([Setting LIBPCREDIR to $withval]) + GIT_CONF_APPEND_LINE(LIBPCREDIR=$withval) + fi) # # Define NO_CURL if you do not have curl installed. git-http-pull and # git-http-push are not built, and you cannot use http:// and https:// @@ -367,7 +365,7 @@ AC_ARG_WITH(tcltk, AS_HELP_STRING([--with-tcltk],[use Tcl/Tk GUI (default is YES)]) AS_HELP_STRING([],[ARG is the full path to the Tcl/Tk interpreter.]) AS_HELP_STRING([],[Bare --with-tcltk will make the GUI part only if]) -AS_HELP_STRING([],[Tcl/Tk interpreter will be found in a system.]),\ +AS_HELP_STRING([],[Tcl/Tk interpreter will be found in a system.]), GIT_PARSE_WITH(tcltk)) # From e339aa92ae2db194a3d5738cb3aee6d8b3bf7b10 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Mon, 26 Mar 2012 15:51:50 -0400 Subject: [PATCH 149/291] clean up struct ref's nonfastforward field Each ref structure contains a "nonfastforward" field which is set during push to show whether the ref rewound history. Originally this was a single bit, but it was changed in f25950f (push: Provide situational hints for non-fast-forward errors) to an enum differentiating a non-ff of the current branch versus another branch. However, we never actually set the member according to the enum values, nor did we ever read it expecting anything but a boolean value. But we did use the side effect of declaring the enum constants to store those values in a totally different integer variable. The code as-is isn't buggy, but the enum declaration inside "struct ref" is somewhat misleading. Let's convert nonfastforward back into a single bit, and then define the NON_FF_* constants closer to where they would be used (they are returned via the "int *nonfastforward" parameter to transport_push, so we can define them there). Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- cache.h | 5 +---- transport.h | 2 ++ 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/cache.h b/cache.h index 427b600267..35f30752c6 100644 --- a/cache.h +++ b/cache.h @@ -1009,6 +1009,7 @@ struct ref { char *symref; unsigned int force:1, merge:1, + nonfastforward:1, deletion:1; enum { REF_STATUS_NONE = 0, @@ -1019,10 +1020,6 @@ struct ref { REF_STATUS_REMOTE_REJECT, REF_STATUS_EXPECTING_REPORT } status; - enum { - NON_FF_HEAD = 1, - NON_FF_OTHER - } nonfastforward; char *remote_status; struct ref *peer_ref; /* when renaming */ char name[FLEX_ARRAY]; /* more */ diff --git a/transport.h b/transport.h index ce99ef8b7e..1631a35ea6 100644 --- a/transport.h +++ b/transport.h @@ -138,6 +138,8 @@ int transport_set_option(struct transport *transport, const char *name, void transport_set_verbosity(struct transport *transport, int verbosity, int force_progress); +#define NON_FF_HEAD 1 +#define NON_FF_OTHER 2 int transport_push(struct transport *connection, int refspec_nr, const char **refspec, int flags, int * nonfastforward); From f9a482e62b079cdf9e80889011b6f41f3c17f0c2 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Mon, 26 Mar 2012 19:51:01 -0400 Subject: [PATCH 150/291] checkout: suppress tracking message with "-q" Like the "switched to..." message (which is already suppressed by "-q"), this message is purely informational. Let's silence it if the user asked us to be quiet. This patch is slightly more than a one-liner, because we have to teach create_branch to propagate the flag all the way down to install_branch_config. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- branch.c | 9 +++++---- branch.h | 2 +- builtin/branch.c | 2 +- builtin/checkout.c | 1 + 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/branch.c b/branch.c index 9971820a18..eccdaf9392 100644 --- a/branch.c +++ b/branch.c @@ -101,9 +101,10 @@ void install_branch_config(int flag, const char *local, const char *origin, cons * config. */ static int setup_tracking(const char *new_ref, const char *orig_ref, - enum branch_track track) + enum branch_track track, int quiet) { struct tracking tracking; + int config_flags = quiet ? 0 : BRANCH_CONFIG_VERBOSE; if (strlen(new_ref) > 1024 - 7 - 7 - 1) return error("Tracking not set up: name too long: %s", @@ -128,7 +129,7 @@ static int setup_tracking(const char *new_ref, const char *orig_ref, return error("Not tracking: ambiguous information for ref %s", orig_ref); - install_branch_config(BRANCH_CONFIG_VERBOSE, new_ref, tracking.remote, + install_branch_config(config_flags, new_ref, tracking.remote, tracking.src ? tracking.src : orig_ref); free(tracking.src); @@ -191,7 +192,7 @@ int validate_new_branchname(const char *name, struct strbuf *ref, void create_branch(const char *head, const char *name, const char *start_name, int force, int reflog, int clobber_head, - enum branch_track track) + int quiet, enum branch_track track) { struct ref_lock *lock = NULL; struct commit *commit; @@ -260,7 +261,7 @@ void create_branch(const char *head, start_name); if (real_ref && track) - setup_tracking(ref.buf+11, real_ref, track); + setup_tracking(ref.buf+11, real_ref, track, quiet); if (!dont_change_ref) if (write_ref_sha1(lock, sha1, msg) < 0) diff --git a/branch.h b/branch.h index b99c5a369e..64173abf4d 100644 --- a/branch.h +++ b/branch.h @@ -14,7 +14,7 @@ */ void create_branch(const char *head, const char *name, const char *start_name, int force, int reflog, - int clobber_head, enum branch_track track); + int clobber_head, int quiet, enum branch_track track); /* * Validates that the requested branch may be created, returning the diff --git a/builtin/branch.c b/builtin/branch.c index d8cccf725d..f1eaf1e411 100644 --- a/builtin/branch.c +++ b/builtin/branch.c @@ -808,7 +808,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix) if (kinds != REF_LOCAL_BRANCH) die(_("-a and -r options to 'git branch' do not make sense with a branch name")); create_branch(head, argv[0], (argc == 2) ? argv[1] : head, - force_create, reflog, 0, track); + force_create, reflog, 0, 0, track); } else usage_with_options(builtin_branch_usage, options); diff --git a/builtin/checkout.c b/builtin/checkout.c index a76aa2a6fd..48f8b430f9 100644 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@ -557,6 +557,7 @@ static void update_refs_for_switch(struct checkout_opts *opts, opts->new_branch_force ? 1 : 0, opts->new_branch_log, opts->new_branch_force ? 1 : 0, + opts->quiet, opts->track); new->name = opts->new_branch; setup_branch_path(new); From d65ddf1984d66e978f0a11e7a4ea2d4eb20193c7 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Mon, 26 Mar 2012 19:51:06 -0400 Subject: [PATCH 151/291] teach "git branch" a --quiet option There's currently no way to suppress the informational "deleted branch..." or "set up tracking..." messages. This patch provides a "-q" option to do so. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- Documentation/git-branch.txt | 5 +++++ builtin/branch.c | 16 ++++++++++------ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/Documentation/git-branch.txt b/Documentation/git-branch.txt index 0427e80a35..d74a30c1ce 100644 --- a/Documentation/git-branch.txt +++ b/Documentation/git-branch.txt @@ -126,6 +126,11 @@ OPTIONS relationship to upstream branch (if any). If given twice, print the name of the upstream branch, as well. +-q:: +--quiet:: + Be more quiet when creating or deleting a branch, suppressing + non-error messages. + --abbrev=:: Alter the sha1's minimum display length in the output listing. The default value is 7 and can be overridden by the `core.abbrev` diff --git a/builtin/branch.c b/builtin/branch.c index f1eaf1e411..5f150b4e8a 100644 --- a/builtin/branch.c +++ b/builtin/branch.c @@ -146,7 +146,8 @@ static int branch_merged(int kind, const char *name, return merged; } -static int delete_branches(int argc, const char **argv, int force, int kinds) +static int delete_branches(int argc, const char **argv, int force, int kinds, + int quiet) { struct commit *rev, *head_rev = NULL; unsigned char sha1[20]; @@ -216,9 +217,10 @@ static int delete_branches(int argc, const char **argv, int force, int kinds) ret = 1; } else { struct strbuf buf = STRBUF_INIT; - printf(_("Deleted %sbranch %s (was %s).\n"), remote, - bname.buf, - find_unique_abbrev(sha1, DEFAULT_ABBREV)); + if (!quiet) + printf(_("Deleted %sbranch %s (was %s).\n"), + remote, bname.buf, + find_unique_abbrev(sha1, DEFAULT_ABBREV)); strbuf_addf(&buf, "branch.%s", bname.buf); if (git_config_rename_section(buf.buf, NULL) < 0) warning(_("Update of config-file failed")); @@ -678,6 +680,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix) int delete = 0, rename = 0, force_create = 0, list = 0; int verbose = 0, abbrev = -1, detached = 0; int reflog = 0, edit_description = 0; + int quiet = 0; enum branch_track track; int kinds = REF_LOCAL_BRANCH; struct commit_list *with_commit = NULL; @@ -686,6 +689,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix) OPT_GROUP("Generic options"), OPT__VERBOSE(&verbose, "show hash and subject, give twice for upstream branch"), + OPT__QUIET(&quiet, "suppress informational messages"), OPT_SET_INT('t', "track", &track, "set up tracking mode (see git-pull(1))", BRANCH_TRACK_EXPLICIT), OPT_SET_INT( 0, "set-upstream", &track, "change upstream info", @@ -766,7 +770,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix) abbrev = DEFAULT_ABBREV; if (delete) - return delete_branches(argc, argv, delete > 1, kinds); + return delete_branches(argc, argv, delete > 1, kinds, quiet); else if (list) return print_ref_list(kinds, detached, verbose, abbrev, with_commit, argv); @@ -808,7 +812,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix) if (kinds != REF_LOCAL_BRANCH) die(_("-a and -r options to 'git branch' do not make sense with a branch name")); create_branch(head, argv[0], (argc == 2) ? argv[1] : head, - force_create, reflog, 0, 0, track); + force_create, reflog, 0, quiet, track); } else usage_with_options(builtin_branch_usage, options); From a604ddef737c79f4df9a943ff316e87b7c8a1de8 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Tue, 27 Mar 2012 15:10:01 -0700 Subject: [PATCH 152/291] apply: rename free_patch() to free_patch_list() As that is the only logical name for a function that walks a list and frees each element on it. Signed-off-by: Junio C Hamano --- builtin/apply.c | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/builtin/apply.c b/builtin/apply.c index 427c2634d7..aff1d9f75d 100644 --- a/builtin/apply.c +++ b/builtin/apply.c @@ -198,19 +198,24 @@ struct patch { static void free_patch(struct patch *patch) { - while (patch) { - struct patch *patch_next = patch->next; - struct fragment *fragment = patch->fragments; + struct fragment *fragment = patch->fragments; - while (fragment) { - struct fragment *fragment_next = fragment->next; - if (fragment->patch != NULL && fragment->free_patch) - free((char *)fragment->patch); - free(fragment); - fragment = fragment_next; - } - free(patch); - patch = patch_next; + while (fragment) { + struct fragment *fragment_next = fragment->next; + if (fragment->patch != NULL && fragment->free_patch) + free((char *)fragment->patch); + free(fragment); + fragment = fragment_next; + } + free(patch); +} + +static void free_patch_list(struct patch *list) +{ + while (list) { + struct patch *next = list->next; + free_patch(list); + list = next; } } @@ -3771,7 +3776,7 @@ static int apply_patch(int fd, const char *filename, int options) if (summary) summary_patch_list(list); - free_patch(list); + free_patch_list(list); strbuf_release(&buf); return 0; } From 2901bbe5be41af3161fe99dede505833f26ff2bf Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Wed, 21 Mar 2012 15:18:18 -0700 Subject: [PATCH 153/291] apply: free patch->{def,old,new}_name fields These were all allocated in the heap by parsing the header parts of the patch, but we did not bother to free them. Some used to share the memory (e.g. copying def_name to old_name) so this is not just the matter of adding three calls to free(). Signed-off-by: Junio C Hamano --- builtin/apply.c | 65 +++++++++++++++++++++++++++++-------------------- 1 file changed, 39 insertions(+), 26 deletions(-) diff --git a/builtin/apply.c b/builtin/apply.c index aff1d9f75d..04cd8d38b0 100644 --- a/builtin/apply.c +++ b/builtin/apply.c @@ -207,6 +207,9 @@ static void free_patch(struct patch *patch) free(fragment); fragment = fragment_next; } + free(patch->def_name); + free(patch->old_name); + free(patch->new_name); free(patch); } @@ -439,7 +442,7 @@ static char *squash_slash(char *name) return name; } -static char *find_name_gnu(const char *line, char *def, int p_value) +static char *find_name_gnu(const char *line, const char *def, int p_value) { struct strbuf name = STRBUF_INIT; char *cp; @@ -462,11 +465,7 @@ static char *find_name_gnu(const char *line, char *def, int p_value) cp++; } - /* name can later be freed, so we need - * to memmove, not just return cp - */ strbuf_remove(&name, 0, cp - name.buf); - free(def); if (root) strbuf_insert(&name, 0, root, root_len); return squash_slash(strbuf_detach(&name, NULL)); @@ -631,8 +630,13 @@ static size_t diff_timestamp_len(const char *line, size_t len) return line + len - end; } -static char *find_name_common(const char *line, char *def, int p_value, - const char *end, int terminate) +static char *null_strdup(const char *s) +{ + return s ? xstrdup(s) : NULL; +} + +static char *find_name_common(const char *line, const char *def, + int p_value, const char *end, int terminate) { int len; const char *start = NULL; @@ -653,10 +657,10 @@ static char *find_name_common(const char *line, char *def, int p_value, start = line; } if (!start) - return squash_slash(def); + return squash_slash(null_strdup(def)); len = line - start; if (!len) - return squash_slash(def); + return squash_slash(null_strdup(def)); /* * Generally we prefer the shorter name, especially @@ -667,8 +671,7 @@ static char *find_name_common(const char *line, char *def, int p_value, if (def) { int deflen = strlen(def); if (deflen < len && !strncmp(start, def, deflen)) - return squash_slash(def); - free(def); + return squash_slash(xstrdup(def)); } if (root) { @@ -865,8 +868,10 @@ static void parse_traditional_patch(const char *first, const char *second, struc name = find_name_traditional(first, NULL, p_value); patch->old_name = name; } else { - name = find_name_traditional(first, NULL, p_value); - name = find_name_traditional(second, name, p_value); + char *first_name; + first_name = find_name_traditional(first, NULL, p_value); + name = find_name_traditional(second, first_name, p_value); + free(first_name); if (has_epoch_timestamp(first)) { patch->is_new = 1; patch->is_delete = 0; @@ -876,7 +881,8 @@ static void parse_traditional_patch(const char *first, const char *second, struc patch->is_delete = 1; patch->old_name = name; } else { - patch->old_name = patch->new_name = name; + patch->old_name = name; + patch->new_name = xstrdup(name); } } if (!name) @@ -926,13 +932,19 @@ static char *gitdiff_verify_name(const char *line, int isnull, char *orig_name, static int gitdiff_oldname(const char *line, struct patch *patch) { + char *orig = patch->old_name; patch->old_name = gitdiff_verify_name(line, patch->is_new, patch->old_name, "old"); + if (orig != patch->old_name) + free(orig); return 0; } static int gitdiff_newname(const char *line, struct patch *patch) { + char *orig = patch->new_name; patch->new_name = gitdiff_verify_name(line, patch->is_delete, patch->new_name, "new"); + if (orig != patch->new_name) + free(orig); return 0; } @@ -951,20 +963,23 @@ static int gitdiff_newmode(const char *line, struct patch *patch) static int gitdiff_delete(const char *line, struct patch *patch) { patch->is_delete = 1; - patch->old_name = patch->def_name; + free(patch->old_name); + patch->old_name = null_strdup(patch->def_name); return gitdiff_oldmode(line, patch); } static int gitdiff_newfile(const char *line, struct patch *patch) { patch->is_new = 1; - patch->new_name = patch->def_name; + free(patch->new_name); + patch->new_name = null_strdup(patch->def_name); return gitdiff_newmode(line, patch); } static int gitdiff_copysrc(const char *line, struct patch *patch) { patch->is_copy = 1; + free(patch->old_name); patch->old_name = find_name(line, NULL, p_value ? p_value - 1 : 0, 0); return 0; } @@ -972,6 +987,7 @@ static int gitdiff_copysrc(const char *line, struct patch *patch) static int gitdiff_copydst(const char *line, struct patch *patch) { patch->is_copy = 1; + free(patch->new_name); patch->new_name = find_name(line, NULL, p_value ? p_value - 1 : 0, 0); return 0; } @@ -979,6 +995,7 @@ static int gitdiff_copydst(const char *line, struct patch *patch) static int gitdiff_renamesrc(const char *line, struct patch *patch) { patch->is_rename = 1; + free(patch->old_name); patch->old_name = find_name(line, NULL, p_value ? p_value - 1 : 0, 0); return 0; } @@ -986,6 +1003,7 @@ static int gitdiff_renamesrc(const char *line, struct patch *patch) static int gitdiff_renamedst(const char *line, struct patch *patch) { patch->is_rename = 1; + free(patch->new_name); patch->new_name = find_name(line, NULL, p_value ? p_value - 1 : 0, 0); return 0; } @@ -1426,7 +1444,8 @@ static int find_header(char *line, unsigned long size, int *hdrsize, struct patc if (!patch->def_name) die("git diff header lacks filename information when removing " "%d leading pathname components (line %d)" , p_value, linenr); - patch->old_name = patch->new_name = patch->def_name; + patch->old_name = xstrdup(patch->def_name); + patch->new_name = xstrdup(patch->def_name); } if (!patch->is_delete && !patch->new_name) die("git diff header lacks filename information " @@ -3109,6 +3128,7 @@ static int check_preimage(struct patch *patch, struct cache_entry **ce, struct s is_new: patch->is_new = 1; patch->is_delete = 0; + free(patch->old_name); patch->old_name = NULL; return 0; } @@ -3689,15 +3709,8 @@ static void prefix_patches(struct patch *p) if (!prefix || p->is_toplevel_relative) return; for ( ; p; p = p->next) { - if (p->new_name == p->old_name) { - char *prefixed = p->new_name; - prefix_one(&prefixed); - p->new_name = p->old_name = prefixed; - } - else { - prefix_one(&p->new_name); - prefix_one(&p->old_name); - } + prefix_one(&p->new_name); + prefix_one(&p->old_name); } } From 5c8774330f5cc7a5e9a4f9e016e06bea6814d8b5 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Tue, 27 Mar 2012 15:14:48 -0700 Subject: [PATCH 154/291] apply: release memory for fn_table The fn_table is used to record the result of earlier patch application in case a hand-crafted input file contains multiple patches to the same file. Both its string key (filename) and the contents are borrowed from "struct patch" that represents the previous application in the same apply_patch() call, and they do not leak, but the table itself was not freed properly. Signed-off-by: Junio C Hamano --- builtin/apply.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builtin/apply.c b/builtin/apply.c index 04cd8d38b0..28668c889a 100644 --- a/builtin/apply.c +++ b/builtin/apply.c @@ -3724,7 +3724,6 @@ static int apply_patch(int fd, const char *filename, int options) struct patch *list = NULL, **listp = &list; int skipped_patch = 0; - memset(&fn_table, 0, sizeof(struct string_list)); patch_input_file = filename; read_patch_file(&buf, fd); offset = 0; @@ -3791,6 +3790,7 @@ static int apply_patch(int fd, const char *filename, int options) free_patch_list(list); strbuf_release(&buf); + string_list_clear(&fn_table, 0); return 0; } From 8192a2fafcd69fe1cad2fe84c99b03c63393c117 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Wed, 21 Mar 2012 15:21:32 -0700 Subject: [PATCH 155/291] apply: free patch->result This is by far the largest piece of data, much larger than the patch and fragment structures or the three name fields in the patch structure. Signed-off-by: Junio C Hamano --- builtin/apply.c | 1 + 1 file changed, 1 insertion(+) diff --git a/builtin/apply.c b/builtin/apply.c index 28668c889a..c65fb3f8da 100644 --- a/builtin/apply.c +++ b/builtin/apply.c @@ -210,6 +210,7 @@ static void free_patch(struct patch *patch) free(patch->def_name); free(patch->old_name); free(patch->new_name); + free(patch->result); free(patch); } From 5d86861c925f15676a14b54062725eb11a85ffbc Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Wed, 28 Mar 2012 09:55:21 -0700 Subject: [PATCH 156/291] am -3: list the paths that needed 3-way fallback When applying a patch that was based on an older release with "am -3", I often wonder changes to which files need to be reviewed with extra care to spot mismerges, but there is no good indication. The paths that needed 3-way fallback can easily be obtained by comparing the synthesized (partial) base tree and the current HEAD and noticing only additions and modifications (removals only show the sparseness of the fake ancestor tree, which is not useful information at all). List them in the usual --name-status format. Signed-off-by: Junio C Hamano --- git-am.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/git-am.sh b/git-am.sh index 4da0ddafc4..e686a17594 100755 --- a/git-am.sh +++ b/git-am.sh @@ -138,6 +138,12 @@ fall_back_3way () { say Using index info to reconstruct a base tree... cmd='GIT_INDEX_FILE="$dotest/patch-merge-tmp-index"' + + if test -z "$GIT_QUIET" + then + eval "$cmd git diff-index --cached --diff-filter=AM --name-status HEAD" + fi + cmd="$cmd git apply --cached $git_apply_opt"' <"$dotest/patch"' if eval "$cmd" then From 58725efd4a0583e4a3793b054ebaf57bd40e82fa Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Wed, 28 Mar 2012 13:11:28 +0200 Subject: [PATCH 157/291] am: support --include option am supports a number of pass-through options to apply, like --exclude and --directory. Add --include to this list. Signed-off-by: Johannes Berg Signed-off-by: Junio C Hamano --- Documentation/git-am.txt | 3 ++- git-am.sh | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Documentation/git-am.txt b/Documentation/git-am.txt index 887466d777..e4c08e122e 100644 --- a/Documentation/git-am.txt +++ b/Documentation/git-am.txt @@ -13,7 +13,7 @@ SYNOPSIS [--3way] [--interactive] [--committer-date-is-author-date] [--ignore-date] [--ignore-space-change | --ignore-whitespace] [--whitespace=