hgext/win32text.py
author Matt Mackall <mpm@selenic.com>
Sun, 26 Apr 2009 16:50:43 -0500
changeset 8188 f3abe032fc89
parent 8150 bbc24c0753a0
child 8253 e553fe565c61
permissions -rw-r--r--
add cmdutil.remoteui remoteui sorts out the issues of getting ssh config options from the local repo into the remote one while not copying other options like hooks.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6481
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
     1
# win32text.py - LF <-> CRLF/CR translation utilities for Windows/Mac users
5675
a5fe27b83a4a Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents: 4859
diff changeset
     2
#
a5fe27b83a4a Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents: 4859
diff changeset
     3
# This software may be used and distributed according to the terms
a5fe27b83a4a Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents: 4859
diff changeset
     4
# of the GNU General Public License, incorporated herein by reference.
a5fe27b83a4a Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents: 4859
diff changeset
     5
#
a5fe27b83a4a Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents: 4859
diff changeset
     6
# To perform automatic newline conversion, use:
a5fe27b83a4a Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents: 4859
diff changeset
     7
#
a5fe27b83a4a Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents: 4859
diff changeset
     8
# [extensions]
a5fe27b83a4a Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents: 4859
diff changeset
     9
# hgext.win32text =
a5fe27b83a4a Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents: 4859
diff changeset
    10
# [encode]
a5fe27b83a4a Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents: 4859
diff changeset
    11
# ** = cleverencode:
6481
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
    12
# # or ** = macencode:
5675
a5fe27b83a4a Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents: 4859
diff changeset
    13
# [decode]
a5fe27b83a4a Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents: 4859
diff changeset
    14
# ** = cleverdecode:
6481
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
    15
# # or ** = macdecode:
5675
a5fe27b83a4a Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents: 4859
diff changeset
    16
#
8002
36a23a18b999 win32text: word-wrap help texts at 70 characters
Martin Geisler <mg@daimi.au.dk>
parents: 7873
diff changeset
    17
# If not doing conversion, to make sure you do not commit CRLF/CR by
36a23a18b999 win32text: word-wrap help texts at 70 characters
Martin Geisler <mg@daimi.au.dk>
parents: 7873
diff changeset
    18
# accident:
5675
a5fe27b83a4a Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents: 4859
diff changeset
    19
#
a5fe27b83a4a Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents: 4859
diff changeset
    20
# [hooks]
a5fe27b83a4a Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents: 4859
diff changeset
    21
# pretxncommit.crlf = python:hgext.win32text.forbidcrlf
6481
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
    22
# # or pretxncommit.cr = python:hgext.win32text.forbidcr
5675
a5fe27b83a4a Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents: 4859
diff changeset
    23
#
8002
36a23a18b999 win32text: word-wrap help texts at 70 characters
Martin Geisler <mg@daimi.au.dk>
parents: 7873
diff changeset
    24
# To do the same check on a server to prevent CRLF/CR from being
36a23a18b999 win32text: word-wrap help texts at 70 characters
Martin Geisler <mg@daimi.au.dk>
parents: 7873
diff changeset
    25
# pushed or pulled:
5675
a5fe27b83a4a Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents: 4859
diff changeset
    26
#
a5fe27b83a4a Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents: 4859
diff changeset
    27
# [hooks]
a5fe27b83a4a Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents: 4859
diff changeset
    28
# pretxnchangegroup.crlf = python:hgext.win32text.forbidcrlf
6481
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
    29
# # or pretxnchangegroup.cr = python:hgext.win32text.forbidcr
5675
a5fe27b83a4a Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents: 4859
diff changeset
    30
7225
59b4ae211584 i18n: import _ instead of gettext
Martin Geisler <mg@daimi.au.dk>
parents: 6750
diff changeset
    31
from mercurial.i18n import _
7873
4a4c7f6a5912 cleanup: drop unused imports
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7225
diff changeset
    32
from mercurial.node import short
6510
37ab2331b94c win32text: actually import util so util.binary() can be used
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6508
diff changeset
    33
from mercurial import util
4859
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4858
diff changeset
    34
import re
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4858
diff changeset
    35
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4858
diff changeset
    36
# regexp for single LF without CR preceding.
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4858
diff changeset
    37
re_single_lf = re.compile('(^|[^\r])\n', re.MULTILINE)
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4858
diff changeset
    38
6481
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
    39
newlinestr = {'\r\n': 'CRLF', '\r': 'CR'}
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
    40
