annotate hgext/interhg.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 0ac6b537893f
children 18091102a633
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4818
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
1 # interhg.py - interhg
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
2 #
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
3 # Copyright 2007 OHASHI Hideya <ohachige@gmail.com>
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
4 #
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
5 # This software may be used and distributed according to the terms
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
6 # of the GNU General Public License, incorporated herein by reference.
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
7 #
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
8 # The `interhg' Mercurial extension allows you to change changelog and
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
9 # summary text just like InterWiki way.
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
10 #
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
11 # To enable this extension:
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
12 #
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
13 # [extensions]
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
14 # interhg =
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
15 #
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
16 # This is an example to link to a bug tracking system.
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
17 #
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
18 # [interhg]
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
19 # pat1 = s/issue(\d+)/ <a href="http:\/\/bts\/issue\1">issue\1<\/a> /
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
20 #
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
21 # You can add patterns to use pat2, pat3, ...
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
22 # For exapmle.
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
23 #
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
24 # pat2 = s/(^|\s)#(\d+)\b/ <b>#\2<\/b> /
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
25
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
26 import re
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
27 from mercurial.hgweb import hgweb_mod
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
28 from mercurial import templater
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
29
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
30 orig_escape = templater.common_filters["escape"]
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
31
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
32 interhg_table = []
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
33
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
34 def interhg_escape(x):
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
35 escstr = orig_escape(x)
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
36 for pat in interhg_table:
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
37 regexp = pat[0]
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
38 format = pat[1]
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
39 escstr = regexp.sub(format, escstr)
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
40 return escstr
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
41
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
42 templater.common_filters["escape"] = interhg_escape
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
43
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
44 orig_refresh = hgweb_mod.hgweb.refresh
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
45
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
46 def interhg_refresh(self):
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
47 interhg_table[:] = []
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
48 num = 1
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
49 while True:
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
50 key = 'pat%d' % num
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
51 pat = self.config('interhg', key)
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
52 if pat == None:
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
53 break
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
54 pat = pat[2:-1]
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
55 span = re.search(r'[^\\]/', pat).span()
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
56 regexp = pat[:span[0] + 1]
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
57 format = pat[span[1]:]
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
58 format = re.sub(r'\\/', '/', format)
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
59 regexp = re.compile(regexp)
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
60 interhg_table.append((regexp, format))
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
61 num += 1
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
62 return orig_refresh(self)
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
63
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
64 hgweb_mod.hgweb.refresh = interhg_refresh