annotate hgsubversion/util.py @ 1182:8f9619a67565

maps: change readmapfile to take a path instead of repo This is a small refactor for an upcoming change that will change map objects to store a svnmeta instead of the repo.
author Sean Farley <sean.michael.farley@gmail.com>
date Mon, 24 Mar 2014 11:20:44 -0500
parents 91d685418490
children 05aea77371a3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1140
9ec3c2e89c94 util: banish pickle to compathacks
Sean Farley <sean.michael.farley@gmail.com>
parents: 1137
diff changeset
1 import compathacks
889
7a98fbadcae9 revsets: huge speedups for fromsvn and svnrev
Bryan O'Sullivan <bryano@fb.com>
parents: 884
diff changeset
2 import errno
440
80909328aef1 move remaining cmdutils into util
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 431
diff changeset
3 import re
0
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
4 import os
440
80909328aef1 move remaining cmdutils into util
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 431
diff changeset
5 import urllib
1135
5a0da3bab8a2 util: try to load data using json
Sean Farley <sean.michael.farley@gmail.com>
parents: 1134
diff changeset
6 import json
0
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
7
620
8acae2416ec1 wrappers: cope with remoteui move to hg (hg cset d1908cb95a82)
Augie Fackler <durin42@gmail.com>
parents: 619
diff changeset
8 from mercurial import cmdutil
722
aa24148a7454 uisetup: add fromsvn() and svnrev() revsets.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 707
diff changeset
9 from mercurial import error
196
77812f98e250 Add a naive hg svn version command that works as long as hgsubversion is run from a checkout.
Augie Fackler <durin42@gmail.com>
parents: 195
diff changeset
10 from mercurial import hg
34
50d55c3e0d85 Some refactors of the previous change, including transparent upgrade of old-style pickled dictionaries.
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
11 from mercurial import node
1040
ada2400241c4 fixes for running under Mercurial 2.0
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 1039
diff changeset
12 from mercurial import repair
250
79349fd04836 utils: standardizing imported name to hgutil, our_util to util
Daniel Tang <dytang@cs.purdue.edu>
parents: 249
diff changeset
13 from mercurial import util as hgutil
1037
2316f2623dd4 Fix for missing mercurial.utils deque
Will Thames <will@thames.id.au>
parents: 1035
diff changeset
14
2316f2623dd4 Fix for missing mercurial.utils deque
Will Thames <will@thames.id.au>
parents: 1035
diff changeset
15 try:
2316f2623dd4 Fix for missing mercurial.utils deque
Will Thames <will@thames.id.au>
parents: 1035
diff changeset
16 from collections import deque
2316f2623dd4 Fix for missing mercurial.utils deque
Will Thames <will@thames.id.au>
parents: 1035
diff changeset
17 except:
2316f2623dd4 Fix for missing mercurial.utils deque
Will Thames <will@thames.id.au>
parents: 1035
diff changeset
18 from mercurial.util import deque
34
50d55c3e0d85 Some refactors of the previous change, including transparent upgrade of old-style pickled dictionaries.
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
19
722
aa24148a7454 uisetup: add fromsvn() and svnrev() revsets.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 707
diff changeset
20 try:
aa24148a7454 uisetup: add fromsvn() and svnrev() revsets.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 707
diff changeset
21 from mercurial import revset
aa24148a7454 uisetup: add fromsvn() and svnrev() revsets.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 707
diff changeset
22 except ImportError:
aa24148a7454 uisetup: add fromsvn() and svnrev() revsets.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 707
diff changeset
23 pass
196
77812f98e250 Add a naive hg svn version command that works as long as hgsubversion is run from a checkout.
Augie Fackler <durin42@gmail.com>
parents: 195
diff changeset
24
889
7a98fbadcae9 revsets: huge speedups for fromsvn and svnrev
Bryan O'Sullivan <bryano@fb.com>
parents: 884
diff changeset
25 import maps
7a98fbadcae9 revsets: huge speedups for fromsvn and svnrev
Bryan O'Sullivan <bryano@fb.com>
parents: 884
diff changeset
26
764
bc5c176b63eb svnexternals: support pushing subrepo based externals
Patrick Mezard <pmezard@gmail.com>
parents: 760
diff changeset
27 ignoredfiles = set(['.hgtags', '.hgsvnexternals', '.hgsub', '.hgsubstate'])
760
bf1c27a89c76 Extract files not to be pushed in util
Patrick Mezard <pmezard@gmail.com>
parents: 754
diff changeset
28
440
80909328aef1 move remaining cmdutils into util
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 431
diff changeset
29 b_re = re.compile(r'^\+\+\+ b\/([^\n]*)', re.MULTILINE)
80909328aef1 move remaining cmdutils into util
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 431
diff changeset
30 a_re = re.compile(r'^--- a\/([^\n]*)', re.MULTILINE)
80909328aef1 move remaining cmdutils into util
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 431
diff changeset
31 devnull_re = re.compile(r'^([-+]{3}) /dev/null', re.MULTILINE)
80909328aef1 move remaining cmdutils into util
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 431
diff changeset
32 header_re = re.compile(r'^diff --git .* b\/(.*)', re.MULTILINE)
80909328aef1 move remaining cmdutils into util
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 431
diff changeset
33 newfile_devnull_re = re.compile(r'^--- /dev/null\n\+\+\+ b/([^\n]*)',
80909328aef1 move remaining cmdutils into util
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 431
diff changeset
34 re.MULTILINE)
80909328aef1 move remaining cmdutils into util
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 431
diff changeset
35
80909328aef1 move remaining cmdutils into util
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 431
diff changeset
36
80909328aef1 move remaining cmdutils into util
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 431
diff changeset
37 def formatrev(rev):
80909328aef1 move remaining cmdutils into util
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 431
diff changeset
38 if rev == -1:
80909328aef1 move remaining cmdutils into util
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 431
diff changeset
39 return '\t(working copy)'
80909328aef1 move remaining cmdutils into util
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 431
diff changeset
40 return '\t(revision %d)' % rev
80909328aef1 move remaining cmdutils into util
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 431
diff changeset
41
973
21197f5ee9de expand configured paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 952
diff changeset
42 def configpath(ui, name):
21197f5ee9de expand configured paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 952
diff changeset
43 path = ui.config('hgsubversion', name)
21197f5ee9de expand configured paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 952
diff changeset
44 return path and hgutil.expandpath(path)
440
80909328aef1 move remaining cmdutils into util
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 431
diff changeset
45
80909328aef1 move remaining cmdutils into util
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 431
diff changeset
46 def filterdiff(diff, oldrev, newrev):
80909328aef1 move remaining cmdutils into util
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 431
diff changeset
47 diff = newfile_devnull_re.sub(r'--- \1\t(revision 0)' '\n'
80909328aef1 move remaining cmdutils into util
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 431
diff changeset
48 r'+++ \1\t(working copy)',
80909328aef1 move remaining cmdutils into util
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 431
diff changeset
49 diff)
80909328aef1 move remaining cmdutils into util
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 431
diff changeset
50 oldrev = formatrev(oldrev)
80909328aef1 move remaining cmdutils into util
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 431
diff changeset
51 newrev = formatrev(newrev)
832
e9af7eba88db globally: clean up whitespace around operators and commas to conform with PEP8
Yonggang Luo <luoyonggang@gmail.com>
parents: 828
diff changeset
52 diff = a_re.sub(r'--- \1' + oldrev, diff)
440
80909328aef1 move remaining cmdutils into util
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 431
diff changeset
53 diff = b_re.sub(r'+++ \1' + newrev, diff)
80909328aef1 move remaining cmdutils into util
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 431
diff changeset
54 diff = devnull_re.sub(r'\1 /dev/null\t(working copy)', diff)
80909328aef1 move remaining cmdutils into util
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 431
diff changeset
55 diff = header_re.sub(r'Index: \1' + '\n' + ('=' * 67), diff)
80909328aef1 move remaining cmdutils into util
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 431
diff changeset
56 return diff
80909328aef1 move remaining cmdutils into util
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 431
diff changeset
57
80909328aef1 move remaining cmdutils into util
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 431
diff changeset
58
80909328aef1 move remaining cmdutils into util
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 431
diff changeset
59 def parentrev(ui, repo, meta, hashes):
80909328aef1 move remaining cmdutils into util
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 431
diff changeset
60 """Find the svn parent revision of the repo's dirstate.
80909328aef1 move remaining cmdutils into util
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 431
diff changeset
61 """
80909328aef1 move remaining cmdutils into util
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 431
diff changeset
62 workingctx = repo.parents()[0]
80909328aef1 move remaining cmdutils into util
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 431
diff changeset
63 outrev = outgoing_revisions(repo, hashes, workingctx.node())
80909328aef1 move remaining cmdutils into util
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 431
diff changeset
64 if outrev:
80909328aef1 move remaining cmdutils into util
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 431
diff changeset
65 workingctx = repo[outrev[-1]].parents()[0]
80909328aef1 move remaining cmdutils into util
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 431
diff changeset
66 return workingctx
80909328aef1 move remaining cmdutils into util
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 431
diff changeset
67
80909328aef1 move remaining cmdutils into util
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 431
diff changeset
68
80909328aef1 move remaining cmdutils into util
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 431
diff changeset
69 def islocalrepo(url):
806
ec074ebaa80f util: make islocalrepo() a bit more tolerant with file:// urls
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 805
diff changeset
70 path = str(url) # convert once up front
ec074ebaa80f util: make islocalrepo() a bit more tolerant with file:// urls
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 805
diff changeset
71 if path.startswith('file:///'):
ec074ebaa80f util: make islocalrepo() a bit more tolerant with file:// urls
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 805
diff changeset
72 prefixlen = len('file://')
ec074ebaa80f util: make islocalrepo() a bit more tolerant with file:// urls
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 805
diff changeset
73 elif path.startswith('file:/'):
ec074ebaa80f util: make islocalrepo() a bit more tolerant with file:// urls
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 805
diff changeset
74 prefixlen = len('file:')
ec074ebaa80f util: make islocalrepo() a bit more tolerant with file:// urls
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 805
diff changeset
75 else:
440
80909328aef1 move remaining cmdutils into util
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 431
diff changeset
76 return False
806
ec074ebaa80f util: make islocalrepo() a bit more tolerant with file:// urls
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 805
diff changeset
77 if '#' in path.split('/')[-1]: # strip off #anchor
ec074ebaa80f util: make islocalrepo() a bit more tolerant with file:// urls
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 805
diff changeset
78 path = path[:path.rfind('#')]
ec074ebaa80f util: make islocalrepo() a bit more tolerant with file:// urls
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 805
diff changeset
79 path = url[prefixlen:]
440
80909328aef1 move remaining cmdutils into util
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 431
diff changeset
80 path = urllib.url2pathname(path).replace(os.sep, '/')
80909328aef1 move remaining cmdutils into util
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 431
diff changeset
81 while '/' in path:
832
e9af7eba88db globally: clean up whitespace around operators and commas to conform with PEP8
Yonggang Luo <luoyonggang@gmail.com>
parents: 828
diff changeset
82 if reduce(lambda x, y: x and y,
440
80909328aef1 move remaining cmdutils into util
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 431
diff changeset
83 map(lambda p: os.path.exists(os.path.join(path, p)),
832
e9af7eba88db globally: clean up whitespace around operators and commas to conform with PEP8
Yonggang Luo <luoyonggang@gmail.com>
parents: 828
diff changeset
84 ('hooks', 'format', 'db',))):
440
80909328aef1 move remaining cmdutils into util
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 431
diff changeset
85 return True
80909328aef1 move remaining cmdutils into util
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 431
diff changeset
86 path = path.rsplit('/', 1)[0]
80909328aef1 move remaining cmdutils into util
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 431
diff changeset
87 return False
80909328aef1 move remaining cmdutils into util
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 431
diff changeset
88
1040
ada2400241c4 fixes for running under Mercurial 2.0
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 1039
diff changeset
89 def strip(ui, repo, changesets, *args , **opts):
ada2400241c4 fixes for running under Mercurial 2.0
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 1039
diff changeset
90 try:
ada2400241c4 fixes for running under Mercurial 2.0
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 1039
diff changeset
91 repair.strip(ui, repo, changesets, *args, **opts)
ada2400241c4 fixes for running under Mercurial 2.0
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 1039
diff changeset
92 except TypeError:
ada2400241c4 fixes for running under Mercurial 2.0
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 1039
diff changeset
93 # only 2.1.2 and later allow strip to take a list of nodes
ada2400241c4 fixes for running under Mercurial 2.0
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 1039
diff changeset
94 for changeset in changesets:
ada2400241c4 fixes for running under Mercurial 2.0
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 1039
diff changeset
95 repair.strip(ui, repo, changeset, *args, **opts)
ada2400241c4 fixes for running under Mercurial 2.0
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 1039
diff changeset
96
440
80909328aef1 move remaining cmdutils into util
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 431
diff changeset
97
196
77812f98e250 Add a naive hg svn version command that works as long as hgsubversion is run from a checkout.
Augie Fackler <durin42@gmail.com>
parents: 195
diff changeset
98 def version(ui):
509
ac9c9e1a8022 setup: write out version info
Augie Fackler <durin42@gmail.com>
parents: 497
diff changeset
99 """Return version information if available."""
ac9c9e1a8022 setup: write out version info
Augie Fackler <durin42@gmail.com>
parents: 497
diff changeset
100 try:
ac9c9e1a8022 setup: write out version info
Augie Fackler <durin42@gmail.com>
parents: 497
diff changeset
101 import __version__
ac9c9e1a8022 setup: write out version info
Augie Fackler <durin42@gmail.com>
parents: 497
diff changeset
102 return __version__.version
ac9c9e1a8022 setup: write out version info
Augie Fackler <durin42@gmail.com>
parents: 497
diff changeset
103 except ImportError:
ac9c9e1a8022 setup: write out version info
Augie Fackler <durin42@gmail.com>
parents: 497
diff changeset
104 try:
ac9c9e1a8022 setup: write out version info
Augie Fackler <durin42@gmail.com>
parents: 497
diff changeset
105 dn = os.path.dirname
ac9c9e1a8022 setup: write out version info
Augie Fackler <durin42@gmail.com>
parents: 497
diff changeset
106 repo = hg.repository(ui, dn(dn(__file__)))
ac9c9e1a8022 setup: write out version info
Augie Fackler <durin42@gmail.com>
parents: 497
diff changeset
107 ver = repo.dirstate.parents()[0]
ac9c9e1a8022 setup: write out version info
Augie Fackler <durin42@gmail.com>
parents: 497
diff changeset
108 return node.hex(ver)[:12]
ac9c9e1a8022 setup: write out version info
Augie Fackler <durin42@gmail.com>
parents: 497
diff changeset
109 except:
ac9c9e1a8022 setup: write out version info
Augie Fackler <durin42@gmail.com>
parents: 497
diff changeset
110 return 'unknown'
196
77812f98e250 Add a naive hg svn version command that works as long as hgsubversion is run from a checkout.
Augie Fackler <durin42@gmail.com>
parents: 195
diff changeset
111
0
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
112
469
5567af673f83 Revive svn+http(s) URLs support (issue94)
Patrick Mezard <pmezard@gmail.com>
parents: 465
diff changeset
113 def normalize_url(url):
754
caa527346a0f svncommands: abort on missing metadata or Subversion URL (fixes #226)
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 752
diff changeset
114 if not url:
caa527346a0f svncommands: abort on missing metadata or Subversion URL (fixes #226)
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 752
diff changeset
115 return url
475
15443c592f7a Remove the svn+ from svn+https urls before calling the Subversion API. This was already being done for svn+http urls.
David Stanek <dstanek@dstanek.com>
parents: 469
diff changeset
116 if url.startswith('svn+http://') or url.startswith('svn+https://'):
469
5567af673f83 Revive svn+http(s) URLs support (issue94)
Patrick Mezard <pmezard@gmail.com>
parents: 465
diff changeset
117 url = url[4:]
555
cbd7065e6ab4 util: add parseurl method to abstract away differences between 1.4 and 1.5
Augie Fackler <durin42@gmail.com>
parents: 509
diff changeset
118 url, revs, checkout = parseurl(url)
284
f8f9a2993705 Implement parseurl support (#revision in repository urls)
Martijn Pieters <mj@zopatista.com>
parents: 281
diff changeset
119 url = url.rstrip('/')
f8f9a2993705 Implement parseurl support (#revision in repository urls)
Martijn Pieters <mj@zopatista.com>
parents: 281
diff changeset
120 if checkout:
f8f9a2993705 Implement parseurl support (#revision in repository urls)
Martijn Pieters <mj@zopatista.com>
parents: 281
diff changeset
121 url = '%s#%s' % (url, checkout)
f8f9a2993705 Implement parseurl support (#revision in repository urls)
Martijn Pieters <mj@zopatista.com>
parents: 281
diff changeset
122 return url
140
9ffde8662967 util: Add a command to normalize svn urls and use it in a couple of places. Test that it works and prevents failed assertions.
Augie Fackler <durin42@gmail.com>
parents: 124
diff changeset
123
1134
a9b6e38d6dc9 util: add visitor pattern for scrubbing json
Sean Farley <sean.michael.farley@gmail.com>
parents: 1128
diff changeset
124 def _scrub(data):
a9b6e38d6dc9 util: add visitor pattern for scrubbing json
Sean Farley <sean.michael.farley@gmail.com>
parents: 1128
diff changeset
125 if not data and not isinstance(data, list):
a9b6e38d6dc9 util: add visitor pattern for scrubbing json
Sean Farley <sean.michael.farley@gmail.com>
parents: 1128
diff changeset
126 return ''
a9b6e38d6dc9 util: add visitor pattern for scrubbing json
Sean Farley <sean.michael.farley@gmail.com>
parents: 1128
diff changeset
127 return data
a9b6e38d6dc9 util: add visitor pattern for scrubbing json
Sean Farley <sean.michael.farley@gmail.com>
parents: 1128
diff changeset
128
a9b6e38d6dc9 util: add visitor pattern for scrubbing json
Sean Farley <sean.michael.farley@gmail.com>
parents: 1128
diff changeset
129 def _descrub(data):
a9b6e38d6dc9 util: add visitor pattern for scrubbing json
Sean Farley <sean.michael.farley@gmail.com>
parents: 1128
diff changeset
130 if isinstance(data, list):
a9b6e38d6dc9 util: add visitor pattern for scrubbing json
Sean Farley <sean.michael.farley@gmail.com>
parents: 1128
diff changeset
131 return tuple(data)
a9b6e38d6dc9 util: add visitor pattern for scrubbing json
Sean Farley <sean.michael.farley@gmail.com>
parents: 1128
diff changeset
132 if data == '':
a9b6e38d6dc9 util: add visitor pattern for scrubbing json
Sean Farley <sean.michael.farley@gmail.com>
parents: 1128
diff changeset
133 return None
a9b6e38d6dc9 util: add visitor pattern for scrubbing json
Sean Farley <sean.michael.farley@gmail.com>
parents: 1128
diff changeset
134 return data
a9b6e38d6dc9 util: add visitor pattern for scrubbing json
Sean Farley <sean.michael.farley@gmail.com>
parents: 1128
diff changeset
135
a9b6e38d6dc9 util: add visitor pattern for scrubbing json
Sean Farley <sean.michael.farley@gmail.com>
parents: 1128
diff changeset
136 def _convert(input, visitor):
a9b6e38d6dc9 util: add visitor pattern for scrubbing json
Sean Farley <sean.michael.farley@gmail.com>
parents: 1128
diff changeset
137 if isinstance(input, dict):
a9b6e38d6dc9 util: add visitor pattern for scrubbing json
Sean Farley <sean.michael.farley@gmail.com>
parents: 1128
diff changeset
138 scrubbed = {}
a9b6e38d6dc9 util: add visitor pattern for scrubbing json
Sean Farley <sean.michael.farley@gmail.com>
parents: 1128
diff changeset
139 d = dict([(_convert(key, visitor), _convert(value, visitor))
a9b6e38d6dc9 util: add visitor pattern for scrubbing json
Sean Farley <sean.michael.farley@gmail.com>
parents: 1128
diff changeset
140 for key, value in input.iteritems()])
a9b6e38d6dc9 util: add visitor pattern for scrubbing json
Sean Farley <sean.michael.farley@gmail.com>
parents: 1128
diff changeset
141 for key, val in d.iteritems():
a9b6e38d6dc9 util: add visitor pattern for scrubbing json
Sean Farley <sean.michael.farley@gmail.com>
parents: 1128
diff changeset
142 scrubbed[visitor(key)] = visitor(val)
a9b6e38d6dc9 util: add visitor pattern for scrubbing json
Sean Farley <sean.michael.farley@gmail.com>
parents: 1128
diff changeset
143 return scrubbed
a9b6e38d6dc9 util: add visitor pattern for scrubbing json
Sean Farley <sean.michael.farley@gmail.com>
parents: 1128
diff changeset
144 elif isinstance(input, list):
a9b6e38d6dc9 util: add visitor pattern for scrubbing json
Sean Farley <sean.michael.farley@gmail.com>
parents: 1128
diff changeset
145 return [_convert(element, visitor) for element in input]
a9b6e38d6dc9 util: add visitor pattern for scrubbing json
Sean Farley <sean.michael.farley@gmail.com>
parents: 1128
diff changeset
146 elif isinstance(input, unicode):
a9b6e38d6dc9 util: add visitor pattern for scrubbing json
Sean Farley <sean.michael.farley@gmail.com>
parents: 1128
diff changeset
147 return input.encode('utf-8')
a9b6e38d6dc9 util: add visitor pattern for scrubbing json
Sean Farley <sean.michael.farley@gmail.com>
parents: 1128
diff changeset
148 return input
a9b6e38d6dc9 util: add visitor pattern for scrubbing json
Sean Farley <sean.michael.farley@gmail.com>
parents: 1128
diff changeset
149
1127
eaefb3413b87 util: rename pickle_atomic to dump
Sean Farley <sean.michael.farley@gmail.com>
parents: 1124
diff changeset
150 def dump(data, file_path):
1136
6e4892b6628a util: serialize data with json instead of pickle
Sean Farley <sean.michael.farley@gmail.com>
parents: 1135
diff changeset
151 """Serialize some data to a path atomically.
1025
2bf860f327e2 util: move pickle_atomic from svnmeta to util
David Schleimer <dschleimer@fb.com>
parents: 1010
diff changeset
152
2bf860f327e2 util: move pickle_atomic from svnmeta to util
David Schleimer <dschleimer@fb.com>
parents: 1010
diff changeset
153 This is present because I kept corrupting my revmap by managing to hit ^C
1136
6e4892b6628a util: serialize data with json instead of pickle
Sean Farley <sean.michael.farley@gmail.com>
parents: 1135
diff changeset
154 during the serialization of that file.
1025
2bf860f327e2 util: move pickle_atomic from svnmeta to util
David Schleimer <dschleimer@fb.com>
parents: 1010
diff changeset
155 """
2bf860f327e2 util: move pickle_atomic from svnmeta to util
David Schleimer <dschleimer@fb.com>
parents: 1010
diff changeset
156 f = hgutil.atomictempfile(file_path, 'w+b', 0644)
1136
6e4892b6628a util: serialize data with json instead of pickle
Sean Farley <sean.michael.farley@gmail.com>
parents: 1135
diff changeset
157 json.dump(_convert(data, _scrub), f)
1124
99c503cfcc9c util: remove pre-1.9 mercurial code from pickle_atomic
Sean Farley <sean.michael.farley@gmail.com>
parents: 1123
diff changeset
158 f.close()
828
016f11e5f189 utils: add {save,load}_string since this is a fairly common idiom
Yonggang Luo <luoyonggang@gmail.com>
parents: 806
diff changeset
159
1147
56f426d0261f util: add resave bool parameter to load
Sean Farley <sean.michael.farley@gmail.com>
parents: 1145
diff changeset
160 def load(file_path, default=None, resave=True):
1135
5a0da3bab8a2 util: try to load data using json
Sean Farley <sean.michael.farley@gmail.com>
parents: 1134
diff changeset
161 """Deserialize some data from a path.
1128
2922f4881a04 util: add a method to load data from a file
Sean Farley <sean.michael.farley@gmail.com>
parents: 1127
diff changeset
162 """
1141
a4b54b19cd2e util: add default parameter to load
Sean Farley <sean.michael.farley@gmail.com>
parents: 1140
diff changeset
163 data = default
1135
5a0da3bab8a2 util: try to load data using json
Sean Farley <sean.michael.farley@gmail.com>
parents: 1134
diff changeset
164 if not os.path.exists(file_path):
5a0da3bab8a2 util: try to load data using json
Sean Farley <sean.michael.farley@gmail.com>
parents: 1134
diff changeset
165 return data
5a0da3bab8a2 util: try to load data using json
Sean Farley <sean.michael.farley@gmail.com>
parents: 1134
diff changeset
166
5a0da3bab8a2 util: try to load data using json
Sean Farley <sean.michael.farley@gmail.com>
parents: 1134
diff changeset
167 f = open(file_path)
5a0da3bab8a2 util: try to load data using json
Sean Farley <sean.michael.farley@gmail.com>
parents: 1134
diff changeset
168 try:
5a0da3bab8a2 util: try to load data using json
Sean Farley <sean.michael.farley@gmail.com>
parents: 1134
diff changeset
169 data = _convert(json.load(f), _descrub)
1137
ad4cb902593e util: convert pickle to json
Sean Farley <sean.michael.farley@gmail.com>
parents: 1136
diff changeset
170 f.close()
1135
5a0da3bab8a2 util: try to load data using json
Sean Farley <sean.michael.farley@gmail.com>
parents: 1134
diff changeset
171 except ValueError:
1148
91d685418490 util: fallback to raw string reading if pickle fails
Sean Farley <sean.michael.farley@gmail.com>
parents: 1147
diff changeset
172 try:
91d685418490 util: fallback to raw string reading if pickle fails
Sean Farley <sean.michael.farley@gmail.com>
parents: 1147
diff changeset
173 # Ok, JSON couldn't be loaded, so we'll try the old way of using pickle
91d685418490 util: fallback to raw string reading if pickle fails
Sean Farley <sean.michael.farley@gmail.com>
parents: 1147
diff changeset
174 data = compathacks.pickle_load(f)
91d685418490 util: fallback to raw string reading if pickle fails
Sean Farley <sean.michael.farley@gmail.com>
parents: 1147
diff changeset
175 except:
91d685418490 util: fallback to raw string reading if pickle fails
Sean Farley <sean.michael.farley@gmail.com>
parents: 1147
diff changeset
176 # well, pickle didn't work either, so we reset the file pointer and
91d685418490 util: fallback to raw string reading if pickle fails
Sean Farley <sean.michael.farley@gmail.com>
parents: 1147
diff changeset
177 # read the string
91d685418490 util: fallback to raw string reading if pickle fails
Sean Farley <sean.michael.farley@gmail.com>
parents: 1147
diff changeset
178 f.seek(0)
91d685418490 util: fallback to raw string reading if pickle fails
Sean Farley <sean.michael.farley@gmail.com>
parents: 1147
diff changeset
179 data = f.read()
1137
ad4cb902593e util: convert pickle to json
Sean Farley <sean.michael.farley@gmail.com>
parents: 1136
diff changeset
180
ad4cb902593e util: convert pickle to json
Sean Farley <sean.michael.farley@gmail.com>
parents: 1136
diff changeset
181 # convert the file to json immediately
ad4cb902593e util: convert pickle to json
Sean Farley <sean.michael.farley@gmail.com>
parents: 1136
diff changeset
182 f.close()
1147
56f426d0261f util: add resave bool parameter to load
Sean Farley <sean.michael.farley@gmail.com>
parents: 1145
diff changeset
183 if resave:
56f426d0261f util: add resave bool parameter to load
Sean Farley <sean.michael.farley@gmail.com>
parents: 1145
diff changeset
184 dump(data, file_path)
1128
2922f4881a04 util: add a method to load data from a file
Sean Farley <sean.michael.farley@gmail.com>
parents: 1127
diff changeset
185 return data
2922f4881a04 util: add a method to load data from a file
Sean Farley <sean.michael.farley@gmail.com>
parents: 1127
diff changeset
186
555
cbd7065e6ab4 util: add parseurl method to abstract away differences between 1.4 and 1.5
Augie Fackler <durin42@gmail.com>
parents: 509
diff changeset
187 def parseurl(url, heads=[]):
1123
37989fbbab5c util: remove pre-1.6 mercurial code from parseurl
Sean Farley <sean.michael.farley@gmail.com>
parents: 1045
diff changeset
188 checkout = None
37989fbbab5c util: remove pre-1.6 mercurial code from parseurl
Sean Farley <sean.michael.farley@gmail.com>
parents: 1045
diff changeset
189 svn_url, (_junk, heads) = hg.parseurl(url, heads)
37989fbbab5c util: remove pre-1.6 mercurial code from parseurl
Sean Farley <sean.michael.farley@gmail.com>
parents: 1045
diff changeset
190 if heads:
37989fbbab5c util: remove pre-1.6 mercurial code from parseurl
Sean Farley <sean.michael.farley@gmail.com>
parents: 1045
diff changeset
191 checkout = heads[0]
555
cbd7065e6ab4 util: add parseurl method to abstract away differences between 1.4 and 1.5
Augie Fackler <durin42@gmail.com>
parents: 509
diff changeset
192 return svn_url, heads, checkout
cbd7065e6ab4 util: add parseurl method to abstract away differences between 1.4 and 1.5
Augie Fackler <durin42@gmail.com>
parents: 509
diff changeset
193
cbd7065e6ab4 util: add parseurl method to abstract away differences between 1.4 and 1.5
Augie Fackler <durin42@gmail.com>
parents: 509
diff changeset
194
39
b3c7b844b782 Some more fixes of cases discovered in the melange repo. If anyone knows how I can reproduce a "replaced" state in Subversion, I'd love to be able to make a real test case for this code.
Augie Fackler <durin42@gmail.com>
parents: 34
diff changeset
195 class PrefixMatch(object):
b3c7b844b782 Some more fixes of cases discovered in the melange repo. If anyone knows how I can reproduce a "replaced" state in Subversion, I'd love to be able to make a real test case for this code.
Augie Fackler <durin42@gmail.com>
parents: 34
diff changeset
196 def __init__(self, prefix):
b3c7b844b782 Some more fixes of cases discovered in the melange repo. If anyone knows how I can reproduce a "replaced" state in Subversion, I'd love to be able to make a real test case for this code.
Augie Fackler <durin42@gmail.com>
parents: 34
diff changeset
197 self.p = prefix
140
9ffde8662967 util: Add a command to normalize svn urls and use it in a couple of places. Test that it works and prevents failed assertions.
Augie Fackler <durin42@gmail.com>
parents: 124
diff changeset
198
39
b3c7b844b782 Some more fixes of cases discovered in the melange repo. If anyone knows how I can reproduce a "replaced" state in Subversion, I'd love to be able to make a real test case for this code.
Augie Fackler <durin42@gmail.com>
parents: 34
diff changeset
199 def files(self):
b3c7b844b782 Some more fixes of cases discovered in the melange repo. If anyone knows how I can reproduce a "replaced" state in Subversion, I'd love to be able to make a real test case for this code.
Augie Fackler <durin42@gmail.com>
parents: 34
diff changeset
200 return []
140
9ffde8662967 util: Add a command to normalize svn urls and use it in a couple of places. Test that it works and prevents failed assertions.
Augie Fackler <durin42@gmail.com>
parents: 124
diff changeset
201
39
b3c7b844b782 Some more fixes of cases discovered in the melange repo. If anyone knows how I can reproduce a "replaced" state in Subversion, I'd love to be able to make a real test case for this code.
Augie Fackler <durin42@gmail.com>
parents: 34
diff changeset
202 def __call__(self, fn):
b3c7b844b782 Some more fixes of cases discovered in the melange repo. If anyone knows how I can reproduce a "replaced" state in Subversion, I'd love to be able to make a real test case for this code.
Augie Fackler <durin42@gmail.com>
parents: 34
diff changeset
203 return fn.startswith(self.p)
99
1da7aafdd323 Refactored outgoing_revisions into util where it really belongs.
Augie Fackler <durin42@gmail.com>
parents: 39
diff changeset
204
416
cd6317fe70be invert the svnmeta/editor relationship
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 410
diff changeset
205 def outgoing_revisions(repo, reverse_map, sourcerev):
99
1da7aafdd323 Refactored outgoing_revisions into util where it really belongs.
Augie Fackler <durin42@gmail.com>
parents: 39
diff changeset
206 """Given a repo and an hg_editor, determines outgoing revisions for the
1da7aafdd323 Refactored outgoing_revisions into util where it really belongs.
Augie Fackler <durin42@gmail.com>
parents: 39
diff changeset
207 current working copy state.
1da7aafdd323 Refactored outgoing_revisions into util where it really belongs.
Augie Fackler <durin42@gmail.com>
parents: 39
diff changeset
208 """
1da7aafdd323 Refactored outgoing_revisions into util where it really belongs.
Augie Fackler <durin42@gmail.com>
parents: 39
diff changeset
209 outgoing_rev_hashes = []
152
1fde85a10f9e push: Fix the bad implementation that required modifying the dirstate to push.
Augie Fackler <durin42@gmail.com>
parents: 140
diff changeset
210 if sourcerev in reverse_map:
99
1da7aafdd323 Refactored outgoing_revisions into util where it really belongs.
Augie Fackler <durin42@gmail.com>
parents: 39
diff changeset
211 return
152
1fde85a10f9e push: Fix the bad implementation that required modifying the dirstate to push.
Augie Fackler <durin42@gmail.com>
parents: 140
diff changeset
212 sourcerev = repo[sourcerev]
1fde85a10f9e push: Fix the bad implementation that required modifying the dirstate to push.
Augie Fackler <durin42@gmail.com>
parents: 140
diff changeset
213 while (not sourcerev.node() in reverse_map
1fde85a10f9e push: Fix the bad implementation that required modifying the dirstate to push.
Augie Fackler <durin42@gmail.com>
parents: 140
diff changeset
214 and sourcerev.node() != node.nullid):
1fde85a10f9e push: Fix the bad implementation that required modifying the dirstate to push.
Augie Fackler <durin42@gmail.com>
parents: 140
diff changeset
215 outgoing_rev_hashes.append(sourcerev.node())
1fde85a10f9e push: Fix the bad implementation that required modifying the dirstate to push.
Augie Fackler <durin42@gmail.com>
parents: 140
diff changeset
216 sourcerev = sourcerev.parents()
221
ced45b753ba7 util: better error messages when finding svn parent of a revision.
Augie Fackler <durin42@gmail.com>
parents: 198
diff changeset
217 if len(sourcerev) != 1:
250
79349fd04836 utils: standardizing imported name to hgutil, our_util to util
Daniel Tang <dytang@cs.purdue.edu>
parents: 249
diff changeset
218 raise hgutil.Abort("Sorry, can't find svn parent of a merge revision.")
152
1fde85a10f9e push: Fix the bad implementation that required modifying the dirstate to push.
Augie Fackler <durin42@gmail.com>
parents: 140
diff changeset
219 sourcerev = sourcerev[0]
1fde85a10f9e push: Fix the bad implementation that required modifying the dirstate to push.
Augie Fackler <durin42@gmail.com>
parents: 140
diff changeset
220 if sourcerev.node() != node.nullid:
99
1da7aafdd323 Refactored outgoing_revisions into util where it really belongs.
Augie Fackler <durin42@gmail.com>
parents: 39
diff changeset
221 return outgoing_rev_hashes
124
291925677a9f tag_repo: remove gentags command, extend repo.tags(), HgChangeEditor now takes either repo or repo_path
Luke Opperman <luke@loppear.com>
parents: 115
diff changeset
222
805
a3f727c41c1d Fix breakage introduced by discovery refactoring
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 794
diff changeset
223 def outgoing_common_and_heads(repo, reverse_map, sourcerev):
a3f727c41c1d Fix breakage introduced by discovery refactoring
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 794
diff changeset
224 """Given a repo and an hg_editor, determines outgoing revisions for the
a3f727c41c1d Fix breakage introduced by discovery refactoring
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 794
diff changeset
225 current working copy state. Returns a tuple (common, heads) like
a3f727c41c1d Fix breakage introduced by discovery refactoring
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 794
diff changeset
226 discovery.findcommonoutgoing does.
a3f727c41c1d Fix breakage introduced by discovery refactoring
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 794
diff changeset
227 """
a3f727c41c1d Fix breakage introduced by discovery refactoring
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 794
diff changeset
228 if sourcerev in reverse_map:
a3f727c41c1d Fix breakage introduced by discovery refactoring
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 794
diff changeset
229 return ([sourcerev], [sourcerev]) # nothing outgoing
a3f727c41c1d Fix breakage introduced by discovery refactoring
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 794
diff changeset
230 sourcecx = repo[sourcerev]
a3f727c41c1d Fix breakage introduced by discovery refactoring
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 794
diff changeset
231 while (not sourcecx.node() in reverse_map
a3f727c41c1d Fix breakage introduced by discovery refactoring
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 794
diff changeset
232 and sourcecx.node() != node.nullid):
a3f727c41c1d Fix breakage introduced by discovery refactoring
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 794
diff changeset
233 ps = sourcecx.parents()
a3f727c41c1d Fix breakage introduced by discovery refactoring
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 794
diff changeset
234 if len(ps) != 1:
a3f727c41c1d Fix breakage introduced by discovery refactoring
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 794
diff changeset
235 raise hgutil.Abort("Sorry, can't find svn parent of a merge revision.")
a3f727c41c1d Fix breakage introduced by discovery refactoring
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 794
diff changeset
236 sourcecx = ps[0]
a3f727c41c1d Fix breakage introduced by discovery refactoring
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 794
diff changeset
237 if sourcecx.node() != node.nullid:
a3f727c41c1d Fix breakage introduced by discovery refactoring
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 794
diff changeset
238 return ([sourcecx.node()], [sourcerev])
a3f727c41c1d Fix breakage introduced by discovery refactoring
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 794
diff changeset
239 return ([sourcerev], [sourcerev]) # nothing outgoing
a3f727c41c1d Fix breakage introduced by discovery refactoring
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 794
diff changeset
240
1045
67e11b650e94 handle invalid UTF-8 in commit messages consistently
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 1040
diff changeset
241 def getmessage(ui, rev):
67e11b650e94 handle invalid UTF-8 in commit messages consistently
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 1040
diff changeset
242 msg = rev.message
67e11b650e94 handle invalid UTF-8 in commit messages consistently
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 1040
diff changeset
243
67e11b650e94 handle invalid UTF-8 in commit messages consistently
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 1040
diff changeset
244 if msg:
67e11b650e94 handle invalid UTF-8 in commit messages consistently
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 1040
diff changeset
245 try:
67e11b650e94 handle invalid UTF-8 in commit messages consistently
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 1040
diff changeset
246 msg.decode('utf-8')
67e11b650e94 handle invalid UTF-8 in commit messages consistently
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 1040
diff changeset
247 return msg
67e11b650e94 handle invalid UTF-8 in commit messages consistently
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 1040
diff changeset
248
67e11b650e94 handle invalid UTF-8 in commit messages consistently
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 1040
diff changeset
249 except UnicodeDecodeError:
67e11b650e94 handle invalid UTF-8 in commit messages consistently
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 1040
diff changeset
250 # ancient svn failed to enforce utf8 encoding
67e11b650e94 handle invalid UTF-8 in commit messages consistently
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 1040
diff changeset
251 return msg.decode('iso-8859-1').encode('utf-8')
67e11b650e94 handle invalid UTF-8 in commit messages consistently
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 1040
diff changeset
252 else:
67e11b650e94 handle invalid UTF-8 in commit messages consistently
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 1040
diff changeset
253 return ui.config('hgsubversion', 'defaultmessage', '')
186
6266ba36ee15 Create patch to make normal output much less verbose…
Dan Villiom Podlaski Christiansen <danchr@cs.au.dk>
parents: 185
diff changeset
254
198
df4611050286 Output consolidation; decrease the ‘Fetching...’ message to debug level.
Dan Villiom Podlaski Christiansen <danchr@cs.au.dk>
parents: 196
diff changeset
255 def describe_commit(ui, h, b):
df4611050286 Output consolidation; decrease the ‘Fetching...’ message to debug level.
Dan Villiom Podlaski Christiansen <danchr@cs.au.dk>
parents: 196
diff changeset
256 ui.note(' committed to "%s" as %s\n' % ((b or 'default'), node.short(h)))
223
330f0b15d417 issue67: mercurial 1.3 util incompatibility with encoding swap
Luke Opperman <luke@loppear.com>
parents: 221
diff changeset
257
330f0b15d417 issue67: mercurial 1.3 util incompatibility with encoding swap
Luke Opperman <luke@loppear.com>
parents: 221
diff changeset
258
330f0b15d417 issue67: mercurial 1.3 util incompatibility with encoding swap
Luke Opperman <luke@loppear.com>
parents: 221
diff changeset
259 def swap_out_encoding(new_encoding="UTF-8"):
281
8ff0b3261b7f util: drop 1.2 support in the encoding swap.
Augie Fackler <durin42@gmail.com>
parents: 275
diff changeset
260 from mercurial import encoding
8ff0b3261b7f util: drop 1.2 support in the encoding swap.
Augie Fackler <durin42@gmail.com>
parents: 275
diff changeset
261 old = encoding.encoding
8ff0b3261b7f util: drop 1.2 support in the encoding swap.
Augie Fackler <durin42@gmail.com>
parents: 275
diff changeset
262 encoding.encoding = new_encoding
223
330f0b15d417 issue67: mercurial 1.3 util incompatibility with encoding swap
Luke Opperman <luke@loppear.com>
parents: 221
diff changeset
263 return old
410
eb524b957345 move aresamefiles() from HgChangeReceiver to util
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 408
diff changeset
264
952
9c3b4f59e7e6 stupid: do not close branch upon branch-wide revert
Patrick Mezard <patrick@mezard.eu>
parents: 951
diff changeset
265 def isancestor(ctx, ancestorctx):
9c3b4f59e7e6 stupid: do not close branch upon branch-wide revert
Patrick Mezard <patrick@mezard.eu>
parents: 951
diff changeset
266 """Return True if ancestorctx is equal or an ancestor of ctx."""
9c3b4f59e7e6 stupid: do not close branch upon branch-wide revert
Patrick Mezard <patrick@mezard.eu>
parents: 951
diff changeset
267 if ctx == ancestorctx:
9c3b4f59e7e6 stupid: do not close branch upon branch-wide revert
Patrick Mezard <patrick@mezard.eu>
parents: 951
diff changeset
268 return True
9c3b4f59e7e6 stupid: do not close branch upon branch-wide revert
Patrick Mezard <patrick@mezard.eu>
parents: 951
diff changeset
269 for actx in ctx.ancestors():
9c3b4f59e7e6 stupid: do not close branch upon branch-wide revert
Patrick Mezard <patrick@mezard.eu>
parents: 951
diff changeset
270 if actx == ancestorctx:
9c3b4f59e7e6 stupid: do not close branch upon branch-wide revert
Patrick Mezard <patrick@mezard.eu>
parents: 951
diff changeset
271 return True
9c3b4f59e7e6 stupid: do not close branch upon branch-wide revert
Patrick Mezard <patrick@mezard.eu>
parents: 951
diff changeset
272 return False
410
eb524b957345 move aresamefiles() from HgChangeReceiver to util
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 408
diff changeset
273
497
cad864ed29de util: make aresamefiles take one file and just be issamefile instead.
Augie Fackler <durin42@gmail.com>
parents: 475
diff changeset
274 def issamefile(parentctx, childctx, f):
582
44c56a7727c4 editor: fix issamefile() and copy detection in replay mode
Patrick Mezard <pmezard@gmail.com>
parents: 580
diff changeset
275 """Return True if f exists and is the same in childctx and parentctx"""
44c56a7727c4 editor: fix issamefile() and copy detection in replay mode
Patrick Mezard <pmezard@gmail.com>
parents: 580
diff changeset
276 if f not in parentctx or f not in childctx:
44c56a7727c4 editor: fix issamefile() and copy detection in replay mode
Patrick Mezard <pmezard@gmail.com>
parents: 580
diff changeset
277 return False
410
eb524b957345 move aresamefiles() from HgChangeReceiver to util
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 408
diff changeset
278 if parentctx == childctx:
eb524b957345 move aresamefiles() from HgChangeReceiver to util
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 408
diff changeset
279 return True
eb524b957345 move aresamefiles() from HgChangeReceiver to util
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 408
diff changeset
280 if parentctx.rev() > childctx.rev():
eb524b957345 move aresamefiles() from HgChangeReceiver to util
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 408
diff changeset
281 parentctx, childctx = childctx, parentctx
eb524b957345 move aresamefiles() from HgChangeReceiver to util
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 408
diff changeset
282
eb524b957345 move aresamefiles() from HgChangeReceiver to util
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 408
diff changeset
283 def selfandancestors(selfctx):
eb524b957345 move aresamefiles() from HgChangeReceiver to util
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 408
diff changeset
284 yield selfctx
eb524b957345 move aresamefiles() from HgChangeReceiver to util
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 408
diff changeset
285 for ctx in selfctx.ancestors():
eb524b957345 move aresamefiles() from HgChangeReceiver to util
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 408
diff changeset
286 yield ctx
eb524b957345 move aresamefiles() from HgChangeReceiver to util
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 408
diff changeset
287
eb524b957345 move aresamefiles() from HgChangeReceiver to util
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 408
diff changeset
288 for pctx in selfandancestors(childctx):
eb524b957345 move aresamefiles() from HgChangeReceiver to util
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 408
diff changeset
289 if pctx.rev() <= parentctx.rev():
eb524b957345 move aresamefiles() from HgChangeReceiver to util
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 408
diff changeset
290 return True
497
cad864ed29de util: make aresamefiles take one file and just be issamefile instead.
Augie Fackler <durin42@gmail.com>
parents: 475
diff changeset
291 if f in pctx.files():
cad864ed29de util: make aresamefiles take one file and just be issamefile instead.
Augie Fackler <durin42@gmail.com>
parents: 475
diff changeset
292 return False
410
eb524b957345 move aresamefiles() from HgChangeReceiver to util
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 408
diff changeset
293 # parentctx is not an ancestor of childctx, files are unrelated
eb524b957345 move aresamefiles() from HgChangeReceiver to util
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 408
diff changeset
294 return False
707
cb32d90f915e templatekw: clean up implementation & test; add help.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 620
diff changeset
295
884
1b261e0f85aa Abstract away the details of where svn revs are stored in a commit
Bryan O'Sullivan <bryano@fb.com>
parents: 832
diff changeset
296
1b261e0f85aa Abstract away the details of where svn revs are stored in a commit
Bryan O'Sullivan <bryano@fb.com>
parents: 832
diff changeset
297 def getsvnrev(ctx, defval=None):
1b261e0f85aa Abstract away the details of where svn revs are stored in a commit
Bryan O'Sullivan <bryano@fb.com>
parents: 832
diff changeset
298 '''Extract SVN revision from commit metadata'''
1b261e0f85aa Abstract away the details of where svn revs are stored in a commit
Bryan O'Sullivan <bryano@fb.com>
parents: 832
diff changeset
299 return ctx.extra().get('convert_revision', defval)
1b261e0f85aa Abstract away the details of where svn revs are stored in a commit
Bryan O'Sullivan <bryano@fb.com>
parents: 832
diff changeset
300
1b261e0f85aa Abstract away the details of where svn revs are stored in a commit
Bryan O'Sullivan <bryano@fb.com>
parents: 832
diff changeset
301
707
cb32d90f915e templatekw: clean up implementation & test; add help.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 620
diff changeset
302 def _templatehelper(ctx, kw):
cb32d90f915e templatekw: clean up implementation & test; add help.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 620
diff changeset
303 '''
cb32d90f915e templatekw: clean up implementation & test; add help.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 620
diff changeset
304 Helper function for displaying information about converted changesets.
cb32d90f915e templatekw: clean up implementation & test; add help.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 620
diff changeset
305 '''
884
1b261e0f85aa Abstract away the details of where svn revs are stored in a commit
Bryan O'Sullivan <bryano@fb.com>
parents: 832
diff changeset
306 convertinfo = getsvnrev(ctx, '')
707
cb32d90f915e templatekw: clean up implementation & test; add help.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 620
diff changeset
307
cb32d90f915e templatekw: clean up implementation & test; add help.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 620
diff changeset
308 if not convertinfo or not convertinfo.startswith('svn:'):
cb32d90f915e templatekw: clean up implementation & test; add help.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 620
diff changeset
309 return ''
cb32d90f915e templatekw: clean up implementation & test; add help.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 620
diff changeset
310
cb32d90f915e templatekw: clean up implementation & test; add help.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 620
diff changeset
311 if kw == 'svnuuid':
cb32d90f915e templatekw: clean up implementation & test; add help.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 620
diff changeset
312 return convertinfo[4:40]
cb32d90f915e templatekw: clean up implementation & test; add help.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 620
diff changeset
313 elif kw == 'svnpath':
cb32d90f915e templatekw: clean up implementation & test; add help.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 620
diff changeset
314 return convertinfo[40:].rsplit('@', 1)[0]
cb32d90f915e templatekw: clean up implementation & test; add help.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 620
diff changeset
315 elif kw == 'svnrev':
cb32d90f915e templatekw: clean up implementation & test; add help.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 620
diff changeset
316 return convertinfo[40:].rsplit('@', 1)[-1]
cb32d90f915e templatekw: clean up implementation & test; add help.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 620
diff changeset
317 else:
cb32d90f915e templatekw: clean up implementation & test; add help.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 620
diff changeset
318 raise hgutil.Abort('unrecognized hgsubversion keyword %s' % kw)
cb32d90f915e templatekw: clean up implementation & test; add help.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 620
diff changeset
319
794
c32c92fdca5b util: use real function definitions for keywords, document them
Patrick Mezard <pmezard@gmail.com>
parents: 770
diff changeset
320 def svnrevkw(**args):
c32c92fdca5b util: use real function definitions for keywords, document them
Patrick Mezard <pmezard@gmail.com>
parents: 770
diff changeset
321 """:svnrev: String. Converted subversion revision number."""
c32c92fdca5b util: use real function definitions for keywords, document them
Patrick Mezard <pmezard@gmail.com>
parents: 770
diff changeset
322 return _templatehelper(args['ctx'], 'svnrev')
c32c92fdca5b util: use real function definitions for keywords, document them
Patrick Mezard <pmezard@gmail.com>
parents: 770
diff changeset
323
c32c92fdca5b util: use real function definitions for keywords, document them
Patrick Mezard <pmezard@gmail.com>
parents: 770
diff changeset
324 def svnpathkw(**args):
c32c92fdca5b util: use real function definitions for keywords, document them
Patrick Mezard <pmezard@gmail.com>
parents: 770
diff changeset
325 """:svnpath: String. Converted subversion revision project path."""
c32c92fdca5b util: use real function definitions for keywords, document them
Patrick Mezard <pmezard@gmail.com>
parents: 770
diff changeset
326 return _templatehelper(args['ctx'], 'svnpath')
c32c92fdca5b util: use real function definitions for keywords, document them
Patrick Mezard <pmezard@gmail.com>
parents: 770
diff changeset
327
c32c92fdca5b util: use real function definitions for keywords, document them
Patrick Mezard <pmezard@gmail.com>
parents: 770
diff changeset
328 def svnuuidkw(**args):
c32c92fdca5b util: use real function definitions for keywords, document them
Patrick Mezard <pmezard@gmail.com>
parents: 770
diff changeset
329 """:svnuuid: String. Converted subversion revision repository identifier."""
c32c92fdca5b util: use real function definitions for keywords, document them
Patrick Mezard <pmezard@gmail.com>
parents: 770
diff changeset
330 return _templatehelper(args['ctx'], 'svnuuid')
c32c92fdca5b util: use real function definitions for keywords, document them
Patrick Mezard <pmezard@gmail.com>
parents: 770
diff changeset
331
707
cb32d90f915e templatekw: clean up implementation & test; add help.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 620
diff changeset
332 templatekeywords = {
794
c32c92fdca5b util: use real function definitions for keywords, document them
Patrick Mezard <pmezard@gmail.com>
parents: 770
diff changeset
333 'svnrev': svnrevkw,
c32c92fdca5b util: use real function definitions for keywords, document them
Patrick Mezard <pmezard@gmail.com>
parents: 770
diff changeset
334 'svnpath': svnpathkw,
c32c92fdca5b util: use real function definitions for keywords, document them
Patrick Mezard <pmezard@gmail.com>
parents: 770
diff changeset
335 'svnuuid': svnuuidkw,
707
cb32d90f915e templatekw: clean up implementation & test; add help.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 620
diff changeset
336 }
722
aa24148a7454 uisetup: add fromsvn() and svnrev() revsets.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 707
diff changeset
337
aa24148a7454 uisetup: add fromsvn() and svnrev() revsets.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 707
diff changeset
338 def revset_fromsvn(repo, subset, x):
752
bb64ad4ce982 revsets: add docstrings.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 722
diff changeset
339 '''``fromsvn()``
bb64ad4ce982 revsets: add docstrings.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 722
diff changeset
340 Select changesets that originate from Subversion.
bb64ad4ce982 revsets: add docstrings.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 722
diff changeset
341 '''
722
aa24148a7454 uisetup: add fromsvn() and svnrev() revsets.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 707
diff changeset
342 args = revset.getargs(x, 0, 0, "fromsvn takes no arguments")
aa24148a7454 uisetup: add fromsvn() and svnrev() revsets.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 707
diff changeset
343
889
7a98fbadcae9 revsets: huge speedups for fromsvn and svnrev
Bryan O'Sullivan <bryano@fb.com>
parents: 884
diff changeset
344 rev = repo.changelog.rev
7a98fbadcae9 revsets: huge speedups for fromsvn and svnrev
Bryan O'Sullivan <bryano@fb.com>
parents: 884
diff changeset
345 bin = node.bin
1182
8f9619a67565 maps: change readmapfile to take a path instead of repo
Sean Farley <sean.michael.farley@gmail.com>
parents: 1148
diff changeset
346 meta = repo.svnmeta(skiperrorcheck=True)
889
7a98fbadcae9 revsets: huge speedups for fromsvn and svnrev
Bryan O'Sullivan <bryano@fb.com>
parents: 884
diff changeset
347 try:
7a98fbadcae9 revsets: huge speedups for fromsvn and svnrev
Bryan O'Sullivan <bryano@fb.com>
parents: 884
diff changeset
348 svnrevs = set(rev(bin(l.split(' ', 2)[1]))
1182
8f9619a67565 maps: change readmapfile to take a path instead of repo
Sean Farley <sean.michael.farley@gmail.com>
parents: 1148
diff changeset
349 for l in maps.RevMap.readmapfile(meta.revmap_file,
8f9619a67565 maps: change readmapfile to take a path instead of repo
Sean Farley <sean.michael.farley@gmail.com>
parents: 1148
diff changeset
350 missingok=False))
889
7a98fbadcae9 revsets: huge speedups for fromsvn and svnrev
Bryan O'Sullivan <bryano@fb.com>
parents: 884
diff changeset
351 return filter(svnrevs.__contains__, subset)
7a98fbadcae9 revsets: huge speedups for fromsvn and svnrev
Bryan O'Sullivan <bryano@fb.com>
parents: 884
diff changeset
352 except IOError, err:
7a98fbadcae9 revsets: huge speedups for fromsvn and svnrev
Bryan O'Sullivan <bryano@fb.com>
parents: 884
diff changeset
353 if err.errno != errno.ENOENT:
7a98fbadcae9 revsets: huge speedups for fromsvn and svnrev
Bryan O'Sullivan <bryano@fb.com>
parents: 884
diff changeset
354 raise
7a98fbadcae9 revsets: huge speedups for fromsvn and svnrev
Bryan O'Sullivan <bryano@fb.com>
parents: 884
diff changeset
355 raise hgutil.Abort("svn metadata is missing - "
7a98fbadcae9 revsets: huge speedups for fromsvn and svnrev
Bryan O'Sullivan <bryano@fb.com>
parents: 884
diff changeset
356 "run 'hg svn rebuildmeta' to reconstruct it")
722
aa24148a7454 uisetup: add fromsvn() and svnrev() revsets.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 707
diff changeset
357
aa24148a7454 uisetup: add fromsvn() and svnrev() revsets.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 707
diff changeset
358 def revset_svnrev(repo, subset, x):
752
bb64ad4ce982 revsets: add docstrings.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 722
diff changeset
359 '''``svnrev(number)``
bb64ad4ce982 revsets: add docstrings.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 722
diff changeset
360 Select changesets that originate in the given Subversion revision.
bb64ad4ce982 revsets: add docstrings.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 722
diff changeset
361 '''
722
aa24148a7454 uisetup: add fromsvn() and svnrev() revsets.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 707
diff changeset
362 args = revset.getargs(x, 1, 1, "svnrev takes one argument")
aa24148a7454 uisetup: add fromsvn() and svnrev() revsets.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 707
diff changeset
363
aa24148a7454 uisetup: add fromsvn() and svnrev() revsets.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 707
diff changeset
364 rev = revset.getstring(args[0],
aa24148a7454 uisetup: add fromsvn() and svnrev() revsets.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 707
diff changeset
365 "the argument to svnrev() must be a number")
aa24148a7454 uisetup: add fromsvn() and svnrev() revsets.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 707
diff changeset
366 try:
889
7a98fbadcae9 revsets: huge speedups for fromsvn and svnrev
Bryan O'Sullivan <bryano@fb.com>
parents: 884
diff changeset
367 revnum = int(rev)
722
aa24148a7454 uisetup: add fromsvn() and svnrev() revsets.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 707
diff changeset
368 except ValueError:
aa24148a7454 uisetup: add fromsvn() and svnrev() revsets.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 707
diff changeset
369 raise error.ParseError("the argument to svnrev() must be a number")
aa24148a7454 uisetup: add fromsvn() and svnrev() revsets.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 707
diff changeset
370
889
7a98fbadcae9 revsets: huge speedups for fromsvn and svnrev
Bryan O'Sullivan <bryano@fb.com>
parents: 884
diff changeset
371 rev = rev + ' '
7a98fbadcae9 revsets: huge speedups for fromsvn and svnrev
Bryan O'Sullivan <bryano@fb.com>
parents: 884
diff changeset
372 revs = []
1182
8f9619a67565 maps: change readmapfile to take a path instead of repo
Sean Farley <sean.michael.farley@gmail.com>
parents: 1148
diff changeset
373 meta = repo.svnmeta(skiperrorcheck=True)
889
7a98fbadcae9 revsets: huge speedups for fromsvn and svnrev
Bryan O'Sullivan <bryano@fb.com>
parents: 884
diff changeset
374 try:
1182
8f9619a67565 maps: change readmapfile to take a path instead of repo
Sean Farley <sean.michael.farley@gmail.com>
parents: 1148
diff changeset
375 for l in maps.RevMap.readmapfile(meta.revmap_file, missingok=False):
889
7a98fbadcae9 revsets: huge speedups for fromsvn and svnrev
Bryan O'Sullivan <bryano@fb.com>
parents: 884
diff changeset
376 if l.startswith(rev):
7a98fbadcae9 revsets: huge speedups for fromsvn and svnrev
Bryan O'Sullivan <bryano@fb.com>
parents: 884
diff changeset
377 n = l.split(' ', 2)[1]
7a98fbadcae9 revsets: huge speedups for fromsvn and svnrev
Bryan O'Sullivan <bryano@fb.com>
parents: 884
diff changeset
378 r = repo[node.bin(n)].rev()
7a98fbadcae9 revsets: huge speedups for fromsvn and svnrev
Bryan O'Sullivan <bryano@fb.com>
parents: 884
diff changeset
379 if r in subset:
7a98fbadcae9 revsets: huge speedups for fromsvn and svnrev
Bryan O'Sullivan <bryano@fb.com>
parents: 884
diff changeset
380 revs.append(r)
7a98fbadcae9 revsets: huge speedups for fromsvn and svnrev
Bryan O'Sullivan <bryano@fb.com>
parents: 884
diff changeset
381 return revs
7a98fbadcae9 revsets: huge speedups for fromsvn and svnrev
Bryan O'Sullivan <bryano@fb.com>
parents: 884
diff changeset
382 except IOError, err:
7a98fbadcae9 revsets: huge speedups for fromsvn and svnrev
Bryan O'Sullivan <bryano@fb.com>
parents: 884
diff changeset
383 if err.errno != errno.ENOENT:
7a98fbadcae9 revsets: huge speedups for fromsvn and svnrev
Bryan O'Sullivan <bryano@fb.com>
parents: 884
diff changeset
384 raise
7a98fbadcae9 revsets: huge speedups for fromsvn and svnrev
Bryan O'Sullivan <bryano@fb.com>
parents: 884
diff changeset
385 raise hgutil.Abort("svn metadata is missing - "
7a98fbadcae9 revsets: huge speedups for fromsvn and svnrev
Bryan O'Sullivan <bryano@fb.com>
parents: 884
diff changeset
386 "run 'hg svn rebuildmeta' to reconstruct it")
722
aa24148a7454 uisetup: add fromsvn() and svnrev() revsets.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 707
diff changeset
387
aa24148a7454 uisetup: add fromsvn() and svnrev() revsets.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 707
diff changeset
388 revsets = {
aa24148a7454 uisetup: add fromsvn() and svnrev() revsets.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 707
diff changeset
389 'fromsvn': revset_fromsvn,
aa24148a7454 uisetup: add fromsvn() and svnrev() revsets.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 707
diff changeset
390 'svnrev': revset_svnrev,
aa24148a7454 uisetup: add fromsvn() and svnrev() revsets.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 707
diff changeset
391 }
944
d6db289f1548 pull: add hgsubversion.filestoresize to control memory consumption
Patrick Mezard <patrick@mezard.eu>
parents: 889
diff changeset
392
1009
f0bde4bf1f78 revsets: add support for 'r123' revision labels
Matt Mackall <mpm@selenic.com>
parents: 975
diff changeset
393 def revset_stringset(orig, repo, subset, x):
f0bde4bf1f78 revsets: add support for 'r123' revision labels
Matt Mackall <mpm@selenic.com>
parents: 975
diff changeset
394 if x.startswith('r') and x[1:].isdigit():
f0bde4bf1f78 revsets: add support for 'r123' revision labels
Matt Mackall <mpm@selenic.com>
parents: 975
diff changeset
395 return revset_svnrev(repo, subset, ('string', x[1:]))
1010
f0ebc7113429 revsets: fix nativerevs fallback
Matt Mackall <mpm@selenic.com>
parents: 1009
diff changeset
396 return orig(repo, subset, x)
1009
f0bde4bf1f78 revsets: add support for 'r123' revision labels
Matt Mackall <mpm@selenic.com>
parents: 975
diff changeset
397
944
d6db289f1548 pull: add hgsubversion.filestoresize to control memory consumption
Patrick Mezard <patrick@mezard.eu>
parents: 889
diff changeset
398 def getfilestoresize(ui):
d6db289f1548 pull: add hgsubversion.filestoresize to control memory consumption
Patrick Mezard <patrick@mezard.eu>
parents: 889
diff changeset
399 """Return the replay or stupid file memory store size in megabytes or -1"""
d6db289f1548 pull: add hgsubversion.filestoresize to control memory consumption
Patrick Mezard <patrick@mezard.eu>
parents: 889
diff changeset
400 size = ui.configint('hgsubversion', 'filestoresize', 200)
d6db289f1548 pull: add hgsubversion.filestoresize to control memory consumption
Patrick Mezard <patrick@mezard.eu>
parents: 889
diff changeset
401 if size >= 0:
d6db289f1548 pull: add hgsubversion.filestoresize to control memory consumption
Patrick Mezard <patrick@mezard.eu>
parents: 889
diff changeset
402 size = size*(2**20)
d6db289f1548 pull: add hgsubversion.filestoresize to control memory consumption
Patrick Mezard <patrick@mezard.eu>
parents: 889
diff changeset
403 else:
d6db289f1548 pull: add hgsubversion.filestoresize to control memory consumption
Patrick Mezard <patrick@mezard.eu>
parents: 889
diff changeset
404 size = -1
d6db289f1548 pull: add hgsubversion.filestoresize to control memory consumption
Patrick Mezard <patrick@mezard.eu>
parents: 889
diff changeset
405 return size
951
bd9c292665fd editor: add a small changectx cache
Patrick Mezard <patrick@mezard.eu>
parents: 944
diff changeset
406
974
336f4bce479a consolidate revision parsing
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 973
diff changeset
407 def parse_revnum(svnrepo, r):
336f4bce479a consolidate revision parsing
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 973
diff changeset
408 try:
336f4bce479a consolidate revision parsing
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 973
diff changeset
409 return int(r or 0)
336f4bce479a consolidate revision parsing
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 973
diff changeset
410 except ValueError:
975
9ffa1daf7b08 understand 'tip' as meaning Subversion 'HEAD'
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 974
diff changeset
411 if isinstance(r, str) and r.lower() in ('head', 'tip'):
974
336f4bce479a consolidate revision parsing
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 973
diff changeset
412 return svnrepo.last_changed_rev
336f4bce479a consolidate revision parsing
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 973
diff changeset
413 else:
1039
3df6ed4e7561 drop support for pre-2.0 versions of Mercurial
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 1037
diff changeset
414 raise error.RepoLookupError("unknown Subversion revision %r" % r)