All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eric Wong <normalperson@yhbt.net>
To: git@vger.kernel.org
Subject: [RFH] git-svn: sanitizing refnames
Date: Thu, 26 Apr 2007 12:49:01 -0700	[thread overview]
Message-ID: <20070426194901.GA913@untitled> (raw)

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

                 reply	other threads:[~2007-04-26 19:49 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20070426194901.GA913@untitled \
    --to=normalperson@yhbt.net \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.