annotate hgsubversion/layouts/custom.py @ 1292:7bbe120be193

layouts: turn taglocations method into a property We no longer need to pass the meta path since we have an internal reference to the meta object, so we remove the parameter from the taglocations method.
author Sean Farley <sean.michael.farley@gmail.com>
date Mon, 24 Mar 2014 11:20:53 -0500
parents 4744b7bfa476
children f5df4bb6f330
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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 """
cd0d14e25757 layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff changeset
9
cd0d14e25757 layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff changeset
10 import base
cd0d14e25757 layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff changeset
11
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 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
14
1265
4744b7bfa476 layouts: change constructor to take a meta object
Sean Farley <sean.michael.farley@gmail.com>
parents: 1153
diff changeset
15 def __init__(self, meta):
4744b7bfa476 layouts: change constructor to take a meta object
Sean Farley <sean.michael.farley@gmail.com>
parents: 1153
diff changeset
16 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
17
cd0d14e25757 layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff changeset
18 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
19 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
20
1265
4744b7bfa476 layouts: change constructor to take a meta object
Sean Farley <sean.michael.farley@gmail.com>
parents: 1153
diff changeset
21 for hg_branch, svn_path in meta.ui.configitems('hgsubversionbranch'):
1092
cd0d14e25757 layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff changeset
22
cd0d14e25757 layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff changeset
23 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
24 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
25 hg_branch = None
cd0d14e25757 layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff changeset
26 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
27
cd0d14e25757 layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff changeset
28 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
29 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
30 msg = 'specified two hg branches for svn path %s: %s and %s'
cd0d14e25757 layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff changeset
31 raise hgutil.Abort(msg % (svn_path, other_hg, hg_branch))
cd0d14e25757 layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff changeset
32
cd0d14e25757 layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff changeset
33 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
34 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
35 msg = 'specified mappings for nested svn paths: %s and %s'
cd0d14e25757 layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff changeset
36 raise hgutl.Abort(msg % (svn_path, other_svn))
cd0d14e25757 layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff changeset
37
cd0d14e25757 layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff changeset
38 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
39 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
40
cd0d14e25757 layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff changeset
41 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
42 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
43 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
44 children = []
cd0d14e25757 layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff changeset
45 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
46 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
47 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
48 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
49 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
50
cd0d14e25757 layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff changeset
51 return '../%s' % path
cd0d14e25757 layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff changeset
52
cd0d14e25757 layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff changeset
53 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
54 if branch =='default':
cd0d14e25757 layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff changeset
55 branch = None
cd0d14e25757 layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff changeset
56 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
57 return branch[3:]
cd0d14e25757 layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff changeset
58 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
59 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
60 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
61
cd0d14e25757 layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff changeset
62 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
63 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
64 subdir += '/'
cd0d14e25757 layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff changeset
65 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
66
1292
7bbe120be193 layouts: turn taglocations method into a property
Sean Farley <sean.michael.farley@gmail.com>
parents: 1265
diff changeset
67 @property
7bbe120be193 layouts: turn taglocations method into a property
Sean Farley <sean.michael.farley@gmail.com>
parents: 1265
diff changeset
68 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
69 return []
cd0d14e25757 layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff changeset
70
cd0d14e25757 layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff changeset
71 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
72 return None
cd0d14e25757 layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff changeset
73
cd0d14e25757 layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff changeset
74 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
75 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
76 return path, ''
cd0d14e25757 layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff changeset
77 children = []
cd0d14e25757 layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff changeset
78 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
79 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
80 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
81 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
82 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
83
cd0d14e25757 layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff changeset
84 # 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
85 # 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
86 # 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
87 # 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
88 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
89 return children[0], ''
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 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
92 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
93 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
94 # -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
95 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
96 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
97 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
98
cd0d14e25757 layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff changeset
99 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
100 return children[0], ''
cd0d14e25757 layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff changeset
101
cd0d14e25757 layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff changeset
102
cd0d14e25757 layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff changeset
103 # 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
104 # 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
105 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
106 return components[0], '/'.join(components[1:])