git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[RFC/PATCH git-remote-bzr] Adapt to new semantics of remote-helper "import" command

From
Jonathan Nieder <jrnieder@gmail.com>
Date
Jan 22, 2012, 05:46 UTC
Message-ID
<20120122054657.GA25103@burratino>

Git 1.7.7 (commit 9504bc9d, "transport-helper: change import semantics", 2011-07-16) incompatibly changed the interface of the "import" capability.

Before, git would always send a single import command, which the remote helper would respond to with a fast-import stream, terminated by end of file, meaning there was no way to fetch multiple refs in one connection. Nowadays, git instead sends a sequence of import lines:

	import refs/heads/foo
	import refs/heads/bar

terminated by a blank line. The helper is to respond with a fast-import stream terminated by the "done" command and process further commands until another blank line indicates the end of the command stream. --- Hi Simon and Gabriel,

Here's a rough patch against git://github.com/lelutin/git-remote-bzr.git master.

Without this patch, whenever I try to use "git clone bzr::<something>", after doing all the work it removes the resulting repo and exits with status 141 (SIGPIPE). Maybe the transport-helper should mask SIGPIPE when writing the final newline to avoid that.

I'd have prefered to write a patch for remote-bzr that works with older versions of git fast-import, too, but it wasn't obvious how. Hints welcome.

BTW, would you mind if I sent a patch to include git-remote-bzr in git.git under contrib/?

Thanks for git remote-bzr!  I'd be happy for any thoughts you have.

Ciao, Jonathan

[1] http://thread.gmane.org/gmane.comp.version-control.git/176002/focus=176606
 README.rst     |    2 +-
 git-remote-bzr |   33 ++++++++++++++++++++++++++++++---
 2 files changed, 31 insertions(+), 4 deletions(-)
diff --git a/README.rst b/README.rst
index 3eb3e476..f4dbbeb2 100644
--- a/README.rst
+++ b/README.rst
@@ -34,7 +34,7 @@ Relevant bug reports
 Requirements
 ------------
 
-- git 1.6.6 or later
+- git 1.7.7 or later
 - python 2.5 +
 - bzr 2.x
 - bzr-fastimport
diff --git a/git-remote-bzr b/git-remote-bzr
index 1e3a05f9..501fffe3 100755
--- a/git-remote-bzr
+++ b/git-remote-bzr
@@ -49,7 +49,7 @@ def do_list(repo, args):
     print  # end list
 
 
-def do_import(repo, args):
+def import_one_ref(repo, args):
     """Import a fast-import stream that is exported from Bazaar."""
     if len(args) != 1:
         die("Import needs exactly one ref")
@@ -65,6 +65,23 @@ def do_import(repo, args):
     if bzrp.wait():
         die("'bzr fast-export' returned unexpectedly with code %d",
             bzrp.returncode)
+    print "done"
+
+
+def do_import(repo,args):
+    import_one_ref(repo, args)
+
+    cmdline = True
+    while cmdline:
+        cmdline = next_command()
+        if not cmdline:
+            # Return to main processing loop
+            return True
+        cmd = cmdline.pop(0)
+        if cmd != "import":
+            warn("Unexpected command %s during import" % cmd)
+            return False
+        import_one_ref(repo, cmdline)
 
 
 def do_push(repo, args):
@@ -123,8 +140,8 @@ def sanitize(value):
     return value
 
 
-def read_one_line(repo):
-    """Read and process one command."""
+def next_command():
+    """Read one command."""
     line = sys.stdin.readline()
 
     cmdline = line
@@ -138,6 +155,16 @@ def read_one_line(repo):
         # Blank line means we're about to quit
         return False
 
+    return cmdline
+
+
+def read_one_line(repo):
+    """Read and process one command."""
+    cmdline = next_command()
+
+    if not cmdline:
+        return False
+
     cmd = cmdline.pop(0)
     debug("Got command '%s' with args '%s'", cmd, ' '.join(cmdline))
 
-- 
1.7.9.rc2
Next: Jelmer Vernooij
Message 1 of 4 in “Adapt to new semantics of remote-helper "import" command”
  1. Adapt to new semantics of remote-helper "import" commandJonathan Nieder, Jan 22, 2012
  2. Jelmer VernooijJan 22, 2012
  3. Jonathan NiederJan 23, 2012
  4. Gabriel FilionFeb 3, 2012

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.