Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: helper script for making ChangeLog entries
- X-seq: zsh-workers 34912
- From: Daniel Shahaf <d.s@xxxxxxxxxxxxxxxxxx>
- To: Mikael Magnusson <mikachu@xxxxxxxxx>
- Subject: Re: helper script for making ChangeLog entries
- Date: Fri, 17 Apr 2015 13:53:07 +0000
- Cc: zsh-workers@xxxxxxx
- Dkim-signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= daniel.shahaf.name; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-sasl-enc :x-sasl-enc; s=mesmtp; bh=DsreuUyiULAJQ3Dk3RpXo7cjh60=; b=z1qetS yNmSeVeQFOvwS/6GZvttrCBdYePYsdgYgtaPzKLo5tmM2KU/nbPm1kcBGIhBs7Z2 TvWmIi4aMhjelqeRrHtECVleuxc7ZqrqEzrgkdksSqho6OXvHoN9WnANZ4YHI9x2 /70PN0g1NGdz7ht53kc1PS5PE5aPtgTRnKV8I=
- Dkim-signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-sasl-enc :x-sasl-enc; s=smtpout; bh=DsreuUyiULAJQ3Dk3RpXo7cjh60=; b=QMtsd +QBlkVmM5SAtgjQzjig9M3O9kLSPbUlamTAlM/VUNc8dTIGApo3dbaw7ZLnsQpSy kSd3DsRs8UuG3IfE1q54/nkfxXhGC8GXECFKF9/AHtq4zuIP8jwBUSOI4HOMUXM9 HSdt8evbGFPtJuIc6zcjBbNLfz++3MmkIoQmb0=
- In-reply-to: <1417623415-7042-1-git-send-email-mikachu@gmail.com>
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- References: <1417623415-7042-1-git-send-email-mikachu@gmail.com>
[following up on a thread from a few months ago]
Mikael Magnusson wrote on Wed, Dec 03, 2014 at 17:16:55 +0100:
> I got a bit tired of constructing these manually, not sure how you guys
> do it but here's my script for it.
Here's my version of this. My workflow is as follows: first, commit the
patches to the 'master' branch (using either 'git am' or 'git apply &&
git commit --author'), then run
% zshdev-add<TAB> 42
% git push
where 42 is the X-Seq number. The first command generates a ChangeLog
entry, updates the commit to include it (with 'git commit --amend'), and
updates the commit's log message to include the X-Seq number. The
ChangeLog entry is based on the first sentence of the commit message.
If there are multiple local commits on top of origin/master, the script
will amend all local commits which haven't already been amended.
Cheers,
Daniel
P.S. I also use
zstyle ':completion:*:-command-:*:commands' ignored-patterns zshdev-add-nnnnn-and-changelog-internal
#!/usr/bin/env zsh
# This is a helper script, invoked by zshdev-add-nnnnn-and-changelog.
## Declarations
local -i WIDTH=74 TAB_WIDTH=8
local title seqno=$seqno files summary
local logmsg
local entry
zmodload -F zsh/datetime b:strftime p:EPOCHSECONDS
## Validate our caller.
[[ $# -eq 0 && -n $seqno ]] || { echo "Usage error" >&2; exit 1 }
## Helper functions.
# Prepend the string $1 to the file $2.
prepend_to_file() {
local prependum=$1
local file=$2
printf "0r %s\nw\nq\n" =(<<<$prependum) | ed -s -- $file
}
## Update ChangeLog.
rev=HEAD
title="$(strftime "%Y-%m-%d" $EPOCHSECONDS) $(git log --no-walk --pretty="%aN <%aE>" $rev --)"
files=( ${(f)$(git show --pretty=%n --name-only $rev --)} )
summary=`git log --no-walk --pretty=%s $rev --`
entry=''
entry+=$title
entry+=$'\n\n'
entry+=$(print -r - "* $seqno: ${(j:, :)files}: $summary" | fmt -w $((WIDTH - TAB_WIDTH)) | sed $'s/^/\t/g')
entry+=$'\n\n'
# Don't duplicate $title
if [[ "$title" == "$(head -n1 < ChangeLog)" ]]; then
print -l '1,2d' 'w' 'q' | ed -s -- ChangeLog
fi
prepend_to_file $entry ChangeLog
## Commit ChangeLog, amend the commit message.
logmsg="$seqno: `git log --no-walk --pretty=%B HEAD`"
git commit --amend -m "$logmsg" ChangeLog
#!/usr/bin/env zsh
local AUTHOR_NAME=$(git config --get user.name)
local UPSTREAM=origin/master
local ENDPOINT
export seqno
fail() { echo "$1" >&2; exit 1 }
usage() {
cat >&2 <<EOF
$0: a zsh developer's add-X-Seq-and-ChangeLog script
Usage: $0 NUMBER
Will prefix NUMBER to the log message of each local commit not yet
in $UPSTREAM, and amend the commit with a ChangeLog entry. The following
formats are accepted for NUMBER: '42', 'users/42', 'unposted'.
Prerequisite: git must have been compiled with PCRE support.
EOF
exit ${1:-1}
}
## Require a recent zsh
if [[ $( (){ shift -p; echo $# } arg1 arg2 arg3 ) -ne 2 ]]; then
fail "This script requires a zsh supporting 'shift -p'"
fi
## Argument parsing
if [[ $# -ne 1 ]] ||
[[ $1 != (<30000->*|users/<->|unposted) ]] ||
[[ $(git log -1 --pretty=%cn) != *"${AUTHOR_NAME}"* ]] ||
false
then
usage
fi
seqno=$1
## Validate worktree state
if [[ -n "`git status --porcelain ChangeLog`" ]]; then
fail "ChangeLog has local mods"
fi
if ! git merge-base --is-ancestor $UPSTREAM HEAD; then
fail "'$UPSTREAM' must be an ancestor of HEAD, but isn't"
fi
## Set ENDPOINT to oldest commit such that $ENDPOINT..HEAD consists of commits
## by $AUTHOR_NAME that don't touch ChangeLog.
# We can't just 'git log --not --committer=$AUTHOR_NAME', since the --not is silently ignored.
# Hence we use --perl-regexp, even though it requires PCRE.
[[ $AUTHOR_NAME == *'\'* ]] && fail "bobby tables"
ENDPOINT=$(git log --perl-regexp --committer='^(?!\Q'$AUTHOR_NAME'\E)' -1 --pretty=%H)
() {
local arg
# Arguments are youngest-to-oldest, so:
while (( $# )); do
arg=$argv[-1]
if [[ $(git diff --name-only $arg^..$arg) != *ChangeLog* ]]; then
ENDPOINT=$argv[-1]
return
fi
shift -p
done
} $(git rev-list $ENDPOINT..HEAD)
## Main body
seqno=$seqno \
GIT_EDITOR='true' git rebase -i $ENDPOINT^ --exec \
"$0-internal"
Messages sorted by:
Reverse Date,
Date,
Thread,
Author