French translation: copy -> copie.
[git/dscho.git] / git-remote-hg.py
blob4b619e9c4ca157d1751ccbc3be5ee5f2d8e8c82c
1 #!/usr/bin/env python
3 import sys
4 import os
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.
19 """
21 try:
22 from mercurial import hg, ui
23 except ImportError:
24 die("Mercurial python libraries not installed")
26 remote = False
28 if url.startswith("remote://"):
29 remote = True
30 url = "file://%s" % url[9:]
32 ui = ui.ui()
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()
37 revs = set(revs)
39 prefix = 'refs/hg/%s/' % alias
40 debug("prefix: '%s'", prefix)
42 repo.marksfile = 'git.marks'
43 repo.hg = hg
44 repo.prefix = prefix
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()
56 return repo
58 def local_repo(self, repo, path):
59 """Returns a hg.repository object initalized for usage.
60 """
62 local = repo.hg.repository(repo.ui, path)
64 self.setup_local_repo(local, repo)
66 local.git_hg = repo.git_hg
67 local.hg = repo.hg
68 local.revs_ = repo.revs_
69 local.exporter = GitExporter(local)
70 local.importer = GitImporter(local)
71 local.is_local = repo.is_local
73 return local
75 def do_list(self, repo, args):
76 """Lists all known references.
77 """
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"
86 print # end list
88 def sanitize(self, value):
89 """Cleans up the url.
90 """
92 if value.startswith('hg::'):
93 value = value[4:]
95 return value
97 def get_refs(self, repo, gitdir):
98 return repo.branchmap()
100 if __name__ == '__main__':
101 sys.exit(HgRemoteHelper().main(sys.argv))