ga, forgot to attach the script in my previous message, so here it is.

thanks

Trev

On Wed, Aug 01, 2018 at 12:16:57AM +0100, Maciej W. Rozycki wrote:
> On Thu, 5 Jul 2018, Tom Tromey wrote:
> 
> > I use git-merge-changelog from gnulib.  If you want to use git am and
> > avoid manually copying ChangeLog text from the commit message back into
> > the appropriate files, then it's much better to install the driver and
> > include the ChangeLog diffs in the patch submission.
> 
>  FWIW, I've found it quite quick to paste ChangeLog text from the commit 
> message after `git am' (directly invocable for the intended submission 
> from alpine e-mail client, which has a "pipe message" command) by adding 
> an empty first line to the intended ChangeLog file, marking it with ^V and 
> then issuing:
> 
> :'<,'>!git log -1
> 
> in vim, removing any commit description preceding the ChangeLog entry and 
> fixing up formatting of the newly-added entry by marking it with ^V and 
> then with:
> 
> :'<,'>s/^    //g
> 
> If more than one ChangeLog file is used, then parts of the entry can be 
> carried over via buffers.  Perhaps the most involving is adding the date 
> and author heading, but I don't think you can completely avoid manual 
> intervention here anyway.  Then:
> 
> $ git commit -a --amend
> $ git rebase --ignore-date origin/master
> 
>  For ChangeLog entries contained in a single file it takes maybe a few 
> seconds, for more complex one a couple dozens perhaps.
> 
>  Of course the amount of effort required for that will likely vary between 
> e-mail clients and editors.
> 
>   Maciej
#!/usr/bin/python

import sys
import os
import re

def finish_logfile(logfile):
    logfile.write('\n')
    oldfile = open(logfile.name[:len(logfile.name) - 1], 'r')
    logfile.write(oldfile.read())
    logfile.close()
    os.rename(logfile.name, logfile.name[:len(logfile.name) - 1])


commit = sys.stdin.readlines()

logfile = None
did_date = False
for line in commit:
    newfile = None
    if '/' in line and not line.startswith('\t'):
        print line
        line = line.strip(' \n\t\r:')
        if os.path.isfile(line):
            newfile = open(line + '~', 'w')
        else:
            if os.path.isdir(line):
                newfile = open(line + '/ChangeLog~', 'w')

    if newfile:
        if logfile:
            finish_logfile(logfile)

        logfile = newfile
        did_date = False
        continue

    if re.match('[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]  .*  <.*@.*>', line):
        dateline = line.strip();
        logfile.write(dateline)
        logfile.write('\n\n')
        did_date = True
        continue

    if not line.startswith('\t'):
        if (not logfile) or line == '\n':
            continue
        else:
            print('error: baddly indented line')
            exit(1)

    if not did_date:
        generate_date(logfile)

    logfile.write(line)

finish_logfile(logfile)

Reply via email to