115
$_before, $_after,
116
$_merge, $_strategy, $_preserve_merges, $_dry_run, $_parents, $_local,
117
$_prefix, $_no_checkout, $_url, $_verbose,
118
- $_commit_url, $_tag, $_merge_info, $_interactive);
118
+ $_commit_url, $_tag, $_merge_info, $_interactive, $_set_svn_props);
119
120
# This is a refactoring artifact so Git::SVN can get at this git-svn switch.
121
sub opt_prefix { return $_prefix || '' }
193
'dry-run|n' => \$_dry_run,
194
'fetch-all|all' => \$_fetch_all,
195
'commit-url=s' => \$_commit_url,
196
+ 'set-svn-props=s' => \$_set_svn_props,
197
'revision|r=i' => \$_revision,
198
'no-rebase' => \$_no_rebase,
199
'mergeinfo=s' => \$_merge_info,
229
'propget' => [ \&cmd_propget,
230
'Print the value of a property on a file or directory',
231
{ 'revision|r=i' => \$_revision } ],
232
+ 'propset' => [ \&cmd_propset,
233
+ 'Set the value of a property on a file or directory - will be set on commit',
234
+ {} ],
235
'proplist' => [ \&cmd_proplist,
236
'List all properties of a file or directory',
237
{ 'revision|r=i' => \$_revision } ],
1380
print $props->{$prop} . "\n";
1381
}
1382
1383
+# cmd_propset (PROPNAME, PROPVAL, PATH)
1384
+# ------------------------
1385
+# Adjust the SVN property PROPNAME to PROPVAL for PATH.
1386
+sub cmd_propset {
1387
+ my ($propname, $propval, $path) = @_;
1388
+ $path = '.' if not defined $path;
1389
+ $path = $cmd_dir_prefix . $path;
1390
+ usage(1) if not defined $propname;
1391
+ usage(1) if not defined $propval;
1392
+ my $file = basename($path);
1393
+ my $dn = dirname($path);
1394
+ my $cur_props = Git::SVN::Editor::check_attr( "svn-properties", $path );
1395
+ my @new_props;
1396
+ if (!$cur_props || $cur_props eq "unset" || $cur_props eq "" || $cur_props eq "set") {
1397
+ push @new_props, "$propname=$propval";
1398
+ } else {
1399
+ # TODO: handle combining properties better
1400
+ my @props = split(/;/, $cur_props);
1401
+ my $replaced_prop;
1402
+ foreach my $prop (@props) {
1403
+ # Parse 'name=value' syntax and set the property.
1404
+ if ($prop =~ /([^=]+)=(.*)/) {
1405
+ my ($n,$v) = ($1,$2);
1406
+ if ($n eq $propname) {
1407
+ $v = $propval;
1408
+ $replaced_prop = 1;
1409
+ }
1410
+ push @new_props, "$n=$v";
1411
+ }
1412
+ }
1413
+ if (!$replaced_prop) {
1414
+ push @new_props, "$propname=$propval";
1415
+ }
1416
+ }
1417
+ my $attrfile = "$dn/.gitattributes";
1418
+ open my $attrfh, '>>', $attrfile or die "Can't open $attrfile: $!\n";
1419
+ # TODO: don't simply append here if $file already has svn-properties
1420
+ my $new_props = join(';', @new_props);
1421
+ print $attrfh "$file svn-properties=$new_props\n" or
1422
+ die "write to $attrfile: $!\n";
1423
+ close $attrfh or die "close $attrfile: $!\n";
1424
+}
1425
+
1426
# cmd_proplist (PATH)
1427
# -------------------
1428
# Print the list of SVN properties for PATH.