filterstr = {'\r\n': 'clever', '\r': 'mac'}
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
    41
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
    42
def checknewline(s, newline, ui=None, repo=None, filename=None):
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
    43
    # warn if already has 'newline' in repository.
4859
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4858
diff changeset
    44
    # it might cause unexpected eol conversion.
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4858
diff changeset
    45
    # see issue 302:
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4858
diff changeset
    46
    #   http://www.selenic.com/mercurial/bts/issue302
6481
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
    47
    if newline in s and ui and filename and repo:
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
    48
        ui.warn(_('WARNING: %s already has %s line endings\n'
5967
f8ad3b76e923 Provide better context for custom Python encode/decode filters.
Jesse Glick <jesse.glick@sun.com>
parents: 5966
diff changeset
    49
                  'and does not need EOL conversion by the win32text plugin.\n'
f8ad3b76e923 Provide better context for custom Python encode/decode filters.
Jesse Glick <jesse.glick@sun.com>
parents: 5966
diff changeset
    50
                  'Before your next commit, please reconsider your '
f8ad3b76e923 Provide better context for custom Python encode/decode filters.
Jesse Glick <jesse.glick@sun.com>
parents: 5966
diff changeset
    51
                  'encode/decode settings in \nMercurial.ini or %s.\n') %
6481
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
    52
                (filename, newlinestr[newline], repo.join('hgrc')))
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
    53
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
    54
def dumbdecode(s, cmd, **kwargs):
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
    55
    checknewline(s, '\r\n', **kwargs)
4859
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4858
diff changeset
    56
    # replace single LF to CRLF
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4858
diff changeset
    57
    return re_single_lf.sub('\\1\r\n', s)
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4858
diff changeset
    58
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4858
diff changeset
    59
def dumbencode(s, cmd):
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4858
diff changeset
    60
    return s.replace('\r\n', '\n')
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4858
diff changeset
    61
6481
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
    62
def macdumbdecode(s, cmd, **kwargs):
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
    63
    checknewline(s, '\r', **kwargs)
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
    64
    return s.replace('\n', '\r')
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
    65
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
    66
def macdumbencode(s, cmd):
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
    67
    return s.replace('\r', '\n')
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
    68
5967
f8ad3b76e923 Provide better context for custom Python encode/decode filters.
Jesse Glick <jesse.glick@sun.com>
parents: 5966
diff changeset
    69
def cleverdecode(s, cmd, **kwargs):
6508
4b2c266bf059 Get rid of reimplementations of util.binary
Bryan O'Sullivan <bos@serpentine.com>
parents: 6484
diff changeset
    70
    if not util.binary(s):
6473
9c897ffd3637 Backed out changeset 7f4257b5cbfc
Patrick Mezard <pmezard@gmail.com>
parents: 6247
diff changeset
    71
        return dumbdecode(s, cmd, **kwargs)
9c897ffd3637 Backed out changeset 7f4257b5cbfc
Patrick Mezard <pmezard@gmail.com>
parents: 6247
diff changeset
    72
    return s
4859
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4858
diff changeset
    73
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4858
diff changeset
    74
def cleverencode(s, cmd):
6508
4b2c266bf059 Get rid of reimplementations of util.binary
Bryan O'Sullivan <bos@serpentine.com>
parents: 6484
diff changeset
    75
    if not util.binary(s):
6473
9c897ffd3637 Backed out changeset 7f4257b5cbfc
Patrick Mezard <pmezard@gmail.com>
parents: 6247
diff changeset
    76
        return dumbencode(s, cmd)
9c897ffd3637 Backed out changeset 7f4257b5cbfc
Patrick Mezard <pmezard@gmail.com>
parents: 6247
diff changeset
    77
    return s
4859
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4858
diff changeset
    78
6481
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
    79
def macdecode(s, cmd, **kwargs):
6508
4b2c266bf059 Get rid of reimplementations of util.binary
Bryan O'Sullivan <bos@serpentine.com>
parents: 6484
diff changeset
    80
    if not util.binary(s):
6484
ab8038bf5127 Merge with macencode branch
Patrick Mezard <pmezard@gmail.com>
parents: 6473 6483
diff changeset
    81
        return macdumbdecode(s, cmd, **kwargs)
ab8038bf5127 Merge with macencode branch
Patrick Mezard <pmezard@gmail.com>
parents: 6473 6483
diff changeset
    82
    return s
6481
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
    83
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
    84
