Autotagging
Greetings all!
Recently, it has been brought to my attention that it would be nice to be able to refer to the top/bottom/base of the patch stack in Guilt by a name instead of fishing around the log for the hash. I quickly coded up the following solution (which I call "autotagging"), which creates unannotated tags for the top (topmost applied patch), bottom (first applied patch), and base (parent of bottom) in with this naming scheme:
${branch}_top
${branch}_bottom
${branch}_baseThe branch name is necessary as each branch has its own series of patches, and potentially different history to begin with.
Of course, I included an option to disable this feature (see patch 2) - just set guilt.autotag=0 in your git config.
Before I merge this into Guilt master, I was hoping for some feedback. Just in case I completely missed something obvious, or perhaps there is a better way to name the branches :)
Thanks,
Josef "Jeff" Sipek.
PATCH 1/2 Automatically create unannotated tags for top, bottom, and base of the stack
On every push or pop operation (refresh is a pop followed by a push), update the stack top (${branch}_top), stack bottom (${branch}_bottom), and stack base (${branch}_base) tags.
Top: Topmost applied patch/commit
Bottom: Bottommost applied patch/commit
Base: Commit on top of which the bottom most patch is applied
Having these three tags, one can easily get the log/diff/other information only for commits that are (or are not!) part of the patch stack.
--- guilt | 34 ++++++++++++++++++++++++++++++++-- 1 files changed, 32 insertions(+), 2 deletions(-)
guilt +32 -2
@@ -277,6 +277,33 @@ function pop_many_patches mv "$applied.tmp" "$applied" cd - 2>&1 >/dev/null + + # update references to top, bottom, and base + update_stack_tags +} + +# usage: update_stack_tags +function update_stack_tags +{ + if [ `wc -l < $applied` -gt 0 ]; then + # there are patches applied, therefore we must get the top, + # bottom and base hashes, and update the tags + + local top_hash=`git-rev-parse HEAD` + local bottom_hash=`head -1 < $applied | cut -d: -f1` + local base_hash=`git-rev-parse $bottom_hash^` + + echo $top_hash > "$GIT_DIR/refs/tags/${branch}_top" + echo $bottom_hash > "$GIT_DIR/refs/tags/${branch}_bottom" + echo $base_hash > "$GIT_DIR/refs/tags/${branch}_base" + else + # there are no patches applied, therefore we must remove the + # tags to old top, bottom, and base + + rm -f "$GIT_DIR/refs/tags/${branch}_top" + rm -f "$GIT_DIR/refs/tags/${branch}_bottom" + rm -f "$GIT_DIR/refs/tags/${branch}_base" + fi } # usage: push_patch patchname [bail_action]
@@ -349,6 +376,11 @@ function push_patch # mark patch as applied echo "$commitish:$pname" >> $applied + cd - 2>&1 >/dev/null + + # update references to top, bottom, and base of the stack + update_stack_tags + # restore original GIT_AUTHOR_{NAME,EMAIL} if [ ! -z "$author_str" ]; then if [ ! -z "$backup_author_name" ]; then
@@ -376,8 +408,6 @@ function push_patch rm -f /tmp/guilt.msg.$$ /tmp/guilt.log.$$ - cd - 2>&1 >/dev/null - return $bail }
Signature · 1 line
1.5.0.3.268.g3dda
PATCH 2/2 Autotag: Read guilt.autotag config var and tag commits only if this feature is enabled
In reply to Josef 'Jeff' SipekSome users may not want to have guilt automatically tag the top, bottom, and base of the stack. Allow them to disable such functionality by setting guilt.autotag=0 in their git config file.
guilt-init now accepts a new parameter '-n' to automatically set guilt.autotag=0 in the current repository.
--- Documentation/guilt-init.txt | 8 +++++++- guilt | 15 +++++++++++++++ guilt-init | 15 ++++++++++++--- 3 files changed, 34 insertions(+), 4 deletions(-)
Documentation/guilt-init.txt +7 -1
@@ -8,12 +8,18 @@ guilt-init - Initialize guilt for use in a git repository SYNOPSIS -------- -'guilt-init' +'guilt-init [-n]' DESCRIPTION ----------- Initialize a git repository for use with guilt +OPTIONS +------- +-n:: + Do not automatically create stack top, bottom, and base tags (sets + guilt.autotag config variable to 0). + EXAMPLES -------- First, get a repository to work on. Here's one that we'll use as an example:
guilt +15 -0
@@ -285,6 +285,11 @@ function pop_many_patches # usage: update_stack_tags function update_stack_tags { + # bail if autotagging is not enabled + if [ $autotag -eq 0 ]; then + return 0 + fi + if [ `wc -l < $applied` -gt 0 ]; then # there are patches applied, therefore we must get the top, # bottom and base hashes, and update the tags
@@ -480,12 +485,22 @@ function munge_hash_range fi } +# # Some constants +# # used for: git-apply -C <val> guilt_push_diff_context=1 # +# Parse any part of .git/config that belongs to us +# + +# autotag? +autotag=`git-config guilt.autotag` +[ -z "$autotag" ] && autotag=1 + +# # The following gets run every time this file is source'd #
guilt-init +12 -3
@@ -5,11 +5,19 @@ DO_NOT_CHECK_BRANCH_EXISTENCE=1 +USAGE="[-n]" . guilt -if [ $# -ne 0 ]; then - usage -fi +autotag=1 + +while case $# in 0) break ;; esac; do + if [ "$1" = "-n" ]; then + autotag=0 + shift + else + usage + fi +done if [ -d "$GUILT_DIR/$branch" ]; then die "Branch $branch appears to be already initialized (GIT_DIR=$GIT_DIR)"
@@ -20,3 +28,4 @@ mkdir $GUILT_DIR/$branch touch $GUILT_DIR/$branch/series touch $GUILT_DIR/$branch/status +git-config --int --replace-all guilt.autotag $autotag
Signature · 1 line
1.5.0.3.268.g3dda