# [PATCH 1/7] remote-bzr: fix directory renaming

9 messages from 2013-04-06 to 2013-04-08. Participants: Felipe Contreras.
Thread: https://gitlist.dev/t/33399

## Felipe Contreras, 2013-04-06 03:49

Subject: [PATCH 0/7] remote-bzr: generic updates
Message-ID: <1365220163-13581-1-git-send-email-felipe.contreras@gmail.com>
URL: https://gitlist.dev/e/1365220163-13581-1-git-send-email-felipe.contreras%40gmail.com

```
Hi,

Here are a couple fixes for remote-bzr, some of these can be really annoying to
certain users. I believe all of them should be safe.

Christophe Simonis (2):
  remote-bzr: fix directory renaming
  remote-bzr: remove files before modifications

David Engster (1):
  remote-bzr: set author if available

Felipe Contreras (3):
  remote-bzr: only update workingtree on local repos
  remote-bzr: avoid unreferred tags
  remote-bzr: add utf-8 support for pushing

Timotheus Pokorra (1):
  remote-bzr: add utf-8 support for fetching

 contrib/remote-helpers/git-remote-bzr | 36 ++++++++++---
 contrib/remote-helpers/test-bzr.sh    | 95 +++++++++++++++++++++++++++++++++++
 2 files changed, 123 insertions(+), 8 deletions(-)

-- 
1.8.2

```

## Felipe Contreras, 2013-04-06 03:49

Subject: [PATCH 1/7] remote-bzr: fix directory renaming
Message-ID: <1365220163-13581-2-git-send-email-felipe.contreras@gmail.com>
URL: https://gitlist.dev/e/1365220163-13581-2-git-send-email-felipe.contreras%40gmail.com
In-Reply-To: <1365220163-13581-1-git-send-email-felipe.contreras@gmail.com>

```
From: Christophe Simonis <christophe@kn.gl>

Git does not handle directories, renaming a directory is renaming every
files in this directory.

[fc: added tests]

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 contrib/remote-helpers/git-remote-bzr |  8 +++++++-
 contrib/remote-helpers/test-bzr.sh    | 24 ++++++++++++++++++++++++
 2 files changed, 31 insertions(+), 1 deletion(-)

diff --git a/contrib/remote-helpers/git-remote-bzr b/contrib/remote-helpers/git-remote-bzr
index c5822e4..a7d041b 100755
--- a/contrib/remote-helpers/git-remote-bzr
+++ b/contrib/remote-helpers/git-remote-bzr
@@ -191,7 +191,13 @@ def get_filechanges(cur, prev):
         modified[path] = fid
     for oldpath, newpath, fid, kind, mod, _ in changes.renamed:
         removed[oldpath] = None
-        modified[newpath] = fid
+        if kind == 'directory':
+            lst = cur.list_files(from_dir=newpath, recursive=True)
+            for path, file_class, kind, fid, entry in lst:
+                if kind != 'directory':
+                    modified[newpath + '/' + path] = fid
+        else:
+            modified[newpath] = fid
 
     return modified, removed
 
diff --git a/contrib/remote-helpers/test-bzr.sh b/contrib/remote-helpers/test-bzr.sh
index 8450432..d26e5c7 100755
--- a/contrib/remote-helpers/test-bzr.sh
+++ b/contrib/remote-helpers/test-bzr.sh
@@ -126,4 +126,28 @@ test_expect_success 'special modes' '
   test_cmp expected actual
 '
 
+cat > expected <<EOF
+100644 blob 54f9d6da5c91d556e6b54340b1327573073030af	content
+100755 blob 68769579c3eaadbe555379b9c3538e6628bae1eb	executable
+120000 blob 6b584e8ece562ebffc15d38808cd6b98fc3d97ea	link
+040000 tree 35c0caa46693cef62247ac89a680f0c5ce32b37b	movedir-new
+EOF
+
+test_expect_success 'moving directory' '
+  (cd bzrrepo &&
+  mkdir movedir &&
+  echo one > movedir/one &&
+  echo two > movedir/two &&
+  bzr add movedir &&
+  bzr commit -m movedir &&
+  bzr mv movedir movedir-new &&
+  bzr commit -m movedir-new) &&
+
+  (cd gitrepo &&
+  git pull &&
+  git ls-tree HEAD > ../actual) &&
+
+  test_cmp expected actual
+'
+
 test_done
-- 
1.8.2

```

## Felipe Contreras, 2013-04-06 03:49