def macencode(s, cmd):
6508
4b2c266bf059 Get rid of reimplementations of util.binary
Bryan O'Sullivan <bos@serpentine.com>
parents: 6484
diff changeset
    85
    if not util.binary(s):
6484
ab8038bf5127 Merge with macencode branch
Patrick Mezard <pmezard@gmail.com>
parents: 6473 6483
diff changeset
    86
        return macdumbencode(s, cmd)
ab8038bf5127 Merge with macencode branch
Patrick Mezard <pmezard@gmail.com>
parents: 6473 6483
diff changeset
    87
    return s
6481
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
    88
5966
11af38a592ae Register data filters in a localrepo instead of util
Patrick Mezard <pmezard@gmail.com>
parents: 5675
diff changeset
    89
_filters = {
4859
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4858
diff changeset
    90
    'dumbdecode:': dumbdecode,
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4858
diff changeset
    91
    'dumbencode:': dumbencode,
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4858
diff changeset
    92
    'cleverdecode:': cleverdecode,
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4858
diff changeset
    93
    'cleverencode:': cleverencode,
6481
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
    94
    'macdumbdecode:': macdumbdecode,
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
    95
    'macdumbencode:': macdumbencode,
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
    96
    'macdecode:': macdecode,
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
    97
    'macencode:': macencode,
5966
11af38a592ae Register data filters in a localrepo instead of util
Patrick Mezard <pmezard@gmail.com>
parents: 5675
diff changeset
    98
    }
5675
a5fe27b83a4a Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents: 4859
diff changeset
    99
6483
0a803195bb29 win32text: rename forbidcrlforcr() function
Patrick Mezard <pmezard@gmail.com>
parents: 6481
diff changeset
   100
def forbidnewline(ui, repo, hooktype, node, newline, **kwargs):
5675
a5fe27b83a4a Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents: 4859
diff changeset
   101
    halt = False
8150
bbc24c0753a0 util: use built-in set and frozenset
Martin Geisler <mg@lazybytes.net>
parents: 8147
diff changeset
   102
    seen = set()
8147
441dc7becd43 win32text: be more careful about rejecting violating changesets
Bryan O'Sullivan <bos@serpentine.com>
parents: 8002
diff changeset
   103
    # we try to walk changesets in reverse order from newest to
441dc7becd43 win32text: be more careful about rejecting violating changesets
Bryan O'Sullivan <bos@serpentine.com>
parents: 8002
diff changeset
   104
    # oldest, so that if we see a file multiple times, we take the
441dc7becd43 win32text: be more careful about rejecting violating changesets
Bryan O'Sullivan <bos@serpentine.com>
parents: 8002
diff changeset
   105
    # newest version as canonical. this prevents us from blocking a
441dc7becd43 win32text: be more careful about rejecting violating changesets
Bryan O'Sullivan <bos@serpentine.com>
parents: 8002
diff changeset
   106
    # changegroup that contains an unacceptable commit followed later
441dc7becd43 win32text: be more careful about rejecting violating changesets
Bryan O'Sullivan <bos@serpentine.com>
parents: 8002
diff changeset
   107
    # by a commit that fixes the problem.
441dc7becd43 win32text: be more careful about rejecting violating changesets
Bryan O'Sullivan <bos@serpentine.com>
parents: 8002
diff changeset
   108
    tip = repo['tip']
441dc7becd43 win32text: be more careful about rejecting violating changesets
Bryan O'Sullivan <bos@serpentine.com>
parents: 8002
diff changeset
   109
    for rev in xrange(len(repo)-1, repo[node].rev()-1, -1):
6747
f6c00b17387c use repo[changeid] to get a changectx
Matt Mackall <mpm@selenic.com>
parents: 6510
diff changeset
   110
        c = repo[rev]
5675
a5fe27b83a4a Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents: 4859
diff changeset
   111
        for f in c.files():
8147
441dc7becd43 win32text: be more careful about rejecting violating changesets
Bryan O'Sullivan <bos@serpentine.com>
parents: 8002
diff changeset
   112
            if f in seen or f not in tip or f not in c:
5675
a5fe27b83a4a Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents: 4859
diff changeset
   113
                continue
8147
441dc7becd43 win32text: be more careful about rejecting violating changesets
Bryan O'Sullivan <bos@serpentine.com>
parents: 8002
diff changeset
   114
            seen.add(f)
5675
a5fe27b83a4a Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents: 4859
diff changeset
   115
            data = c[f].data()
