When git wants to fetch multiple refs from a remote helper, it will issue multiple "import" lines. In this case, testgit would then run multiple fast-exports, one per commit. Not only is this inefficient (since the refs may have shared history), but the data stream will appear bogus to fast-import, which sees the output of the exports concatenated (specifically, each export starts with "feature" lines, which are not allowed to come after "data" lines). Instead, the helper needs to collect the list of refs to be imported, and then run a single fast-import with all of the refs (once git has signalled to us the list is done by hanging up). Signed-off-by: Jeff King <peff@xxxxxxxx> --- git-remote-testgit.py | 24 +++++++++++++++++++++--- t/t5800-remote-helpers.sh | 2 +- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/git-remote-testgit.py b/git-remote-testgit.py index e2ad98e..c04f1b3 100644 --- a/git-remote-testgit.py +++ b/git-remote-testgit.py @@ -113,9 +113,13 @@ def update_local_repo(repo): return repo +to_import = [] def do_import(repo, args): - """Exports a fast-import stream from testgit for git to import. + """Collect a set of refs to import; we must do the final + import at the end, since we only want to exec fast-export + once. """ + global to_import if len(args) != 1: die("Import needs exactly one ref") @@ -123,11 +127,24 @@ def do_import(repo, args): if not repo.gitdir: die("Need gitdir to import") - repo = update_local_repo(repo) - repo.exporter.export_repo(repo.gitdir, args) + to_import.append(args[0]) return True +def finalize_import(repo): + """Exports a fast-import stream from testgit for git to import; + we should have collected the list of refs already in + to_import. + """ + global to_import + + if len(to_import) == 0: + return + + repo = update_local_repo(repo) + repo.exporter.export_repo(repo.gitdir, to_import) + + def do_export(repo, args): """Imports a fast-import stream from git to testgit. """ @@ -199,6 +216,7 @@ def read_one_line(repo): cmdline = cmdline.strip().split() if not cmdline: # Blank line means we're about to quit + finalize_import(repo) return False cmd = cmdline.pop(0) diff --git a/t/t5800-remote-helpers.sh b/t/t5800-remote-helpers.sh index 562edf4..b28f2b3 100755 --- a/t/t5800-remote-helpers.sh +++ b/t/t5800-remote-helpers.sh @@ -94,7 +94,7 @@ test_expect_success PYTHON_24 'fetch new branch' ' compare_refs public HEAD localclone FETCH_HEAD ' -test_expect_failure PYTHON_24 'fetch multiple branches' ' +test_expect_success PYTHON_24 'fetch multiple branches' ' (cd localclone && git fetch ) && -- 1.7.6.rc0.35.gc40cb -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html