tests/test-custom-filters
author Renato Cunha <renatoc@gmail.com>
Tue, 03 Aug 2010 13:41:47 -0300
changeset 11747 40d5633889bb
parent 8742 a964ab624385
permissions -rwxr-xr-x
hgfixes: add a fixer to convert plain strings to bytestrings This patch implements a 2to3 fixer that converts all plain strings in a python source file to byte strings syntax. Example: foo = 'Normal string' would become foo = b'Normal string' The motivation behind this fixer can be found in http://selenic.com/pipermail/mercurial-devel/2010-June/022363.html or, in other words: the current hg source assumes that _most_ strings are "meant" to be byte sequences, so it makes sense to make the convertion implemented by this patch. As mentioned above, not all mercurial modules want to use strings as bytes, examples include i18n (which uses unicode), and demandimport (in py3k, module names are normal strings, thus unicode, and there's no need for a convertion). Therefore, these modules are blacklisted in the fixer. There are also a few functions that can take only unicode arguments, thus the convertion shouldn't be done for those.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6066
f3a8b5360100 Strip filter name from command before passing to filter function.
Jesse Glick <jesse.glick@sun.com>
parents:
diff changeset
     1
#!/bin/sh
f3a8b5360100 Strip filter name from command before passing to filter function.
Jesse Glick <jesse.glick@sun.com>
parents:
diff changeset
     2
f3a8b5360100 Strip filter name from command before passing to filter function.
Jesse Glick <jesse.glick@sun.com>
parents:
diff changeset
     3
hg init
f3a8b5360100 Strip filter name from command before passing to filter function.
Jesse Glick <jesse.glick@sun.com>
parents:
diff changeset
     4
f3a8b5360100 Strip filter name from command before passing to filter function.
Jesse Glick <jesse.glick@sun.com>
parents:
diff changeset
     5
cat > .hg/hgrc <<EOF
f3a8b5360100 Strip filter name from command before passing to filter function.
Jesse Glick <jesse.glick@sun.com>
parents:
diff changeset
     6
[extensions]
f3a8b5360100 Strip filter name from command before passing to filter function.
Jesse Glick <jesse.glick@sun.com>
parents:
diff changeset
     7
prefixfilter = prefix.py
f3a8b5360100 Strip filter name from command before passing to filter function.
Jesse Glick <jesse.glick@sun.com>
parents:
diff changeset
     8
[encode]
f3a8b5360100 Strip filter name from command before passing to filter function.
Jesse Glick <jesse.glick@sun.com>
parents:
diff changeset
     9
*.txt = stripprefix: Copyright 2046, The Masters
f3a8b5360100 Strip filter name from command before passing to filter function.
Jesse Glick <jesse.glick@sun.com>
parents:
diff changeset
    10
[decode]
f3a8b5360100 Strip filter name from command before passing to filter function.
Jesse Glick <jesse.glick@sun.com>
parents:
diff changeset
    11
*.txt = insertprefix: Copyright 2046, The Masters
f3a8b5360100 Strip filter name from command before passing to filter function.
Jesse Glick <jesse.glick@sun.com>
parents:
diff changeset
    12
EOF
f3a8b5360100 Strip filter name from command before passing to filter function.
Jesse Glick <jesse.glick@sun.com>
parents:
diff changeset
    13
f3a8b5360100 Strip filter name from command before passing to filter function.
Jesse Glick <jesse.glick@sun.com>
parents:
diff changeset
    14
cat > prefix.py <<EOF
f3a8b5360100 Strip filter name from command before passing to filter function.
Jesse Glick <jesse.glick@sun.com>
parents:
diff changeset
    15
from mercurial import util
f3a8b5360100 Strip filter name from command before passing to filter function.
Jesse Glick <jesse.glick@sun.com>
parents:
diff changeset
    16
