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

[RFH] git-svn: sanitizing refnames

From
EWEric Wong <normalperson@yhbt.net>
Date
Apr 26, 2007, 19:49 UTC
Message-ID
<20070426194901.GA913@untitled>

I had a small pocket of time on Sunday and started working on this, but probably won't finish soon (the segfault issue take precedence, and *that* is taking a while to complete with other things going on...).

Problem: git-svn maps directory names (branches and tags) from SVN into
refnames for git.  Unfortunately, some SVN users create branches and
tags with characters that git doesn't like.

Below is my work-in-progress patch to handle sanitation of refnames.

It seems that storing a refmap dictionary in .git/config (or git/svn/config) of already-translated refnames is necessary so we can avoid conflicts with different refs sanitizing.

How to populate that dictionary is another problem. Should we prompt the user for input[1]? Or should we just escape and append[2] characters to the end?

We could probably just copy and modify the uri_encode() function to %xx escape all the characters we don't like, and append '-'

[1] - keep in mind that some people probably run cron-jobs to keep their mirrors synced. [2] - parent following appends a "@<revision_number>", and then enough '-'s until it's unique.

diff --git a/git-svn.perl b/git-svn.perl
index 4ea6f20..8d08572 100755
--- a/git-svn.perl
+++ b/git-svn.perl
@@ -987,6 +987,29 @@ sub sanitize_remote_name {
 	$name;
 }
 
+sub sanitize_ref_name {
+	my ($ref) = @_;
+	eval { command('check-ref-format', $ref) };
+	return unless $@;
+	my ($cfg, $ctx) = command_output_pipe('config', '--get-all',
+	                                      "svn-remote.$repo_id.refmap");
+	my $ref_encoded = uri_encode($ref);
+	my $re = qr/^\Q$ref_encoded\E=/;
+	my $ret;
+	while (<$ls>) {
+		next unless s/$re//;
+		chomp;
+		$ret = $_;
+		last;
+	}
+	close $cfg; # break the pipe
+	unless (defined $ret) {
+		command_noisy('config', '--add', "svn-remote.$repo_id.refmap",
+		              "$ref_encoded=$ret");
+	}
+	$ret;
+}
+
 sub find_existing_remote {
 	my ($url, $remotes) = @_;
 	return undef if $no_reuse_existing;
@@ -2088,6 +2111,7 @@ sub _new {
 		$_[2] = $ref_id = $Git::SVN::default_ref_id;
 	}
 	$_[1] = $repo_id = sanitize_remote_name($repo_id);
+	$_[2] = $ref_id = sanitize_ref_name($repo_id, $ref_id);
 	my $dir = "$ENV{GIT_DIR}/svn/$ref_id";
 	$_[3] = $path = '' unless (defined $path);
 	mkpath(["$ENV{GIT_DIR}/svn"]);
-- 
Eric Wong
Message 1 of 1 in “[RFH] git-svn: sanitizing refnames”
  1. Eric WongApr 26, 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.