From: Jonathan Nieder <jrnieder@gmail.com>
To: git@vger.kernel.org
Cc: Eric Wong <normalperson@yhbt.net>, Jens Seidel <jensseidel@users.sf.net>
Subject: [PATCH/WIP] git-svn: tweak log format to match "svn log" output
Date: Sat, 24 Jul 2010 21:31:14 -0500 [thread overview]
Message-ID: <20100725023114.GB18606@burratino> (raw)
In-Reply-To: <20100427112656.GB16323@merkur.sol.de>
From: Jens Seidel <jensseidel@users.sf.net>
Tweak "git svn log" output to more closely match what svn produces.
In particular, if Locale::gettext is available, use that to produce
localized output using svn’s translations.
So now instead of
git:
r2105 | viktor | 2010-03-19 13:40:54 +0100 (Fr, 19 Mär 2010) | 2 lines
svn:
r2105 | viktor | 2010-03-19 13:40:54 +0100 (Fr, 19. Mär 2010) | 1 Zeile
we get the much closer
git:
r2105 | viktor | 2010-03-19 13:40:54 +0100 (Fr, 19. Mär 2010) | 2 Zeilen
svn:
r2105 | viktor | 2010-03-19 13:40:54 +0100 (Fr, 19. Mär 2010) | 1 Zeile
and a script for munging to compare logs would only have to fuzz
out the extra blank lines in git svn’s commit log.
[jn: made Locale::gettext dependency optional; added a test script]
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
Jens Seidel wrote at http://bugs.debian.org/578915:
>> Jens Seidel wrote:
> Ah, git svn ignores any locale, this explains the problem.
>
>>> The dot stands for an ordinal number (e.g. "19." == "19th").
>>> Second: "line(s)" is not translated. I can workaround by starting git/svn in an
>>> English locale ...
>
> I tried to fix both.
>
>>> Third: the git log often contains an addional empty line.
>
> This remains open. Probably that can be solved by setting a git config
> option and resyncing all git svn history from git.
Sorry to leave this hanging for so long. I think it is an improvement
as is, but I have not tested in the following scenarios:
- Locale::gettext not available
- subversion not translated
- subversion translated but not to the current language
And the extra blank line at the end of log messages remains unsolved.
Thoughts?
diff --git i/git-svn.perl w/git-svn.perl
index c416358..55dc50d 100755
--- i/git-svn.perl
+++ w/git-svn.perl
@@ -45,6 +45,7 @@ sub _req_svn {
}
}
my $can_compress = eval { require Compress::Zlib; 1};
+my $can_localize = eval { require Locale::gettext; 1};
push @Git::SVN::Ra::ISA, 'SVN::Ra';
push @SVN::Git::Editor::ISA, 'SVN::Delta::Editor';
push @SVN::Git::Fetcher::ISA, 'SVN::Delta::Editor';
@@ -5535,7 +5536,14 @@ sub format_svn_date {
my $gm = timelocal(gmtime($t));
my $sign = qw( + + - )[ $t <=> $gm ];
my $gmoff = sprintf("%s%02d%02d", $sign, (gmtime(abs($t - $gm)))[2,1]);
- return strftime("%Y-%m-%d %H:%M:%S $gmoff (%a, %d %b %Y)", localtime($t));
+ my $format;
+ if ($can_localize) {
+ my $d = Locale::gettext->domain("subversion");
+ $format = "%Y-%m-%d %H:%M:%S $gmoff" . $d->get(" (%a, %d %b %Y)");
+ } else {
+ $format = "%Y-%m-%d %H:%M:%S $gmoff (%a, %d %b %Y)";
+ }
+ return strftime($format, localtime($t));
}
sub parse_git_date {
@@ -5631,9 +5639,16 @@ sub show_commit_normal {
my ($c) = @_;
print commit_log_separator, "r$c->{r} | ";
print "$c->{c} | " if $show_commit;
- print "$c->{a} | ", format_svn_date($c->{t_utc}), ' | ';
+ print "$c->{a} | ", format_svn_date($c->{t_utc});
my $nr_line = 0;
+ my $sing_fmt = " | %d line";
+ my $plur_fmt = " | %d lines";
+ if ($can_localize) {
+ my $d = Locale::gettext->domain("subversion");
+ $sing_fmt = $d->nget(" | %d line", " | %d lines", 1);
+ $plur_fmt = $d->nget(" | %d line", " | %d lines", 10);
+ }
if (my $l = $c->{l}) {
while ($l->[$#$l] eq "\n" && $#$l > 0
&& $l->[($#$l - 1)] eq "\n") {
@@ -5641,20 +5656,23 @@ sub show_commit_normal {
}
$nr_line = scalar @$l;
if (!$nr_line) {
- print "1 line\n\n\n";
+ print sprintf($sing_fmt, 1), "\n\n\n";
} else {
if ($nr_line == 1) {
- $nr_line = '1 line';
+ print sprintf($sing_fmt, $nr_line), "\n";
} else {
- $nr_line .= ' lines';
+ print sprintf($plur_fmt, $nr_line), "\n";
}
- print $nr_line, "\n";
show_commit_changed_paths($c);
print "\n";
print $_ foreach @$l;
}
} else {
- print "1 line\n";
+ if ($nr_line == 1) {
+ print sprintf($sing_fmt, $nr_line), "\n";
+ } else {
+ print sprintf($plur_fmt, $nr_line), "\n";
+ }
show_commit_changed_paths($c);
print "\n";
diff --git i/t/t9116-git-svn-log.sh w/t/t9116-git-svn-log.sh
index 0374a74..586f64b 100755
--- i/t/t9116-git-svn-log.sh
+++ w/t/t9116-git-svn-log.sh
@@ -16,6 +16,7 @@ test_expect_success 'setup repository and import' '
done && \
svn_cmd import -m test . "$svnrepo"
cd .. &&
+ svn_cmd checkout "$svnrepo"/branches/a checkout &&
git svn init "$svnrepo" -T trunk -b branches -t tags &&
git svn fetch &&
git reset --hard trunk &&
@@ -36,7 +37,38 @@ test_expect_success 'setup repository and import' '
git commit -a -m spy &&
echo try >> README &&
git commit -a -m try &&
- git svn dcommit
+ git svn dcommit &&
+ (
+ cd checkout &&
+ svn_cmd update
+ ) &&
+
+ if test -n "$ORIGINAL_LANG" && test "$ORIGINAL_LANG" != C
+ then
+ test_set_prereq NONCLOCALE
+ fi
+ '
+
+test_expect_failure 'log matches svn log' '
+ git reset --hard a &&
+ (
+ cd checkout &&
+ svn_cmd log >../expected
+ ) &&
+ git svn log >actual &&
+ test_cmp expected actual
+ '
+
+test_expect_failure NONCLOCALE 'log matches svn log, original locale' '
+ (
+ LC_ALL=$ORIGINAL_LANG &&
+ (
+ cd checkout &&
+ svn_cmd log >../expected
+ ) &&
+ git svn log >actual
+ ) &&
+ test_cmp expected actual
'
test_expect_success 'run log' "
diff --git i/t/test-lib.sh w/t/test-lib.sh
index e5523dd..62aa48c 100644
--- i/t/test-lib.sh
+++ w/t/test-lib.sh
@@ -34,6 +34,9 @@ esac
# Keep the original TERM for say_color
ORIGINAL_TERM=$TERM
+# Keep the original locale for tests
+ORIGINAL_LANG=$LANG
+
# For repeatability, reset the environment to known value.
LANG=C
LC_ALL=C
--
next parent reply other threads:[~2010-07-25 2:32 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20100423134611.GA3440@merkur.sol.de>
[not found] ` <20100426132710.GA9930@progeny.tock>
[not found] ` <20100427112656.GB16323@merkur.sol.de>
2010-07-25 2:31 ` Jonathan Nieder [this message]
2010-07-25 8:10 ` [PATCH/WIP] git-svn: tweak log format to match "svn log" output Eric Wong
2010-07-25 8:13 ` [PATCH 2/1] git svn: remove extraneous newline from log output Eric Wong
2010-07-25 17:35 ` Jens Seidel
2010-07-26 19:09 ` Eric Wong
2010-07-25 8:37 ` [PATCH/WIP] git-svn: tweak log format to match "svn log" output Jonathan Nieder
2010-07-25 8:40 ` Eric Wong
2010-07-25 9:09 ` Jens Seidel
2010-07-25 17:52 ` Jens Seidel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20100725023114.GB18606@burratino \
--to=jrnieder@gmail.com \
--cc=git@vger.kernel.org \
--cc=jensseidel@users.sf.net \
--cc=normalperson@yhbt.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).