Thursday Aug 07, 2008

Customizing Mercurial outgoing output

Part of the transition of Mercurial in OpenSolaris are changes in the integration processes. Every RTI has to contain output of hg outgoing -v so the CRT advocates can better see the impact of the changes in terms of changed files. However, the default output is not very readable:

    $ hg outgoing -v
    comparing with /local/ws-mirrors/onnv-clone.hg
    searching for changes
    changeset:   7248:225922d15fe6
    user:        Vladimir Kotal 
    date:        2008-08-06 23:39 +0200
    
    modified:    usr/src/cmd/ldap/ns_ldap/ldapaddent.c usr/src/cmd/sendmail/db/config.h usr/src/cmd/ssh/include/config.h usr/src
    /cmd/ssh/include/openbsd-compat.h usr/src/cmd/ssh/include/strsep.h usr/src/cmd/ssh/libopenbsd-compat/Makefile.com usr/src
    /cmd/ssh/libopenbsd-compat/common/llib-lopenbsd-compat usr/src/cmd/ssh/libopenbsd-compat/common/strsep.c usr/src/cmd/ssh/libssh
    /common/llib-lssh usr/src/common/util/string.c usr/src/head/string.h usr/src/lib/libc/amd64/Makefile usr/src/lib/libc
    /i386/Makefile.com usr/src/lib/libc/port/gen/strsep.c usr/src/lib/libc/port/llib-lc usr/src/lib/libc/port/mapfile-vers usr/src
    /lib/libc/sparc/Makefile usr/src/lib/libc/sparcv9/Makefile usr/src/lib/passwdutil/Makefile.com usr/src/lib/passwdutil
    /bsd-strsep.c usr/src/lib/passwdutil/passwdutil.h usr/src/lib/smbsrv/libsmb/common/mapfile-vers usr/src/lib/smbsrv/libsmb
    /common/smb_util.c
    added:       usr/src/lib/libc/port/gen/strsep.c
    deleted:     usr/src/cmd/ssh/include/strsep.h usr/src/cmd/ssh/libopenbsd-compat/common/strsep.c usr/src/lib/passwdutil/bsd-strsep.c
    log:PSARC 2008/305 strsep() in libc
    4383867 need strsep() in libc
    --------------------------------------------------------------------
    

In the above case, the list of modified files spans single line which makes the web form used for RTI go really wild in terms of width (I had to wrap the lines manually in the above example otherwise this page would suffer from the same problem). The following steps can be used to make the output a bit nicer:

  1. create ~/bin/Mercurial/outproc.py with the following contents:
    from mercurial import templatefilters
    
    def newlines(text):
        return text.replace(' ', '\\n')
    
    def outgoing_hook(ui, repo, \*\*kwargs):
        templatefilters.filters["newlines"] = newlines
    
  2. hook into outgoing command in ~/.hgrc by adding the following lines into [hooks], [extensions] sections so it looks like this:
    [extensions]
    outproc=~/bin/Mercurial/outproc.py
    
    [hooks]
    pre-outgoing=python:outproc.outgoing_hook
    
  3. create ~/bin/Mercurial/style.outgoing with the following contents:
    changeset = outgoing.template
    
  4. create ~/bin/Mercurial/outgoing.template with the following contents (the file can be downloaded here):
    changeset:	{rev}:{node|short}
    user:		{author}
    date:		{date|isodate}
    
    modified:
    {files|stringify|newlines}
    
    added:
    {file_adds|stringify|newlines}
    
    deleted:
    {file_dels|stringify|newlines}
    
    log:
    {desc}
    ------------------------------------------------------------------------
    
  5. add the following into your ~/.bashrc (or to .rc file of the shell of your choice):
    alias outgoing='hg outgoing --style ~/bin/Mercurial/style.outgoing'
    

After that it works like this:

    $ outgoing
    comparing with /local/ws-mirrors/onnv-clone.hg
    searching for changes
    changeset:	7248:225922d15fe6
    user:		Vladimir Kotal 
    date:		2008-08-06 23:39 +0200
    
    modified:
    usr/src/cmd/ldap/ns_ldap/ldapaddent.c
    usr/src/cmd/sendmail/db/config.h
    usr/src/cmd/ssh/include/config.h
    usr/src/cmd/ssh/include/openbsd-compat.h
    usr/src/cmd/ssh/include/strsep.h
    usr/src/cmd/ssh/libopenbsd-compat/Makefile.com
    usr/src/cmd/ssh/libopenbsd-compat/common/llib-lopenbsd-compat
    usr/src/cmd/ssh/libopenbsd-compat/common/strsep.c
    usr/src/cmd/ssh/libssh/common/llib-lssh
    usr/src/common/util/string.c
    usr/src/head/string.h
    usr/src/lib/libc/amd64/Makefile
    usr/src/lib/libc/i386/Makefile.com
    usr/src/lib/libc/port/gen/strsep.c
    usr/src/lib/libc/port/llib-lc
    usr/src/lib/libc/port/mapfile-vers
    usr/src/lib/libc/sparc/Makefile
    usr/src/lib/libc/sparcv9/Makefile
    usr/src/lib/passwdutil/Makefile.com
    usr/src/lib/passwdutil/bsd-strsep.c
    usr/src/lib/passwdutil/passwdutil.h
    usr/src/lib/smbsrv/libsmb/common/mapfile-vers
    usr/src/lib/smbsrv/libsmb/common/smb_util.c
    
    added:
    usr/src/lib/libc/port/gen/strsep.c
    
    deleted:
    usr/src/cmd/ssh/include/strsep.h
    usr/src/cmd/ssh/libopenbsd-compat/common/strsep.c
    usr/src/lib/passwdutil/bsd-strsep.c
    
    log:
    PSARC 2008/305 strsep() in libc
    4383867 need strsep() in libc
    ------------------------------------------------------------------------
    

I asked Richard Lowe (who has been very helpful with helping getting the transition process done) if next Mercurial version can have newlines function already included and if there could be outgoingtemplate which would be similar to logtemplate in hgrc(5).
In the meantime I will be using the above for my RTIs.

About

blog about security and various tools in Solaris

Search

Categories
Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today