Skip to content
Newer
Older
100644 82 lines (66 sloc) 3.01 KB
59c7b6d @durin42 hgrepo: completely rework handing of remote refs marking
durin42 authored
1 import os
2
82f1c1a @abderrahim hgrepo: remove unused imports
abderrahim authored
3 from mercurial.node import bin
4f43cdf @schacon almost got everything working
schacon authored
4
73a0dbc @abderrahim Initial clone/pull/push support for git repositories
abderrahim authored
5 from git_handler import GitHandler
6 from gitrepo import gitrepo
7
8
18ce680 @abderrahim create the repository subclass in reposetup
abderrahim authored
9 def generate_repo_subclass(baseclass):
10 class hgrepo(baseclass):
11 def pull(self, remote, heads=None, force=False):
12 if isinstance(remote, gitrepo):
13 git = GitHandler(self, self.ui)
835b6e4 @bcully Make pull results more like hg pulls.
bcully authored
14 return git.fetch(remote.path, heads)
8453b63 @abderrahim add some annotations for test coverage
abderrahim authored
15 else: #pragma: no cover
1bfa167 @abderrahim hgrepo: forward the return value of pull and push (fixes issue 8 bb)
abderrahim authored
16 return super(hgrepo, self).pull(remote, heads, force)
18ce680 @abderrahim create the repository subclass in reposetup
abderrahim authored
17
0b20fae @durin42 push: handle argspec change from e43c23d189a5
durin42 authored
18 # TODO figure out something useful to do with the newbranch param
19 def push(self, remote, force=False, revs=None, newbranch=None):
18ce680 @abderrahim create the repository subclass in reposetup
abderrahim authored
20 if isinstance(remote, gitrepo):
21 git = GitHandler(self, self.ui)
ba8f84c @abderrahim rework pushing to support --rev and --force options
abderrahim authored
22 git.push(remote.path, revs, force)
8453b63 @abderrahim add some annotations for test coverage
abderrahim authored
23 else: #pragma: no cover
b32669f @durin42 tests: import test-push-r (with slight changes) from Mercurial
durin42 authored
24 # newbranch was added in 1.6
25 if newbranch is None:
26 return super(hgrepo, self).push(remote, force, revs)
27 else:
28 return super(hgrepo, self).push(remote, force, revs,
29 newbranch)
18ce680 @abderrahim create the repository subclass in reposetup
abderrahim authored
30
04fa9f0 @abderrahim initial support for 'hg outgoing'
abderrahim authored
31 def findoutgoing(self, remote, base=None, heads=None, force=False):
32 if isinstance(remote, gitrepo):
33 git = GitHandler(self, self.ui)
34 base, heads = git.get_refs(remote.path)
35 out, h = super(hgrepo, self).findoutgoing(remote, base, heads, force)
36 return out
37 else: #pragma: no cover
38 return super(hgrepo, self).findoutgoing(remote, base, heads, force)
39
47d8642 @abderrahim handle the new tag cache in mercurial crew
abderrahim authored
40 def _findtags(self):
41 (tags, tagtypes) = super(hgrepo, self)._findtags()
42
43 git = GitHandler(self, self.ui)
44 for tag, rev in git.tags.iteritems():
45 tags[tag] = bin(rev)
46 tagtypes[tag] = 'git'
47
48 return (tags, tagtypes)
49
59c7b6d @durin42 hgrepo: completely rework handing of remote refs marking
durin42 authored
50 def gitrefs(self):
51 tagfile = self.join(os.path.join('git-remote-refs'))
52 if os.path.exists(tagfile):
53 tf = open(tagfile, 'rb')
54 tagdata = tf.read().split('\n')
55 td = [line.split(' ', 1) for line in tagdata if line]
56 return dict([(name, bin(sha)) for sha, name in td])
57 return {}
58
18ce680 @abderrahim create the repository subclass in reposetup
abderrahim authored
59 def tags(self):
ae0b0be @sampsyo use new names for tags cache attributes if they're available
sampsyo authored
60 if hasattr(self, 'tagscache') and self.tagscache:
61 # Mercurial 1.4 and earlier.
18ce680 @abderrahim create the repository subclass in reposetup
abderrahim authored
62 return self.tagscache
ae0b0be @sampsyo use new names for tags cache attributes if they're available
sampsyo authored
63 elif hasattr(self, '_tags') and self._tags:
64 # Mercurial 1.5 and later.
65 return self._tags
c6b9fad @abderrahim Store git tags in .hg/git-tags and let localtags be *local*
abderrahim authored
66
18ce680 @abderrahim create the repository subclass in reposetup
abderrahim authored
67 git = GitHandler(self, self.ui)
68 tagscache = super(hgrepo, self).tags()
ae0b0be @sampsyo use new names for tags cache attributes if they're available
sampsyo authored
69 tagscache.update(self.gitrefs())
47d8642 @abderrahim handle the new tag cache in mercurial crew
abderrahim authored
70 for tag, rev in git.tags.iteritems():
71 if tag in tagscache:
72 continue
73
74 tagscache[tag] = bin(rev)
ae0b0be @sampsyo use new names for tags cache attributes if they're available
sampsyo authored
75 if hasattr(self, '_tagstypecache'):
76 # Only present in Mercurial 1.3 and earlier.
77 self._tagstypecache[tag] = 'git'
47d8642 @abderrahim handle the new tag cache in mercurial crew
abderrahim authored
78
18ce680 @abderrahim create the repository subclass in reposetup
abderrahim authored
79 return tagscache
c6b9fad @abderrahim Store git tags in .hg/git-tags and let localtags be *local*
abderrahim authored
80
18ce680 @abderrahim create the repository subclass in reposetup
abderrahim authored
81 return hgrepo
Something went wrong with that request. Please try again.