zsh-workers
 help / color / mirror / code / Atom feed
* helper script for making ChangeLog entries
@ 2014-12-03 16:16 Mikael Magnusson
  2014-12-03 21:10 ` Bart Schaefer
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Mikael Magnusson @ 2014-12-03 16:16 UTC (permalink / raw)
  To: zsh-workers

I got a bit tired of constructing these manually, not sure how you guys
do it but here's my script for it.

% gen-zsh-cl-entry HEAD
2014-12-03  Mikael Magnusson  <mikachu@gmail.com>

	* Eric Cook: 33689: Completion/Unix/Command/_cp: make cp
	--reflink's argument optional

% gen-zsh-cl-entry :/33712:
2014-12-03  Oliver Kiddle  <opk@zsh.org>

	* saga: 33712: Completion/Debian/Command/_apt: add --auto-remove
	option

You have to commit your changes first (with --author=someoneelse'
<their@email>' if needed), either prepend the X-Seq to the start of
the commit message, or specify it as the second argument to this script
(but then the commit message still won't have it).

You still need to copy and paste the output into ChangeLog and update
the commit (if it's the top commit, git add ChangeLog; git commit --amend
-C HEAD)

#!/bin/zsh
if > /dev/null git rev-parse --quiet --verify $1; then
  if [[ -z $2 ]]; then
    2=$(git show -s --pretty=format:%s $1)
    3=${2#*:}
    2=${2%%:*}
  else
    3=\ $(git show -s --pretty=format:%s $1)
  fi
  cminfo=(${(0)"$(git show -s --pretty=format:%an%x00%cn%x00%ce $1)"})
  author=$cminfo[1]
  committer=$cminfo[2]
  cmmail=$cminfo[3]
  if [[ "$author" != "$committer" ]]; then
    2="$author: $2"
  fi
  zmodload zsh/datetime
  strftime "%Y-%m-%d  $committer  <$cmmail>" $EPOCHSECONDS
  echo $'\n\t* '$2: ${(j:, :)${(f)"$(git diff --name-only $1\^!|grep -v ChangeLog)"}}:$3|fmt
else
  echo >&2 "You need to pass a valid commit, you may also pass an X-seq"
fi


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: helper script for making ChangeLog entries
  2014-12-03 16:16 helper script for making ChangeLog entries Mikael Magnusson
@ 2014-12-03 21:10 ` Bart Schaefer
  2014-12-05 18:43 ` Frank Terbeck
  2015-04-17 13:53 ` Daniel Shahaf
  2 siblings, 0 replies; 4+ messages in thread
From: Bart Schaefer @ 2014-12-03 21:10 UTC (permalink / raw)
  To: Mikael Magnusson; +Cc: Zsh hackers list

On Wed, Dec 3, 2014 at 8:16 AM, Mikael Magnusson <mikachu@gmail.com> wrote:
> I got a bit tired of constructing these manually, not sure how you guys
> do it but here's my script for it.

I've been doing it the other way around, that is, write the ChangeLog
entry first and then generate the commit message from *that*, so that
the ChangeLog and the corresponding changed files are all a single
git-commit.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: helper script for making ChangeLog entries
  2014-12-03 16:16 helper script for making ChangeLog entries Mikael Magnusson
  2014-12-03 21:10 ` Bart Schaefer
@ 2014-12-05 18:43 ` Frank Terbeck
  2015-04-17 13:53 ` Daniel Shahaf
  2 siblings, 0 replies; 4+ messages in thread
From: Frank Terbeck @ 2014-12-05 18:43 UTC (permalink / raw)
  To: Mikael Magnusson; +Cc: zsh-workers

Hey,

Mikael Magnusson wrote:
> I got a bit tired of constructing these manually, not sure how you guys
> do it but here's my script for it.

I've got a ChangeLog generator in this: https://github.com/ft/zsh-am

That thing removes a lot of the manual labour with importing patches
from the mailing list.  Works pretty well for me. No idea is anybody
else uses it.


Regards, Frank

-- 
In protocol design, perfection has been reached not when there is
nothing left to add, but when there is nothing left to take away.
                                                  -- RFC 1925


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: helper script for making ChangeLog entries
  2014-12-03 16:16 helper script for making ChangeLog entries Mikael Magnusson
  2014-12-03 21:10 ` Bart Schaefer
  2014-12-05 18:43 ` Frank Terbeck
@ 2015-04-17 13:53 ` Daniel Shahaf
  2 siblings, 0 replies; 4+ messages in thread
From: Daniel Shahaf @ 2015-04-17 13:53 UTC (permalink / raw)
  To: Mikael Magnusson; +Cc: zsh-workers

[-- 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"

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2015-04-17 13:53 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-12-03 16:16 helper script for making ChangeLog entries Mikael Magnusson
2014-12-03 21:10 ` Bart Schaefer
2014-12-05 18:43 ` Frank Terbeck
2015-04-17 13:53 ` Daniel Shahaf

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