From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 1894 invoked by alias); 17 Apr 2015 13:53:13 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 34912 Received: (qmail 18144 invoked from network); 17 Apr 2015 13:53:12 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 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= X-Sasl-enc: stzwdb/N3H9an3SKLGPFDkqWInfNkY/vfdp6v7va+Dw4 1429278790 Date: Fri, 17 Apr 2015 13:53:07 +0000 From: Daniel Shahaf To: Mikael Magnusson Cc: zsh-workers@zsh.org Subject: Re: helper script for making ChangeLog entries Message-ID: <20150417135307.GC2426@tarsus.local2> References: <1417623415-7042-1-git-send-email-mikachu@gmail.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="1yeeQ81UyVL57Vl7" Content-Disposition: inline In-Reply-To: <1417623415-7042-1-git-send-email-mikachu@gmail.com> User-Agent: Mutt/1.5.21 (2010-09-15) --1yeeQ81UyVL57Vl7 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline [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 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 --1yeeQ81UyVL57Vl7 Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=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 --1yeeQ81UyVL57Vl7 Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=zshdev-add-nnnnn-and-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 <*|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" --1yeeQ81UyVL57Vl7--