git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Robin Rosenberg <robin.rosenberg@dewire.com>
To: Junio C Hamano <junkio@cox.net>
Cc: git@vger.kernel.org
Subject: Re: [PATCH] Rework cvsexportcommit to handle binary files for all cases.
Date: Mon, 13 Nov 2006 21:40:01 +0100	[thread overview]
Message-ID: <200611132140.01578.robin.rosenberg@dewire.com> (raw)
In-Reply-To: <7vmz6wark9.fsf@assigned-by-dhcp.cox.net>

[-- Attachment #1: Type: text/plain, Size: 55 bytes --]

And the updated fix for spaces in file names

-- robin

[-- Attachment #2: 0002-Make-cvsexportcommit-work-with-filenames-containing-spaces.txt --]
[-- Type: text/plain, Size: 3439 bytes --]

From bf4030e88bfd5b5f1a84b19a1be36f8178f2b24a Mon Sep 17 00:00:00 2001
From: Robin Rosenberg <robin.rosenberg@dewire.com>
Date: Mon, 13 Nov 2006 21:29:06 +0100
Subject: [PATCH] Make cvsexportcommit work with filenames containing spaces.

Binary files are except to this so far.

Signed-off-by: Robin Rosenberg <robin.rosenberg@dewire.com>

diff --git a/git-cvsexportcommit.perl b/git-cvsexportcommit.perl
index facb4667eefe79cbd4d29e542ec5e8111a7a973c..017648c8c252e60151320f09a428f0bff6ae46de 100755
--- a/git-cvsexportcommit.perl
+++ b/git-cvsexportcommit.perl
@@ -4,7 +4,7 @@ # Known limitations:
 # - does not propagate permissions
 # - tells "ready for commit" even when things could not be completed
 #   (not sure this is true anymore, maybe more testing is needed)
-# - does not handle whitespace in pathnames at all.
+# - Fedora/RHEL uses patch 2.5.4 which doesn't handles spaces in file names
 
 use strict;
 use Getopt::Std;
@@ -121,7 +121,14 @@ #print @files;
 $? && die "Error in git-diff-tree";
 foreach my $f (@files) {
     chomp $f;
-    my @fields = split(m!\s+!, $f);
+    $f =~ m/^(\S+) (\S+) (\S+) (\S+) (\S+)	(.*)/;
+    my @fields = ();
+    $fields[++$#fields] = $1;
+    $fields[++$#fields] = $2;
+    $fields[++$#fields] = $3;
+    $fields[++$#fields] = $4;
+    $fields[++$#fields] = $5;
+    $fields[++$#fields] = $6;
     if ($fields[4] eq 'A') {
         my $path = $fields[5];
 	push @afiles, $path;
@@ -256,7 +263,19 @@ my $fuzz = $opt_p ? 0 : 2;
 print "Patching non-binary files\n";
 
 if (scalar(@afiles)+scalar(@dfiles)+scalar(@mfiles) != scalar(@bfiles)) {
-    print `(git-diff-tree -p $parent -p $commit | patch -p1 -F $fuzz ) 2>&1`;
+    my $saveslash = $/;
+    undef $/;
+
+    open DIFF, "git-diff-tree -p $parent -p $commit|" || die "Cannot diff";
+    open PATCH, "|tee \$\$.diff|patch -p1 -F $fuzz" || die "Cannot patch";
+    my $delta = <DIFF>;
+    close DIFF || die "Could not diff";
+    unless (defined $ENV{'GIT_CVSEXPORTCOMMIT_NO_SPACES'}) {
+        $delta =~ s/\n(index [^\n]*)\n(--- [^\n]*)\n(\+\+\+ [^\n]*)\n(@@[^\n]*@@)\n/$1\n$2\t\n$3\t\n$4\n/sg
+    }
+    print PATCH $delta;
+    close PATCH || die "Could not patch";
+    $/ = $saveslash;
 }
 
 my $dirtypatch = 0;
diff --git a/t/t9200-git-cvsexportcommit.sh b/t/t9200-git-cvsexportcommit.sh
index 0ae03f80694a5d4ca3e61b40f6787a89fe8a496e..bf40d12f27ddde562da8f8526349df1784a48ae8 100755
--- a/t/t9200-git-cvsexportcommit.sh
+++ b/t/t9200-git-cvsexportcommit.sh
@@ -142,4 +142,28 @@ test_expect_success \
      diff F/newfile6.png ../F/newfile6.png
      )' 
 
+test_expect_success \
+     'New file with spaces in file name' \
+     'mkdir G &&
+      echo ok then >"G/with spaces.txt" &&
+      git add "G/with spaces.txt" && \
+      git commit -a -m "With spaces" &&
+      id=$(git rev-list --max-count=1 HEAD) &&
+      (cd "$CVSWORK" &&
+      git-cvsexportcommit -c $id &&
+      test $(cat G/CVS/Entries|wc -l) = 1
+      )'
+
+test_expect_success \
+     'Update file with spaces in file name' \
+     'echo Ok then >>"G/with spaces.txt" &&
+      git add "G/with spaces.txt" &&
+      git commit -a -m "Update with spaces" &&
+      id=$(git rev-list --max-count=1 HEAD) &&
+      (cd "$CVSWORK" &&
+      git-cvsexportcommit -c $id &&
+      test $(cat G/CVS/Entries|wc -l) = 1
+      )'
+     
+
 test_done
-- 
1.4.2


      parent reply	other threads:[~2006-11-13 20:38 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-11-12 15:29 [PATCH] Rework cvsexportcommit to handle binary files for all cases Robin Rosenberg
2006-11-13  4:39 ` Junio C Hamano
2006-11-13 20:39   ` Robin Rosenberg
2006-11-14  0:47     ` Junio C Hamano
2006-11-14  6:49       ` Robin Rosenberg
2006-11-14  6:56         ` Junio C Hamano
2006-11-13 20:40   ` Robin Rosenberg [this message]

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=200611132140.01578.robin.rosenberg@dewire.com \
    --to=robin.rosenberg@dewire.com \
    --cc=git@vger.kernel.org \
    --cc=junkio@cox.net \
    /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 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).