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

[PATCH] translate bad characters in refnames during git-svn fetch

From
MKmartin f krafft <madduck@madduck.net>
Date
Jul 15, 2007, 13:05 UTC
Message-ID
<20070715130548.GA6144@piper.oerlikon.madduck.net>
Hi,

I am trying to track/convert the Debian pkg-mdadm repository with git-svn:

  svn://svn.debian.org/svn/pkg-mdadm/mdadm/trunk
My problem is that the fetching fails:
  fatal: refs/remotes/tags/2.6.1-1~exp.1: cannot lock the ref
  update-ref -m r311 refs/remotes/tags/2.6.1-1~exp.1
  c6e351ea25dc90714048e33693099595c2d5dab8: command returned error:
  128

This is because the ~ character is an invalid character for a refname (it's used to specify the nth parent).

So I figured that the best way to deal with this is to introduce a conversion filter to git-svn, but I cannot figure out where it has to go. My perl is rusty and even after an hour now with the code, I could not find the right spot.

The following patch works, but I can't really explain why. Moreover, it does not change the STDERR output, so you'll still get stuff like

  r340 = 0dc5693471af9dfdb712c1342071ba1040af8963
  (tags/2.6.1-1~exp.3)

which makes me think that it's translating the refname too late. However, the end result looks sane.

Comments welcome, m

--- git-check-ref-format(1) documents which characters may be contained in a refname. Since Subversion has different rules, an import can result in problems, such as:

  fatal: refs/remotes/tags/2.6.1-1~exp.1: cannot lock the ref
  update-ref -m r311 refs/remotes/tags/2.6.1-1~exp.1
  c6e351ea25dc90714048e33693099595c2d5dab8: command returned error: 128

This patch translates bad characters to valid substitutes to enable imports of tags/branches/whatever using characters that git does not allow in refnames.

Signed-off-by: martin f. krafft <madduck@piper.oerlikon.madduck.net>
---
 git-svn.perl |   24 +++++++++++++++++++++++-
 1 files changed, 23 insertions(+), 1 deletions(-)
diff --git a/git-svn.perl b/git-svn.perl
index 299b40f..de43697 100755
--- a/git-svn.perl
+++ b/git-svn.perl
@@ -1239,7 +1239,29 @@ sub new {
 	$self;
 }
 
-sub refname { "refs/remotes/$_[0]->{ref_id}" }
+sub refname {
+	my ($refname) = $_[0]->{ref_id};
+	## transform the refname as per rules in git-check-ref-format(1):
+	# no slash-separated omponent can begin with a dot .
+	# /.* becomes /,*
+	$refname =~ s|/\.|/,|g;
+	# It cannot have two consecutive dots .. anywhere
+	# .. becomes ,,
+	$refname =~ s|\.\.|,,|g;
+	# It cannot have ASCII control character space, tilde ~, caret ^,
+	# colon :, question-mark ?, asterisk *, or open bracket[ anywhere
+	# <space> becomes _
+	# ~ becomes =
+	# ^ becomes @
+	# : becomes %
+	# ? becomes $
+	# * becomes +
+	# [ becomes (
+	$refname =~ y| ~^:?*[|_=@%\$+(|;
+	# It cannot end with a slash /
+	$refname =~ s|/$||g;
+	"refs/remotes/$refname";
+}
 
 sub svm_uuid {
 	my ($self) = @_;
-- 
1.5.3.rc1.27.ga5e40


-- 
martin;              (greetings from the heart of the sun.)
  \____ echo mailto: !#^."<*>"|tr "<*> mailto:" net@madduck
 
spamtraps: madduck.bogus@madduck.net
 
"a warm bed in a house sounds a mite better
 than eating a hot dog on a stick
 with an old geezer traveling on a lawn mower."
                                -- alvin straight (the straight story)
Next: Eric Wong
Message 1 of 10 in “translate bad characters in refnames during git-svn fetch”
  1. translate bad characters in refnames during git-svn fetchmartin f krafft, Jul 15, 2007
  2. Eric WongJul 16, 2007
  3. Jan HudecJul 16, 2007
  4. martin f krafftJul 16, 2007
  5. Eric WongJul 17, 2007
  6. martin f krafftJul 17, 2007
  7. Robert EwaldJul 26, 2007
  8. Martin F KrafftJul 26, 2007
  9. Mike HommeyJul 28, 2007
  10. David KastrupJul 28, 2007

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.