summaryrefslogtreecommitdiff
path: root/git-svn.perl
diff options
context:
space:
mode:
Diffstat (limited to 'git-svn.perl')
-rwxr-xr-xgit-svn.perl132
1 files changed, 104 insertions, 28 deletions
diff --git a/git-svn.perl b/git-svn.perl
index 7349ffe..32d109e 100755
--- a/git-svn.perl
+++ b/git-svn.perl
@@ -115,7 +115,7 @@ my ($_stdin, $_help, $_edit,
$_before, $_after,
$_merge, $_strategy, $_preserve_merges, $_dry_run, $_parents, $_local,
$_prefix, $_no_checkout, $_url, $_verbose,
- $_commit_url, $_tag, $_merge_info, $_interactive);
+ $_commit_url, $_tag, $_merge_info, $_interactive, $_set_svn_props);
# This is a refactoring artifact so Git::SVN can get at this git-svn switch.
sub opt_prefix { return $_prefix || '' }
@@ -193,6 +193,7 @@ my %cmd = (
'dry-run|n' => \$_dry_run,
'fetch-all|all' => \$_fetch_all,
'commit-url=s' => \$_commit_url,
+ 'set-svn-props=s' => \$_set_svn_props,
'revision|r=i' => \$_revision,
'no-rebase' => \$_no_rebase,
'mergeinfo=s' => \$_merge_info,
@@ -228,6 +229,9 @@ my %cmd = (
'propget' => [ \&cmd_propget,
'Print the value of a property on a file or directory',
{ 'revision|r=i' => \$_revision } ],
+ 'propset' => [ \&cmd_propset,
+ 'Set the value of a property on a file or directory - will be set on commit',
+ {} ],
'proplist' => [ \&cmd_proplist,
'List all properties of a file or directory',
{ 'revision|r=i' => \$_revision } ],
@@ -260,8 +264,8 @@ my %cmd = (
} ],
'find-rev' => [ \&cmd_find_rev,
"Translate between SVN revision numbers and tree-ish",
- { 'before' => \$_before,
- 'after' => \$_after } ],
+ { 'B|before' => \$_before,
+ 'A|after' => \$_after } ],
'rebase' => [ \&cmd_rebase, "Fetch and rebase your working directory",
{ 'merge|m|M' => \$_merge,
'verbose|v' => \$_verbose,
@@ -306,13 +310,16 @@ sub readline {
}
package main;
-my $term = eval {
- $ENV{"GIT_SVN_NOTTY"}
- ? new Term::ReadLine 'git-svn', \*STDIN, \*STDOUT
- : new Term::ReadLine 'git-svn';
-};
-if ($@) {
- $term = new FakeTerm "$@: going non-interactive";
+my $term;
+sub term_init {
+ $term = eval {
+ $ENV{"GIT_SVN_NOTTY"}
+ ? new Term::ReadLine 'git-svn', \*STDIN, \*STDOUT
+ : new Term::ReadLine 'git-svn';
+ };
+ if ($@) {
+ $term = new FakeTerm "$@: going non-interactive";
+ }
}
my $cmd;
@@ -330,6 +337,12 @@ for (my $i = 0; $i < @ARGV; $i++) {
# make sure we're always running at the top-level working directory
if ($cmd && $cmd =~ /(?:clone|init|multi-init)$/) {
$ENV{GIT_DIR} ||= ".git";
+ # catch the submodule case
+ if (-f $ENV{GIT_DIR}) {
+ open(my $fh, '<', $ENV{GIT_DIR}) or
+ die "failed to open $ENV{GIT_DIR}: $!\n";
+ $ENV{GIT_DIR} = $1 if <$fh> =~ /^gitdir: (.+)$/;
+ }
} else {
my ($git_dir, $cdup);
git_cmd_try {
@@ -424,6 +437,7 @@ sub ask {
my $default = $arg{default};
my $resp;
my $i = 0;
+ term_init() unless $term;
if ( !( defined($term->IN)
&& defined( fileno($term->IN) )
@@ -1161,7 +1175,9 @@ sub cmd_branch {
::_req_svn();
my $ctx = SVN::Client->new(
- auth => Git::SVN::Ra::_auth_providers(),
+ config => SVN::Core::config_get_config(
+ $Git::SVN::Ra::config_dir
+ ),
log_msg => sub {
${ $_[0] } = defined $_message
? $_message
@@ -1370,6 +1386,49 @@ sub cmd_propget {
print $props->{$prop} . "\n";
}
+# cmd_propset (PROPNAME, PROPVAL, PATH)
+# ------------------------
+# Adjust the SVN property PROPNAME to PROPVAL for PATH.
+sub cmd_propset {
+ my ($propname, $propval, $path) = @_;
+ $path = '.' if not defined $path;
+ $path = $cmd_dir_prefix . $path;
+ usage(1) if not defined $propname;
+ usage(1) if not defined $propval;
+ my $file = basename($path);
+ my $dn = dirname($path);
+ my $cur_props = Git::SVN::Editor::check_attr( "svn-properties", $path );
+ my @new_props;
+ if (!$cur_props || $cur_props eq "unset" || $cur_props eq "" || $cur_props eq "set") {
+ push @new_props, "$propname=$propval";
+ } else {
+ # TODO: handle combining properties better
+ my @props = split(/;/, $cur_props);
+ my $replaced_prop;
+ foreach my $prop (@props) {
+ # Parse 'name=value' syntax and set the property.
+ if ($prop =~ /([^=]+)=(.*)/) {
+ my ($n,$v) = ($1,$2);
+ if ($n eq $propname) {
+ $v = $propval;
+ $replaced_prop = 1;
+ }
+ push @new_props, "$n=$v";
+ }
+ }
+ if (!$replaced_prop) {
+ push @new_props, "$propname=$propval";
+ }
+ }
+ my $attrfile = "$dn/.gitattributes";
+ open my $attrfh, '>>', $attrfile or die "Can't open $attrfile: $!\n";
+ # TODO: don't simply append here if $file already has svn-properties
+ my $new_props = join(';', @new_props);
+ print $attrfh "$file svn-properties=$new_props\n" or
+ die "write to $attrfile: $!\n";
+ close $attrfh or die "close $attrfile: $!\n";
+}
+
# cmd_proplist (PATH)
# -------------------
# Print the list of SVN properties for PATH.
@@ -1389,17 +1448,7 @@ sub cmd_multi_init {
usage(1);
}
- unless (defined $_prefix) {
- $_prefix = '';
- warn <<EOF
-WARNING: --prefix is not given, defaulting to empty prefix.
- This is probably not what you want! In order to stay compatible
- with regular remote-tracking refs, provide a prefix like
- --prefix=origin/ (remember the trailing slash), which will cause
- the SVN-tracking refs to be placed at refs/remotes/origin/*.
-NOTE: In Git v2.0, the default prefix will change from empty to 'origin/'.
-EOF
- }
+ $_prefix = 'origin/' unless defined $_prefix;
if (defined $url) {
$url = canonicalize_url($url);
init_subdir(@_);
@@ -1485,10 +1534,37 @@ sub cmd_commit_diff {
}
}
-
sub cmd_info {
- my $path = canonicalize_path(defined($_[0]) ? $_[0] : ".");
- my $fullpath = canonicalize_path($cmd_dir_prefix . $path);
+ my $path_arg = defined($_[0]) ? $_[0] : '.';
+ my $path = $path_arg;
+ if (File::Spec->file_name_is_absolute($path)) {
+ $path = canonicalize_path($path);
+
+ my $toplevel = eval {
+ my @cmd = qw/rev-parse --show-toplevel/;
+ command_oneline(\@cmd, STDERR => 0);
+ };
+
+ # remove $toplevel from the absolute path:
+ my ($vol, $dirs, $file) = File::Spec->splitpath($path);
+ my (undef, $tdirs, $tfile) = File::Spec->splitpath($toplevel);
+ my @dirs = File::Spec->splitdir($dirs);
+ my @tdirs = File::Spec->splitdir($tdirs);
+ pop @dirs if $dirs[-1] eq '';
+ pop @tdirs if $tdirs[-1] eq '';
+ push @dirs, $file;
+ push @tdirs, $tfile;
+ while (@tdirs && @dirs && $tdirs[0] eq $dirs[0]) {
+ shift @dirs;
+ shift @tdirs;
+ }
+ $dirs = File::Spec->catdir(@dirs);
+ $path = File::Spec->catpath($vol, $dirs);
+
+ $path = canonicalize_path($path);
+ } else {
+ $path = canonicalize_path($cmd_dir_prefix . $path);
+ }
if (exists $_[1]) {
die "Too many arguments specified\n";
}
@@ -1509,14 +1585,14 @@ sub cmd_info {
# canonicalize_path() will return "" to make libsvn 1.5.x happy,
$path = "." if $path eq "";
- my $full_url = canonicalize_url( add_path_to_url( $url, $fullpath ) );
+ my $full_url = canonicalize_url( add_path_to_url( $url, $path ) );
if ($_url) {
print "$full_url\n";
return;
}
- my $result = "Path: $path\n";
+ my $result = "Path: $path_arg\n";
$result .= "Name: " . basename($path) . "\n" if $file_type ne "dir";
$result .= "URL: $full_url\n";
@@ -1547,7 +1623,7 @@ sub cmd_info {
}
my ($lc_author, $lc_rev, $lc_date_utc);
- my @args = Git::SVN::Log::git_svn_log_cmd($rev, $rev, "--", $fullpath);
+ my @args = Git::SVN::Log::git_svn_log_cmd($rev, $rev, "--", $path);
my $log = command_output_pipe(@args);
my $esc_color = qr/(?:\033\[(?:(?:\d+;)*\d*)?m)*/;
while (<$log>) {