git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFH] git-svn: sanitizing refnames
@ 2007-04-26 19:49 Eric Wong
  0 siblings, 0 replies; only message in thread
From: Eric Wong @ 2007-04-26 19:49 UTC (permalink / raw)
  To: git

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

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2007-04-26 19:49 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-04-26 19:49 [RFH] git-svn: sanitizing refnames Eric Wong

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).