From: Pierre Habouzit <madcoder@debian.org>
To: Josef Jeff Sipek <jsipek@cs.sunysb.edu>
Cc: git@vger.kernel.org, Pierre Habouzit <madcoder@debian.org>
Subject: [PATCH] guilt(1): reimplement push_patch, using a subshell to avoid locals.
Date: Thu, 14 Jun 2007 14:50:59 +0200 [thread overview]
Message-ID: <11818254623497-git-send-email-madcoder@debian.org> (raw)
In-Reply-To: <11818254621527-git-send-email-madcoder@debian.org>
this is a bit ugly, but makes the code really shorter, and more readable
anyway. We still need the old bail variable, named __push_patch_bail to
avoid spurious collisions (we are not recursing into ourselves, so it's
safe).
Signed-off-by: Pierre Habouzit <madcoder@debian.org>
---
guilt | 133 ++++++++++++++++++++++++-----------------------------------------
1 files changed, 49 insertions(+), 84 deletions(-)
diff --git a/guilt b/guilt
index 44273f3..f77c050 100755
--- a/guilt
+++ b/guilt
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
#
# Copyright (c) Josef "Jeff" Sipek, 2006, 2007
#
@@ -341,106 +341,71 @@ update_stack_tags()
# usage: push_patch patchname [bail_action]
push_patch()
{
- local p="$GUILT_DIR/$branch/$1"
- local pname="$1"
- local bail_action="$2"
+ __push_patch_bail=0
- local bail=0
- local reject="--reject"
-
- assert_head_check
-
- cd "$TOP_DIR"
+ (
+ p="$GUILT_DIR/$branch/$1"
+ pname="$1"
+ bail_action="$2"
+ reject="--reject"
- # apply the patch if and only if there is something to apply
- if [ `git-apply --numstat "$p" | wc -l` -gt 0 ]; then
- if [ "$bail_action" = abort ]; then
- reject=""
- fi
- git-apply -C$guilt_push_diff_context \
- $reject "$p" > /dev/null 2> /tmp/guilt.log.$$
- bail=$?
+ assert_head_check
+ cd "$TOP_DIR"
- if [ $bail -ne 0 ]; then
- cat /tmp/guilt.log.$$ >&2
+ # apply the patch if and only if there is something to apply
+ if [ `git-apply --numstat "$p" | wc -l` -gt 0 ]; then
if [ "$bail_action" = abort ]; then
- return $bail
+ reject=""
+ fi
+ git-apply -C$guilt_push_diff_context \
+ $reject "$p" > /dev/null 2> /tmp/guilt.log.$$
+ __push_patch_bail=$?
+
+ if [ $__push_patch_bail -ne 0 ]; then
+ cat /tmp/guilt.log.$$ >&2
+ if [ "$bail_action" = "abort" ]; then
+ rm -f /tmp/guilt.log.$$ /tmp/guilt.msg.$$
+ return $__push_patch_bail
+ fi
fi
- fi
-
- # FIXME: Path munging is being done, we need to convince
- # git-apply to just give us list of files with \0 as a
- # delimiter, and pass -z to git-update-index
- git-apply --numstat "$p" | cut -f 3- | git-update-index --add --remove --stdin
- fi
- # grab a commit message out of the patch
- do_get_header "$p" > /tmp/guilt.msg.$$
+ # FIXME: Path munging is being done, we need to convince
+ # git-apply to just give us list of files with \0 as a
+ # delimiter, and pass -z to git-update-index
+ git-apply --numstat "$p" | cut -f 3- | git-update-index --add --remove --stdin
+ fi
- # make a default commit message if patch doesn't contain one
- [ ! -s /tmp/guilt.msg.$$ ] && echo "patch $pname" > /tmp/guilt.msg.$$
+ # grab a commit message out of the patch
+ do_get_header "$p" > /tmp/guilt.msg.$$
- # extract a From line from the patch header, and set
- # GIT_AUTHOR_{NAME,EMAIL}
- local author_str=`cat "$p" | grep -e '^From: ' | sed -e 's/^From: //'`
- if [ ! -z "$author_str" ]; then
- local backup_author_name="$GIT_AUTHOR_NAME"
- local backup_author_email="$GIT_AUTHOR_EMAIL"
- GIT_AUTHOR_NAME=`echo $author_str | sed -e 's/ *<.*$//'`
- GIT_AUTHOR_EMAIL=`echo $author_str | sed -e 's/[^<]*//'`
+ # make a default commit message if patch doesn't contain one
+ [ ! -s /tmp/guilt.msg.$$ ] && echo "patch $pname" > /tmp/guilt.msg.$$
- if [ -z "$GIT_AUTHOR_NAME" ]; then
- GIT_AUTHOR_NAME=" "
+ # extract a From line from the patch header, and set
+ # GIT_AUTHOR_{NAME,EMAIL}
+ author_str=`sed -n -e '/^From:/ { s/^From: //; p; q }' "$p"`
+ if [ ! -z "$author_str" ]; then
+ GIT_AUTHOR_NAME=`echo $author_str | sed -e 's/ *<.*$//'`
+ export GIT_AUTHOR_NAME="${GIT_AUTHOR_NAME:-" "}"
+ export GIT_AUTHOR_EMAIL="`echo $author_str | sed -e 's/[^<]*//'`"
fi
+ export GIT_AUTHOR_DATE="`stat -c %y "$p"`"
+ export GIT_COMMITTER_DATE="$GIT_AUTHOR_DATE"
- export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL
- fi
- local backup_author_date="$GIT_AUTHOR_DATE"
- local backup_committer_date="$GIT_COMMITTER_DATE"
- export GIT_AUTHOR_DATE=`stat -c %y "$p"`
- export GIT_COMMITTER_DATE=$GIT_AUTHOR_DATE
-
- # commit
- local treeish=`git-write-tree`
- local commitish=`git-commit-tree $treeish -p HEAD < /tmp/guilt.msg.$$`
- echo $commitish > $GIT_DIR/`git-symbolic-ref HEAD`
+ # commit
+ treeish=`git-write-tree`
+ commitish=`git-commit-tree $treeish -p HEAD < /tmp/guilt.msg.$$`
+ echo $commitish > $GIT_DIR/`git-symbolic-ref HEAD`
- # mark patch as applied
- echo "$commitish:$pname" >> $applied
-
- cd - 2>&1 >/dev/null
+ # mark patch as applied
+ echo "$commitish:$pname" >> $applied
+ )
# 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
- export GIT_AUTHOR_NAME="$backup_author_name"
- else
- unset GIT_AUTHOR_NAME
- fi
-
- if [ ! -z "$backup_author_name" ]; then
- export GIT_AUTHOR_EMAIL="$backup_author_email"
- else
- unset GIT_AUTHOR_EMAIL
- fi
- fi
- if [ ! -z "$backup_author_date" ]; then
- export GIT_AUTHOR_DATE="$backup_author_date"
- else
- unset GIT_AUTHOR_DATE
- fi
- if [ ! -z "$backup_committer_date" ]; then
- export GIT_COMMITTER_DATE="$backup_committer_date"
- else
- unset GIT_COMMITTER_DATE
- fi
-
rm -f /tmp/guilt.msg.$$ /tmp/guilt.log.$$
-
- return $bail
+ return $__push_patch_bail
}
# usage: must_commit_first
--
1.5.2.1
next prev parent reply other threads:[~2007-06-14 12:51 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-06-14 12:50 [PATCH guilt] make guilt use standard POSIX shell Pierre Habouzit
2007-06-14 12:50 ` [PATCH] Regression test suite needs bash, that's OK Pierre Habouzit
2007-06-14 12:50 ` [PATCH] guilt(1): Obvious bashisms fixed Pierre Habouzit
2007-06-14 15:15 ` Josef Sipek
2007-06-14 15:18 ` Pierre Habouzit
2007-06-14 12:50 ` [PATCH] guilt(1): simplifications Pierre Habouzit
2007-06-14 14:58 ` Josef Sipek
2007-06-14 15:16 ` Pierre Habouzit
2007-06-14 12:50 ` Pierre Habouzit [this message]
2007-06-14 12:51 ` [PATCH] Easy commands, without bashisms Pierre Habouzit
2007-06-14 12:51 ` [PATCH] guilt-status(1): Remove bashisms Pierre Habouzit
2007-06-14 12:51 ` [PATCH] Remove last bashisms from remaining commands Pierre Habouzit
2007-06-14 13:07 ` [PATCH guilt] make guilt use standard POSIX shell Pierre Habouzit
2007-06-14 13:20 ` [PATCH] Small regresson when series file is empty Pierre Habouzit
2007-06-14 15:27 ` [PATCH guilt] make guilt use standard POSIX shell Josef Sipek
2007-06-14 15:56 ` Pierre Habouzit
2007-06-14 15:58 ` Pierre Habouzit
2007-06-14 16:39 ` Josef Sipek
2007-06-14 17:16 ` Pierre Habouzit
2007-06-14 15:50 ` [PATCH] More regressions fixes Pierre Habouzit
2007-06-15 8:01 ` [PATCH guilt] make guilt use standard POSIX shell Derek Fawcus
2007-06-15 22:31 ` Benjamin Sergeant
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=11818254623497-git-send-email-madcoder@debian.org \
--to=madcoder@debian.org \
--cc=git@vger.kernel.org \
--cc=jsipek@cs.sunysb.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).