##// END OF EJS Templates
convert: add bookmarks reading support to git backend
Edouard Gomez -
r13756:6b7077df default
parent child Browse files
Show More
@@ -17,19 +17,27 b' class convert_git(converter_source):'
17 # cannot remove environment variable. Just assume none have
17 # cannot remove environment variable. Just assume none have
18 # both issues.
18 # both issues.
19 if hasattr(os, 'unsetenv'):
19 if hasattr(os, 'unsetenv'):
20 def gitopen(self, s):
20 def gitopen(self, s, noerr=False):
21 prevgitdir = os.environ.get('GIT_DIR')
21 prevgitdir = os.environ.get('GIT_DIR')
22 os.environ['GIT_DIR'] = self.path
22 os.environ['GIT_DIR'] = self.path
23 try:
23 try:
24 return util.popen(s, 'rb')
24 if noerr:
25 (stdin, stdout, stderr) = util.popen3(s)
26 return stdout
27 else:
28 return util.popen(s, 'rb')
25 finally:
29 finally:
26 if prevgitdir is None:
30 if prevgitdir is None:
27 del os.environ['GIT_DIR']
31 del os.environ['GIT_DIR']
28 else:
32 else:
29 os.environ['GIT_DIR'] = prevgitdir
33 os.environ['GIT_DIR'] = prevgitdir
30 else:
34 else:
31 def gitopen(self, s):
35 def gitopen(self, s, noerr=False):
32 return util.popen('GIT_DIR=%s %s' % (self.path, s), 'rb')
36 if noerr:
37 (sin, so, se) = util.popen3('GIT_DIR=%s %s' % (self.path, s))
38 return stdout
39 else:
40 util.popen('GIT_DIR=%s %s' % (self.path, s), 'rb')
33
41
34 def gitread(self, s):
42 def gitread(self, s):
35 fh = self.gitopen(s)
43 fh = self.gitopen(s)
@@ -168,3 +176,30 b' class convert_git(converter_source):'
168 raise util.Abort(_('cannot read changes in %s') % version)
176 raise util.Abort(_('cannot read changes in %s') % version)
169
177
170 return changes
178 return changes
179
180 def getbookmarks(self):
181 bookmarks = {}
182
183 # Interesting references in git are prefixed
184 prefix = 'refs/heads/'
185 prefixlen = len(prefix)
186
187 # factor two commands
188 gitcmd = { 'remote/': 'git ls-remote --heads origin',
189 '': 'git show-ref'}
190
191 # Origin heads
192 for reftype in gitcmd:
193 try:
194 fh = self.gitopen(gitcmd[reftype], noerr=True)
195 for line in fh:
196 line = line.strip()
197 rev, name = line.split(None, 1)
198 if not name.startswith(prefix):
199 continue
200 name = '%s%s' % (reftype, name[prefixlen:])
201 bookmarks[name] = rev
202 except:
203 pass
204
205 return bookmarks
@@ -57,9 +57,11 b' Remove the directory, then try to replac'
57 2 t4.1
57 2 t4.1
58 1 t4.2
58 1 t4.2
59 0 Merge branch other
59 0 Merge branch other
60 updating bookmarks
60 $ hg up -q -R git-repo-hg
61 $ hg up -q -R git-repo-hg
61 $ hg -R git-repo-hg tip -v
62 $ hg -R git-repo-hg tip -v
62 changeset: 5:c78094926be2
63 changeset: 5:c78094926be2
64 bookmark: master
63 tag: tip
65 tag: tip
64 parent: 3:f5f5cb45432b
66 parent: 3:f5f5cb45432b
65 parent: 4:4e174f80c67c
67 parent: 4:4e174f80c67c
@@ -217,6 +219,7 b' convert binary file'
217 sorting...
219 sorting...
218 converting...
220 converting...
219 0 addbinary
221 0 addbinary
222 updating bookmarks
220 $ cd git-repo3-hg
223 $ cd git-repo3-hg
221 $ hg up -C
224 $ hg up -C
222 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
225 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
@@ -248,8 +251,10 b' convert author committer'
248 converting...
251 converting...
249 1 addfoo
252 1 addfoo
250 0 addfoo2
253 0 addfoo2
254 updating bookmarks
251 $ hg -R git-repo4-hg log -v
255 $ hg -R git-repo4-hg log -v
252 changeset: 1:d63e967f93da
256 changeset: 1:d63e967f93da
257 bookmark: master
253 tag: tip
258 tag: tip
254 user: nottest <test@example.org>
259 user: nottest <test@example.org>
255 date: Mon Jan 01 00:00:21 2007 +0000
260 date: Mon Jan 01 00:00:21 2007 +0000
@@ -49,6 +49,7 b' Do a first conversion'
49 converting...
49 converting...
50 0 rev1
50 0 rev1
51 updating tags
51 updating tags
52 updating bookmarks
52
53
53 Simulate upstream updates after first conversion
54 Simulate upstream updates after first conversion
54
55
@@ -67,6 +68,7 b' Perform an incremental conversion'
67 converting...
68 converting...
68 0 rev2
69 0 rev2
69 updating tags
70 updating tags
71 updating bookmarks
70
72
71 Print the log
73 Print the log
72
74
General Comments 0
You need to be logged in to leave comments. Login now