This repository has been archived by the owner on Nov 9, 2017. It is now read-only.
forked from git-for-windows/git
-
Notifications
You must be signed in to change notification settings - Fork 316
/
git-remote-hg.py
101 lines (73 loc) · 2.64 KB
/
git-remote-hg.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/usr/bin/env python
import sys
import os
sys.path.insert(0, os.getenv("GITPYTHONLIB","."))
from git_remote_helpers.helper import RemoteHelper
from git_remote_helpers.util import debug, die, warn
from git_remote_helpers.hg import util
from git_remote_helpers.hg.hg import GitHg
from git_remote_helpers.hg.exporter import GitExporter
from git_remote_helpers.hg.importer import GitImporter
from git_remote_helpers.hg.non_local import NonLocalHg
class HgRemoteHelper(RemoteHelper):
def get_repo(self, alias, url):
"""Returns a hg.repository object initialized for usage.
"""
try:
from mercurial import hg, ui
except ImportError:
die("Mercurial python libraries not installed")
remote = False
if url.startswith("remote://"):
remote = True
url = "file://%s" % url[9:]
ui = ui.ui()
source, revs, checkout = util.parseurl(ui.expandpath(url), ['default'])
repo = hg.repository(ui, source)
if repo.capable('branchmap'):
revs += repo.branchmap().keys()
revs = set(revs)
prefix = 'refs/hg/%s/' % alias
debug("prefix: '%s'", prefix)
repo.marksfile = 'git.marks'
repo.hg = hg
repo.prefix = prefix
repo.revs_ = revs # must not override repo.revs()
self.setup_repo(repo, alias)
repo.git_hg = GitHg(warn)
repo.exporter = GitExporter(repo)
repo.importer = GitImporter(repo)
repo.non_local = NonLocalHg(repo)
repo.is_local = not remote and repo.local()
return repo
def local_repo(self, repo, path):
"""Returns a hg.repository object initalized for usage.
"""
local = repo.hg.repository(repo.ui, path)
self.setup_local_repo(local, repo)
local.git_hg = repo.git_hg
local.hg = repo.hg
local.revs_ = repo.revs_
local.exporter = GitExporter(local)
local.importer = GitImporter(local)
local.is_local = repo.is_local
return local
def do_list(self, repo, args):
"""Lists all known references.
"""
for ref in repo.revs_:
debug("? refs/heads/%s", ref)
print "? refs/heads/%s" % ref
debug("@refs/heads/default HEAD")
print "@refs/heads/default HEAD"
print # end list
def sanitize(self, value):
"""Cleans up the url.
"""
if value.startswith('hg::'):
value = value[4:]
return value
def get_refs(self, repo, gitdir):
return repo.branchmap()
if __name__ == '__main__':
sys.exit(HgRemoteHelper().main(sys.argv))