def stripprefix(s, cmd, filename, **kwargs):
f3a8b5360100 Strip filter name from command before passing to filter function.
Jesse Glick <jesse.glick@sun.com>
parents:
diff changeset
    17
    header = '%s\n' % cmd
f3a8b5360100 Strip filter name from command before passing to filter function.
Jesse Glick <jesse.glick@sun.com>
parents:
diff changeset
    18
    if s[:len(header)] != header:
f3a8b5360100 Strip filter name from command before passing to filter function.
Jesse Glick <jesse.glick@sun.com>
parents:
diff changeset
    19
        raise util.Abort('missing header "%s" in %s' % (cmd, filename))
f3a8b5360100 Strip filter name from command before passing to filter function.
Jesse Glick <jesse.glick@sun.com>
parents:
diff changeset
    20
    return s[len(header):]
f3a8b5360100 Strip filter name from command before passing to filter function.
Jesse Glick <jesse.glick@sun.com>
parents:
diff changeset
    21
def insertprefix(s, cmd):
f3a8b5360100 Strip filter name from command before passing to filter function.
Jesse Glick <jesse.glick@sun.com>
parents:
diff changeset
    22
    return '%s\n%s' % (cmd, s)
f3a8b5360100 Strip filter name from command before passing to filter function.
Jesse Glick <jesse.glick@sun.com>
parents:
diff changeset
    23
def reposetup(ui, repo):
f3a8b5360100 Strip filter name from command before passing to filter function.
Jesse Glick <jesse.glick@sun.com>
parents:
diff changeset
    24
    repo.adddatafilter('stripprefix:', stripprefix)
f3a8b5360100 Strip filter name from command before passing to filter function.
Jesse Glick <jesse.glick@sun.com>
parents:
diff changeset
    25
    repo.adddatafilter('insertprefix:', insertprefix)
f3a8b5360100 Strip filter name from command before passing to filter function.
Jesse Glick <jesse.glick@sun.com>
parents:
diff changeset
    26
EOF
f3a8b5360100 Strip filter name from command before passing to filter function.
Jesse Glick <jesse.glick@sun.com>
parents:
diff changeset
    27
f3a8b5360100 Strip filter name from command before passing to filter function.
Jesse Glick <jesse.glick@sun.com>
parents:
diff changeset
    28
cat > .hgignore <<EOF
f3a8b5360100 Strip filter name from command before passing to filter function.
Jesse Glick <jesse.glick@sun.com>
parents:
diff changeset
    29
.hgignore
f3a8b5360100 Strip filter name from command before passing to filter function.
Jesse Glick <jesse.glick@sun.com>
parents:
diff changeset
    30
prefix.py
f3a8b5360100 Strip filter name from command before passing to filter function.
Jesse Glick <jesse.glick@sun.com>
parents:
diff changeset
    31
prefix.pyc
f3a8b5360100 Strip filter name from command before passing to filter function.
Jesse Glick <jesse.glick@sun.com>
parents:
diff changeset
    32
EOF
f3a8b5360100 Strip filter name from command before passing to filter function.
Jesse Glick <jesse.glick@sun.com>
parents:
diff changeset
    33
f3a8b5360100 Strip filter name from command before passing to filter function.
Jesse Glick <jesse.glick@sun.com>
parents:
diff changeset
    34
cat > stuff.txt <<EOF
f3a8b5360100 Strip filter name from command before passing to filter function.
Jesse Glick <jesse.glick@sun.com>
parents:
diff changeset
    35
Copyright 2046, The Masters
f3a8b5360100 Strip filter name from command before passing to filter function.
Jesse Glick <jesse.glick@sun.com>
parents:
diff changeset
    36
Some stuff to ponder very carefully.
f3a8b5360100 Strip filter name from command before passing to filter function.
Jesse Glick <jesse.glick@sun.com>
parents:
diff changeset
    37
EOF
f3a8b5360100 Strip filter name from command before passing to filter function.
Jesse Glick <jesse.glick@sun.com>
parents:
diff changeset
    38
