View | Details | Raw Unified | Return to bug 194999
Collapse All | Expand All

(-)devel/git/files/patch-git-svn.perl (+80 lines)
Added Link Here
1
--- git-svn.perl.orig	2014-11-13 08:43:00 UTC
2
+++ git-svn.perl
3
@@ -115,7 +115,7 @@ my ($_stdin, $_help, $_edit,
4
 	$_before, $_after,
5
 	$_merge, $_strategy, $_preserve_merges, $_dry_run, $_parents, $_local,
6
 	$_prefix, $_no_checkout, $_url, $_verbose,
7
-	$_commit_url, $_tag, $_merge_info, $_interactive);
8
+	$_commit_url, $_tag, $_merge_info, $_interactive, $_set_svn_props);
9
 
10
 # This is a refactoring artifact so Git::SVN can get at this git-svn switch.
11
 sub opt_prefix { return $_prefix || '' }
12
@@ -193,6 +193,7 @@ my %cmd = (
13
 			  'dry-run|n' => \$_dry_run,
14
 			  'fetch-all|all' => \$_fetch_all,
15
 			  'commit-url=s' => \$_commit_url,
16
+			  'set-svn-props=s' => \$_set_svn_props,
17
 			  'revision|r=i' => \$_revision,
18
 			  'no-rebase' => \$_no_rebase,
19
 			  'mergeinfo=s' => \$_merge_info,
20
@@ -228,6 +229,9 @@ my %cmd = (
21
         'propget' => [ \&cmd_propget,
22
 		       'Print the value of a property on a file or directory',
23
 		       { 'revision|r=i' => \$_revision } ],
24
+        'propset' => [ \&cmd_propset,
25
+		       'Set the value of a property on a file or directory - will be set on commit',
26
+		       {} ],
27
         'proplist' => [ \&cmd_proplist,
28
 		       'List all properties of a file or directory',
29
 		       { 'revision|r=i' => \$_revision } ],
30
@@ -1370,6 +1374,50 @@ sub cmd_propget {
31
 	print $props->{$prop} . "\n";
32
 }
33
 
34
+# cmd_propset (PROPNAME, PROPVAL, PATH)
35
+# ------------------------
36
+# Adjust the SVN property PROPNAME to PROPVAL for PATH.
37
+sub cmd_propset {
38
+	my ($propname, $propval, $path) = @_;
39
+	$path = '.' if not defined $path;
40
+	$path = $cmd_dir_prefix . $path;
41
+	usage(1) if not defined $propname;
42
+	usage(1) if not defined $propval;
43
+	my $file = basename($path);
44
+	my $dn = dirname($path);
45
+	# diff has check_attr locally, so just call direct 
46
+	#my $current_properties = check_attr( "svn-properties", $path );
47
+	my $current_properties = Git::SVN::Editor::check_attr( "svn-properties", $path );
48
+	my $new_properties = "";
49
+	if ($current_properties eq "unset" || $current_properties eq "" || $current_properties eq "set") {
50
+		$new_properties = "$propname=$propval";
51
+	} else {
52
+		# TODO: handle combining properties better
53
+		my @props = split(/;/, $current_properties);
54
+		my $replaced_prop = 0;
55
+		foreach my $prop (@props) {
56
+			# Parse 'name=value' syntax and set the property.
57
+			if ($prop =~ /([^=]+)=(.*)/) {
58
+				my ($n,$v) = ($1,$2);
59
+				if ($n eq $propname)
60
+				{
61
+					$v = $propval;
62
+					$replaced_prop = 1;
63
+				}
64
+				if ($new_properties eq "") { $new_properties="$n=$v"; }
65
+				else { $new_properties="$new_properties;$n=$v"; }
66
+			}
67
+		}
68
+		if ($replaced_prop eq 0) {
69
+			$new_properties = "$new_properties;$propname=$propval";
70
+		}
71
+	}
72
+	my $attrfile = "$dn/.gitattributes";
73
+	open my $attrfh, '>>', $attrfile or die "Can't open $attrfile: $!\n";
74
+	# TODO: don't simply append here if $file already has svn-properties
75
+	print $attrfh "$file svn-properties=$new_properties\n";
76
+}
77
+
78
 # cmd_proplist (PATH)
79
 # -------------------
80
 # Print the list of SVN properties for PATH.
(-)devel/git/files/patch-perl_Git_SVN_Editor.pm (+92 lines)
Added Link Here
1
--- perl/Git/SVN/Editor.pm.orig	2014-09-30 19:00:40 UTC
2
+++ perl/Git/SVN/Editor.pm
3
@@ -288,6 +288,57 @@ sub apply_autoprops {
4
 	}
5
 }
6
 
7
+sub check_attr
8
+{
9
+    my ($attr,$path) = @_;
10
+    if ( open my $fh, '-|', "git", "check-attr", $attr, "--", $path )
11
+    {
12
+	my $val = <$fh>;
13
+	close $fh;
14
+	$val =~ s/^[^:]*:\s*[^:]*:\s*(.*)\s*$/$1/;
15
+	return $val;
16
+    }
17
+    else
18
+    {
19
+	return undef;
20
+    }
21
+}
22
+
23
+# From which subdir have we been invoked?
24
+my $cmd_dir_prefix = eval {
25
+    command_oneline([qw/rev-parse --show-prefix/], STDERR => 0)
26
+} || '';
27
+
28
+sub apply_manualprops {
29
+	my ($self, $file, $fbat) = @_;
30
+	my $path = $cmd_dir_prefix . $file;
31
+	# diff has ::check_attr
32
+	#my $pending_properties = ::check_attr( "svn-properties", $path );
33
+	my $pending_properties = check_attr( "svn-properties", $path );
34
+	if ($pending_properties eq "") { return; }
35
+	# Parse the list of properties to set.
36
+	my @props = split(/;/, $pending_properties);
37
+	# TODO: get existing properties to compare to - this fails for add so currently not done
38
+	# my $existing_props = ::get_svnprops($file);
39
+	my $existing_props = {};
40
+	# TODO: caching svn properties or storing them in .gitattributes would make that faster
41
+	foreach my $prop (@props) {
42
+		# Parse 'name=value' syntax and set the property.
43
+		if ($prop =~ /([^=]+)=(.*)/) {
44
+			my ($n,$v) = ($1,$2);
45
+			for ($n, $v) {
46
+				s/^\s+//; s/\s+$//;
47
+			}
48
+			# FIXME: clearly I don't know perl and couldn't work out how to evaluate this better
49
+			if (defined $existing_props->{$n} && $existing_props->{$n} eq $v) {
50
+				my $needed = 0;
51
+			} else {
52
+				$self->change_file_prop($fbat, $n, $v);
53
+			}
54
+		}
55
+	}
56
+}
57
+
58
 sub A {
59
 	my ($self, $m, $deletions) = @_;
60
 	my ($dir, $file) = split_path($m->{file_b});
61
@@ -296,6 +347,7 @@ sub A {
62
 					undef, -1);
63
 	print "\tA\t$m->{file_b}\n" unless $::_q;
64
 	$self->apply_autoprops($file, $fbat);
65
+	$self->apply_manualprops($file, $fbat);
66
 	$self->chg_file($fbat, $m);
67
 	$self->close_file($fbat,undef,$self->{pool});
68
 }
69
@@ -311,6 +363,7 @@ sub C {
70
 	my $fbat = $self->add_file($self->repo_path($m->{file_b}), $pbat,
71
 				$upa, $self->{r});
72
 	print "\tC\t$m->{file_a} => $m->{file_b}\n" unless $::_q;
73
+	$self->apply_manualprops($file, $fbat);
74
 	$self->chg_file($fbat, $m);
75
 	$self->close_file($fbat,undef,$self->{pool});
76
 }
77
@@ -333,6 +386,7 @@ sub R {
78
 				$upa, $self->{r});
79
 	print "\tR\t$m->{file_a} => $m->{file_b}\n" unless $::_q;
80
 	$self->apply_autoprops($file, $fbat);
81
+	$self->apply_manualprops($file, $fbat);
82
 	$self->chg_file($fbat, $m);
83
 	$self->close_file($fbat,undef,$self->{pool});
84
 
85
@@ -348,6 +402,7 @@ sub M {
86
 	my $fbat = $self->open_file($self->repo_path($m->{file_b}),
87
 				$pbat,$self->{r},$self->{pool});
88
 	print "\t$m->{chg}\t$m->{file_b}\n" unless $::_q;
89
+	$self->apply_manualprops($file, $fbat);
90
 	$self->chg_file($fbat, $m);
91
 	$self->close_file($fbat,undef,$self->{pool});
92
 }

Return to bug 194999