annotate hgsubversion/layouts/custom.py @ 1265:4744b7bfa476

layouts: change constructor to take a meta object This change is another step forward to centralize subversion configuration options and help refactor. I couldn't find an easier way to split up this change since there are many interdependent function calls. There is no functionality change in this patch, only renaming ui -> meta.
author Sean Farley <sean.michael.farley@gmail.com>
date Mon, 24 Mar 2014 11:20:49 -0500
parents c3c4518e00aa
children 7bbe120be193
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
1153
c3c4518e00aa svnmeta: rename meta_data_dir to metapath
Sean Farley <sean.michael.farley@gmail.com>
parents: 1092
diff changeset
67 def taglocations(self, metapath):
1092
cd0d14e25757 layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff changeset
68 return []
cd0d14e25757 layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff changeset
69
cd0d14e25757 layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff changeset
70 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
71 return None
cd0d14e25757 layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff changeset
72
cd0d14e25757 layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff changeset
73 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
74 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
75 return path, ''
cd0d14e25757 layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff changeset
76 children = []
cd0d14e25757 layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff changeset
77 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
78 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
79 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
80 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
81 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
82
cd0d14e25757 layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff changeset
83 # 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
84 # 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
85 # 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
86 # 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
87 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
88 return children[0], ''
cd0d14e25757 layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff changeset
89
cd0d14e25757 layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff changeset
90 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
91 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
92 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
93 # -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
94 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
95 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
96 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
97
cd0d14e25757 layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff changeset
98 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
99 return children[0], ''
cd0d14e25757 layouts: add custom layout for those of us that need weird mappings
David Schleimer <dschleimer@fb.com>
parents:
diff changeset
100
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 # 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
103 # 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
104 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
105 return components[0], '/'.join(components[1:])