Mercurial > hgsubversion
comparison svnrepo.py @ 328:48ec2d62dc29
Rename tag_repo.py to svnrepo.py and get rid of the 'fake' tags.
| author | Dan Villiom Podlaski Christiansen <danchr@gmail.com> |
|---|---|
| date | Sat, 09 May 2009 12:34:29 +0200 |
| parents | tag_repo.py@98740f66a70c |
| children | 75f082b5897e |
comparison
equal
deleted
inserted
replaced
| 327:98740f66a70c | 328:48ec2d62dc29 |
|---|---|
| 1 from mercurial import node | |
| 2 from mercurial import util as hgutil | |
| 3 import mercurial.repo | |
| 4 | |
| 5 import hg_delta_editor | |
| 6 import util | |
| 7 import wrappers | |
| 8 | |
| 9 def generate_repo_class(ui, repo): | |
| 10 def localsvn(fn): | |
| 11 ''' | |
| 12 Filter for instance methods which only apply to local Subversion | |
| 13 repositories. | |
| 14 ''' | |
| 15 if util.is_svn_repo(repo): | |
| 16 return fn | |
| 17 else: | |
| 18 original = repo.__getattribute__(fn.__name__) | |
| 19 return original | |
| 20 | |
| 21 def remotesvn(fn): | |
| 22 ''' | |
| 23 Filter for instance methods which require the first argument | |
| 24 to be a remote Subversion repository instance. | |
| 25 ''' | |
| 26 original = repo.__getattribute__(fn.__name__) | |
| 27 def wrapper(self, *args, **opts): | |
| 28 if not isinstance(args[0], svnremoterepo): | |
| 29 return original(*args, **opts) | |
| 30 else: | |
| 31 return fn(self, *args, **opts) | |
| 32 wrapper.__name__ = fn.__name__ + '_wrapper' | |
| 33 wrapper.__doc__ = fn.__doc__ | |
| 34 return wrapper | |
| 35 | |
| 36 class svnlocalrepo(repo.__class__): | |
| 37 @remotesvn | |
| 38 def pull(self, remote, heads=None, force=False): | |
| 39 try: | |
| 40 lock = self.wlock() | |
| 41 wrappers.pull(None, self.ui, self, source=remote.path, | |
| 42 svn=True, rev=heads, force=force) | |
| 43 except KeyboardInterrupt: | |
| 44 pass | |
| 45 finally: | |
| 46 lock.release() | |
| 47 | |
| 48 @localsvn | |
| 49 def tags(self): | |
| 50 tags = super(svnlocalrepo, self).tags() | |
| 51 hg_editor = hg_delta_editor.HgChangeReceiver(repo=self) | |
| 52 for tag, source in hg_editor.tags.iteritems(): | |
| 53 target = hg_editor.get_parent_revision(source[1]+1, source[0]) | |
| 54 tags['tag/%s' % tag] = node.hex(target) | |
| 55 return tags | |
| 56 | |
| 57 repo.__class__ = svnlocalrepo | |
| 58 | |
| 59 class svnremoterepo(mercurial.repo.repository): | |
| 60 def __init__(self, ui, path): | |
| 61 self.ui = ui | |
| 62 self.path = path | |
| 63 self.capabilities = set(['lookup']) | |
| 64 | |
| 65 def url(self): | |
| 66 return self.path | |
| 67 | |
| 68 def lookup(self, key): | |
| 69 return key | |
| 70 | |
| 71 def cancopy(self): | |
| 72 return False | |
| 73 | |
| 74 def heads(self, *args, **opts): | |
| 75 """ | |
| 76 Whenever this function is hit, we abort. The traceback is useful for | |
| 77 figuring out where to intercept the functionality. | |
| 78 """ | |
| 79 raise hgutil.Abort('command unavailable for Subversion repositories') | |
| 80 | |
| 81 def instance(ui, url, create): | |
| 82 if create: | |
| 83 raise hgutil.Abort('cannot create new remote Subversion repository') | |
| 84 | |
| 85 if url.startswith('svn+') and not url.startswith('svn+ssh:'): | |
| 86 url = url[4:] | |
| 87 return svnremoterepo(ui, util.normalize_url(url)) |
