zsh-workers
 help / color / mirror / code / Atom feed
From: Daniel Shahaf <d.s@daniel.shahaf.name>
To: Mikael Magnusson <mikachu@gmail.com>
Cc: zsh-workers@zsh.org
Subject: Re: helper script for making ChangeLog entries
Date: Fri, 17 Apr 2015 13:53:07 +0000	[thread overview]
Message-ID: <20150417135307.GC2426@tarsus.local2> (raw)
In-Reply-To: <1417623415-7042-1-git-send-email-mikachu@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 992 bytes --]

[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

[-- Attachment #2: zshdev-add-nnnnn-and-changelog-internal --]
[-- Type: text/plain, Size: 1227 bytes --]

#!/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

[-- Attachment #3: zshdev-add-nnnnn-and-changelog --]
[-- Type: text/plain, Size: 1912 bytes --]

#!/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"

      parent reply	other threads:[~2015-04-17 13:53 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-12-03 16:16 Mikael Magnusson
2014-12-03 21:10 ` Bart Schaefer
2014-12-05 18:43 ` Frank Terbeck
2015-04-17 13:53 ` Daniel Shahaf [this message]

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=20150417135307.GC2426@tarsus.local2 \
    --to=d.s@daniel.shahaf.name \
    --cc=mikachu@gmail.com \
    --cc=zsh-workers@zsh.org \
    /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.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

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).