* [PATCH 0/3 v3] Implement git-svn info
@ 2007-11-21 19:57 David D. Kilzer
2007-11-21 19:57 ` [PATCH 1/3 v3] git-svn: extract reusable code into utility functions David D. Kilzer
2007-11-22 2:23 ` [PATCH 4/3] git-svn: allow `info' command to work offline Eric Wong
0 siblings, 2 replies; 11+ messages in thread
From: David D. Kilzer @ 2007-11-21 19:57 UTC (permalink / raw)
To: Eric Wong; +Cc: git, David D. Kilzer
Changes since the last patch series I posted (last night):
- Patch 1/3: No changes.
- Patch 2/3: Only changes to test code.
- Renamed t/t9117-git-svn-info.sh to t/t9119-git-svn-info.sh.
- Removed static expected.* files and reinstated dynamic generation.
- Replaced "touch -c -r" with ptouch (portable/perl touch) function.
(Should this go in t/lib-git-svn.sh?)
- Use sed(1) inline to work around minor "svn info" vs. "git svn info"
difference.
- Minor test name and expected.*/actual.* file name changes.
- Updated comments.
- Patch 3/3: Added 17 more tests (mirroring the existing 18 tests from
Patch 2/3).
"David D. Kilzer" <ddkilzer@kilzer.net> wrote:
> "David D. Kilzer" <ddkilzer@kilzer.net> wrote:
> > Eric Wong <normalperson@yhbt.net> wrote:
> > > Can we expect the output of "svn info" to not change between
> > > versions? I know "svn status" has changed between versions of
> > > svn. I'd prefer if we keep the expected.* files hard-coded
> > > in a test directory and compare those instead. Maybe use sed
> > > to substitute placeholders for timestamps..
> > Done.
> Grrr. I remember the reason I didn't do this in the first place.
> In Patch 2/3, there are now hard-coded directory paths and my
> username in the static expected-* files.
Actually, using "svn info" to dynamically generate the results means
that the tests will break when "svn info" does change, which is a good
thing. In other words, I think we want to know when that happens so
that we can make a decision about whether to support the change or not.
Dave
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH 1/3 v3] git-svn: extract reusable code into utility functions
2007-11-21 19:57 [PATCH 0/3 v3] Implement git-svn info David D. Kilzer
@ 2007-11-21 19:57 ` David D. Kilzer
2007-11-21 19:57 ` [PATCH 2/3 v3] git-svn info: implement info command David D. Kilzer
2007-11-22 1:19 ` [PATCH 1/3 v3] git-svn: extract reusable code into utility functions Eric Wong
2007-11-22 2:23 ` [PATCH 4/3] git-svn: allow `info' command to work offline Eric Wong
1 sibling, 2 replies; 11+ messages in thread
From: David D. Kilzer @ 2007-11-21 19:57 UTC (permalink / raw)
To: Eric Wong; +Cc: git, David D. Kilzer
Extacted canonicalize_path() in the main package.
Created new Git::SVN::Util package with an md5sum() function. A
new package was created so that Digest::MD5 did not have to be
loaded in the main package. Replaced code in the SVN::Git::Editor
and SVN::Git::Fetcher packages with calls to md5sum().
Extracted the format_svn_date(), parse_git_date() and
set_local_timezone() functions within the Git::SVN::Log package.
Signed-off-by: David D. Kilzer <ddkilzer@kilzer.net>
---
git-svn.perl | 96 ++++++++++++++++++++++++++++++++++++++-------------------
1 files changed, 64 insertions(+), 32 deletions(-)
diff --git a/git-svn.perl b/git-svn.perl
index 5b1deea..98c980f 100755
--- a/git-svn.perl
+++ b/git-svn.perl
@@ -48,7 +48,8 @@ BEGIN {
foreach (qw/command command_oneline command_noisy command_output_pipe
command_input_pipe command_close_pipe/) {
for my $package ( qw(SVN::Git::Editor SVN::Git::Fetcher
- Git::SVN::Migration Git::SVN::Log Git::SVN),
+ Git::SVN::Migration Git::SVN::Log Git::SVN
+ Git::SVN::Util),
__PACKAGE__) {
*{"${package}::$_"} = \&{"Git::$_"};
}
@@ -583,6 +584,17 @@ sub cmd_create_ignore {
});
}
+sub canonicalize_path {
+ my ($path) = @_;
+ # File::Spec->canonpath doesn't collapse x/../y into y (for a
+ # good reason), so let's do this manually.
+ $path =~ s#/+#/#g;
+ $path =~ s#/\.(?:/|$)#/#g;
+ $path =~ s#/[^/]+/\.\.##g;
+ $path =~ s#/$##g;
+ return $path;
+}
+
# get_svnprops(PATH)
# ------------------
# Helper for cmd_propget and cmd_proplist below.
@@ -600,12 +612,7 @@ sub get_svnprops {
# canonicalize the path (otherwise libsvn will abort or fail to
# find the file)
- # File::Spec->canonpath doesn't collapse x/../y into y (for a
- # good reason), so let's do this manually.
- $path =~ s#/+#/#g;
- $path =~ s#/\.(?:/|$)#/#g;
- $path =~ s#/[^/]+/\.\.##g;
- $path =~ s#/$##g;
+ $path = canonicalize_path($path);
my $r = (defined $_revision ? $_revision : $gs->ra->get_latest_revnum);
my $props;
@@ -1043,6 +1050,27 @@ sub linearize_history {
(\@linear_refs, \%parents);
}
+package Git::SVN::Util;
+use strict;
+use warnings;
+use Digest::MD5;
+
+sub md5sum {
+ my $arg = shift;
+ my $ref = ref $arg;
+ my $md5 = Digest::MD5->new();
+ if ($ref eq 'GLOB' || $ref eq 'IO::File') {
+ $md5->addfile($arg) or croak $!;
+ } elsif ($ref eq 'SCALAR') {
+ $md5->add($$arg) or croak $!;
+ } elsif (!$ref) {
+ $md5->add($arg) or croak $!;
+ } else {
+ ::fatal "Can't provide MD5 hash for unknown ref type: '", $ref, "'";
+ }
+ return $md5->hexdigest();
+}
+
package Git::SVN;
use strict;
use warnings;
@@ -2610,7 +2638,6 @@ use strict;
use warnings;
use Carp qw/croak/;
use IO::File qw//;
-use Digest::MD5;
# file baton members: path, mode_a, mode_b, pool, fh, blob, base
sub new {
@@ -2762,9 +2789,7 @@ sub apply_textdelta {
if (defined $exp) {
seek $base, 0, 0 or croak $!;
- my $md5 = Digest::MD5->new;
- $md5->addfile($base);
- my $got = $md5->hexdigest;
+ my $got = Git::SVN::Util::md5sum($base);
die "Checksum mismatch: $fb->{path} $fb->{blob}\n",
"expected: $exp\n",
" got: $got\n" if ($got ne $exp);
@@ -2783,9 +2808,7 @@ sub close_file {
if (my $fh = $fb->{fh}) {
if (defined $exp) {
seek($fh, 0, 0) or croak $!;
- my $md5 = Digest::MD5->new;
- $md5->addfile($fh);
- my $got = $md5->hexdigest;
+ my $got = Git::SVN::Util::md5sum($fh);
if ($got ne $exp) {
die "Checksum mismatch: $path\n",
"expected: $exp\n got: $got\n";
@@ -2837,7 +2860,6 @@ use strict;
use warnings;
use Carp qw/croak/;
use IO::File;
-use Digest::MD5;
sub new {
my ($class, $opts) = @_;
@@ -3141,11 +3163,9 @@ sub chg_file {
$fh->flush == 0 or croak $!;
seek $fh, 0, 0 or croak $!;
- my $md5 = Digest::MD5->new;
- $md5->addfile($fh) or croak $!;
+ my $exp = Git::SVN::Util::md5sum($fh);
seek $fh, 0, 0 or croak $!;
- my $exp = $md5->hexdigest;
my $pool = SVN::Pool->new;
my $atd = $self->apply_textdelta($fbat, undef, $pool);
my $got = SVN::TxDelta::send_stream($fh, @$atd, $pool);
@@ -3859,6 +3879,29 @@ sub run_pager {
exec $pager or ::fatal "Can't run pager: $! ($pager)";
}
+sub format_svn_date {
+ return strftime("%Y-%m-%d %H:%M:%S %z (%a, %d %b %Y)", localtime(shift));
+}
+
+sub parse_git_date {
+ my ($t, $tz) = @_;
+ # Date::Parse isn't in the standard Perl distro :(
+ if ($tz =~ s/^\+//) {
+ $t += tz_to_s_offset($tz);
+ } elsif ($tz =~ s/^\-//) {
+ $t -= tz_to_s_offset($tz);
+ }
+ return $t;
+}
+
+sub set_local_timezone {
+ if (defined $TZ) {
+ $ENV{TZ} = $TZ;
+ } else {
+ delete $ENV{TZ};
+ }
+}
+
sub tz_to_s_offset {
my ($tz) = @_;
$tz =~ s/(\d\d)$//;
@@ -3879,13 +3922,7 @@ sub get_author_info {
$dest->{t} = $t;
$dest->{tz} = $tz;
$dest->{a} = $au;
- # Date::Parse isn't in the standard Perl distro :(
- if ($tz =~ s/^\+//) {
- $t += tz_to_s_offset($tz);
- } elsif ($tz =~ s/^\-//) {
- $t -= tz_to_s_offset($tz);
- }
- $dest->{t_utc} = $t;
+ $dest->{t_utc} = parse_git_date($t, $tz);
}
sub process_commit {
@@ -3939,8 +3976,7 @@ sub show_commit_normal {
my ($c) = @_;
print commit_log_separator, "r$c->{r} | ";
print "$c->{c} | " if $show_commit;
- print "$c->{a} | ", strftime("%Y-%m-%d %H:%M:%S %z (%a, %d %b %Y)",
- localtime($c->{t_utc})), ' | ';
+ print "$c->{a} | ", format_svn_date($c->{t_utc}), ' | ';
my $nr_line = 0;
if (my $l = $c->{l}) {
@@ -3980,11 +4016,7 @@ sub cmd_show_log {
my (@args) = @_;
my ($r_min, $r_max);
my $r_last = -1; # prevent dupes
- if (defined $TZ) {
- $ENV{TZ} = $TZ;
- } else {
- delete $ENV{TZ};
- }
+ set_local_timezone();
if (defined $::_revision) {
if ($::_revision =~ /^(\d+):(\d+)$/) {
($r_min, $r_max) = ($1, $2);
--
1.5.3.4
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 2/3 v3] git-svn info: implement info command
2007-11-21 19:57 ` [PATCH 1/3 v3] git-svn: extract reusable code into utility functions David D. Kilzer
@ 2007-11-21 19:57 ` David D. Kilzer
2007-11-21 19:57 ` [PATCH 3/3 v3] git-svn: info --url [path] David D. Kilzer
2007-11-22 1:40 ` [PATCH 2/3 v3] git-svn info: implement info command Eric Wong
2007-11-22 1:19 ` [PATCH 1/3 v3] git-svn: extract reusable code into utility functions Eric Wong
1 sibling, 2 replies; 11+ messages in thread
From: David D. Kilzer @ 2007-11-21 19:57 UTC (permalink / raw)
To: Eric Wong; +Cc: git, David D. Kilzer
Implement "git-svn info" for files and directories based on the
"svn info" command. Note that the -r/--revision argument is not
supported yet.
Added 18 tests in t/t9119-git-svn-info.sh.
Signed-off-by: David D. Kilzer <ddkilzer@kilzer.net>
---
Documentation/git-svn.txt | 5 +
git-svn.perl | 132 ++++++++++++++++++++++
t/t9119-git-svn-info.sh | 274 +++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 411 insertions(+), 0 deletions(-)
create mode 100644 t/t9119-git-svn-info.sh
diff --git a/Documentation/git-svn.txt b/Documentation/git-svn.txt
index 488e4b1..c3fc878 100644
--- a/Documentation/git-svn.txt
+++ b/Documentation/git-svn.txt
@@ -193,6 +193,11 @@ Any other arguments are passed directly to `git log'
repository (that has been init-ed with git-svn).
The -r<revision> option is required for this.
+'info'::
+ Shows information about a file or directory similar to what
+ `svn info' provides. Does not currently support a -r/--revision
+ argument.
+
--
OPTIONS
diff --git a/git-svn.perl b/git-svn.perl
index 98c980f..be9290c 100755
--- a/git-svn.perl
+++ b/git-svn.perl
@@ -178,6 +178,10 @@ my %cmd = (
'file|F=s' => \$_file,
'revision|r=s' => \$_revision,
%cmt_opts } ],
+ 'info' => [ \&cmd_info,
+ "Show info about the latest SVN revision
+ on the current branch",
+ { } ],
);
my $cmd;
@@ -586,12 +590,18 @@ sub cmd_create_ignore {
sub canonicalize_path {
my ($path) = @_;
+ my $dot_slash_added = 0;
+ if (substr($path, 0, 1) ne "/") {
+ $path = "./" . $path;
+ $dot_slash_added = 1;
+ }
# File::Spec->canonpath doesn't collapse x/../y into y (for a
# good reason), so let's do this manually.
$path =~ s#/+#/#g;
$path =~ s#/\.(?:/|$)#/#g;
$path =~ s#/[^/]+/\.\.##g;
$path =~ s#/$##g;
+ $path =~ s#^\./## if $dot_slash_added;
return $path;
}
@@ -743,6 +753,104 @@ sub cmd_commit_diff {
}
}
+sub cmd_info {
+ my $path = canonicalize_path(shift or ".");
+ unless (scalar(@_) == 0) {
+ die "Too many arguments specified\n";
+ }
+
+ my ($file_type, $diff_status) = find_file_type_and_diff_status($path);
+
+ if (!$file_type && !$diff_status) {
+ print STDERR "$path: (Not a versioned resource)\n\n";
+ return;
+ }
+
+ my ($url, $rev, $uuid, $gs) = working_head_info('HEAD');
+ unless ($gs) {
+ die "Unable to determine upstream SVN information from ",
+ "working tree history\n";
+ }
+ my $full_url = $url . ($path eq "." ? "" : "/$path");
+
+ my $result = "Path: $path\n";
+ $result .= "Name: " . basename($path) . "\n" if $file_type ne "dir";
+ $result .= "URL: " . $full_url . "\n";
+
+ my $repos_root = $gs->ra->{repos_root};
+ Git::SVN::remove_username($repos_root);
+ $result .= "Repository Root: $repos_root\n";
+ $result .= "Repository UUID: $uuid\n" unless $diff_status eq "A";
+ $result .= "Revision: " . ($diff_status eq "A" ? 0 : $rev) . "\n";
+
+ $result .= "Node Kind: " .
+ ($file_type eq "dir" ? "directory" : "file") . "\n";
+
+ my $schedule = $diff_status eq "A"
+ ? "add"
+ : ($diff_status eq "D" ? "delete" : "normal");
+ $result .= "Schedule: $schedule\n";
+
+ if ($diff_status eq "A") {
+ print $result, "\n";
+ return;
+ }
+
+ my ($lc_author, $lc_rev, $lc_date_utc);
+ 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>) {
+ if (/^${esc_color}author (.+) <[^>]+> (\d+) ([\-\+]?\d+)$/o) {
+ $lc_author = $1;
+ $lc_date_utc = Git::SVN::Log::parse_git_date($2, $3);
+ } elsif (/^${esc_color} (git-svn-id:.+)$/o) {
+ (undef, $lc_rev, undef) = ::extract_metadata($1);
+ }
+ }
+ close $log;
+
+ Git::SVN::Log::set_local_timezone();
+
+ $result .= "Last Changed Author: $lc_author\n";
+ $result .= "Last Changed Rev: $lc_rev\n";
+ $result .= "Last Changed Date: " .
+ Git::SVN::Log::format_svn_date($lc_date_utc) . "\n";
+
+ if ($file_type ne "dir") {
+ my $text_last_updated_date =
+ ($diff_status eq "D" ? $lc_date_utc : (stat $path)[9]);
+ $result .=
+ "Text Last Updated: " .
+ Git::SVN::Log::format_svn_date($text_last_updated_date) .
+ "\n";
+ my $checksum;
+ if ($diff_status eq "D") {
+ my ($fh, $ctx) =
+ command_output_pipe(qw(cat-file blob), "HEAD:$path");
+ if ($file_type eq "link") {
+ my $file_name = <$fh>;
+ $checksum = Git::SVN::Util::md5sum("link $file_name");
+ } else {
+ $checksum = Git::SVN::Util::md5sum($fh);
+ }
+ command_close_pipe($fh, $ctx);
+ } elsif ($file_type eq "link") {
+ my $file_name =
+ command(qw(cat-file blob), "HEAD:$path");
+ $checksum =
+ Git::SVN::Util::md5sum("link " . $file_name);
+ } else {
+ open FILE, "<", $path or die $!;
+ $checksum = Git::SVN::Util::md5sum(\*FILE);
+ close FILE or die $!;
+ }
+ $result .= "Checksum: " . $checksum . "\n";
+ }
+
+ print $result, "\n";
+}
+
########################### utility functions #########################
sub rebase_cmd {
@@ -1050,6 +1158,30 @@ sub linearize_history {
(\@linear_refs, \%parents);
}
+sub find_file_type_and_diff_status {
+ my ($path) = @_;
+
+ my $diff_output =
+ command_oneline(qw(diff --cached --name-status --), $path) || "";
+ my $diff_status = (split(' ', $diff_output))[0] || "";
+
+ my $ls_tree = command_oneline(qw(ls-tree HEAD), $path) || "";
+
+ return (undef, undef) if !$diff_status && !$ls_tree;
+
+ if ($diff_status eq "A") {
+ return ("link", $diff_status) if -l $path;
+ return ("dir", $diff_status) if -d $path;
+ return ("file", $diff_status);
+ }
+
+ my $mode = (split(' ', $ls_tree))[0] || "";
+
+ return ("link", $diff_status) if $mode eq "120000";
+ return ("dir", $diff_status) if $mode eq "040000";
+ return ("file", $diff_status);
+}
+
package Git::SVN::Util;
use strict;
use warnings;
diff --git a/t/t9119-git-svn-info.sh b/t/t9119-git-svn-info.sh
new file mode 100644
index 0000000..edd64d6
--- /dev/null
+++ b/t/t9119-git-svn-info.sh
@@ -0,0 +1,274 @@
+#!/bin/sh
+#
+# Copyright (c) 2007 David D. Kilzer
+
+test_description='git-svn info'
+
+. ./lib-git-svn.sh
+
+ptouch() {
+ perl -w -e '
+ use strict;
+ die "ptouch requires exactly 2 arguments" if @ARGV != 2;
+ die "$ARGV[0] does not exist" if ! -e $ARGV[0];
+ my @s = stat $ARGV[0];
+ utime $s[8], $s[9], $ARGV[1];
+ ' "$1" "$2"
+}
+
+test_expect_success 'setup repository and import' "
+ mkdir info &&
+ cd info &&
+ echo one > file &&
+ ln -s file symlink-file &&
+ mkdir directory &&
+ touch directory/.placeholder &&
+ ln -s directory symlink-directory &&
+ svn import -m 'initial' . $svnrepo &&
+ cd .. &&
+ mkdir gitwc &&
+ cd gitwc &&
+ git-svn init $svnrepo &&
+ git-svn fetch &&
+ cd .. &&
+ svn co $svnrepo svnwc &&
+ ptouch svnwc/file gitwc/file &&
+ ptouch svnwc/directory gitwc/directory &&
+ ptouch svnwc/symlink-file gitwc/symlink-file &&
+ ptouch svnwc/symlink-directory gitwc/symlink-directory
+ "
+
+test_expect_success 'info' "
+ (cd svnwc; svn info) > expected.info &&
+ (cd gitwc; git-svn info) > actual.info &&
+ git-diff expected.info actual.info
+ "
+
+test_expect_success 'info .' "
+ (cd svnwc; svn info .) > expected.info-dot &&
+ (cd gitwc; git-svn info .) > actual.info-dot &&
+ git-diff expected.info-dot actual.info-dot
+ "
+
+test_expect_success 'info file' "
+ (cd svnwc; svn info file) > expected.info-file &&
+ (cd gitwc; git-svn info file) > actual.info-file &&
+ git-diff expected.info-file actual.info-file
+ "
+
+test_expect_success 'info directory' "
+ (cd svnwc; svn info directory) > expected.info-directory &&
+ (cd gitwc; git-svn info directory) > actual.info-directory &&
+ git-diff expected.info-directory actual.info-directory
+ "
+
+test_expect_success 'info symlink-file' "
+ (cd svnwc; svn info symlink-file) > expected.info-symlink-file &&
+ (cd gitwc; git-svn info symlink-file) > actual.info-symlink-file &&
+ git-diff expected.info-symlink-file actual.info-symlink-file
+ "
+
+test_expect_success 'info symlink-directory' "
+ (cd svnwc; svn info symlink-directory) \
+ > expected.info-symlink-directory &&
+ (cd gitwc; git-svn info symlink-directory) \
+ > actual.info-symlink-directory &&
+ git-diff expected.info-symlink-directory actual.info-symlink-directory
+ "
+
+test_expect_success 'info added-file' "
+ echo two > gitwc/added-file &&
+ cd gitwc &&
+ git add added-file &&
+ cd .. &&
+ cp gitwc/added-file svnwc/added-file &&
+ ptouch gitwc/added-file svnwc/added-file &&
+ cd svnwc &&
+ svn add added-file > /dev/null &&
+ cd .. &&
+ (cd svnwc; svn info added-file) > expected.info-added-file &&
+ (cd gitwc; git-svn info added-file) > actual.info-added-file &&
+ git-diff expected.info-added-file actual.info-added-file
+ "
+
+test_expect_success 'info added-directory' "
+ mkdir gitwc/added-directory svnwc/added-directory &&
+ ptouch gitwc/added-directory svnwc/added-directory &&
+ touch gitwc/added-directory/.placeholder &&
+ cd svnwc &&
+ svn add added-directory > /dev/null &&
+ cd .. &&
+ cd gitwc &&
+ git add added-directory &&
+ cd .. &&
+ (cd svnwc; svn info added-directory) \
+ > expected.info-added-directory &&
+ (cd gitwc; git-svn info added-directory) \
+ > actual.info-added-directory &&
+ git-diff expected.info-added-directory actual.info-added-directory
+ "
+
+test_expect_success 'info added-symlink-file' "
+ cd gitwc &&
+ ln -s added-file added-symlink-file &&
+ git add added-symlink-file &&
+ cd .. &&
+ cd svnwc &&
+ ln -s added-file added-symlink-file &&
+ svn add added-symlink-file > /dev/null &&
+ cd .. &&
+ ptouch gitwc/added-symlink-file svnwc/added-symlink-file &&
+ (cd svnwc; svn info added-symlink-file) \
+ > expected.info-added-symlink-file &&
+ (cd gitwc; git-svn info added-symlink-file) \
+ > actual.info-added-symlink-file &&
+ git-diff expected.info-added-symlink-file \
+ actual.info-added-symlink-file
+ "
+
+test_expect_success 'info added-symlink-directory' "
+ cd gitwc &&
+ ln -s added-directory added-symlink-directory &&
+ git add added-symlink-directory &&
+ cd .. &&
+ cd svnwc &&
+ ln -s added-directory added-symlink-directory &&
+ svn add added-symlink-directory > /dev/null &&
+ cd .. &&
+ ptouch gitwc/added-symlink-directory svnwc/added-symlink-directory &&
+ (cd svnwc; svn info added-symlink-directory) \
+ > expected.info-added-symlink-directory &&
+ (cd gitwc; git-svn info added-symlink-directory) \
+ > actual.info-added-symlink-directory &&
+ git-diff expected.info-added-symlink-directory \
+ actual.info-added-symlink-directory
+ "
+
+# The next few tests replace the "Text Last Updated" value with a
+# placeholder since git doesn't have a way to know the date that a
+# now-deleted file was last checked out locally. Internally it
+# simply reuses the Last Changed Date.
+
+test_expect_success 'info deleted-file' "
+ cd gitwc &&
+ git rm -f file > /dev/null &&
+ cd .. &&
+ cd svnwc &&
+ svn rm --force file > /dev/null &&
+ cd .. &&
+ (cd svnwc; svn info file) |
+ sed -e 's/^\(Text Last Updated:\).*/\1 TEXT-LAST-UPDATED-STRING/' \
+ > expected.info-deleted-file &&
+ (cd gitwc; git-svn info file) |
+ sed -e 's/^\(Text Last Updated:\).*/\1 TEXT-LAST-UPDATED-STRING/' \
+ > actual.info-deleted-file &&
+ git-diff expected.info-deleted-file actual.info-deleted-file
+ "
+
+test_expect_success 'info deleted-directory' "
+ cd gitwc &&
+ git rm -r -f directory > /dev/null &&
+ cd .. &&
+ cd svnwc &&
+ svn rm --force directory > /dev/null &&
+ cd .. &&
+ (cd svnwc; svn info directory) |
+ sed -e 's/^\(Text Last Updated:\).*/\1 TEXT-LAST-UPDATED-STRING/' \
+ > expected.info-deleted-directory &&
+ (cd gitwc; git-svn info directory) |
+ sed -e 's/^\(Text Last Updated:\).*/\1 TEXT-LAST-UPDATED-STRING/' \
+ > actual.info-deleted-directory &&
+ git-diff expected.info-deleted-directory actual.info-deleted-directory
+ "
+
+test_expect_success 'info deleted-symlink-file' "
+ cd gitwc &&
+ git rm -f symlink-file > /dev/null &&
+ cd .. &&
+ cd svnwc &&
+ svn rm --force symlink-file > /dev/null &&
+ cd .. &&
+ (cd svnwc; svn info symlink-file) |
+ sed -e 's/^\(Text Last Updated:\).*/\1 TEXT-LAST-UPDATED-STRING/' \
+ > expected.info-deleted-symlink-file &&
+ (cd gitwc; git-svn info symlink-file) |
+ sed -e 's/^\(Text Last Updated:\).*/\1 TEXT-LAST-UPDATED-STRING/' \
+ > actual.info-deleted-symlink-file &&
+ git-diff expected.info-deleted-symlink-file \
+ actual.info-deleted-symlink-file
+ "
+
+test_expect_success 'info deleted-symlink-directory' "
+ cd gitwc &&
+ git rm -f symlink-directory > /dev/null &&
+ cd .. &&
+ cd svnwc &&
+ svn rm --force symlink-directory > /dev/null &&
+ cd .. &&
+ (cd svnwc; svn info symlink-directory) |
+ sed -e 's/^\(Text Last Updated:\).*/\1 TEXT-LAST-UPDATED-STRING/' \
+ > expected.info-deleted-symlink-directory &&
+ (cd gitwc; git-svn info symlink-directory) |
+ sed -e 's/^\(Text Last Updated:\).*/\1 TEXT-LAST-UPDATED-STRING/' \
+ > actual.info-deleted-symlink-directory &&
+ git-diff expected.info-deleted-symlink-directory \
+ actual.info-deleted-symlink-directory
+ "
+
+# NOTE: git does not have the concept of replaced objects,
+# so we can't test for files in that state.
+
+test_expect_success 'info unknown-file' "
+ echo two > gitwc/unknown-file &&
+ cp gitwc/unknown-file svnwc/unknown-file &&
+ ptouch gitwc/unknown-file svnwc/unknown-file &&
+ (cd svnwc; svn info unknown-file) 2> expected.info-unknown-file &&
+ (cd gitwc; git-svn info unknown-file) 2> actual.info-unknown-file &&
+ git-diff expected.info-unknown-file actual.info-unknown-file
+ "
+
+test_expect_success 'info unknown-directory' "
+ mkdir gitwc/unknown-directory svnwc/unknown-directory &&
+ ptouch gitwc/unknown-directory svnwc/unknown-directory &&
+ touch gitwc/unknown-directory/.placeholder &&
+ (cd svnwc; svn info unknown-directory) \
+ 2> expected.info-unknown-directory &&
+ (cd gitwc; git-svn info unknown-directory) \
+ 2> actual.info-unknown-directory &&
+ git-diff expected.info-unknown-directory actual.info-unknown-directory
+ "
+
+test_expect_success 'info unknown-symlink-file' "
+ cd gitwc &&
+ ln -s unknown-file unknown-symlink-file &&
+ cd .. &&
+ cd svnwc &&
+ ln -s unknown-file unknown-symlink-file &&
+ cd .. &&
+ ptouch gitwc/unknown-symlink-file svnwc/unknown-symlink-file &&
+ (cd svnwc; svn info unknown-symlink-file) \
+ 2> expected.info-unknown-symlink-file &&
+ (cd gitwc; git-svn info unknown-symlink-file) \
+ 2> actual.info-unknown-symlink-file &&
+ git-diff expected.info-unknown-symlink-file \
+ actual.info-unknown-symlink-file
+ "
+
+test_expect_success 'info unknown-symlink-directory' "
+ cd gitwc &&
+ ln -s unknown-directory unknown-symlink-directory &&
+ cd .. &&
+ cd svnwc &&
+ ln -s unknown-directory unknown-symlink-directory &&
+ cd .. &&
+ ptouch gitwc/unknown-symlink-directory \
+ svnwc/unknown-symlink-directory &&
+ (cd svnwc; svn info unknown-symlink-directory) \
+ 2> expected.info-unknown-symlink-directory &&
+ (cd gitwc; git-svn info unknown-symlink-directory) \
+ 2> actual.info-unknown-symlink-directory &&
+ git-diff expected.info-unknown-symlink-directory \
+ actual.info-unknown-symlink-directory
+ "
+
+test_done
--
1.5.3.4
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 3/3 v3] git-svn: info --url [path]
2007-11-21 19:57 ` [PATCH 2/3 v3] git-svn info: implement info command David D. Kilzer
@ 2007-11-21 19:57 ` David D. Kilzer
2007-11-22 1:40 ` [PATCH 2/3 v3] git-svn info: implement info command Eric Wong
1 sibling, 0 replies; 11+ messages in thread
From: David D. Kilzer @ 2007-11-21 19:57 UTC (permalink / raw)
To: Eric Wong; +Cc: git, David D. Kilzer
Return the svn URL for the given path, or return the svn
repository URL if no path is given.
Added 18 tests to t/t9119-git-svn-info.sh.
Signed-off-by: David D. Kilzer <ddkilzer@kilzer.net>
---
Documentation/git-svn.txt | 3 +-
git-svn.perl | 9 +++-
t/t9119-git-svn-info.sh | 93 +++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 102 insertions(+), 3 deletions(-)
diff --git a/Documentation/git-svn.txt b/Documentation/git-svn.txt
index c3fc878..918a992 100644
--- a/Documentation/git-svn.txt
+++ b/Documentation/git-svn.txt
@@ -196,7 +196,8 @@ Any other arguments are passed directly to `git log'
'info'::
Shows information about a file or directory similar to what
`svn info' provides. Does not currently support a -r/--revision
- argument.
+ argument. Use the --url option to output only the value of the
+ 'URL:' field.
--
diff --git a/git-svn.perl b/git-svn.perl
index be9290c..62801c8 100755
--- a/git-svn.perl
+++ b/git-svn.perl
@@ -65,7 +65,7 @@ my ($_stdin, $_help, $_edit,
$_template, $_shared,
$_version, $_fetch_all, $_no_rebase,
$_merge, $_strategy, $_dry_run, $_local,
- $_prefix, $_no_checkout, $_verbose);
+ $_prefix, $_no_checkout, $_url, $_verbose);
$Git::SVN::_follow_parent = 1;
my %remote_opts = ( 'username=s' => \$Git::SVN::Prompt::_username,
'config-dir=s' => \$Git::SVN::Ra::config_dir,
@@ -181,7 +181,7 @@ my %cmd = (
'info' => [ \&cmd_info,
"Show info about the latest SVN revision
on the current branch",
- { } ],
+ { 'url' => \$_url, } ],
);
my $cmd;
@@ -773,6 +773,11 @@ sub cmd_info {
}
my $full_url = $url . ($path eq "." ? "" : "/$path");
+ if ($_url) {
+ print $full_url, "\n";
+ return;
+ }
+
my $result = "Path: $path\n";
$result .= "Name: " . basename($path) . "\n" if $file_type ne "dir";
$result .= "URL: " . $full_url . "\n";
diff --git a/t/t9119-git-svn-info.sh b/t/t9119-git-svn-info.sh
index edd64d6..e81457f 100644
--- a/t/t9119-git-svn-info.sh
+++ b/t/t9119-git-svn-info.sh
@@ -44,30 +44,51 @@ test_expect_success 'info' "
git-diff expected.info actual.info
"
+test_expect_success 'info --url' '
+ test $(cd gitwc; git-svn info --url) = $svnrepo
+ '
+
test_expect_success 'info .' "
(cd svnwc; svn info .) > expected.info-dot &&
(cd gitwc; git-svn info .) > actual.info-dot &&
git-diff expected.info-dot actual.info-dot
"
+test_expect_success 'info --url .' '
+ test $(cd gitwc; git-svn info --url .) = $svnrepo
+ '
+
test_expect_success 'info file' "
(cd svnwc; svn info file) > expected.info-file &&
(cd gitwc; git-svn info file) > actual.info-file &&
git-diff expected.info-file actual.info-file
"
+test_expect_success 'info --url file' '
+ test $(cd gitwc; git-svn info --url file) = "$svnrepo/file"
+ '
+
test_expect_success 'info directory' "
(cd svnwc; svn info directory) > expected.info-directory &&
(cd gitwc; git-svn info directory) > actual.info-directory &&
git-diff expected.info-directory actual.info-directory
"
+test_expect_success 'info --url directory' '
+ test $(cd gitwc; git-svn info --url directory) = "$svnrepo/directory"
+ '
+
test_expect_success 'info symlink-file' "
(cd svnwc; svn info symlink-file) > expected.info-symlink-file &&
(cd gitwc; git-svn info symlink-file) > actual.info-symlink-file &&
git-diff expected.info-symlink-file actual.info-symlink-file
"
+test_expect_success 'info --url symlink-file' '
+ test $(cd gitwc; git-svn info --url symlink-file) \
+ = "$svnrepo/symlink-file"
+ '
+
test_expect_success 'info symlink-directory' "
(cd svnwc; svn info symlink-directory) \
> expected.info-symlink-directory &&
@@ -76,6 +97,11 @@ test_expect_success 'info symlink-directory' "
git-diff expected.info-symlink-directory actual.info-symlink-directory
"
+test_expect_success 'info --url symlink-directory' '
+ test $(cd gitwc; git-svn info --url symlink-directory) \
+ = "$svnrepo/symlink-directory"
+ '
+
test_expect_success 'info added-file' "
echo two > gitwc/added-file &&
cd gitwc &&
@@ -91,6 +117,11 @@ test_expect_success 'info added-file' "
git-diff expected.info-added-file actual.info-added-file
"
+test_expect_success 'info --url added-file' '
+ test $(cd gitwc; git-svn info --url added-file) \
+ = "$svnrepo/added-file"
+ '
+
test_expect_success 'info added-directory' "
mkdir gitwc/added-directory svnwc/added-directory &&
ptouch gitwc/added-directory svnwc/added-directory &&
@@ -108,6 +139,11 @@ test_expect_success 'info added-directory' "
git-diff expected.info-added-directory actual.info-added-directory
"
+test_expect_success 'info --url added-directory' '
+ test $(cd gitwc; git-svn info --url added-directory) \
+ = "$svnrepo/added-directory"
+ '
+
test_expect_success 'info added-symlink-file' "
cd gitwc &&
ln -s added-file added-symlink-file &&
@@ -126,6 +162,11 @@ test_expect_success 'info added-symlink-file' "
actual.info-added-symlink-file
"
+test_expect_success 'info --url added-symlink-file' '
+ test $(cd gitwc; git-svn info --url added-symlink-file) \
+ = "$svnrepo/added-symlink-file"
+ '
+
test_expect_success 'info added-symlink-directory' "
cd gitwc &&
ln -s added-directory added-symlink-directory &&
@@ -144,6 +185,11 @@ test_expect_success 'info added-symlink-directory' "
actual.info-added-symlink-directory
"
+test_expect_success 'info --url added-symlink-directory' '
+ test $(cd gitwc; git-svn info --url added-symlink-directory) \
+ = "$svnrepo/added-symlink-directory"
+ '
+
# The next few tests replace the "Text Last Updated" value with a
# placeholder since git doesn't have a way to know the date that a
# now-deleted file was last checked out locally. Internally it
@@ -165,6 +211,11 @@ test_expect_success 'info deleted-file' "
git-diff expected.info-deleted-file actual.info-deleted-file
"
+test_expect_success 'info --url file (deleted)' '
+ test $(cd gitwc; git-svn info --url file) \
+ = "$svnrepo/file"
+ '
+
test_expect_success 'info deleted-directory' "
cd gitwc &&
git rm -r -f directory > /dev/null &&
@@ -181,6 +232,11 @@ test_expect_success 'info deleted-directory' "
git-diff expected.info-deleted-directory actual.info-deleted-directory
"
+test_expect_success 'info --url directory (deleted)' '
+ test $(cd gitwc; git-svn info --url directory) \
+ = "$svnrepo/directory"
+ '
+
test_expect_success 'info deleted-symlink-file' "
cd gitwc &&
git rm -f symlink-file > /dev/null &&
@@ -198,6 +254,11 @@ test_expect_success 'info deleted-symlink-file' "
actual.info-deleted-symlink-file
"
+test_expect_success 'info --url symlink-file (deleted)' '
+ test $(cd gitwc; git-svn info --url symlink-file) \
+ = "$svnrepo/symlink-file"
+ '
+
test_expect_success 'info deleted-symlink-directory' "
cd gitwc &&
git rm -f symlink-directory > /dev/null &&
@@ -215,6 +276,11 @@ test_expect_success 'info deleted-symlink-directory' "
actual.info-deleted-symlink-directory
"
+test_expect_success 'info --url symlink-directory (deleted)' '
+ test $(cd gitwc; git-svn info --url symlink-directory) \
+ = "$svnrepo/symlink-directory"
+ '
+
# NOTE: git does not have the concept of replaced objects,
# so we can't test for files in that state.
@@ -227,6 +293,12 @@ test_expect_success 'info unknown-file' "
git-diff expected.info-unknown-file actual.info-unknown-file
"
+test_expect_success 'info --url unknown-file' '
+ test -z $(cd gitwc; git-svn info --url unknown-file \
+ 2> ../actual.info--url-unknown-file) &&
+ git-diff expected.info-unknown-file actual.info--url-unknown-file
+ '
+
test_expect_success 'info unknown-directory' "
mkdir gitwc/unknown-directory svnwc/unknown-directory &&
ptouch gitwc/unknown-directory svnwc/unknown-directory &&
@@ -238,6 +310,13 @@ test_expect_success 'info unknown-directory' "
git-diff expected.info-unknown-directory actual.info-unknown-directory
"
+test_expect_success 'info --url unknown-directory' '
+ test -z $(cd gitwc; git-svn info --url unknown-directory \
+ 2> ../actual.info--url-unknown-directory) &&
+ git-diff expected.info-unknown-directory \
+ actual.info--url-unknown-directory
+ '
+
test_expect_success 'info unknown-symlink-file' "
cd gitwc &&
ln -s unknown-file unknown-symlink-file &&
@@ -254,6 +333,13 @@ test_expect_success 'info unknown-symlink-file' "
actual.info-unknown-symlink-file
"
+test_expect_success 'info --url unknown-symlink-file' '
+ test -z $(cd gitwc; git-svn info --url unknown-symlink-file \
+ 2> ../actual.info--url-unknown-symlink-file) &&
+ git-diff expected.info-unknown-symlink-file \
+ actual.info--url-unknown-symlink-file
+ '
+
test_expect_success 'info unknown-symlink-directory' "
cd gitwc &&
ln -s unknown-directory unknown-symlink-directory &&
@@ -271,4 +357,11 @@ test_expect_success 'info unknown-symlink-directory' "
actual.info-unknown-symlink-directory
"
+test_expect_success 'info --url unknown-symlink-directory' '
+ test -z $(cd gitwc; git-svn info --url unknown-symlink-directory \
+ 2> ../actual.info--url-unknown-symlink-directory) &&
+ git-diff expected.info-unknown-symlink-directory \
+ actual.info--url-unknown-symlink-directory
+ '
+
test_done
--
1.5.3.4
^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH 1/3 v3] git-svn: extract reusable code into utility functions
2007-11-21 19:57 ` [PATCH 1/3 v3] git-svn: extract reusable code into utility functions David D. Kilzer
2007-11-21 19:57 ` [PATCH 2/3 v3] git-svn info: implement info command David D. Kilzer
@ 2007-11-22 1:19 ` Eric Wong
1 sibling, 0 replies; 11+ messages in thread
From: Eric Wong @ 2007-11-22 1:19 UTC (permalink / raw)
To: David D. Kilzer; +Cc: git
"David D. Kilzer" <ddkilzer@kilzer.net> wrote:
> Extacted canonicalize_path() in the main package.
>
> Created new Git::SVN::Util package with an md5sum() function. A
> new package was created so that Digest::MD5 did not have to be
> loaded in the main package. Replaced code in the SVN::Git::Editor
> and SVN::Git::Fetcher packages with calls to md5sum().
>
> Extracted the format_svn_date(), parse_git_date() and
> set_local_timezone() functions within the Git::SVN::Log package.
>
> Signed-off-by: David D. Kilzer <ddkilzer@kilzer.net>
Thanks, this patch is independently useful.
Acked-by: Eric Wong <normalperson@yhbt.net>
I'm having a problem with [2/3] currently:
$file_type not being detected correctly when running "git svn info"
on the top-level directory with no arguments. It's opening the
directory and trying to md5 it here:
} else {
open FILE, "<", $path or die $!;
$checksum = Git::SVN::Util::md5sum(\*FILE);
close FILE or die $!;
}
> ---
> git-svn.perl | 96 ++++++++++++++++++++++++++++++++++++++-------------------
> 1 files changed, 64 insertions(+), 32 deletions(-)
>
> diff --git a/git-svn.perl b/git-svn.perl
> index 5b1deea..98c980f 100755
> --- a/git-svn.perl
> +++ b/git-svn.perl
> @@ -48,7 +48,8 @@ BEGIN {
> foreach (qw/command command_oneline command_noisy command_output_pipe
> command_input_pipe command_close_pipe/) {
> for my $package ( qw(SVN::Git::Editor SVN::Git::Fetcher
> - Git::SVN::Migration Git::SVN::Log Git::SVN),
> + Git::SVN::Migration Git::SVN::Log Git::SVN
> + Git::SVN::Util),
> __PACKAGE__) {
> *{"${package}::$_"} = \&{"Git::$_"};
> }
> @@ -583,6 +584,17 @@ sub cmd_create_ignore {
> });
> }
>
> +sub canonicalize_path {
> + my ($path) = @_;
> + # File::Spec->canonpath doesn't collapse x/../y into y (for a
> + # good reason), so let's do this manually.
> + $path =~ s#/+#/#g;
> + $path =~ s#/\.(?:/|$)#/#g;
> + $path =~ s#/[^/]+/\.\.##g;
> + $path =~ s#/$##g;
> + return $path;
> +}
> +
> # get_svnprops(PATH)
> # ------------------
> # Helper for cmd_propget and cmd_proplist below.
> @@ -600,12 +612,7 @@ sub get_svnprops {
>
> # canonicalize the path (otherwise libsvn will abort or fail to
> # find the file)
> - # File::Spec->canonpath doesn't collapse x/../y into y (for a
> - # good reason), so let's do this manually.
> - $path =~ s#/+#/#g;
> - $path =~ s#/\.(?:/|$)#/#g;
> - $path =~ s#/[^/]+/\.\.##g;
> - $path =~ s#/$##g;
> + $path = canonicalize_path($path);
>
> my $r = (defined $_revision ? $_revision : $gs->ra->get_latest_revnum);
> my $props;
> @@ -1043,6 +1050,27 @@ sub linearize_history {
> (\@linear_refs, \%parents);
> }
>
> +package Git::SVN::Util;
> +use strict;
> +use warnings;
> +use Digest::MD5;
> +
> +sub md5sum {
> + my $arg = shift;
> + my $ref = ref $arg;
> + my $md5 = Digest::MD5->new();
> + if ($ref eq 'GLOB' || $ref eq 'IO::File') {
> + $md5->addfile($arg) or croak $!;
> + } elsif ($ref eq 'SCALAR') {
> + $md5->add($$arg) or croak $!;
> + } elsif (!$ref) {
> + $md5->add($arg) or croak $!;
> + } else {
> + ::fatal "Can't provide MD5 hash for unknown ref type: '", $ref, "'";
> + }
> + return $md5->hexdigest();
> +}
> +
> package Git::SVN;
> use strict;
> use warnings;
> @@ -2610,7 +2638,6 @@ use strict;
> use warnings;
> use Carp qw/croak/;
> use IO::File qw//;
> -use Digest::MD5;
>
> # file baton members: path, mode_a, mode_b, pool, fh, blob, base
> sub new {
> @@ -2762,9 +2789,7 @@ sub apply_textdelta {
>
> if (defined $exp) {
> seek $base, 0, 0 or croak $!;
> - my $md5 = Digest::MD5->new;
> - $md5->addfile($base);
> - my $got = $md5->hexdigest;
> + my $got = Git::SVN::Util::md5sum($base);
> die "Checksum mismatch: $fb->{path} $fb->{blob}\n",
> "expected: $exp\n",
> " got: $got\n" if ($got ne $exp);
> @@ -2783,9 +2808,7 @@ sub close_file {
> if (my $fh = $fb->{fh}) {
> if (defined $exp) {
> seek($fh, 0, 0) or croak $!;
> - my $md5 = Digest::MD5->new;
> - $md5->addfile($fh);
> - my $got = $md5->hexdigest;
> + my $got = Git::SVN::Util::md5sum($fh);
> if ($got ne $exp) {
> die "Checksum mismatch: $path\n",
> "expected: $exp\n got: $got\n";
> @@ -2837,7 +2860,6 @@ use strict;
> use warnings;
> use Carp qw/croak/;
> use IO::File;
> -use Digest::MD5;
>
> sub new {
> my ($class, $opts) = @_;
> @@ -3141,11 +3163,9 @@ sub chg_file {
> $fh->flush == 0 or croak $!;
> seek $fh, 0, 0 or croak $!;
>
> - my $md5 = Digest::MD5->new;
> - $md5->addfile($fh) or croak $!;
> + my $exp = Git::SVN::Util::md5sum($fh);
> seek $fh, 0, 0 or croak $!;
>
> - my $exp = $md5->hexdigest;
> my $pool = SVN::Pool->new;
> my $atd = $self->apply_textdelta($fbat, undef, $pool);
> my $got = SVN::TxDelta::send_stream($fh, @$atd, $pool);
> @@ -3859,6 +3879,29 @@ sub run_pager {
> exec $pager or ::fatal "Can't run pager: $! ($pager)";
> }
>
> +sub format_svn_date {
> + return strftime("%Y-%m-%d %H:%M:%S %z (%a, %d %b %Y)", localtime(shift));
> +}
> +
> +sub parse_git_date {
> + my ($t, $tz) = @_;
> + # Date::Parse isn't in the standard Perl distro :(
> + if ($tz =~ s/^\+//) {
> + $t += tz_to_s_offset($tz);
> + } elsif ($tz =~ s/^\-//) {
> + $t -= tz_to_s_offset($tz);
> + }
> + return $t;
> +}
> +
> +sub set_local_timezone {
> + if (defined $TZ) {
> + $ENV{TZ} = $TZ;
> + } else {
> + delete $ENV{TZ};
> + }
> +}
> +
> sub tz_to_s_offset {
> my ($tz) = @_;
> $tz =~ s/(\d\d)$//;
> @@ -3879,13 +3922,7 @@ sub get_author_info {
> $dest->{t} = $t;
> $dest->{tz} = $tz;
> $dest->{a} = $au;
> - # Date::Parse isn't in the standard Perl distro :(
> - if ($tz =~ s/^\+//) {
> - $t += tz_to_s_offset($tz);
> - } elsif ($tz =~ s/^\-//) {
> - $t -= tz_to_s_offset($tz);
> - }
> - $dest->{t_utc} = $t;
> + $dest->{t_utc} = parse_git_date($t, $tz);
> }
>
> sub process_commit {
> @@ -3939,8 +3976,7 @@ sub show_commit_normal {
> my ($c) = @_;
> print commit_log_separator, "r$c->{r} | ";
> print "$c->{c} | " if $show_commit;
> - print "$c->{a} | ", strftime("%Y-%m-%d %H:%M:%S %z (%a, %d %b %Y)",
> - localtime($c->{t_utc})), ' | ';
> + print "$c->{a} | ", format_svn_date($c->{t_utc}), ' | ';
> my $nr_line = 0;
>
> if (my $l = $c->{l}) {
> @@ -3980,11 +4016,7 @@ sub cmd_show_log {
> my (@args) = @_;
> my ($r_min, $r_max);
> my $r_last = -1; # prevent dupes
> - if (defined $TZ) {
> - $ENV{TZ} = $TZ;
> - } else {
> - delete $ENV{TZ};
> - }
> + set_local_timezone();
> if (defined $::_revision) {
> if ($::_revision =~ /^(\d+):(\d+)$/) {
> ($r_min, $r_max) = ($1, $2);
--
Eric Wong
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 2/3 v3] git-svn info: implement info command
2007-11-21 19:57 ` [PATCH 2/3 v3] git-svn info: implement info command David D. Kilzer
2007-11-21 19:57 ` [PATCH 3/3 v3] git-svn: info --url [path] David D. Kilzer
@ 2007-11-22 1:40 ` Eric Wong
2007-11-22 3:16 ` David D. Kilzer
1 sibling, 1 reply; 11+ messages in thread
From: Eric Wong @ 2007-11-22 1:40 UTC (permalink / raw)
To: David D. Kilzer; +Cc: git
"David D. Kilzer" <ddkilzer@kilzer.net> wrote:
> Implement "git-svn info" for files and directories based on the
> "svn info" command. Note that the -r/--revision argument is not
> supported yet.
>
> Added 18 tests in t/t9119-git-svn-info.sh.
Eric Wong <normalperson@yhbt.net> wrote:
> I'm having a problem with [2/3] currently:
>
> $file_type not being detected correctly when running "git svn info"
> on the top-level directory with no arguments. It's opening the
> directory and trying to md5 it here:
>
> } else {
> open FILE, "<", $path or die $!;
> $checksum = Git::SVN::Util::md5sum(\*FILE);
> close FILE or die $!;
> }
>
>
When running from a top-level directory with no arguments, the first
line of git-ls-tree was being read. This allowed the test case to pass
because ls-tree sorts the output and 'directory' just happened to
be up top; so we were getting the 040000 mode from the 'directory'
tree and not the top-level tree.
The below test should fix it for the trivial case I have.
diff --git a/git-svn.perl b/git-svn.perl
index 62801c8..7d86870 100755
--- a/git-svn.perl
+++ b/git-svn.perl
@@ -1165,6 +1165,7 @@ sub linearize_history {
sub find_file_type_and_diff_status {
my ($path) = @_;
+ return ('dir', '') if $path eq '.';
my $diff_output =
command_oneline(qw(diff --cached --name-status --), $path) || "";
diff --git a/t/t9119-git-svn-info.sh b/t/t9119-git-svn-info.sh
index e81457f..439bd93 100644
--- a/t/t9119-git-svn-info.sh
+++ b/t/t9119-git-svn-info.sh
@@ -19,6 +19,7 @@ ptouch() {
test_expect_success 'setup repository and import' "
mkdir info &&
cd info &&
+ echo FIRST > A &&
echo one > file &&
ln -s file symlink-file &&
mkdir directory &&
--
Eric Wong
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 4/3] git-svn: allow `info' command to work offline
2007-11-21 19:57 [PATCH 0/3 v3] Implement git-svn info David D. Kilzer
2007-11-21 19:57 ` [PATCH 1/3 v3] git-svn: extract reusable code into utility functions David D. Kilzer
@ 2007-11-22 2:23 ` Eric Wong
2007-11-22 3:24 ` Adam Roben
1 sibling, 1 reply; 11+ messages in thread
From: Eric Wong @ 2007-11-22 2:23 UTC (permalink / raw)
To: David D. Kilzer; +Cc: git
Cache the repository root whenever we connect to the repository.
This will allow us to notice URL changes if the user changes the
URL in .git/config, too.
If the repository is no longer accessible, or if `git svn info'
is the first and only command run; then '(offline)' will be
displayed for "Repository Root:" in the output.
Signed-off-by: Eric Wong <normalperson@yhbt.net>
---
David:
I'll apply this once you've verified my fix to 1/3 is correct behavior,
too.
git-svn.perl | 26 +++++++++++++++++++++++---
1 files changed, 23 insertions(+), 3 deletions(-)
diff --git a/git-svn.perl b/git-svn.perl
index 7d86870..43e1591 100755
--- a/git-svn.perl
+++ b/git-svn.perl
@@ -782,9 +782,14 @@ sub cmd_info {
$result .= "Name: " . basename($path) . "\n" if $file_type ne "dir";
$result .= "URL: " . $full_url . "\n";
- my $repos_root = $gs->ra->{repos_root};
- Git::SVN::remove_username($repos_root);
- $result .= "Repository Root: $repos_root\n";
+ eval {
+ my $repos_root = $gs->repos_root;
+ Git::SVN::remove_username($repos_root);
+ $result .= "Repository Root: $repos_root\n";
+ };
+ if ($@) {
+ $result .= "Repository Root: (offline)\n";
+ }
$result .= "Repository UUID: $uuid\n" unless $diff_status eq "A";
$result .= "Revision: " . ($diff_status eq "A" ? 0 : $rev) . "\n";
@@ -1773,9 +1778,24 @@ sub ra_uuid {
$self->{ra_uuid};
}
+sub _set_repos_root {
+ my ($self, $repos_root) = @_;
+ my $k = "svn-remote.$self->{repo_id}.reposRoot";
+ $repos_root ||= $self->ra->{repos_root};
+ tmp_config($k, $repos_root);
+ $repos_root;
+}
+
+sub repos_root {
+ my ($self) = @_;
+ my $k = "svn-remote.$self->{repo_id}.reposRoot";
+ eval { tmp_config('--get', $k) } || $self->_set_repos_root;
+}
+
sub ra {
my ($self) = shift;
my $ra = Git::SVN::Ra->new($self->{url});
+ $self->_set_repos_root($ra->{repos_root});
if ($self->use_svm_props && !$self->{svm}) {
if ($self->no_metadata) {
die "Can't have both 'noMetadata' and ",
--
Eric Wong
^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH 2/3 v3] git-svn info: implement info command
2007-11-22 1:40 ` [PATCH 2/3 v3] git-svn info: implement info command Eric Wong
@ 2007-11-22 3:16 ` David D. Kilzer
2007-11-22 4:17 ` Eric Wong
0 siblings, 1 reply; 11+ messages in thread
From: David D. Kilzer @ 2007-11-22 3:16 UTC (permalink / raw)
To: Eric Wong; +Cc: git
Eric Wong <normalperson@yhbt.net> wrote:
> When running from a top-level directory with no arguments, the first
> line of git-ls-tree was being read. This allowed the test case to pass
> because ls-tree sorts the output and 'directory' just happened to
> be up top; so we were getting the 040000 mode from the 'directory'
> tree and not the top-level tree.
>
> The below test should fix it for the trivial case I have.
Acked-by: David D. Kilzer <ddkilzer@kilzer.net>
Looks good! Thanks!
Dave
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 4/3] git-svn: allow `info' command to work offline
2007-11-22 2:23 ` [PATCH 4/3] git-svn: allow `info' command to work offline Eric Wong
@ 2007-11-22 3:24 ` Adam Roben
2007-11-22 3:56 ` Eric Wong
0 siblings, 1 reply; 11+ messages in thread
From: Adam Roben @ 2007-11-22 3:24 UTC (permalink / raw)
To: Eric Wong; +Cc: David D. Kilzer, git
Eric Wong wrote:
> + my $k = "svn-remote.$self->{repo_id}.reposRoot";
>
"repoRoot" seems slightly more intuitive than "reposRoot", given that
"repository" is normally abbreviated as "repo".
-Adam
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 4/3] git-svn: allow `info' command to work offline
2007-11-22 3:24 ` Adam Roben
@ 2007-11-22 3:56 ` Eric Wong
0 siblings, 0 replies; 11+ messages in thread
From: Eric Wong @ 2007-11-22 3:56 UTC (permalink / raw)
To: Adam Roben; +Cc: David D. Kilzer, git
Adam Roben <aroben@apple.com> wrote:
> Eric Wong wrote:
> >+ my $k = "svn-remote.$self->{repo_id}.reposRoot";
> >
>
> "repoRoot" seems slightly more intuitive than "reposRoot", given that
> "repository" is normally abbreviated as "repo".
>From a git-only point of view, yes. But it's repos_root everywhere
inside git-svn because SVN uses "*_repos_root" for their API.
This is inside the hidden metadata file that users
shouldn't have to touch anyways.
On a side note:
I personally *hate* camelCase names (or worse, alllowercase), but
git config doesn't allow underscores in config keys for some
strange reason (especially strange since most of the git and Linux
source code use snake_case...)
--
Eric Wong
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 2/3 v3] git-svn info: implement info command
2007-11-22 3:16 ` David D. Kilzer
@ 2007-11-22 4:17 ` Eric Wong
0 siblings, 0 replies; 11+ messages in thread
From: Eric Wong @ 2007-11-22 4:17 UTC (permalink / raw)
To: David D. Kilzer, Junio C Hamano; +Cc: git
"David D. Kilzer" <ddkilzer@kilzer.net> wrote:
> Eric Wong <normalperson@yhbt.net> wrote:
> > When running from a top-level directory with no arguments, the first
> > line of git-ls-tree was being read. This allowed the test case to pass
> > because ls-tree sorts the output and 'directory' just happened to
> > be up top; so we were getting the 040000 mode from the 'directory'
> > tree and not the top-level tree.
> >
> > The below test should fix it for the trivial case I have.
>
> Acked-by: David D. Kilzer <ddkilzer@kilzer.net>
>
> Looks good! Thanks!
Ok, I've folded that into your [2/3] and pushed everything (and an
earlier fix) out to
git://git.bogomips.org/git-svn.git
David D. Kilzer (3):
git-svn: extract reusable code into utility functions
git-svn info: implement info command
git-svn: info --url [path]
Eric Wong (2):
t9106: fix a race condition that caused svn to miss modifications
git-svn: allow `info' command to work offline
Junio, please pull, thanks.
--
Eric Wong
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2007-11-22 4:18 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-11-21 19:57 [PATCH 0/3 v3] Implement git-svn info David D. Kilzer
2007-11-21 19:57 ` [PATCH 1/3 v3] git-svn: extract reusable code into utility functions David D. Kilzer
2007-11-21 19:57 ` [PATCH 2/3 v3] git-svn info: implement info command David D. Kilzer
2007-11-21 19:57 ` [PATCH 3/3 v3] git-svn: info --url [path] David D. Kilzer
2007-11-22 1:40 ` [PATCH 2/3 v3] git-svn info: implement info command Eric Wong
2007-11-22 3:16 ` David D. Kilzer
2007-11-22 4:17 ` Eric Wong
2007-11-22 1:19 ` [PATCH 1/3 v3] git-svn: extract reusable code into utility functions Eric Wong
2007-11-22 2:23 ` [PATCH 4/3] git-svn: allow `info' command to work offline Eric Wong
2007-11-22 3:24 ` Adam Roben
2007-11-22 3:56 ` Eric Wong
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).