@matheusbsbs / matheus-bagliano / commits / 36f5b1f0c8
Fork 0

git-svn: ignore expansion of svn:keywords

Unlike my earlier test patch, this also checks svn:eol-style and makes sure it's applied to working copy updates. This is definitely more correct than my original attempt at killing keyword expansions, but I still haven't tested it enough to know. Feedback would be much appreciated. Also changed assert_svn_wc_clean() to only work on the svn working copy. This requires a separate call to assert_tree() to check wc integrity against git in preparation for another change I'm planning. Signed-off-by: Eric Wong <normalperson@yhbt.net> Signed-off-by: Junio C Hamano <junkio@cox.net>

Eric Wong committed May 23, 2006 at 19:23 UTC 36f5b1f0c800a23b9755a0214c1c3250f34f2486
5 files changed +254 -60
contrib/git-svn/Makefile
+1
@@ -30,6 +30,7 @@ git-svn.html : git-svn.txt
30 -f ../../Documentation/asciidoc.conf $<
31 test: git-svn
32 cd t && $(SHELL) ./t0000-contrib-git-svn.sh
33 + cd t && $(SHELL) ./t0001-contrib-git-svn-props.sh
34
35 clean:
36 rm -f git-svn *.xml *.html *.1
contrib/git-svn/git-svn.perl
+87 -19
@@ -39,6 +39,10 @@ my $_svn_co_url_revs;
39 my %fc_opts = ( 'no-ignore-externals' => \$_no_ignore_ext,
40 'branch|b=s' => \@_branch_from,
41 'authors-file|A=s' => \$_authors );
42 +
43 +# yes, 'native' sets "\n". Patches to fix this for non-*nix systems welcome:
44 +my %EOL = ( CR => "\015", LF => "\012", CRLF => "\015\012", native => "\012" );
45 +
46 my %cmd = (
47 fetch => [ \&fetch, "Download new revisions from SVN",
48 { 'revision|r=s' => \$_revision, %fc_opts } ],
@@ -207,7 +211,7 @@ sub rebuild {
211 push @svn_up, '--ignore-externals' unless $_no_ignore_ext;
212 sys(@svn_up,"-r$newest_rev");
213 $ENV{GIT_INDEX_FILE} = $GIT_SVN_INDEX;
210 - git_addremove();
214 + index_changes();
215 exec('git-write-tree');
216 }
217 waitpid $pid, 0;
@@ -249,7 +253,7 @@ sub fetch {
253 chdir $SVN_WC or croak $!;
254 read_uuid();
255 $last_commit = git_commit($base, @parents);
252 - assert_svn_wc_clean($base->{revision}, $last_commit);
256 + assert_tree($last_commit);
257 } else {
258 chdir $SVN_WC or croak $!;
259 read_uuid();
@@ -259,16 +263,20 @@ sub fetch {
263 push @svn_up, '--ignore-externals' unless $_no_ignore_ext;
264 my $last = $base;
265 while (my $log_msg = next_log_entry($svn_log)) {
262 - assert_svn_wc_clean($last->{revision}, $last_commit);
266 + assert_tree($last_commit);
267 if ($last->{revision} >= $log_msg->{revision}) {
268 croak "Out of order: last >= current: ",
269 "$last->{revision} >= $log_msg->{revision}\n";
270 }
271 + # Revert is needed for cases like:
272 + # https://svn.musicpd.org/Jamming/trunk (r166:167), but
273 + # I can't seem to reproduce something like that on a test...
274 + sys(qw/svn revert -R ./);
275 + assert_svn_wc_clean($last->{revision});
276 sys(@svn_up,"-r$log_msg->{revision}");
277 $last_commit = git_commit($log_msg, $last_commit, @parents);
278 $last = $log_msg;
279 }
271 - assert_svn_wc_clean($last->{revision}, $last_commit);
280 unless (-e "$GIT_DIR/refs/heads/master") {
281 sys(qw(git-update-ref refs/heads/master),$last_commit);
282 }
@@ -314,7 +322,6 @@ sub commit {
322 $svn_current_rev = svn_commit_tree($svn_current_rev, $c);
323 }
324 print "Done committing ",scalar @revs," revisions to SVN\n";
317 -
325 }
326
327 sub show_ignore {
@@ -367,13 +374,11 @@ sub setup_git_svn {
374 }
375
376 sub assert_svn_wc_clean {
370 - my ($svn_rev, $treeish) = @_;
377 + my ($svn_rev) = @_;
378 croak "$svn_rev is not an integer!\n" unless ($svn_rev =~ /^\d+$/);
372 - croak "$treeish is not a sha1!\n" unless ($treeish =~ /^$sha1$/o);
379 my $lcr = svn_info('.')->{'Last Changed Rev'};
380 if ($svn_rev != $lcr) {
381 print STDERR "Checking for copy-tree ... ";
376 - # use
382 my @diff = grep(/^Index: /,(safe_qx(qw(svn diff),
383 "-r$lcr:$svn_rev")));
384 if (@diff) {
@@ -389,7 +394,6 @@ sub assert_svn_wc_clean {
394 print STDERR $_ foreach @status;
395 croak;
396 }
392 - assert_tree($treeish);
397 }
398
399 sub assert_tree {
@@ -416,7 +420,7 @@ sub assert_tree {
420 unlink $tmpindex or croak $!;
421 }
422 $ENV{GIT_INDEX_FILE} = $tmpindex;
419 - git_addremove();
423 + index_changes(1);
424 chomp(my $tree = `git-write-tree`);
425 if ($old_index) {
426 $ENV{GIT_INDEX_FILE} = $old_index;
@@ -426,6 +430,7 @@ sub assert_tree {
430 if ($tree ne $expected) {
431 croak "Tree mismatch, Got: $tree, Expected: $expected\n";
432 }
433 + unlink $tmpindex;
434 }
435
436 sub parse_diff_tree {
@@ -562,7 +567,8 @@ sub precommit_check {
567 sub svn_checkout_tree {
568 my ($svn_rev, $treeish) = @_;
569 my $from = file_to_s("$REV_DIR/$svn_rev");
565 - assert_svn_wc_clean($svn_rev,$from);
570 + assert_svn_wc_clean($svn_rev);
571 + assert_tree($from);
572 print "diff-tree $from $treeish\n";
573 my $pid = open my $diff_fh, '-|';
574 defined $pid or croak $!;
@@ -852,13 +858,75 @@ sub svn_info {
858
859 sub sys { system(@_) == 0 or croak $? }
860
855 -sub git_addremove {
856 - system( "git-diff-files --name-only -z ".
857 - " | git-update-index --remove -z --stdin && ".
858 - "git-ls-files -z --others ".
859 - "'--exclude-from=$GIT_DIR/$GIT_SVN/info/exclude'".
860 - " | git-update-index --add -z --stdin"
861 - ) == 0 or croak $?
861 +sub eol_cp {
862 + my ($from, $to) = @_;
863 + my $es = safe_qx(qw/svn propget svn:eol-style/, $to);
864 + open my $rfd, '<', $from or croak $!;
865 + binmode $rfd or croak $!;
866 + open my $wfd, '>', $to or croak $!;
867 + binmode $wfd or croak $!;
868 +
869 + my $eol = $EOL{$es} or undef;
870 + if ($eol) {
871 + print "$eol: $from => $to\n";
872 + }
873 + my $buf;
874 + while (1) {
875 + my ($r, $w, $t);
876 + defined($r = sysread($rfd, $buf, 4096)) or croak $!;
877 + return unless $r;
878 + $buf =~ s/(?:\015|\012|\015\012)/$eol/gs if $eol;
879 + for ($w = 0; $w < $r; $w += $t) {
880 + $t = syswrite($wfd, $buf, $r - $w, $w) or croak $!;
881 + }
882 + }
883 +}
884 +
885 +sub do_update_index {
886 + my ($z_cmd, $cmd, $no_text_base) = @_;
887 +
888 + my $z = open my $p, '-|';
889 + defined $z or croak $!;
890 + unless ($z) { exec @$z_cmd or croak $! }
891 +
892 + my $pid = open my $ui, '|-';
893 + defined $pid or croak $!;
894 + unless ($pid) {
895 + exec('git-update-index',"--$cmd",'-z','--stdin') or croak $!;
896 + }
897 + local $/ = "\0";
898 + while (my $x = <$p>) {
899 + chomp $x;
900 + if (!$no_text_base && lstat $x && ! -l _ &&
901 + safe_qx(qw/svn propget svn:keywords/,$x)) {
902 + my $mode = -x _ ? 0755 : 0644;
903 + my ($v,$d,$f) = File::Spec->splitpath($x);
904 + my $tb = File::Spec->catfile($d, '.svn', 'tmp',
905 + 'text-base',"$f.svn-base");
906 + $tb =~ s#^/##;
907 + unless (-f $tb) {
908 + $tb = File::Spec->catfile($d, '.svn',
909 + 'text-base',"$f.svn-base");
910 + $tb =~ s#^/##;
911 + }
912 + unlink $x or croak $!;
913 + eol_cp($tb, $x);
914 + chmod(($mode &~ umask), $x) or croak $!;
915 + }
916 + print $ui $x,"\0";
917 + }
918 + close $ui or croak $!;
919 +}
920 +
921 +sub index_changes {
922 + my $no_text_base = shift;
923 + do_update_index([qw/git-diff-files --name-only -z/],
924 + 'remove',
925 + $no_text_base);
926 + do_update_index([qw/git-ls-files -z --others/,
927 + "--exclude-from=$GIT_DIR/$GIT_SVN/info/exclude"],
928 + 'add',
929 + $no_text_base);
930 }
931
932 sub s_to_file {
@@ -936,7 +1004,7 @@ sub git_commit {
1004 defined $pid or croak $!;
1005 if ($pid == 0) {
1006 $ENV{GIT_INDEX_FILE} = $GIT_SVN_INDEX;
939 - git_addremove();
1007 + index_changes();
1008 chomp(my $tree = `git-write-tree`);
1009 croak if $?;
1010 if (exists $tree_map{$tree}) {
contrib/git-svn/t/lib-git-svn.sh new
+39
@@ -0,0 +1,39 @@
1 +PATH=$PWD/../:$PATH
2 +if test -d ../../../t
3 +then
4 + cd ../../../t
5 +else
6 + echo "Must be run in contrib/git-svn/t" >&2
7 + exit 1
8 +fi
9 +
10 +. ./test-lib.sh
11 +
12 +GIT_DIR=$PWD/.git
13 +GIT_SVN_DIR=$GIT_DIR/git-svn
14 +SVN_TREE=$GIT_SVN_DIR/tree
15 +
16 +svnadmin >/dev/null 2>&1
17 +if test $? != 1
18 +then
19 + test_expect_success 'skipping contrib/git-svn test' :
20 + test_done
21 + exit
22 +fi
23 +
24 +svn >/dev/null 2>&1
25 +if test $? != 1
26 +then
27 + test_expect_success 'skipping contrib/git-svn test' :
28 + test_done
29 + exit
30 +fi
31 +
32 +svnrepo=$PWD/svnrepo
33 +
34 +set -e
35 +
36 +svnadmin create $svnrepo
37 +svnrepo="file://$svnrepo/test-git-svn"
38 +
39 +
contrib/git-svn/t/t0000-contrib-git-svn.sh
+2 -41
@@ -3,48 +3,10 @@
3 # Copyright (c) 2006 Eric Wong
4 #
5
6 -
7 -PATH=$PWD/../:$PATH
6 test_description='git-svn tests'
9 -if test -d ../../../t
10 -then
11 - cd ../../../t
12 -else
13 - echo "Must be run in contrib/git-svn/t" >&2
14 - exit 1
15 -fi
16 -
17 -. ./test-lib.sh
18 -
19 -GIT_DIR=$PWD/.git
20 -GIT_SVN_DIR=$GIT_DIR/git-svn
21 -SVN_TREE=$GIT_SVN_DIR/tree
22 -
23 -svnadmin >/dev/null 2>&1
24 -if test $? != 1
25 -then
26 - test_expect_success 'skipping contrib/git-svn test' :
27 - test_done
28 - exit
29 -fi
30 -
31 -svn >/dev/null 2>&1
32 -if test $? != 1
33 -then
34 - test_expect_success 'skipping contrib/git-svn test' :
35 - test_done
36 - exit
37 -fi
38 -
39 -svnrepo=$PWD/svnrepo
40 -
41 -set -e
42 -
43 -svnadmin create $svnrepo
44 -svnrepo="file://$svnrepo/test-git-svn"
7 +. ./lib-git-svn.sh
8
9 mkdir import
47 -
10 cd import
11
12 echo foo > foo
@@ -55,10 +17,9 @@ mkdir -p bar
17 echo 'zzz' > bar/zzz
18 echo '#!/bin/sh' > exec.sh
19 chmod +x exec.sh
58 -svn import -m 'import for git-svn' . $svnrepo >/dev/null
20 +svn import -m 'import for git-svn' . "$svnrepo" >/dev/null
21
22 cd ..
61 -
23 rm -rf import
24
25 test_expect_success \
contrib/git-svn/t/t0001-contrib-git-svn-props.sh new
+125
@@ -0,0 +1,125 @@
1 +#!/bin/sh
2 +#
3 +# Copyright (c) 2006 Eric Wong
4 +#
5 +
6 +test_description='git-svn property tests'
7 +. ./lib-git-svn.sh
8 +
9 +mkdir import
10 +
11 +a_crlf=
12 +a_lf=
13 +a_cr=
14 +a_ne_crlf=
15 +a_ne_lf=
16 +a_ne_cr=
17 +a_empty=
18 +a_empty_lf=
19 +a_empty_cr=
20 +a_empty_crlf=
21 +
22 +cd import
23 + cat >> kw.c <<''
24 +/* Make it look like somebody copied a file from CVS into SVN: */
25 +/* $Id: kw.c,v 1.1.1.1 1994/03/06 00:00:00 eric Exp $ */
26 +
27 + printf "Hello\r\nWorld\r\n" > crlf
28 + a_crlf=`git-hash-object -w crlf`
29 + printf "Hello\rWorld\r" > cr
30 + a_cr=`git-hash-object -w cr`
31 + printf "Hello\nWorld\n" > lf
32 + a_lf=`git-hash-object -w lf`
33 +
34 + printf "Hello\r\nWorld" > ne_crlf
35 + a_ne_crlf=`git-hash-object -w ne_crlf`
36 + printf "Hello\nWorld" > ne_lf
37 + a_ne_lf=`git-hash-object -w ne_lf`
38 + printf "Hello\rWorld" > ne_cr
39 + a_ne_cr=`git-hash-object -w ne_cr`
40 +
41 + touch empty
42 + a_empty=`git-hash-object -w empty`
43 + printf "\n" > empty_lf
44 + a_empty_lf=`git-hash-object -w empty_lf`
45 + printf "\r" > empty_cr
46 + a_empty_cr=`git-hash-object -w empty_cr`
47 + printf "\r\n" > empty_crlf
48 + a_empty_crlf=`git-hash-object -w empty_crlf`
49 +
50 + svn import -m 'import for git-svn' . "$svnrepo" >/dev/null
51 +cd ..
52 +
53 +rm -rf import
54 +svn co "$svnrepo" test_wc
55 +
56 +cd test_wc
57 + echo 'Greetings' >> kw.c
58 + svn commit -m 'Not yet an $Id$'
59 + svn up
60 +
61 + echo 'Hello world' >> kw.c
62 + svn commit -m 'Modified file, but still not yet an $Id$'
63 + svn up
64 +
65 + svn propset svn:keywords Id kw.c
66 + svn commit -m 'Propset $Id$'
67 + svn up
68 +cd ..
69 +
70 +git-svn init "$svnrepo"
71 +git-svn fetch
72 +
73 +git checkout -b mybranch remotes/git-svn
74 +echo 'Hi again' >> kw.c
75 +name='test svn:keywords ignoring'
76 +
77 +git commit -a -m "$name"
78 +git-svn commit remotes/git-svn..mybranch
79 +git pull . remotes/git-svn
80 +
81 +expect='/* $Id$ */'
82 +got="`sed -ne 2p kw.c`"
83 +test_expect_success 'raw $Id$ found in kw.c' "test '$expect' = '$got'"
84 +
85 +cd test_wc
86 + svn propset svn:eol-style CR empty
87 + svn propset svn:eol-style CR crlf
88 + svn propset svn:eol-style CR ne_crlf
89 + svn commit -m 'propset CR on crlf files'
90 + svn up
91 +cd ..
92 +
93 +git-svn fetch
94 +git pull . remotes/git-svn
95 +
96 +svn co "$svnrepo" new_wc
97 +for i in crlf ne_crlf lf ne_lf cr ne_cr empty_cr empty_lf empty empty_crlf
98 +do
99 + test_expect_success "Comparing $i" "cmp $i new_wc/$i"
100 +done
101 +
102 +
103 +cd test_wc
104 + printf '$Id$\rHello\rWorld\r' > cr
105 + printf '$Id$\rHello\rWorld' > ne_cr
106 + a_cr=`printf '$Id$\r\nHello\r\nWorld\r\n' | git-hash-object --stdin`
107 + a_ne_cr=`printf '$Id$\r\nHello\r\nWorld' | git-hash-object --stdin`
108 + svn propset svn:eol-style CRLF cr
109 + svn propset svn:eol-style CRLF ne_cr
110 + svn propset svn:keywords Id cr
111 + svn propset svn:keywords Id ne_cr
112 + svn commit -m 'propset CRLF on cr files'
113 + svn up
114 +cd ..
115 +
116 +git-svn fetch
117 +git pull . remotes/git-svn
118 +
119 +b_cr="`git-hash-object cr`"
120 +b_ne_cr="`git-hash-object ne_cr`"
121 +
122 +test_expect_success 'CRLF + $Id$' "test '$a_cr' = '$b_cr'"
123 +test_expect_success 'CRLF + $Id$ (no newline)' "test '$a_ne_cr' = '$b_ne_cr'"
124 +
125 +test_done