Skip to content

Commit 6c8151a

Browse files
SRabbeliergitster
authored andcommitted
transport-helper: update ref status after push with export
Also add check_output from python 2.7. Signed-off-by: Sverre Rabbelier <[email protected]> Acked-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1f25c50 commit 6c8151a

File tree

4 files changed

+67
-2
lines changed

4 files changed

+67
-2
lines changed

git-remote-testgit.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,15 @@ def do_export(repo, args):
147147
sys.stdout.flush()
148148

149149
update_local_repo(repo)
150-
repo.importer.do_import(repo.gitdir)
150+
changed = repo.importer.do_import(repo.gitdir)
151151

152152
if not repo.local:
153153
repo.non_local.push(repo.gitdir)
154154

155+
for ref in changed:
156+
print "ok %s" % ref
157+
print
158+
155159

156160
COMMANDS = {
157161
'capabilities': do_capabilities,

git_remote_helpers/git/importer.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import os
22
import subprocess
33

4-
from git_remote_helpers.util import check_call
4+
from git_remote_helpers.util import check_call, check_output
55

66

77
class GitImporter(object):
@@ -16,6 +16,18 @@ def __init__(self, repo):
1616

1717
self.repo = repo
1818

19+
def get_refs(self, gitdir):
20+
"""Returns a dictionary with refs.
21+
"""
22+
args = ["git", "--git-dir=" + gitdir, "for-each-ref", "refs/heads"]
23+
lines = check_output(args).strip().split('\n')
24+
refs = {}
25+
for line in lines:
26+
value, name = line.split(' ')
27+
name = name.strip('commit\t')
28+
refs[name] = value
29+
return refs
30+
1931
def do_import(self, base):
2032
"""Imports a fast-import stream to the given directory.
2133
@@ -32,9 +44,23 @@ def do_import(self, base):
3244
if not os.path.exists(dirname):
3345
os.makedirs(dirname)
3446

47+
refs_before = self.get_refs(gitdir)
48+
3549
args = ["git", "--git-dir=" + gitdir, "fast-import", "--quiet", "--export-marks=" + path]
3650

3751
if os.path.exists(path):
3852
args.append("--import-marks=" + path)
3953

4054
check_call(args)
55+
56+
refs_after = self.get_refs(gitdir)
57+
58+
changed = {}
59+
60+
for name, value in refs_after.iteritems():
61+
if refs_before.get(name) == value:
62+
continue
63+
64+
changed[name] = value
65+
66+
return changed

git_remote_helpers/util.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,40 @@ def check_call(*popenargs, **kwargs):
175175
return 0
176176

177177

178+
# from python2.7:subprocess.py
179+
def check_output(*popenargs, **kwargs):
180+
r"""Run command with arguments and return its output as a byte string.
181+
182+
If the exit code was non-zero it raises a CalledProcessError. The
183+
CalledProcessError object will have the return code in the returncode
184+
attribute and output in the output attribute.
185+
186+
The arguments are the same as for the Popen constructor. Example:
187+
188+
>>> check_output(["ls", "-l", "/dev/null"])
189+
'crw-rw-rw- 1 root root 1, 3 Oct 18 2007 /dev/null\n'
190+
191+
The stdout argument is not allowed as it is used internally.
192+
To capture standard error in the result, use stderr=STDOUT.
193+
194+
>>> check_output(["/bin/sh", "-c",
195+
... "ls -l non_existent_file ; exit 0"],
196+
... stderr=STDOUT)
197+
'ls: non_existent_file: No such file or directory\n'
198+
"""
199+
if 'stdout' in kwargs:
200+
raise ValueError('stdout argument not allowed, it will be overridden.')
201+
process = subprocess.Popen(stdout=subprocess.PIPE, *popenargs, **kwargs)
202+
output, unused_err = process.communicate()
203+
retcode = process.poll()
204+
if retcode:
205+
cmd = kwargs.get("args")
206+
if cmd is None:
207+
cmd = popenargs[0]
208+
raise subprocess.CalledProcessError(retcode, cmd)
209+
return output
210+
211+
178212
def file_reader_method (missing_ok = False):
179213
"""Decorator for simplifying reading of files.
180214

transport-helper.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,7 @@ static int push_refs_with_export(struct transport *transport,
764764

765765
if (finish_command(&exporter))
766766
die("Error while running fast-export");
767+
push_update_refs_status(data, remote_refs);
767768
return 0;
768769
}
769770

0 commit comments

Comments
 (0)