Skip to content

Commit

Permalink
Merge branch 'mob' of git://repo.or.cz/guilt/mob
Browse files Browse the repository at this point in the history
Conflicts:
	guilt
  • Loading branch information
jeffpc committed Jan 27, 2013
2 parents 8644cef + f1c2f45 commit fc5caa7
Show file tree
Hide file tree
Showing 14 changed files with 731 additions and 37 deletions.
4 changes: 4 additions & 0 deletions Documentation/guilt.7
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ guards: This file contains any guards that should be applied to the series when
series: This file contains a list of all the patch filenames relative to the per\-branch patch directory\&. Empty and commented out lines are ignored\&.

status: This file contains the state of the stack\&. What patches are applied\&.
.SH "BRANCH USAGE"
When you have pushed a patch, Guilt automatically changes to a freshly created Git branch\&. The name of the new branch is formed by prepending \fBguilt/\fR to the name of the original branch\&. This is done so that you do not accidentally push a set of Guilt patches to a remote Git repository\&. Once you pop all patches Guilt automatically changes back to the original branch\&.

This is mostly transparent\&. The only thing you need to remember is that if you use \fBgit checkout\fR to switch to a branch while you have Guilt patches applied, you should use \fBgit checkout guilt/BRANCH\fR instead of \fBgit checkout BRANCH\fR when you want to change back later.
.SH "HOOKS"
Any guilt operation may execute zero or more hook scripts which can be used to run any housekeeping commands or even abort the execution of the command\&.
.SH "HOOKS DIRECTORY"
Expand Down
63 changes: 48 additions & 15 deletions guilt
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,6 @@ SUBDIRECTORY_OK=1

. "$(git --exec-path)/git-sh-setup"

#
# Git version check
#
gitver=`git --version | cut -d' ' -f3 | sed -e 's/^debian\.//'`
case "$gitver" in
1.5.*) ;; # git config
1.6.*) ;; # git config
1.7.*) ;; # git config
*) die "Unsupported version of git ($gitver)" ;;
esac

#
# Shell library
#
Expand Down Expand Up @@ -422,9 +411,9 @@ head_check()
return 0 ;;
esac

if [ "`git rev-parse refs/heads/$branch`" != "`git rev-parse $1`" ]; then
if [ "`git rev-parse refs/heads/\`git_branch\``" != "`git rev-parse $1`" ]; then
disp "Expected HEAD commit $1" >&2
disp " got `git rev-parse refs/heads/$branch`" >&2
disp " got `git rev-parse refs/heads/\`git_branch\``" >&2
return 1
fi
return 0
Expand Down Expand Up @@ -514,6 +503,11 @@ pop_many_patches()
n=`expr $n - $2`
head_n "$n" < "$applied" > "$applied.tmp"
mv "$applied.tmp" "$applied"
if [ -z "`get_top 2>/dev/null`" ] && [ "`git symbolic-ref HEAD`" = "refs/heads/$GUILT_PREFIX$branch" ] && ! $old_style_prefix
then
git symbolic-ref HEAD refs/heads/$branch
git update-ref -d refs/heads/$GUILT_PREFIX$branch
fi
)
}

Expand Down Expand Up @@ -599,7 +593,13 @@ commit()
# commit
treeish=`git write-tree`
commitish=`git commit-tree $treeish -p $2 < "$TMP_MSG"`
git update-ref HEAD $commitish
if $old_style_prefix || git rev-parse --verify --quiet refs/heads/$GUILT_PREFIX$branch >/dev/null
then
git update-ref HEAD $commitish
else
git branch $GUILT_PREFIX$branch $commitish
git symbolic-ref HEAD refs/heads/$GUILT_PREFIX$branch
fi

# mark patch as applied
git update-ref "refs/patches/$branch/$pname" HEAD
Expand Down Expand Up @@ -839,6 +839,9 @@ guilt_push_diff_context=1
# default diffstat value: true or false
DIFFSTAT_DEFAULT="false"

# Prefix for guilt branches.
GUILT_PREFIX=guilt/

#
# Parse any part of .git/config that belongs to us
#
Expand All @@ -853,7 +856,28 @@ diffstat=`git config --bool guilt.diffstat`

GUILT_DIR="$GIT_DIR/patches"

branch=`get_branch`
# To make it harder to accidentally do "git push" with a guilt patch
# applied, "guilt push" changes branch from e.g. "master" to
# "guilt/master". Set $git_branch to the full branch name, and
# $branch to the abbreviated name that the user sees most of the time.
# Note: old versions of guilt did not add the "guilt/" prefix. This
# code handles that case as well. The prefix will be added when you
# have no patches applied and do a "guilt push".
raw_git_branch=`get_branch`
branch=`echo "$raw_git_branch" | sed -e 's,^'$GUILT_PREFIX',,'`

git_branch()
{
if $old_style_prefix
then
echo $branch
elif [ -z "`get_top 2>/dev/null`" ]
then
echo $branch
else
echo $GUILT_PREFIX$branch
fi
}

