annotate svnrepo.py @ 332:56d877e6ccbb

__init__: rewrite extension docstring to be slightly less hostile.
author Dan Villiom Podlaski Christiansen <danchr@gmail.com>
date Tue, 19 May 2009 11:05:45 +0200
parents 75f082b5897e
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
331
75f082b5897e Switch to using url scheme wrappers instead of duplicating each command we wrap.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 328
diff changeset
1 """
75f082b5897e Switch to using url scheme wrappers instead of duplicating each command we wrap.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 328
diff changeset
2 repository class-based interface for hgsubversion
75f082b5897e Switch to using url scheme wrappers instead of duplicating each command we wrap.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 328
diff changeset
3
75f082b5897e Switch to using url scheme wrappers instead of duplicating each command we wrap.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 328
diff changeset
4 Copyright (C) 2009, Dan Villiom Podlaski Christiansen <danchr@gmail.com>
75f082b5897e Switch to using url scheme wrappers instead of duplicating each command we wrap.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 328
diff changeset
5 See parent package for licensing.
75f082b5897e Switch to using url scheme wrappers instead of duplicating each command we wrap.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 328
diff changeset
6
75f082b5897e Switch to using url scheme wrappers instead of duplicating each command we wrap.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 328
diff changeset
7 Internally, Mercurial assumes that every single repository is a localrepository
75f082b5897e Switch to using url scheme wrappers instead of duplicating each command we wrap.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 328
diff changeset
8 subclass: pull() is called on the instance pull *to*, but not the one pulled
75f082b5897e Switch to using url scheme wrappers instead of duplicating each command we wrap.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 328
diff changeset
9 *from*. To work around this, we create two classes:
75f082b5897e Switch to using url scheme wrappers instead of duplicating each command we wrap.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 328
diff changeset
10
75f082b5897e Switch to using url scheme wrappers instead of duplicating each command we wrap.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 328
diff changeset
11 - svnremoterepo for Subversion repositories, but it doesn't really do anything.
75f082b5897e Switch to using url scheme wrappers instead of duplicating each command we wrap.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 328
diff changeset
12 - svnlocalrepo for local repositories which handles both operations on itself --
75f082b5897e Switch to using url scheme wrappers instead of duplicating each command we wrap.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 328
diff changeset
13 the local, hgsubversion-enabled clone -- and the remote repository. Decorators
75f082b5897e Switch to using url scheme wrappers instead of duplicating each command we wrap.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 328
diff changeset
14 are used to distinguish and filter these operations from others.
75f082b5897e Switch to using url scheme wrappers instead of duplicating each command we wrap.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 328
diff changeset
15 """
75f082b5897e Switch to using url scheme wrappers instead of duplicating each command we wrap.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 328
diff changeset
16
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
17 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
18 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
19 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
20
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
21 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
22 import util
33736e2e25f0 alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 158
diff changeset
23 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
24
326
33736e2e25f0 alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 158
diff changeset
25 def generate_repo_class(ui, repo):
331
75f082b5897e Switch to using url scheme wrappers instead of duplicating each command we wrap.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 328
diff changeset
26 """ This function generates the local repository wrapper. """
75f082b5897e Switch to using url scheme wrappers instead of duplicating each command we wrap.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 328
diff changeset
27
326
33736e2e25f0 alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 158
diff changeset
28 def localsvn(fn):
331
75f082b5897e Switch to using url scheme wrappers instead of duplicating each command we wrap.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 328
diff changeset
29 """
326
33736e2e25f0 alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 158
diff changeset
30 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
31 repositories.
331
75f082b5897e Switch to using url scheme wrappers instead of duplicating each command we wrap.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 328
diff changeset
32 """
326
33736e2e25f0 alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 158
diff changeset
33 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
34 return fn
33736e2e25f0 alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 158
diff changeset
35 else:
331
75f082b5897e Switch to using url scheme wrappers instead of duplicating each command we wrap.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 328
diff changeset
36 return getattr(repo, fn.__name__)
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
37
326
33736e2e25f0 alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 158
diff changeset
38 def remotesvn(fn):
331
75f082b5897e Switch to using url scheme wrappers instead of duplicating each command we wrap.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 328
diff changeset
39 """
326
33736e2e25f0 alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 158
diff changeset
40 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
41 to be a remote Subversion repository instance.
331
75f082b5897e Switch to using url scheme wrappers instead of duplicating each command we wrap.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 328
diff changeset
42 """
75f082b5897e Switch to using url scheme wrappers instead of duplicating each command we wrap.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 328
diff changeset
43 original = getattr(repo.__class__, fn.__name__)
326
33736e2e25f0 alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 158
diff changeset
44 def wrapper(self, *args, **opts):
331
75f082b5897e Switch to using url scheme wrappers instead of duplicating each command we wrap.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 328
diff changeset
45 if 'subversion' in getattr(args[0], 'capabilities', []):
326
33736e2e25f0 alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 158
diff changeset
46 return fn(self, *args, **opts)
331
75f082b5897e Switch to using url scheme wrappers instead of duplicating each command we wrap.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 328
diff changeset
47 else:
75f082b5897e Switch to using url scheme wrappers instead of duplicating each command we wrap.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 328
diff changeset
48 return original(self, *args, **opts)
326
33736e2e25f0 alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 158
diff changeset
49 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
50 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
51 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
52
326
33736e2e25f0 alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 158
diff changeset
53 class svnlocalrepo(repo.__class__):
331
75f082b5897e Switch to using url scheme wrappers instead of duplicating each command we wrap.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 328
diff changeset
54 @remotesvn
75f082b5897e Switch to using url scheme wrappers instead of duplicating each command we wrap.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 328
diff changeset
55 def push(self, remote, force=False, revs=None):
75f082b5897e Switch to using url scheme wrappers instead of duplicating each command we wrap.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 328
diff changeset
56 # TODO: pass on revs
75f082b5897e Switch to using url scheme wrappers instead of duplicating each command we wrap.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 328
diff changeset
57 wrappers.push(self, dest=remote.svnurl, force=force, revs=None)
75f082b5897e Switch to using url scheme wrappers instead of duplicating each command we wrap.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 328
diff changeset
58
326
33736e2e25f0 alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 158
diff changeset
59 @remotesvn
33736e2e25f0 alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 158
diff changeset
60 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
61 try:
33736e2e25f0 alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 158
diff changeset
62 lock = self.wlock()
331
75f082b5897e Switch to using url scheme wrappers instead of duplicating each command we wrap.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 328
diff changeset
63 wrappers.pull(self, source=remote.svnurl, rev=heads, force=force)
326
33736e2e25f0 alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 158
diff changeset
64 except KeyboardInterrupt:
33736e2e25f0 alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 158
diff changeset
65 pass
33736e2e25f0 alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 158
diff changeset
66 finally:
33736e2e25f0 alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 158
diff changeset
67 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
68
326
33736e2e25f0 alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 158
diff changeset
69 @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
70 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
71 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
72 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
73 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
74 target = hg_editor.get_parent_revision(source[1]+1, source[0])
331
75f082b5897e Switch to using url scheme wrappers instead of duplicating each command we wrap.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 328
diff changeset
75 tags['tag/%s' % tag] = 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
76 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
77
326
33736e2e25f0 alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 158
diff changeset
78 repo.__class__ = svnlocalrepo
33736e2e25f0 alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 158
diff changeset
79
33736e2e25f0 alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 158
diff changeset
80 class svnremoterepo(mercurial.repo.repository):
331
75f082b5897e Switch to using url scheme wrappers instead of duplicating each command we wrap.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 328
diff changeset
81 """ the dumb wrapper for actual Subversion repositories """
75f082b5897e Switch to using url scheme wrappers instead of duplicating each command we wrap.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 328
diff changeset
82
326
33736e2e25f0 alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 158
diff changeset
83 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
84 self.ui = ui
33736e2e25f0 alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 158
diff changeset
85 self.path = path
331
75f082b5897e Switch to using url scheme wrappers instead of duplicating each command we wrap.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 328
diff changeset
86 self.capabilities = set(['lookup', 'subversion'])
75f082b5897e Switch to using url scheme wrappers instead of duplicating each command we wrap.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 328
diff changeset
87
75f082b5897e Switch to using url scheme wrappers instead of duplicating each command we wrap.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 328
diff changeset
88 @property
75f082b5897e Switch to using url scheme wrappers instead of duplicating each command we wrap.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 328
diff changeset
89 def svnurl(self):
75f082b5897e Switch to using url scheme wrappers instead of duplicating each command we wrap.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 328
diff changeset
90 return util.normalize_url(self.path)
326
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 def url(self):
33736e2e25f0 alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 158
diff changeset
93 return self.path
33736e2e25f0 alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 158
diff changeset
94
33736e2e25f0 alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 158
diff changeset
95 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
96 return key
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 def cancopy(self):
33736e2e25f0 alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 158
diff changeset
99 return False
33736e2e25f0 alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 158
diff changeset
100
33736e2e25f0 alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 158
diff changeset
101 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
102 """
33736e2e25f0 alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 158
diff changeset
103 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
104 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
105 """
33736e2e25f0 alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 158
diff changeset
106 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
107
33736e2e25f0 alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 158
diff changeset
108 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
109 if create:
33736e2e25f0 alternate approach for supporting svn schemes for repository paths
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 158
diff changeset
110 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
111
331
75f082b5897e Switch to using url scheme wrappers instead of duplicating each command we wrap.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 328
diff changeset
112 return svnremoterepo(ui, url)