Subject: [PATCH 2/7] remote-bzr: remove files before modifications
Message-ID: <1365220163-13581-3-git-send-email-felipe.contreras@gmail.com>
URL: https://gitlist.dev/e/1365220163-13581-3-git-send-email-felipe.contreras%40gmail.com
In-Reply-To: <1365220163-13581-1-git-send-email-felipe.contreras@gmail.com>

```
From: Christophe Simonis <christophe@kn.gl>

Allow re-add of a deleted file in the same commit.

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 contrib/remote-helpers/git-remote-bzr | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/contrib/remote-helpers/git-remote-bzr b/contrib/remote-helpers/git-remote-bzr
index a7d041b..f818e93 100755
--- a/contrib/remote-helpers/git-remote-bzr
+++ b/contrib/remote-helpers/git-remote-bzr
@@ -303,10 +303,10 @@ def export_branch(branch, name):
             else:
                 print "merge :%s" % m
 
+        for f in removed:
+            print "D %s" % (f,)
         for f in modified_final:
             print "M %s :%u %s" % f
-        for f in removed:
-            print "D %s" % (f)
         print
 
         count += 1
-- 
1.8.2

```

## Felipe Contreras, 2013-04-06 03:49

Subject: [PATCH 3/7] remote-bzr: set author if available
Message-ID: <1365220163-13581-4-git-send-email-felipe.contreras@gmail.com>
URL: https://gitlist.dev/e/1365220163-13581-4-git-send-email-felipe.contreras%40gmail.com
In-Reply-To: <1365220163-13581-1-git-send-email-felipe.contreras@gmail.com>

```
From: David Engster <deng@randomsample.de>

[fc: added tests]

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 contrib/remote-helpers/git-remote-bzr |  7 ++++++-
 contrib/remote-helpers/test-bzr.sh    | 15 +++++++++++++++
 2 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/contrib/remote-helpers/git-remote-bzr b/contrib/remote-helpers/git-remote-bzr
index f818e93..a99a924 100755
--- a/contrib/remote-helpers/git-remote-bzr
+++ b/contrib/remote-helpers/git-remote-bzr
@@ -266,7 +266,12 @@ def export_branch(branch, name):
         tz = rev.timezone
         committer = rev.committer.encode('utf-8')
         committer = "%s %u %s" % (fixup_user(committer), time, gittz(tz))
-        author = committer
+        authors = rev.get_apparent_authors()
+        if authors:
+            author = authors[0].encode('utf-8')
+            author = "%s %u %s" % (fixup_user(author), time, gittz(tz))
+        else:
+            author = committer
         msg = rev.message.encode('utf-8')
 
         msg += '\n'
diff --git a/contrib/remote-helpers/test-bzr.sh b/contrib/remote-helpers/test-bzr.sh
index d26e5c7..68105fc 100755
--- a/contrib/remote-helpers/test-bzr.sh
+++ b/contrib/remote-helpers/test-bzr.sh
@@ -150,4 +150,19 @@ test_expect_success 'moving directory' '
   test_cmp expected actual
 '
 
+test_expect_success 'different authors' '
+  (cd bzrrepo &&
+  echo john >> content &&
+  bzr commit -m john \
+    --author "Jane Rey <jrey@example.com>" \
+    --author "John Doe <jdoe@example.com>") &&
+
+  (cd gitrepo &&
+  git pull &&
+  git show --format="%an <%ae>, %cn <%ce>" --quiet > ../actual) &&
+
+  echo "Jane Rey <jrey@example.com>, A U Thor <author@example.com>" > expected &&
+  test_cmp expected actual
+'
+
 test_done
-- 
1.8.2

```

## Felipe Contreras, 2013-04-06 03:49

Subject: [PATCH 4/7] remote-bzr: only update workingtree on local repos
Message-ID: <1365220163-13581-5-git-send-email-felipe.contreras@gmail.com>
URL: https://gitlist.dev/e/1365220163-13581-5-git-send-email-felipe.contreras%40gmail.com
In-Reply-To: <1365220163-13581-1-git-send-email-felipe.contreras@gmail.com>

```
Apparently, that's the only way it's possible.

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 contrib/remote-helpers/git-remote-bzr | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/contrib/remote-helpers/git-remote-bzr b/contrib/remote-helpers/git-remote-bzr
index a99a924..9466cb9 100755
--- a/contrib/remote-helpers/git-remote-bzr
+++ b/contrib/remote-helpers/git-remote-bzr
@@ -630,10 +630,9 @@ def do_export(parser):
                     peer.import_last_revision_info_and_tags(repo, revno, revid)
                 else:
                     peer.import_last_revision_info(repo.repository, revno, revid)
-                wt = peer.bzrdir.open_workingtree()
             else:
                 wt = repo.bzrdir.open_workingtree()
-            wt.update()
+                wt.update()
         print "ok %s" % ref
     print
 
-- 
1.8.2

```

