annotate svnrepo.py @ 330:5f8f2fd4fd54

hg_delta_editor: simplify repository instantiation.
author Dan Villiom Podlaski Christiansen <danchr@gmail.com>
date Sat, 09 May 2009 14:46:12 +0200
parents 48ec2d62dc29
children 75f082b5897e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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 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
29 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
30 else:
33736e2e25f0 alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 158
diff changeset
31 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
32 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
33 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
34 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
35
326
33736e2e25f0 alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 158
diff changeset
36 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
37 @remotesvn
33736e2e25f0 alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 158
diff changeset
38 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
39 try:
33736e2e25f0 alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 158
diff changeset
40 lock = self.wlock()
33736e2e25f0 alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 158
diff changeset
41 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
42 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
43 except KeyboardInterrupt:
33736e2e25f0 alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 158
diff changeset
44 pass
33736e2e25f0 alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 158
diff changeset
45 finally:
33736e2e25f0 alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 158
diff changeset
46 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
47
326
33736e2e25f0 alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 158
diff changeset
48 @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
49 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
50 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
51 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
52 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
53 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
54 tags['tag/%s' % tag] = node.hex(target)
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
55 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
56
326
33736e2e25f0 alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 158
diff changeset
57 repo.__class__ = svnlocalrepo
33736e2e25f0 alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 158
diff changeset
58
33736e2e25f0 alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 158
diff changeset
59 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
60 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
61 self.ui = ui
33736e2e25f0 alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 158
diff changeset
62 self.path = path
33736e2e25f0 alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 158
diff changeset
63 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
64
33736e2e25f0 alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 158
diff changeset
65 def url(self):
33736e2e25f0 alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 158
diff changeset
66 return self.path
33736e2e25f0 alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 158
diff changeset
67
33736e2e25f0 alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 158
diff changeset
68 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
69 return key
33736e2e25f0 alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 158
diff changeset
70
33736e2e25f0 alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 158
diff changeset
71 def cancopy(self):
33736e2e25f0 alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 158
diff changeset
72 return False
33736e2e25f0 alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 158
diff changeset
73
33736e2e25f0 alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 158
diff changeset
74 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
75 """
33736e2e25f0 alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 158
diff changeset
76 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
77 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
78 """
33736e2e25f0 alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 158
diff changeset
79 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
80
33736e2e25f0 alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 158
diff changeset
81 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
82 if create:
33736e2e25f0 alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 158
diff changeset
83 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
84
33736e2e25f0 alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 158
diff changeset
85 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
86 url = url[4:]
33736e2e25f0 alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 158
diff changeset
87 return svnremoterepo(ui, util.normalize_url(url))