bug-vc-dwim
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Bug-vc-dwim] [PATCH] vc-dwim: use --author= internally also with bzr...


From: Jim Meyering
Subject: [Bug-vc-dwim] [PATCH] vc-dwim: use --author= internally also with bzr...
Date: Sat, 21 Apr 2012 21:37:26 +0200

FYI,

>From d1f61ab8c87d1565261c83c088b21a9f9cbc3df3 Mon Sep 17 00:00:00 2001
From: Jim Meyering <address@hidden>
Date: Sat, 21 Apr 2012 21:34:51 +0200
Subject: [PATCH 1/2] vc-dwim: use --author= internally also with bzr as well
 as with git

* VC.pm (author): New method.
($vc_cmd) [AUTHOR_FMT]: New key/val, defined for GIT and BZR.
* vc-dwim.pl (do_commit): Generalize --author=...-using code to
work with BZR as well.
* tests/author-bzr: New test, derived from tests/author.
* tests/Makefile.am (TESTS): Add it.
* NEWS (Bug fixes): Mention the fix.
Reported by Paul Eggert.
---
 NEWS              |    5 +++++
 VC.pm             |   11 +++++++++++
 tests/Makefile.am |    1 +
 tests/author-bzr  |   32 ++++++++++++++++++++++++++++++++
 vc-dwim.pl        |   11 +++++++----
 5 files changed, 56 insertions(+), 4 deletions(-)
 create mode 100755 tests/author-bzr

diff --git a/NEWS b/NEWS
index 19503d9..33ff220 100644
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,11 @@ vc-dwim NEWS                                          -*- 
outline -*-

 * Noteworthy changes in release ?.? (????-??-??) [?]

+** Bug fixes
+
+  vc-dwim now applies --author= for ChangeLog-derived name/email for bzr,
+  just like it has always done for git.
+

 * Noteworthy changes in release 1.6 (2011-12-23) [stable]

diff --git a/VC.pm b/VC.pm
index 7cade12..6512cbf 100644
--- a/VC.pm
+++ b/VC.pm
@@ -55,6 +55,7 @@ my $vc_cmd =
    },
    GIT() =>
    {
+    AUTHOR_FMT => '--author=%s',
     DIFF_COMMAND => [qw(git diff -B -C HEAD --)],
     DIFF_PRISTINE => [qw(git diff --no-ext-diff -B -C HEAD --)],
     VALID_DIFF_EXIT_STATUS => {0 => 1},
@@ -78,6 +79,7 @@ my $vc_cmd =
    },
    BZR() => # aka bazaar
    {
+    AUTHOR_FMT => '--author=%s',
     DIFF_COMMAND => [qw(bzr diff --)],
     VALID_DIFF_EXIT_STATUS => {0 => 1, 1 => 1},
     COMMIT_COMMAND => [qw(bzr ci -q -F)],
@@ -189,6 +191,15 @@ sub diff_cmd()
   return @$cmd_ref;
 }

+sub author_option()
+{
+  my $self = shift;
+  my $author = shift;
+  my $fmt = $vc_cmd->{$self->name()}->{AUTHOR_FMT};
+  my $opt = $fmt ? sprintf ($fmt, $author) : undef;
+  return $opt;
+}
+
 # Print diff -u style diffs, regardless of envvar settings
 # like GIT_EXTERNAL_DIFF or options like git's --ext-diff.
 # If no DIFF_PRISTINE member is specified, just use DIFF_COMMAND.
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 314cd36..8e8279f 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -9,6 +9,7 @@ TESTS = \
   changelog-header-at-end-of-log \
   git-log-summary \
   author \
+  author-bzr \
   subdir-middle \
   add-empty \
   git-mv \
diff --git a/tests/author-bzr b/tests/author-bzr
new file mode 100755
index 0000000..25933fb
--- /dev/null
+++ b/tests/author-bzr
@@ -0,0 +1,32 @@
+#!/bin/sh
+# Exercise the --author='user name <address@hidden>' option.
+
+. "${srcdir=.}/init.sh"; path_prepend_ ..
+print_ver_ vc-dwim
+
+require_bzr_
+
+cat <<EOF > ChangeLog || framework_failure_
+2006-09-04  Jim Meyering  <address@hidden>
+EOF
+bzr init > /dev/null 2>&1              \
+  && bzr add .                         \
+  && bzr commit -m m . > /dev/null 2>&1        \
+    || framework_failure_
+
+echo foo > x || framework_failure_
+bzr add x || framework_failure_
+cat <<EOF >> ChangeLog || framework_failure_
+
+       * x: whatever...
+EOF
+
+set -e
+fail=0
+
+name_and_addr='joe blow <address@hidden>'
+vc-dwim --commit --author="$name_and_addr" > /dev/null
+bzr log -r-1 > out
+grep "^author: $name_and_addr" out > /dev/null
+
+Exit 0
diff --git a/vc-dwim.pl b/vc-dwim.pl
index 60902ce..439a49b 100755
--- a/vc-dwim.pl
+++ b/vc-dwim.pl
@@ -484,8 +484,7 @@ sub find_author($$)
 # If there's only one file, say F, and its name starts with "/", then
 # do "chdir(dirname(F))" before performing the commit (committing
 # "basename(F)" in that case), and restore the initial working directory
-# afterwards.  If $AUTHOR is defined, and the vc back-end is GIT, then
-# use 'git commit's --author option.
+# afterwards.
 sub do_commit ($$$$)
 {
   my ($vc, $author, $log_msg_lines, $file_list_arg) = @_;
@@ -523,8 +522,12 @@ sub do_commit ($$$$)

   my @vc_commit = $vc->commit_cmd();
   push @vc_commit, $commit_log_filename;
-  defined $author && $vc->name() eq VC::GIT
-    and push @vc_commit, '--author', $author;
+
+  # If the back-end has an --author=... option, use it.
+  my $author_opt = $vc->author_option($author);
+  $author_opt
+    and push @vc_commit, $author_opt;
+
   my @cmd = (@vc_commit, '--', @file_list);

   my $options =
--
1.7.10.228.g81f95


>From 97046cf005cec6c0bde0bbe284d02c241b5958a5 Mon Sep 17 00:00:00 2001
From: Jim Meyering <address@hidden>
Date: Sat, 21 Apr 2012 21:35:40 +0200
Subject: [PATCH 2/2] build: update gnulib submodule to latest

---
 gnulib |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gnulib b/gnulib
index 262ac66..66aa696 160000
--- a/gnulib
+++ b/gnulib
@@ -1 +1 @@
-Subproject commit 262ac66688545fb2b0af9400d675839d1d437ddb
+Subproject commit 66aa696bb1e9ccf0d984c33db684c30c245624af
--
1.7.10.228.g81f95



reply via email to

[Prev in Thread] Current Thread [Next in Thread]