## Felipe Contreras, 2013-04-06 03:49

Subject: [PATCH 5/7] remote-bzr: avoid unreferred tags
Message-ID: <1365220163-13581-6-git-send-email-felipe.contreras@gmail.com>
URL: https://gitlist.dev/e/1365220163-13581-6-git-send-email-felipe.contreras%40gmail.com
In-Reply-To: <1365220163-13581-1-git-send-email-felipe.contreras@gmail.com>

```
They have no content, there's nothing we can do with them.

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 contrib/remote-helpers/git-remote-bzr | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/contrib/remote-helpers/git-remote-bzr b/contrib/remote-helpers/git-remote-bzr
index 9466cb9..0bcf8c5 100755
--- a/contrib/remote-helpers/git-remote-bzr
+++ b/contrib/remote-helpers/git-remote-bzr
@@ -654,7 +654,11 @@ def do_capabilities(parser):
 def do_list(parser):
     global tags
     print "? refs/heads/%s" % 'master'
+
+    history = parser.repo.revision_history()
     for tag, revid in parser.repo.tags.get_tag_dict().items():
+        if revid not in history:
+            continue
         print "? refs/tags/%s" % tag
         tags[tag] = revid
     print "@refs/heads/%s HEAD" % 'master'
-- 
1.8.2

```

## Felipe Contreras, 2013-04-06 03:49

Subject: [PATCH 6/7] remote-bzr: add utf-8 support for fetching
Message-ID: <1365220163-13581-7-git-send-email-felipe.contreras@gmail.com>
URL: https://gitlist.dev/e/1365220163-13581-7-git-send-email-felipe.contreras%40gmail.com
In-Reply-To: <1365220163-13581-1-git-send-email-felipe.contreras@gmail.com>

```
From: Timotheus Pokorra <timotheus.pokorra@gmail.com>

[fc: added tests]

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 contrib/remote-helpers/git-remote-bzr |  4 ++--
 contrib/remote-helpers/test-bzr.sh    | 25 +++++++++++++++++++++++++
 2 files changed, 27 insertions(+), 2 deletions(-)

diff --git a/contrib/remote-helpers/git-remote-bzr b/contrib/remote-helpers/git-remote-bzr
index 0bcf8c5..0bd0759 100755
--- a/contrib/remote-helpers/git-remote-bzr
+++ b/contrib/remote-helpers/git-remote-bzr
@@ -223,7 +223,7 @@ def export_files(tree, files):
             # is the blog already exported?
             if h in filenodes:
                 mark = filenodes[h]
-                final.append((mode, mark, path))
+                final.append((mode, mark, path.encode('utf-8')))
                 continue
 
             d = tree.get_file_text(fid)
@@ -240,7 +240,7 @@ def export_files(tree, files):
         print "data %d" % len(d)
         print d
 
-        final.append((mode, mark, path))
+        final.append((mode, mark, path.encode('utf-8')))
 
     return final
 
diff --git a/contrib/remote-helpers/test-bzr.sh b/contrib/remote-helpers/test-bzr.sh
index 68105fc..e468079 100755
--- a/contrib/remote-helpers/test-bzr.sh
+++ b/contrib/remote-helpers/test-bzr.sh
@@ -165,4 +165,29 @@ test_expect_success 'different authors' '
   test_cmp expected actual
 '
 
+test_expect_success 'fetch utf-8 filenames' '
+  mkdir -p tmp && cd tmp &&
+  test_when_finished "cd .. && rm -rf tmp && LC_ALL=C" &&
+
+  export LC_ALL=en_US.UTF-8
+
+  (
+  bzr init bzrrepo &&
+  cd bzrrepo &&
+
+  echo test >> "áéíóú" &&
+  bzr add "áéíóú" &&
+  bzr commit -m utf-8
+  ) &&
+
+  (
+  git clone "bzr::$PWD/bzrrepo" gitrepo &&
+  cd gitrepo &&
+  git ls-files > ../actual
+  ) &&
+
+  echo "\"\\303\\241\\303\\251\\303\\255\\303\\263\\303\\272\"" > expected &&
+  test_cmp expected actual
+'
+
 test_done
-- 
1.8.2

```

## Felipe Contreras, 2013-04-06 03:49

