annotate hgsubversion/layouts/custom.py @ 1311:f5df4bb6f330

layouts: add a name property to custom
author Sean Farley <sean.michael.farley@gmail.com>
date Mon, 24 Mar 2014 11:20:55 -0500
parents 7bbe120be193
children 118e6d31b5fc
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
1311
f5df4bb6f330 layouts: add a name property to custom
Sean Farley <sean.michael.farley@gmail.com>
parents: 1292
diff changeset
41 @property
f5df4bb6f330 layouts: add a name property to custom
Sean Farley <sean.michael.farley@gmail.com>
parents: 1292
diff changeset
42 def name(self):
f5df4bb6f330 layouts: add a name property to custom
Sean Farley <sean.michael.farley@gmail.com>
parents: 1292
diff changeset
43 return 'custom'
f5df4bb6f330 layouts: add a name property to custom
Sean Farley <sean.michael.farley@gmail.com>
parents: 1292
diff changeset
44
1092
cd0d14e25757 layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff changeset
45 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
46 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
47 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
48 children = []
cd0d14e25757 layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff changeset
49 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
50 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
51 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
52 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
53 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
54
cd0d14e25757 layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff changeset
55 return '../%s' % path
cd0d14e25757 layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff changeset
56
cd0d14e25757 layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff changeset
57 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
58 if branch =='default':
cd0d14e25757 layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff changeset
59 branch = None
cd0d14e25757 layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff changeset
60 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
61 return branch[3:]
cd0d14e25757 layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff changeset
62 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
63 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
64 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
65
cd0d14e25757 layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff changeset
66 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
67 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
68 subdir += '/'
cd0d14e25757 layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff changeset
69 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
70
1292
7bbe120be193 layouts: turn taglocations method into a property
Sean Farley <sean.michael.farley@gmail.com>
parents: 1265
diff changeset
71 @property
7bbe120be193 layouts: turn taglocations method into a property
Sean Farley <sean.michael.farley@gmail.com>
parents: 1265
diff changeset
72 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
73 return []
cd0d14e25757 layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff changeset
74
cd0d14e25757 layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff changeset
75 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
76 return None
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 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
79 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
80 return path, ''
cd0d14e25757 layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff changeset
81 children = []
cd0d14e25757 layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff changeset
82 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
83 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
84 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
85 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
86 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
87
cd0d14e25757 layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff changeset
88 # 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
89 # 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
90 # 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
91 # 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
92 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
93 return children[0], ''
cd0d14e25757 layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff changeset
94
cd0d14e25757 layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff changeset
95 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
96 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
97 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
98 # -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
99 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
100 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
101 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
102
cd0d14e25757 layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff changeset
103 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
104 return children[0], ''
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
cd0d14e25757 layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff changeset
107 # 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
108 # 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
109 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
110 return components[0], '/'.join(components[1:])