Mercurial > hgsubversion
annotate tag_repo.py @ 326:33736e2e25f0
alternate approach for supporting svn schemes for repository paths
We now intercept the operations in the local repo class, and handle
the relevant operation ourselves. This frees us from wrapping all
relevant commands and replicating their functionality.
The implementation is incomplete; only one test has been modified to
use the standard Mercurial API with the changed URLs. Once changed,
those tests will likely reveal bugs or missing features in the new
wrappers. Also, new wrappers will be needed for handling conversion
flags such as -A/--authormap.
author | Dan Villiom Podlaski Christiansen <danchr@gmail.com> |
---|---|
date | Thu, 07 May 2009 20:50:53 +0200 |
parents | 91c818377703 |
children | 98740f66a70c |
rev | line source |
---|---|
124
291925677a9f
tag_repo: remove gentags command, extend repo.tags(), HgChangeEditor now takes either repo or repo_path
Luke Opperman <luke@loppear.com>
parents:
diff
changeset
|
1 from mercurial import node |
326
33736e2e25f0
alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
158
diff
changeset
|
2 from mercurial import util as hgutil |
33736e2e25f0
alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
158
diff
changeset
|
3 import mercurial.repo |
124
291925677a9f
tag_repo: remove gentags command, extend repo.tags(), HgChangeEditor now takes either repo or repo_path
Luke Opperman <luke@loppear.com>
parents:
diff
changeset
|
4 |
291925677a9f
tag_repo: remove gentags command, extend repo.tags(), HgChangeEditor now takes either repo or repo_path
Luke Opperman <luke@loppear.com>
parents:
diff
changeset
|
5 import hg_delta_editor |
326
33736e2e25f0
alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
158
diff
changeset
|
6 import util |
33736e2e25f0
alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
158
diff
changeset
|
7 import wrappers |
124
291925677a9f
tag_repo: remove gentags command, extend repo.tags(), HgChangeEditor now takes either repo or repo_path
Luke Opperman <luke@loppear.com>
parents:
diff
changeset
|
8 |
326
33736e2e25f0
alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
158
diff
changeset
|
9 def generate_repo_class(ui, repo): |
33736e2e25f0
alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
158
diff
changeset
|
10 def localsvn(fn): |
33736e2e25f0
alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
158
diff
changeset
|
11 ''' |
33736e2e25f0
alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
158
diff
changeset
|
12 Filter for instance methods which only apply to local Subversion |
33736e2e25f0
alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
158
diff
changeset
|
13 repositories. |
33736e2e25f0
alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
158
diff
changeset
|
14 ''' |
33736e2e25f0
alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
158
diff
changeset
|
15 if util.is_svn_repo(repo): |
33736e2e25f0
alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
158
diff
changeset
|
16 return fn |
33736e2e25f0
alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
158
diff
changeset
|
17 else: |
33736e2e25f0
alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
158
diff
changeset
|
18 original = repo.__getattribute__(fn.__name__) |
33736e2e25f0
alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
158
diff
changeset
|
19 return original |
124
291925677a9f
tag_repo: remove gentags command, extend repo.tags(), HgChangeEditor now takes either repo or repo_path
Luke Opperman <luke@loppear.com>
parents:
diff
changeset
|
20 |
326
33736e2e25f0
alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
158
diff
changeset
|
21 def remotesvn(fn): |
33736e2e25f0
alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
158
diff
changeset
|
22 ''' |
33736e2e25f0
alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
158
diff
changeset
|
23 Filter for instance methods which require the first argument |
33736e2e25f0
alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
158
diff
changeset
|
24 to be a remote Subversion repository instance. |
33736e2e25f0
alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
158
diff
changeset
|
25 ''' |
33736e2e25f0
alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
158
diff
changeset
|
26 original = repo.__getattribute__(fn.__name__) |
33736e2e25f0
alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
158
diff
changeset
|
27 def wrapper(self, *args, **opts): |
33736e2e25f0
alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
158
diff
changeset
|
28 print args |
33736e2e25f0
alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
158
diff
changeset
|
29 if not isinstance(args[0], svnremoterepo): |
33736e2e25f0
alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
158
diff
changeset
|
30 return original(*args, **opts) |
33736e2e25f0
alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
158
diff
changeset
|
31 else: |
33736e2e25f0
alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
158
diff
changeset
|
32 return fn(self, *args, **opts) |
33736e2e25f0
alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
158
diff
changeset
|
33 wrapper.__name__ = fn.__name__ + '_wrapper' |
33736e2e25f0
alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
158
diff
changeset
|
34 wrapper.__doc__ = fn.__doc__ |
33736e2e25f0
alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
158
diff
changeset
|
35 return wrapper |
124
291925677a9f
tag_repo: remove gentags command, extend repo.tags(), HgChangeEditor now takes either repo or repo_path
Luke Opperman <luke@loppear.com>
parents:
diff
changeset
|
36 |
326
33736e2e25f0
alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
158
diff
changeset
|
37 class svnlocalrepo(repo.__class__): |
33736e2e25f0
alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
158
diff
changeset
|
38 @remotesvn |
33736e2e25f0
alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
158
diff
changeset
|
39 def pull(self, remote, heads=None, force=False): |
33736e2e25f0
alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
158
diff
changeset
|
40 try: |
33736e2e25f0
alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
158
diff
changeset
|
41 lock = self.wlock() |
33736e2e25f0
alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
158
diff
changeset
|
42 wrappers.pull(None, self.ui, self, source=remote.path, |
33736e2e25f0
alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
158
diff
changeset
|
43 svn=True, rev=heads, force=force) |
33736e2e25f0
alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
158
diff
changeset
|
44 except KeyboardInterrupt: |
33736e2e25f0
alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
158
diff
changeset
|
45 pass |
33736e2e25f0
alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
158
diff
changeset
|
46 finally: |
33736e2e25f0
alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
158
diff
changeset
|
47 lock.release() |
124
291925677a9f
tag_repo: remove gentags command, extend repo.tags(), HgChangeEditor now takes either repo or repo_path
Luke Opperman <luke@loppear.com>
parents:
diff
changeset
|
48 |
326
33736e2e25f0
alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
158
diff
changeset
|
49 @localsvn |
124
291925677a9f
tag_repo: remove gentags command, extend repo.tags(), HgChangeEditor now takes either repo or repo_path
Luke Opperman <luke@loppear.com>
parents:
diff
changeset
|
50 def tags(self): |
326
33736e2e25f0
alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
158
diff
changeset
|
51 tags = super(svnlocalrepo, self).tags() |
33736e2e25f0
alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
158
diff
changeset
|
52 hg_editor = hg_delta_editor.HgChangeReceiver(repo=self) |
33736e2e25f0
alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
158
diff
changeset
|
53 for tag, source in hg_editor.tags.iteritems(): |
33736e2e25f0
alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
158
diff
changeset
|
54 target = hg_editor.get_parent_revision(source[1]+1, source[0]) |
33736e2e25f0
alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
158
diff
changeset
|
55 tags['tag/%s' % tag] = node.hex(target) |
33736e2e25f0
alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
158
diff
changeset
|
56 # TODO: should we even generate these tags? |
33736e2e25f0
alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
158
diff
changeset
|
57 if not hasattr(self, '_nofaketags'): |
33736e2e25f0
alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
158
diff
changeset
|
58 for (revnum, branch), node_hash in hg_editor.revmap.iteritems(): |
33736e2e25f0
alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
158
diff
changeset
|
59 tags['%s@r%d' % (branch or 'trunk', revnum)] = node_hash |
124
291925677a9f
tag_repo: remove gentags command, extend repo.tags(), HgChangeEditor now takes either repo or repo_path
Luke Opperman <luke@loppear.com>
parents:
diff
changeset
|
60 return tags |
291925677a9f
tag_repo: remove gentags command, extend repo.tags(), HgChangeEditor now takes either repo or repo_path
Luke Opperman <luke@loppear.com>
parents:
diff
changeset
|
61 |
326
33736e2e25f0
alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
158
diff
changeset
|
62 @localsvn |
33736e2e25f0
alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
158
diff
changeset
|
63 def tagslist(self): |
33736e2e25f0
alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
158
diff
changeset
|
64 try: |
33736e2e25f0
alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
158
diff
changeset
|
65 self._nofaketags = True |
33736e2e25f0
alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
158
diff
changeset
|
66 return super(svnlocalrepo, self).tagslist() |
33736e2e25f0
alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
158
diff
changeset
|
67 finally: |
33736e2e25f0
alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
158
diff
changeset
|
68 del self._nofaketags |
33736e2e25f0
alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
158
diff
changeset
|
69 |
33736e2e25f0
alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
158
diff
changeset
|
70 repo.__class__ = svnlocalrepo |
33736e2e25f0
alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
158
diff
changeset
|
71 |
33736e2e25f0
alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
158
diff
changeset
|
72 class svnremoterepo(mercurial.repo.repository): |
33736e2e25f0
alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
158
diff
changeset
|
73 def __init__(self, ui, path): |
33736e2e25f0
alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
158
diff
changeset
|
74 self.ui = ui |
33736e2e25f0
alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
158
diff
changeset
|
75 self.path = path |
33736e2e25f0
alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
158
diff
changeset
|
76 self.capabilities = set(['lookup']) |
33736e2e25f0
alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
158
diff
changeset
|
77 |
33736e2e25f0
alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
158
diff
changeset
|
78 def url(self): |
33736e2e25f0
alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
158
diff
changeset
|
79 return self.path |
33736e2e25f0
alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
158
diff
changeset
|
80 |
33736e2e25f0
alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
158
diff
changeset
|
81 def lookup(self, key): |
33736e2e25f0
alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
158
diff
changeset
|
82 return key |
33736e2e25f0
alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
158
diff
changeset
|
83 |
33736e2e25f0
alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
158
diff
changeset
|
84 def cancopy(self): |
33736e2e25f0
alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
158
diff
changeset
|
85 return False |
33736e2e25f0
alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
158
diff
changeset
|
86 |
33736e2e25f0
alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
158
diff
changeset
|
87 def heads(self, *args, **opts): |
33736e2e25f0
alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
158
diff
changeset
|
88 """ |
33736e2e25f0
alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
158
diff
changeset
|
89 Whenever this function is hit, we abort. The traceback is useful for |
33736e2e25f0
alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
158
diff
changeset
|
90 figuring out where to intercept the functionality. |
33736e2e25f0
alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
158
diff
changeset
|
91 """ |
33736e2e25f0
alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
158
diff
changeset
|
92 raise hgutil.Abort('command unavailable for Subversion repositories') |
33736e2e25f0
alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
158
diff
changeset
|
93 |
33736e2e25f0
alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
158
diff
changeset
|
94 def instance(ui, url, create): |
33736e2e25f0
alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
158
diff
changeset
|
95 if create: |
33736e2e25f0
alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
158
diff
changeset
|
96 raise hgutil.Abort('cannot create new remote Subversion repository') |
33736e2e25f0
alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
158
diff
changeset
|
97 |
33736e2e25f0
alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
158
diff
changeset
|
98 if url.startswith('svn+') and not url.startswith('svn+ssh:'): |
33736e2e25f0
alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
158
diff
changeset
|
99 url = url[4:] |
33736e2e25f0
alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
158
diff
changeset
|
100 return svnremoterepo(ui, util.normalize_url(url)) |