Subject: [PATCH 7/7] remote-bzr: add utf-8 support for pushing
Message-ID: <1365220163-13581-8-git-send-email-felipe.contreras@gmail.com>
URL: https://gitlist.dev/e/1365220163-13581-8-git-send-email-felipe.contreras%40gmail.com
In-Reply-To: <1365220163-13581-1-git-send-email-felipe.contreras@gmail.com>

```
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 contrib/remote-helpers/git-remote-bzr |  6 ++++++
 contrib/remote-helpers/test-bzr.sh    | 31 +++++++++++++++++++++++++++++++
 2 files changed, 37 insertions(+)

diff --git a/contrib/remote-helpers/git-remote-bzr b/contrib/remote-helpers/git-remote-bzr
index 0bd0759..fad4a48 100755
--- a/contrib/remote-helpers/git-remote-bzr
+++ b/contrib/remote-helpers/git-remote-bzr
@@ -512,6 +512,11 @@ class CustomTree():
     def get_symlink_target(self, file_id):
         return self.updates[file_id]['data']
 
+def c_style_unescape(string):
+    if string[0] == string[-1] == '"':
+        return string.decode('string-escape')[1:-1]
+    return string
+
 def parse_commit(parser):
     global marks, blob_marks, bmarks, parsed_refs
     global mode
@@ -551,6 +556,7 @@ def parse_commit(parser):
             f = { 'deleted' : True }
         else:
             die('Unknown file command: %s' % line)
+        path = c_style_unescape(path).decode('utf-8')
         files[path] = f
 
     repo = parser.repo
diff --git a/contrib/remote-helpers/test-bzr.sh b/contrib/remote-helpers/test-bzr.sh
index e468079..f4c7768 100755
--- a/contrib/remote-helpers/test-bzr.sh
+++ b/contrib/remote-helpers/test-bzr.sh
@@ -190,4 +190,35 @@ test_expect_success 'fetch utf-8 filenames' '
   test_cmp expected actual
 '
 
+test_expect_success 'push utf-8 filenames' '
+  mkdir -p tmp && cd tmp &&
+  test_when_finished "cd .. && rm -rf tmp && LC_ALL=C" &&
+
+  export LC_ALL=en_US.UTF-8
+
+  (
+  bzr init bzrrepo &&
+  cd bzrrepo &&
+
+  echo one >> content &&
+  bzr add content &&
+  bzr commit -m one
+  ) &&
+
+  (
+  git clone "bzr::$PWD/bzrrepo" gitrepo &&
+  cd gitrepo &&
+
+  echo test >> "áéíóú" &&
+  git add "áéíóú" &&
+  git commit -m utf-8 &&
+
+  git push
+  ) &&
+
+  (cd bzrrepo && bzr ls > ../actual) &&
+  echo -e "content\náéíóú" > expected &&
+  test_cmp expected actual
+'
+
 test_done
-- 
1.8.2

```

## Felipe Contreras, 2013-04-08 16:30

Subject: Re: [PATCH 5/7] remote-bzr: avoid unreferred tags
Message-ID: <CAMP44s33_SrAN=RyT_8N=RTAGFGwO3FcxQPU=0aRSLCy9suVRg@mail.gmail.com>
URL: https://gitlist.dev/e/CAMP44s33_SrAN%3DRyT_8N%3DRTAGFGwO3FcxQPU%3D0aRSLCy9suVRg%40mail.gmail.com
In-Reply-To: <CABLWAfRfpCwxc_V1gD5QsZGgaQ7gtEfyad8dKSCNM-pA7TX6TQ@mail.gmail.com>

```
Hi,

On Mon, Apr 8, 2013 at 5:33 AM, Sandor Bodo-Merle <sbodomerle@gmail.com> wrote:
> this have a regression when i try to clone the current bugzilla repository
> (previous version was ok):
>
> git clone bzr::http://bzr.mozilla.org/bugzilla/trunk bugzilla
> Cloning into 'bugzilla'...
> Traceback (most recent call last):sions:Finishing stream:Done
> 88662/886628662
>   File "/home/bms/bin/git-remote-bzr", line 745, in <module>
>     sys.exit(main(sys.argv))
>   File "/home/bms/bin/git-remote-bzr", line 734, in main
>     do_list(parser)
>   File "/home/bms/bin/git-remote-bzr", line 664, in do_list
>     history = parser.repo.revision_history()
> AttributeError: 'BzrBranch7' object has no attribute 'revision_history'

I just pushed this fix:
https://github.com/felipec/git/commit/8161a8479dfb59dfac016e3cfa292e003e7585ce

I think it would do the trick.

--
Felipe Contreras

```
