5 sys
.path
.insert(0, os
.getenv("GITPYTHONLIB","."))
7 from git_remote_helpers
.helper
import RemoteHelper
8 from git_remote_helpers
.util
import debug
, die
, warn
9 from git_remote_helpers
.hg
import util
10 from git_remote_helpers
.hg
.hg
import GitHg
11 from git_remote_helpers
.hg
.exporter
import GitExporter
12 from git_remote_helpers
.hg
.importer
import GitImporter
13 from git_remote_helpers
.hg
.non_local
import NonLocalHg
16 class HgRemoteHelper(RemoteHelper
):
17 def get_repo(self
, alias
, url
):
18 """Returns a hg.repository object initialized for usage.
22 from mercurial
import hg
, ui
24 die("Mercurial python libraries not installed")
28 if url
.startswith("remote://"):
30 url
= "file://%s" % url
[9:]
33 source
, revs
, checkout
= util
.parseurl(ui
.expandpath(url
), ['default'])
34 repo
= hg
.repository(ui
, source
)
35 if repo
.capable('branchmap'):
36 revs
+= repo
.branchmap().keys()
39 prefix
= 'refs/hg/%s/' % alias
40 debug("prefix: '%s'", prefix
)
42 repo
.marksfile
= 'git.marks'
45 repo
.revs_
= revs
# must not override repo.revs()
47 self
.setup_repo(repo
, alias
)
49 repo
.git_hg
= GitHg(warn
)
50 repo
.exporter
= GitExporter(repo
)
51 repo
.importer
= GitImporter(repo
)
52 repo
.non_local
= NonLocalHg(repo
)
54 repo
.is_local
= not remote
and repo
.local()
58 def local_repo(self
, repo
, path
):
59 """Returns a hg.repository object initalized for usage.
62 local
= repo
.hg
.repository(repo
.ui
, path
)
64 self
.setup_local_repo(local
, repo
)
66 local
.git_hg
= repo
.git_hg
68 local
.revs_
= repo
.revs_
69 local
.exporter
= GitExporter(local
)
70 local
.importer
= GitImporter(local
)
71 local
.is_local
= repo
.is_local
75 def do_list(self
, repo
, args
):
76 """Lists all known references.
79 for ref
in repo
.revs_
:
80 debug("? refs/heads/%s", ref
)
81 print "? refs/heads/%s" % ref
83 debug("@refs/heads/default HEAD")
84 print "@refs/heads/default HEAD"
88 def sanitize(self
, value
):
92 if value
.startswith('hg::'):
97 def get_refs(self
, repo
, gitdir
):
98 return repo
.branchmap()
100 if __name__
== '__main__':
101 sys
.exit(HgRemoteHelper().main(sys
.argv
))