6508
4b2c266bf059 Get rid of reimplementations of util.binary
Bryan O'Sullivan <bos@serpentine.com>
parents: 6484
diff changeset
   116
            if not util.binary(data) and newline in data:
5675
a5fe27b83a4a Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents: 4859
diff changeset
   117
                if not halt:
a5fe27b83a4a Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents: 4859
diff changeset
   118
                    ui.warn(_('Attempt to commit or push text file(s) '
6481
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
   119
                              'using %s line endings\n') %
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
   120
                              newlinestr[newline])
5675
a5fe27b83a4a Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents: 4859
diff changeset
   121
                ui.warn(_('in %s: %s\n') % (short(c.node()), f))
a5fe27b83a4a Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents: 4859
diff changeset
   122
                halt = True
a5fe27b83a4a Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents: 4859
diff changeset
   123
    if halt and hooktype == 'pretxnchangegroup':
6481
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
   124
        crlf = newlinestr[newline].lower()
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
   125
        filter = filterstr[newline]
5675
a5fe27b83a4a Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents: 4859
diff changeset
   126
        ui.warn(_('\nTo prevent this mistake in your local repository,\n'
a5fe27b83a4a Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents: 4859
diff changeset
   127
                  'add to Mercurial.ini or .hg/hgrc:\n'
a5fe27b83a4a Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents: 4859
diff changeset
   128
                  '\n'
a5fe27b83a4a Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents: 4859
diff changeset
   129
                  '[hooks]\n'
6481
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
   130
                  'pretxncommit.%s = python:hgext.win32text.forbid%s\n'
5675
a5fe27b83a4a Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents: 4859
diff changeset
   131
                  '\n'
a5fe27b83a4a Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents: 4859
diff changeset
   132
                  'and also consider adding:\n'
a5fe27b83a4a Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents: 4859
diff changeset
   133
                  '\n'
a5fe27b83a4a Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents: 4859
diff changeset
   134
                  '[extensions]\n'
a5fe27b83a4a Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents: 4859
diff changeset
   135
                  'hgext.win32text =\n'
a5fe27b83a4a Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents: 4859
diff changeset
   136
                  '[encode]\n'
6481
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
   137
                  '** = %sencode:\n'
5675
a5fe27b83a4a Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents: 4859
diff changeset
   138
                  '[decode]\n'
6481
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
   139
                  '** = %sdecode:\n') % (crlf, crlf, filter, filter))
5675
a5fe27b83a4a Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents: 4859
diff changeset
   140
    return halt
5966
11af38a592ae Register data filters in a localrepo instead of util
Patrick Mezard <pmezard@gmail.com>
parents: 5675
diff changeset
   141
6481
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
   142
def forbidcrlf(ui, repo, hooktype, node, **kwargs):
6483
0a803195bb29 win32text: rename forbidcrlforcr() function
Patrick Mezard <pmezard@gmail.com>
parents: 6481
diff changeset
   143
    return forbidnewline(ui, repo, hooktype, node, '\r\n', **kwargs)
6481
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
   144
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
   145
def forbidcr(ui, repo, hooktype, node, **kwargs):
6483
0a803195bb29 win32text: rename forbidcrlforcr() function
Patrick Mezard <pmezard@gmail.com>
parents: 6481
diff changeset
   146
    return forbidnewline(ui, repo, hooktype, node, '\r', **kwargs)
6481
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
   147
5966
11af38a592ae Register data filters in a localrepo instead of util
Patrick Mezard <pmezard@gmail.com>
parents: 5675
diff changeset
   148
def reposetup(ui, repo):
11af38a592ae Register data filters in a localrepo instead of util
Patrick Mezard <pmezard@gmail.com>
parents: 5675
diff changeset
   149
    if not repo.local():
11af38a592ae Register data filters in a localrepo instead of util
Patrick Mezard <pmezard@gmail.com>
parents: 5675
diff changeset
   150
        return
11af38a592ae Register data filters in a localrepo instead of util
Patrick Mezard <pmezard@gmail.com>
parents: 5675
diff changeset
   151
    for name, fn in _filters.iteritems():
11af38a592ae Register data filters in a localrepo instead of util
Patrick Mezard <pmezard@gmail.com>
parents: 5675
diff changeset
   152
        repo.adddatafilter(name, fn)
11af38a592ae Register data filters in a localrepo instead of util
Patrick Mezard <pmezard@gmail.com>
parents: 5675
diff changeset
   153