view tests/test-convert-filemap @ 11989:f853873fc66d

aliases: provide more flexible ways to work with shell alias arguments This patch changes the functionality of shell aliases to add more powerful options for working with shell alias arguments. First: the alias name + arguments to a shell alias are set as an HG_ARGS environment variable, delimited by spaces. This matches the behavior of hooks. Second: any occurrences of "$@" (without quotes) are replaced with the arguments, separated by spaces. This happens *before* the alias gets to the shell. Third: any positive numeric variables ("$1", "$2", etc) are replaced with the appropriate argument, indexed from 1. "$0" is replaced with the name of the alias. Any "extra" numeric variables are replaced with an empty string. This happens *before* the alias gets to the shell. These changes allow for more flexible shell aliases: [alias] echo = !echo $@ count = !hg log -r "$@" --template='.' | wc -c | sed -e 's/ //g' qqueuemv = !mv "`hg root`/.hg/patches-$1" "`hg root`/.hg/patches-$2" In action: $ hg echo foo foo $ hg count 'branch(default)' 901 $ hg count 'branch(stable) and keyword(fixes)' 102 $ hg qqueuemv myfeature somefeature
author Steve Losh <steve@stevelosh.com>
date Wed, 18 Aug 2010 18:56:44 -0400
parents 7fefef3ce791
children
line wrap: on
line source

#!/bin/sh

HGMERGE=true; export HGMERGE

echo '[extensions]' >> $HGRCPATH
echo 'graphlog =' >> $HGRCPATH
echo 'convert =' >> $HGRCPATH

glog()
{
    hg glog --template '{rev} "{desc}" files: {files}\n' "$@"
}

hg init source
cd source

echo foo > foo
echo baz > baz
mkdir -p dir/subdir
echo dir/file >> dir/file
echo dir/file2 >> dir/file2
echo dir/subdir/file3 >> dir/subdir/file3
echo dir/subdir/file4 >> dir/subdir/file4
hg ci -d '0 0' -qAm '0: add foo baz dir/'

echo bar > bar
echo quux > quux
hg copy foo copied
hg ci -d '1 0' -qAm '1: add bar quux; copy foo to copied'

echo >> foo
hg ci -d '2 0' -m '2: change foo'

hg up -qC 1
echo >> bar
echo >> quux
hg ci -d '3 0' -m '3: change bar quux'

hg up -qC 2
hg merge -qr 3
echo >> bar
echo >> baz
hg ci -d '4 0' -m '4: first merge; change bar baz'

echo >> bar
echo 1 >> baz
echo >> quux
hg ci -d '5 0' -m '5: change bar baz quux'

hg up -qC 4
echo >> foo
echo 2 >> baz
hg ci -d '6 0' -m '6: change foo baz'

hg up -qC 5
hg merge -qr 6
echo >> bar
hg ci -d '7 0' -m '7: second merge; change bar'

echo >> foo
hg ci -m '8: change foo'

glog

echo '% final file versions in this repo:'
hg manifest --debug
hg debugrename copied
echo

cd ..

splitrepo()
{
    msg="$1"
    files="$2"
    opts=$3
    echo "% $files: $msg"
    prefix=`echo "$files" | sed -e 's/ /-/g'`
    fmap="$prefix.fmap"
    repo="$prefix.repo"
    for i in $files; do
	echo "include $i" >> "$fmap"
    done
    hg -q convert $opts --filemap "$fmap" --datesort source "$repo"
    hg up -q -R "$repo"
    glog -R "$repo"
    hg -R "$repo" manifest --debug
}

splitrepo 'skip unwanted merges; use 1st parent in 1st merge, 2nd in 2nd' foo

splitrepo 'merges are not merges anymore' bar

splitrepo '1st merge is not a merge anymore; 2nd still is' baz

splitrepo 'we add additional merges when they are interesting' 'foo quux'

splitrepo 'partial conversion' 'bar quux' '-r 3'
splitrepo 'complete the partial conversion' 'bar quux'

rm -r foo.repo
splitrepo 'partial conversion' 'foo' '-r 3'
splitrepo 'complete the partial conversion' 'foo'

splitrepo 'copied file; source not included in new repo' copied
hg --cwd copied.repo debugrename copied

splitrepo 'copied file; source included in new repo' 'foo copied'
hg --cwd foo-copied.repo debugrename copied

cat > renames.fmap <<EOF
include dir
exclude dir/file2
rename dir dir2
include foo
include copied
rename foo foo2
rename copied copied2
exclude dir/subdir
include dir/subdir/file3
EOF
hg -q convert --filemap renames.fmap --datesort source renames.repo
hg up -q -R renames.repo
glog -R renames.repo
hg -R renames.repo manifest --debug
hg --cwd renames.repo debugrename copied2
echo 'copied:'
hg --cwd source cat copied
echo 'copied2:'
hg --cwd renames.repo cat copied2

echo % filemap errors
cat > errors.fmap <<EOF
include dir/ # beware that comments changes error line numbers!
exclude /dir
rename dir//dir /dir//dir/ "out of sync"
include
EOF
hg -q convert --filemap errors.fmap source errors.repo

true # happy ending