Hi Jiri,

Thanks for sharing.  I like the idea of having a post-process that can
be tailored.  I took your idea and experimented with it. Rather than
place some code in .hgrc and another file (~/how/Userland/hgignore) I
placed the script and hgignore contents into a script. 

~/.hgrc
[hooks]
post-clone=hg_post_clone

I've attached the script so far, should share this on some repo... 
Should rewrite in Python.

Stace

On 13/07/2012 01:45, Jiri Sasek wrote:
> Hi Brian,
>
> Various users has an individual habits. The most annoying way I can
> imagine is to push the prefabricated .hgignore to the gate.
>
> Much better way seems to me to set the post-clone hook in the ~/.hgrc
> in the individual users directory:
> ----------------------------------------------------------------------------------------
>
> [hooks]
> post-clone = ( cphgign () { dir="$1" ; [ x"$1" != x ] || dir="gate" ;
> cd "$dir" ; echo "cloned to: `pwd`" ; cat ~/how/Userland/hgignore >
> .hgignore ; } ; cphgign "`echo $HG_PATS | sed -e 's/\[//;s/\]//;s/,/
> /' | sed -e "s/\'//g" | sed -e 's/userland//' | sed -e 's/^[ ]*//'`")
> ----------------------------------------------------------------------------------------
>
>
> Prerequisites are:
> ----------------------------------------------------------------------------------------
>
> [paths]
> ...
> userland=ssh://[email protected]//gates/gate
> ----------------------------------------------------------------------------------------
>
> ...in the ~/.hgrc
>
> ~/how/Userland/hgignore  ...user's customized "hgignore"
>
> i.e. mine:
> ----------------------------------------------------------------------------------------
>
> .hgignore
>
> syntax: regexp
> ^i386/.*
> ^sparc/.*
> ^tools/.+\.(o|so)
> ^tools/.+\.pyc
> ^components/components.mk
> ^components/depends.mk
> ^components/.+/build/.*
>
> ^components/zip/zip30.*
> ^components/unzip/unzip60.*
> ^components/samba/mozldap/mozldap-6\.0\.7.*
> ^components/samba/samba30/samba-3\.0\.37.*
> ^components/samba/samba/samba-3\.6\.6.*
> ^components/samba/samba/samba-3\.5\.15.*
> ^components/cups/cups-1\.4\.5.*
> ^components/foomatic/filters/foomatic-filters-4\.0\.15.*
> ^components/foomatic/db/foomatic-db-20080903.*
> ^components/foomatic/fppd/foomatic-filters-ppds-20080818.*
> ^components/foomatic/db-engine/foomatic-db-engine-3\.0-20080903.*
> ^samba/.*
> ^webrev/.*
> ^fix-cups/.*
> ^foomatic/.*
>
> syntax: glob
> *.tar
> *.tar.gz
> *.tar.bz2
> *.zip
> *.tgz
> nohup.out
> ----------------------------------------------------------------------------------------
>
> ...is customized for Samba and printing
>
> As a subject of discussion for improvement is to push i.e.
> userland-hgignore-base into the gate and individual users can modify
> their post-clone to do i.e.:
>
> cat userland-hgignore-base ~/how/Userland/hgignore-cust > .hgignore
>
> ...which can be subject of CR 7119950 integration
>
> Jiri
>
>
> On 06/14/12 06:23 PM, [email protected] wrote:
>> Please Review the new comment logged against CI4651
>>      7119950 Userland gate needs a .hgignore file.
>>          http://monaco.us.oracle.com/detail.jsp?cr=7119950
>>
>> https://rpetools.uk.oracle.com/citool/CI4651/
>>
>> 2012-06-14 17:23:12 Europe/London [[email protected]]
>> Hi,
>>
>> To check that the hgignore does not ignore anything you can clone
>> fresh workspace and do
>> hg status -I
>>
>> I tried that and that is clean now.
>>
>> But I wonder, should not we build full workspace and add any things
>> which are missed by the generic rules?
>>
>> Also the file could contain hints how to test that your modified
>> .hgignore is correct (hg status -I on fresh workspace and hg status
>> being clean on full build).
> _______________________________________________
> userland-discuss mailing list
> [email protected]
> http://mail.opensolaris.org/mailman/listinfo/userland-discuss


#!/bin/ksh
# Script to add hgignore to newly cloned repository.
#
# This script adds a .hgignore file to a cloned repository. The
# contents of which depend on the cloned repo name.
#
# To automatically run following a clone update ~/.hgrc "[hooks]"
# section to include "post-clone=" line with filename (if in PATH) or
# pathname of this script.
#
# The script relies on "HG_PATS" environment variable set by 'hg
# clone'; a python list containing the repository alias and repo name
# (if set).
#
# In testing 'env' showed "hg clone userland" caused the following
# variables to be set:
#
# HG_ARGS=clone userland
# HG_OPTS={'branch': [], 'insecure': None, 'noupdate': None, 'pull': None,
#          'remotecmd': '', 'rev': [], 'ssh': '', 'uncompressed': None,
#          'updaterev': ''}
# HG_PATS=['userland']
# HG_RESULT=0

I=${0##*/}

function cphgign {
    [[ -n $DEBUG ]] && print -u2 "$I: $0: DEBUG: args: $@"
    src=$1
    dst=$2
    # Open brace is important below, used by usage.
    # might need to read dst from ~/.hgrc if not provided....
    case $src in
        ('userland')
            dst=${2:-gate}${2}/.hgignore
            echo "userland clone detected, updating $dst"
            userland > $dst
            ;;
        (*on11update-clone)
            dst=${2:-on11update-clone}${2}/.hgignore
            print -u2 "Empty!"
            ;;
        (*closed*)
            dst=${2:-closed}${2}/.hgignore
            print -u2 "Empty!"
            ;;
        *)
            print "$I Unrecognised src $src ${dst:+"(args: $@) "}"
            ;;
    esac
}
function userland {
# Output contents of hgignore for userland repository.
    cat <<-EOF
        syntax: regexp
        ^i386/.*
        ^sparc/.*
        ^tools/.+\.(o|so)
        ^tools/.+\.pyc
        ^components/components.mk
        ^components/depends.mk
        ^components/.+/build/.*

        ^components/zip/zip30.*
        ^components/unzip/unzip60.*
        ^components/samba/mozldap/mozldap-6\.0\.7.*
        ^components/samba/samba30/samba-3\.0\.37.*
        ^components/samba/samba/samba-3\.6\.6.*
        ^components/samba/samba/samba-3\.5\.15.*
        ^components/cups/cups-1\.4\.5.*
        ^components/foomatic/filters/foomatic-filters-4\.0\.15.*
        ^components/foomatic/db/foomatic-db-20080903.*
        ^components/foomatic/fppd/foomatic-filters-ppds-20080818.*
        ^components/foomatic/db-engine/foomatic-db-engine-3\.0-20080903.*
        ^samba/.*
        ^webrev/.*
        ^fix-cups/.*
        ^foomatic/.*

        syntax: glob
        *.tar
        *.tar.gz
        *.tar.bz2
        *.zip
        *.tgz
        nohup.out
        EOF
}

if [[ -z ${HG_PATS} ]]; then # command not run as a post-process.
    if [[ -n $1 && $1 != '-'[h?] ]]; then # options given
        if [[ -n $2 ]]; then # pathname given to.
            if [[ ! -d $2/.hg ]]; then
                print -u2 "Argument 2 not a path to a mercurial repo"
                exit 1
            fi
            dir=$2
        elif ! dir=$(hg root); then
            exit 2
        fi
        cphgign $1 $dir
        exit
    fi # options given
    print "usage: \"$I repo-name [pathname]\" overwrites .hgignore in hg root."
    print 'recognised repo-names are:'
    nawk '/^[    ]*\(/ {print}' $0
    exit 1
fi # HG_PATS not set - command not run as post-process.

# Post Process
args=${HG_PATS:1:${#HG_PATS} - 2} # remove the braces
ifs=$IFS; IFS=,;set -- $args;IFS=${ifs}
cphgign $@
_______________________________________________
userland-discuss mailing list
[email protected]
http://mail.opensolaris.org/mailman/listinfo/userland-discuss

Reply via email to