hg add stuff.txt
f3a8b5360100 Strip filter name from command before passing to filter function.
Jesse Glick <jesse.glick@sun.com>
parents:
diff changeset
    39
hg ci -m stuff
f3a8b5360100 Strip filter name from command before passing to filter function.
Jesse Glick <jesse.glick@sun.com>
parents:
diff changeset
    40
f3a8b5360100 Strip filter name from command before passing to filter function.
Jesse Glick <jesse.glick@sun.com>
parents:
diff changeset
    41
echo '% Repository data:'
f3a8b5360100 Strip filter name from command before passing to filter function.
Jesse Glick <jesse.glick@sun.com>
parents:
diff changeset
    42
hg cat stuff.txt
f3a8b5360100 Strip filter name from command before passing to filter function.
Jesse Glick <jesse.glick@sun.com>
parents:
diff changeset
    43
f3a8b5360100 Strip filter name from command before passing to filter function.
Jesse Glick <jesse.glick@sun.com>
parents:
diff changeset
    44
echo '% Fresh checkout:'
f3a8b5360100 Strip filter name from command before passing to filter function.
Jesse Glick <jesse.glick@sun.com>
parents:
diff changeset
    45
rm stuff.txt
8742
a964ab624385 merge: allow merging going backwards
Matt Mackall <mpm@selenic.com>
parents: 6066
diff changeset
    46
hg up -C
6066
f3a8b5360100 Strip filter name from command before passing to filter function.
Jesse Glick <jesse.glick@sun.com>
parents:
diff changeset
    47
cat stuff.txt
f3a8b5360100 Strip filter name from command before passing to filter function.
Jesse Glick <jesse.glick@sun.com>
parents:
diff changeset
    48
echo >> stuff.txt <<EOF
f3a8b5360100 Strip filter name from command before passing to filter function.
Jesse Glick <jesse.glick@sun.com>
parents:
diff changeset
    49
Very very carefully.
f3a8b5360100 Strip filter name from command before passing to filter function.
Jesse Glick <jesse.glick@sun.com>
parents:
diff changeset
    50
EOF
f3a8b5360100 Strip filter name from command before passing to filter function.
Jesse Glick <jesse.glick@sun.com>
parents:
diff changeset
    51
hg stat
f3a8b5360100 Strip filter name from command before passing to filter function.
Jesse Glick <jesse.glick@sun.com>
parents:
diff changeset
    52
f3a8b5360100 Strip filter name from command before passing to filter function.
Jesse Glick <jesse.glick@sun.com>
parents:
diff changeset
    53
cat > morestuff.txt <<EOF
f3a8b5360100 Strip filter name from command before passing to filter function.
Jesse Glick <jesse.glick@sun.com>
parents:
diff changeset
    54
Unauthorized material subject to destruction.
f3a8b5360100 Strip filter name from command before passing to filter function.
Jesse Glick <jesse.glick@sun.com>
parents:
diff changeset
    55
EOF
f3a8b5360100 Strip filter name from command before passing to filter function.
Jesse Glick <jesse.glick@sun.com>
parents:
diff changeset
    56
f3a8b5360100 Strip filter name from command before passing to filter function.
Jesse Glick <jesse.glick@sun.com>
parents:
diff changeset
    57
echo '% Problem encoding:'
f3a8b5360100 Strip filter name from command before passing to filter function.
Jesse Glick <jesse.glick@sun.com>
parents:
diff changeset
    58
hg add morestuff.txt
f3a8b5360100 Strip filter name from command before passing to filter function.
Jesse Glick <jesse.glick@sun.com>
parents:
diff changeset
    59
hg ci -m morestuff
f3a8b5360100 Strip filter name from command before passing to filter function.
Jesse Glick <jesse.glick@sun.com>
parents:
diff changeset
    60
hg stat