annotate hgext/win32text.py @ 5192:33015dac5df5

convert: fix mercurial_sink.putcommit Changeset 4ebc8693ce72 added some code to putcommit to avoid creating a revision that touches no files, but this can break regular conversions from some repositories: - conceptually, since we're converting a repo, we should try to make the new hg repo as similar as possible to the original repo - we should create a new changeset, even if the original revision didn't touch any files (maybe the commit message had some important bit); - even if a "regular" revision that doesn't touch any file may seem weird (and maybe even broken), it's completely legitimate for a merge revision to not touch any file, and, if we just skip it, the converted repo will end up with wrong history and possibly an extra head. As an example, say the crew and main hg repos are sync'ed. Somebody sends an important patch to the mailing list. Matt quickly applies and pushes it. But at the same time somebody also applies it to crew and pushes it. Suppose the commit message ended up being a bit different (say, there was a typo and somebody didn't fix it) or that the date ended up being different (because of different patch-applying scripts): the changeset hashes will be different, but the manifests will be the same. Since both changesets were pushed to public repos, it's hard to recall them. If both are merged, the manifest from the resulting merge revision will have the exact same contents as its parents - i.e. the merge revision really doesn't touch any file at all. To keep the file filtering stuff "working", the generic code was changed to skip empty revisions if we're filtering the repo, fixing a bug in the process (we want parents[0] instead of tip).
author Alexis S. L. Carvalho <alexis@cecm.usp.br>
date Fri, 17 Aug 2007 20:18:05 -0300
parents 8c5aca855b5d
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4849
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4848
diff changeset
1 from mercurial import util, ui
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4848
diff changeset
2 from mercurial.i18n import gettext as _
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4848
diff changeset
3 import re
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4848
diff changeset
4
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4848
diff changeset
5 # regexp for single LF without CR preceding.
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4848
diff changeset
6 re_single_lf = re.compile('(^|[^\r])\n', re.MULTILINE)
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4848
diff changeset
7
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4848
diff changeset
8 def dumbdecode(s, cmd):
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4848
diff changeset
9 # warn if already has CRLF in repository.
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4848
diff changeset
10 # it might cause unexpected eol conversion.
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4848
diff changeset
11 # see issue 302:
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4848
diff changeset
12 # http://www.selenic.com/mercurial/bts/issue302
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4848
diff changeset
13 if '\r\n' in s:
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4848
diff changeset
14 u = ui.ui()
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4848
diff changeset
15 u.warn(_('WARNING: file in repository already has CRLF line ending \n'
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4848
diff changeset
16 ' which does not need eol conversion by win32text plugin.\n'
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4848
diff changeset
17 ' Please reconsider encode/decode setting in'
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4848
diff changeset
18 ' mercurial.ini or .hg/hgrc\n'
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4848
diff changeset
19 ' before next commit.\n'))
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4848
diff changeset
20 # replace single LF to CRLF
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4848
diff changeset
21 return re_single_lf.sub('\\1\r\n', s)
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4848
diff changeset
22
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4848
diff changeset
23 def dumbencode(s, cmd):
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4848
diff changeset
24 return s.replace('\r\n', '\n')
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4848
diff changeset
25
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4848
diff changeset
26 def clevertest(s, cmd):
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4848
diff changeset
27 if '\0' in s: return False
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4848
diff changeset
28 return True
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4848
diff changeset
29
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4848
diff changeset
30 def cleverdecode(s, cmd):
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4848
diff changeset
31 if clevertest(s, cmd):
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4848
diff changeset
32 return dumbdecode(s, cmd)
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4848
diff changeset
33 return s
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4848
diff changeset
34
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4848
diff changeset
35 def cleverencode(s, cmd):
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4848
diff changeset
36 if clevertest(s, cmd):
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4848
diff changeset
37 return dumbencode(s, cmd)
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4848
diff changeset
38 return s
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4848
diff changeset
39
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4848
diff changeset
40 util.filtertable.update({
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4848
diff changeset
41 'dumbdecode:': dumbdecode,
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4848
diff changeset
42 'dumbencode:': dumbencode,
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4848
diff changeset
43 'cleverdecode:': cleverdecode,
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4848
diff changeset
44 'cleverencode:': cleverencode,
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4848
diff changeset
45 })