# most of the time we want to verify that the repo's branch has been
# initialized, but every once in a blue moon (e.g., we want to run guilt init),
Expand Down Expand Up @@ -890,4 +914,13 @@ else
die "Unsupported operating system: $UNAME_S"
fi

if [ "$branch" = "$raw_git_branch" ] && [ -n "`get_top 2>/dev/null`" ]
then
# This is for compat with old repositories that still have a
# pushed patch without the new-style branch prefix.
old_style_prefix=true
else
old_style_prefix=false
fi

_main "$@"
12 changes: 10 additions & 2 deletions guilt-branch
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,16 @@ cat "$applied" | while read n; do
`git rev-parse "refs/patches/$branch/$n"` ""
done

git branch "$newbranch"
git checkout "$newbranch"
if $old_style_prefix || [ -z "`get_top 2>/dev/null`" ]
then
newgitbranch="$newbranch"
else
git update-ref "refs/heads/$newbranch" "refs/heads/$branch" ""
newgitbranch="$GUILT_PREFIX$newbranch"
fi

git branch "$newgitbranch"
git checkout "$newgitbranch"

mkdir -p "$GUILT_DIR/`dirname $newbranch`"

Expand Down
7 changes: 7 additions & 0 deletions guilt-commit
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,11 @@ done
sed -n -e "${pat_keep}" "$applied" > "$applied.tmp"
mv "$applied.tmp" "$applied"

# if we removed the last patch, switch back to the base branch
if [ `wc -l < "$applied"` -eq 0 ] && [ "`git symbolic-ref HEAD`" = "refs/heads/$GUILT_PREFIX$branch" ] && ! $old_style_prefix
then
git update-ref refs/heads/$branch refs/heads/$GUILT_PREFIX$branch
git symbolic-ref HEAD refs/heads/$branch
git update-ref -d refs/heads/$GUILT_PREFIX$branch
fi
}
4 changes: 2 additions & 2 deletions guilt-import-commit
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ if ! must_commit_first; then
fi

disp "About to begin conversion..." >&2
disp "Current head: `cat $GIT_DIR/refs/heads/$branch`" >&2
disp "Current head: `cat $GIT_DIR/refs/heads/\`git_branch\``" >&2

for rev in `git rev-list $rhash`; do
s=`git log --pretty=oneline -1 $rev | cut -c 42-`
Expand Down Expand Up @@ -68,6 +68,6 @@ for rev in `git rev-list $rhash`; do
done

disp "Done." >&2
disp "Current head: `cat $GIT_DIR/refs/heads/$branch`" >&2
disp "Current head: `cat $GIT_DIR/refs/heads/\`git_branch\``" >&2

}
7 changes: 6 additions & 1 deletion guilt-repair
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ repair_pushed()

# blow away any commits
git reset --hard "$newrev" > /dev/null
if [ "`git symbolic-ref HEAD`" = "refs/heads/$GUILT_PREFIX$branch" ] && ! $old_style_prefix
then
git symbolic-ref HEAD refs/heads/$branch
git update-ref -d refs/heads/$GUILT_PREFIX$branch
fi

# blow away the applied stack
remove_patch_refs < "$applied"
Expand Down Expand Up @@ -112,7 +117,7 @@ case "$1" in
;;
esac

oldrev=`git show-ref -s "refs/heads/$branch"`
oldrev=`git show-ref -s "refs/heads/\`git_branch\`"`

