Mercurial > hgsubversion
annotate hgsubversion/layouts/custom.py @ 1555:cff81f35b31e
cleanup: reference Abort from mercurial.error instead of mercurial.util
It's been there since hg 1.7 or so, which lets us avoid any need for
compat shims.
author | Augie Fackler <raf@durin42.com> |
---|---|
date | Sat, 24 Mar 2018 16:39:30 -0400 |
parents | 118e6d31b5fc |
children |
rev | line source |
---|---|
1092
cd0d14e25757
layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff
changeset
|
1 """Layout that allows you to define arbitrary subversion to mercurial mappings. |
cd0d14e25757
layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff
changeset
|
2 |
cd0d14e25757
layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff
changeset
|
3 This is the simplest layout to use if your layout is just plain weird. |
cd0d14e25757
layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff
changeset
|
4 Also useful if your layout is pretty normal, but you personally only |
cd0d14e25757
layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff
changeset
|
5 want a couple of branches. |
cd0d14e25757
layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff
changeset
|
6 |
cd0d14e25757
layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff
changeset
|
7 |
cd0d14e25757
layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff
changeset
|
8 """ |
1555
cff81f35b31e
cleanup: reference Abort from mercurial.error instead of mercurial.util
Augie Fackler <raf@durin42.com>
parents:
1328
diff
changeset
|
9 from mercurial import error as hgerror |
1092
cd0d14e25757
layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff
changeset
|
10 |
cd0d14e25757
layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff
changeset
|
11 import base |
cd0d14e25757
layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff
changeset
|
12 |
cd0d14e25757
layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff
changeset
|
13 |
cd0d14e25757
layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff
changeset
|
14 class CustomLayout(base.BaseLayout): |
cd0d14e25757
layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff
changeset
|
15 |
1265
4744b7bfa476
layouts: change constructor to take a meta object
Sean Farley <sean.michael.farley@gmail.com>
parents:
1153
diff
changeset
|
16 def __init__(self, meta): |
4744b7bfa476
layouts: change constructor to take a meta object
Sean Farley <sean.michael.farley@gmail.com>
parents:
1153
diff
changeset
|
17 base.BaseLayout.__init__(self, meta) |
1092
cd0d14e25757
layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff
changeset
|
18 |
cd0d14e25757
layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff
changeset
|
19 self.svn_to_hg = {} |
cd0d14e25757
layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff
changeset
|
20 self.hg_to_svn = {} |
cd0d14e25757
layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff
changeset
|
21 |
1328
118e6d31b5fc
layouts: generate cached property for custom branches
Sean Farley <sean.michael.farley@gmail.com>
parents:
1311
diff
changeset
|
22 meta._gen_cachedconfig('custombranches', {}, configname='hgsubversionbranch') |
118e6d31b5fc
layouts: generate cached property for custom branches
Sean Farley <sean.michael.farley@gmail.com>
parents:
1311
diff
changeset
|
23 |
118e6d31b5fc
layouts: generate cached property for custom branches
Sean Farley <sean.michael.farley@gmail.com>
parents:
1311
diff
changeset
|
24 for hg_branch, svn_path in meta.custombranches.iteritems(): |
1092
cd0d14e25757
layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff
changeset
|
25 |
cd0d14e25757
layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff
changeset
|
26 hg_branch = hg_branch.strip() |
cd0d14e25757
layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff
changeset
|
27 if hg_branch == 'default' or not hg_branch: |
cd0d14e25757
layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff
changeset
|
28 hg_branch = None |
cd0d14e25757
layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff
changeset
|
29 svn_path = svn_path.strip('/') |
cd0d14e25757
layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff
changeset
|
30 |
cd0d14e25757
layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff
changeset
|
31 for other_svn in self.svn_to_hg: |
cd0d14e25757
layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff
changeset
|
32 if other_svn == svn_path: |
cd0d14e25757
layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff
changeset
|
33 msg = 'specified two hg branches for svn path %s: %s and %s' |
1555
cff81f35b31e
cleanup: reference Abort from mercurial.error instead of mercurial.util
Augie Fackler <raf@durin42.com>
parents:
1328
diff
changeset
|
34 raise hgerror.Abort(msg % (svn_path, other_hg, hg_branch)) |
1092
cd0d14e25757
layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff
changeset
|
35 |
cd0d14e25757
layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff
changeset
|
36 if (other_svn.startswith(svn_path + '/') or |
cd0d14e25757
layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff
changeset
|
37 svn_path.startswith(other_svn + '/')): |
cd0d14e25757
layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff
changeset
|
38 msg = 'specified mappings for nested svn paths: %s and %s' |
1555
cff81f35b31e
cleanup: reference Abort from mercurial.error instead of mercurial.util
Augie Fackler <raf@durin42.com>
parents:
1328
diff
changeset
|
39 raise hgerror.Abort(msg % (svn_path, other_svn)) |
1092
cd0d14e25757
layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff
changeset
|
40 |
cd0d14e25757
layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff
changeset
|
41 self.svn_to_hg[svn_path] = hg_branch |
cd0d14e25757
layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff
changeset
|
42 self.hg_to_svn[hg_branch] = svn_path |
cd0d14e25757
layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff
changeset
|
43 |
1311
f5df4bb6f330
layouts: add a name property to custom
Sean Farley <sean.michael.farley@gmail.com>
parents:
1292
diff
changeset
|
44 @property |
f5df4bb6f330
layouts: add a name property to custom
Sean Farley <sean.michael.farley@gmail.com>
parents:
1292
diff
changeset
|
45 def name(self): |
f5df4bb6f330
layouts: add a name property to custom
Sean Farley <sean.michael.farley@gmail.com>
parents:
1292
diff
changeset
|
46 return 'custom' |
f5df4bb6f330
layouts: add a name property to custom
Sean Farley <sean.michael.farley@gmail.com>
parents:
1292
diff
changeset
|
47 |
1092
cd0d14e25757
layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff
changeset
|
48 def localname(self, path): |
cd0d14e25757
layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff
changeset
|
49 if path in self.svn_to_hg: |
cd0d14e25757
layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff
changeset
|
50 return self.svn_to_hg[path] |
cd0d14e25757
layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff
changeset
|
51 children = [] |
cd0d14e25757
layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff
changeset
|
52 for svn_path in self.svn_to_hg: |
cd0d14e25757
layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff
changeset
|
53 if svn_path.startswith(path + '/'): |
cd0d14e25757
layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff
changeset
|
54 children.append(svn_path) |
cd0d14e25757
layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff
changeset
|
55 if len(children) == 1: |
cd0d14e25757
layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff
changeset
|
56 return self.svn_to_hg[children[0]] |
cd0d14e25757
layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff
changeset
|
57 |
cd0d14e25757
layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff
changeset
|
58 return '../%s' % path |
cd0d14e25757
layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff
changeset
|
59 |
cd0d14e25757
layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff
changeset
|
60 def remotename(self, branch): |
cd0d14e25757
layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff
changeset
|
61 if branch =='default': |
cd0d14e25757
layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff
changeset
|
62 branch = None |
cd0d14e25757
layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff
changeset
|
63 if branch and branch.startswith('../'): |
cd0d14e25757
layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff
changeset
|
64 return branch[3:] |
cd0d14e25757
layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff
changeset
|
65 if branch not in self.hg_to_svn: |
cd0d14e25757
layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff
changeset
|
66 raise KeyError('Unknown mercurial branch: %s' % branch) |
cd0d14e25757
layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff
changeset
|
67 return self.hg_to_svn[branch] |
cd0d14e25757
layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff
changeset
|
68 |
cd0d14e25757
layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff
changeset
|
69 def remotepath(self, branch, subdir='/'): |
cd0d14e25757
layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff
changeset
|
70 if not subdir.endswith('/'): |
cd0d14e25757
layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff
changeset
|
71 subdir += '/' |
cd0d14e25757
layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff
changeset
|
72 return subdir + self.remotename(branch) |
cd0d14e25757
layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff
changeset
|
73 |
1292
7bbe120be193
layouts: turn taglocations method into a property
Sean Farley <sean.michael.farley@gmail.com>
parents:
1265
diff
changeset
|
74 @property |
7bbe120be193
layouts: turn taglocations method into a property
Sean Farley <sean.michael.farley@gmail.com>
parents:
1265
diff
changeset
|
75 def taglocations(self): |
1092
cd0d14e25757
layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff
changeset
|
76 return [] |
cd0d14e25757
layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff
changeset
|
77 |
cd0d14e25757
layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff
changeset
|
78 def get_path_tag(self, path, taglocations): |
cd0d14e25757
layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff
changeset
|
79 return None |
cd0d14e25757
layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff
changeset
|
80 |
cd0d14e25757
layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff
changeset
|
81 def split_remote_name(self, path, known_branches): |
cd0d14e25757
layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff
changeset
|
82 if path in self.svn_to_hg: |
cd0d14e25757
layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff
changeset
|
83 return path, '' |
cd0d14e25757
layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff
changeset
|
84 children = [] |
cd0d14e25757
layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff
changeset
|
85 for svn_path in self.svn_to_hg: |
cd0d14e25757
layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff
changeset
|
86 if path.startswith(svn_path + '/'): |
cd0d14e25757
layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff
changeset
|
87 return svn_path, path[len(svn_path)+1:] |
cd0d14e25757
layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff
changeset
|
88 if svn_path.startswith(path + '/'): |
cd0d14e25757
layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff
changeset
|
89 children.append(svn_path) |
cd0d14e25757
layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff
changeset
|
90 |
cd0d14e25757
layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff
changeset
|
91 # if the path represents the parent of exactly one of our svn |
cd0d14e25757
layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff
changeset
|
92 # branches, treat it as though it were that branch, because |
cd0d14e25757
layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff
changeset
|
93 # that means we are probably pulling in a subproject of an svn |
cd0d14e25757
layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff
changeset
|
94 # project, and someone copied the parent svn project. |
cd0d14e25757
layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff
changeset
|
95 if len(children) == 1: |
cd0d14e25757
layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff
changeset
|
96 return children[0], '' |
cd0d14e25757
layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff
changeset
|
97 |
cd0d14e25757
layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff
changeset
|
98 for branch in known_branches: |
cd0d14e25757
layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff
changeset
|
99 if branch and branch.startswith('../'): |
cd0d14e25757
layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff
changeset
|
100 if path.startswith(branch[3:] + '/'): |
cd0d14e25757
layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff
changeset
|
101 # -3 for the leading ../, plus one for the trailing / |
cd0d14e25757
layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff
changeset
|
102 return branch[3:], path[len(branch) - 2:] |
cd0d14e25757
layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff
changeset
|
103 if branch[3:].startswith(path + '/'): |
cd0d14e25757
layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff
changeset
|
104 children.append(branch[3:]) |
cd0d14e25757
layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff
changeset
|
105 |
cd0d14e25757
layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff
changeset
|
106 if len(children) == 1: |
cd0d14e25757
layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff
changeset
|
107 return children[0], '' |
cd0d14e25757
layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff
changeset
|
108 |
cd0d14e25757
layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff
changeset
|
109 |
cd0d14e25757
layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff
changeset
|
110 # this splits on the rightmost '/' but considers the entire |
cd0d14e25757
layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff
changeset
|
111 # string to be the branch component of the path if there is no '/' |
cd0d14e25757
layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff
changeset
|
112 components = path.rsplit('/', 1) |
cd0d14e25757
layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff
changeset
|
113 return components[0], '/'.join(components[1:]) |