case "$repair" in
full)
Expand Down
7 changes: 6 additions & 1 deletion os.Darwin
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@ head_n()
# usage: sha1 [file]
sha1()
{
openssl dgst -sha1 "$1" | sed "s,SHA1.\(.*\).= \(.*\),\2 \1,"
if [ $# = 1 ]
then
openssl dgst -sha1 "$1" | sed "s,SHA1.\(.*\).= \(.*\),\2 \1,"
else
openssl dgst -sha1 | sed 's,\(.*= \)*\(.*\),\2 -,'
fi
}

# usage: cp_a <src> <dst>
Expand Down
7 changes: 6 additions & 1 deletion os.Linux
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@ head_n()
# usage: sha1 [file]
sha1()
{
sha1sum "$1"
if [ $# = 1 ]
then
sha1sum "$1"
else
sha1sum
fi
}

# usage: cp_a <src> <dst>
Expand Down
7 changes: 6 additions & 1 deletion os.SunOS
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@ head_n()
# usage: sha1 [file]
sha1()
{
sha1sum "$1"
if [ $# = 1 ]
then
sha1sum "$1"
else
sha1sum
fi
}

# usage: cp_a <src> <dst>
Expand Down
3 changes: 2 additions & 1 deletion regression/scaffold
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ function replace_path
-e "s,^Usage: guilt-,Usage: guilt ,g" \
-e "s,\.\.\. initial, initial,g" \
-e "s,^Already on\( branch\)\? [\"']\([^\"']*\)[\"']$,Already on \"\2\",g" \
-e "s,^Switched to branch [\"']\([^\"']*\)[\"'],Switched to branch \"\1\",g"
-e "s,^Switched to branch [\"']\([^\"']*\)[\"'],Switched to branch \"\1\",g" \
-e "\\,^Deleted branch guilt/.* (was .*).$,d"
}

function filter_dd
Expand Down
24 changes: 12 additions & 12 deletions regression/t-052.out
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ f da39a3ee5e6b4b0d3255bfef95601890afd80709 .git/patches/master/status
Applying patch..modify
Patch applied.
% guilt branch br-modify
Switched to branch "br-modify"
Switched to branch "guilt/br-modify"
% list_files
d .git/patches
d .git/patches/br-
Expand Down Expand Up @@ -76,8 +76,8 @@ f bc9ab2e0f5db99d483961e956e814d963f0309f8 .git/patches/master/modify
f da39a3ee5e6b4b0d3255bfef95601890afd80709 .git/patches/br-/status
r 33633e7a1aa31972f125878baf7807be57b1672d .git/refs/patches/br-modify/modify
r 33633e7a1aa31972f125878baf7807be57b1672d .git/refs/patches/master/modify
% git checkout master
Switched to branch "master"
% git checkout guilt/master
Switched to branch "guilt/master"
% list_files
d .git/patches
d .git/patches/br-
Expand Down Expand Up @@ -109,7 +109,7 @@ r 33633e7a1aa31972f125878baf7807be57b1672d .git/refs/patches/master/modify
Applying patch..add
Patch applied.
% guilt branch br-add
Switched to branch "br-add"
Switched to branch "guilt/br-add"
% list_files
d .git/patches
d .git/patches/br-
Expand Down Expand Up @@ -149,8 +149,8 @@ r 33633e7a1aa31972f125878baf7807be57b1672d .git/refs/patches/br-modify/modify
r 33633e7a1aa31972f125878baf7807be57b1672d .git/refs/patches/master/modify
r 37d588cc39848368810e88332bd03b083f2ce3ac .git/refs/patches/br-add/add
r 37d588cc39848368810e88332bd03b083f2ce3ac .git/refs/patches/master/add
% git checkout master
Switched to branch "master"
% git checkout guilt/master
Switched to branch "guilt/master"
% list_files
d .git/patches
d .git/patches/br-
Expand Down Expand Up @@ -193,7 +193,7 @@ r 37d588cc39848368810e88332bd03b083f2ce3ac .git/refs/patches/master/add
Applying patch..remove
Patch applied.
% guilt branch br-remove
Switched to branch "br-remove"
Switched to branch "guilt/br-remove"
% list_files
d .git/patches
d .git/patches/br-
Expand Down Expand Up @@ -245,8 +245,8 @@ r 37d588cc39848368810e88332bd03b083f2ce3ac .git/refs/patches/br-remove/add
r 37d588cc39848368810e88332bd03b083f2ce3ac .git/refs/patches/master/add
r ffb7faa126a6d91bcdd44a494f76b96dd860b8b9 .git/refs/patches/br-remove/remove
r ffb7faa126a6d91bcdd44a494f76b96dd860b8b9 .git/refs/patches/master/remove
% git checkout master
Switched to branch "master"
% git checkout guilt/master
Switched to branch "guilt/master"
% list_files
d .git/patches
d .git/patches/br-
Expand Down Expand Up @@ -301,7 +301,7 @@ r ffb7faa126a6d91bcdd44a494f76b96dd860b8b9 .git/refs/patches/master/remove
Applying patch..mode
Patch applied.
% guilt branch br-mode
Switched to branch "br-mode"
Switched to branch "guilt/br-mode"
% list_files
d .git/patches
d .git/patches/br-
Expand Down Expand Up @@ -366,5 +366,5 @@ r ccd56089d1b5305a9d35617cb7f6f4b06ffa68ba .git/refs/patches/master/mode
r ffb7faa126a6d91bcdd44a494f76b96dd860b8b9 .git/refs/patches/br-mode/remove
r ffb7faa126a6d91bcdd44a494f76b96dd860b8b9 .git/refs/patches/br-remove/remove
r ffb7faa126a6d91bcdd44a494f76b96dd860b8b9 .git/refs/patches/master/remove
% git checkout master
Switched to branch "master"
% git checkout guilt/master
Switched to branch "guilt/master"
7 changes: 6 additions & 1 deletion regression/t-052.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,10 @@ for x in "" modify add remove mode ; do
[ "$x" != "" ] && guilt push "$x"
cmd guilt branch br-$x
cmd list_files
cmd git checkout master
if [ "$x" != "" ]
then
cmd git checkout guilt/master
else
cmd git checkout master
fi
done
Loading

0 comments on commit fc5caa7

Please sign in to comment.