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

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

[Bug-vc-dwim] [PATCH 3a/3] vc-chlog: new option --dirty-workdir for git


From: Ralf Wildenhues
Subject: [Bug-vc-dwim] [PATCH 3a/3] vc-chlog: new option --dirty-workdir for git add --interactive.
Date: Sat, 12 Mar 2011 12:39:01 +0100
User-agent: Mutt/1.5.20 (2010-08-04)

With 'git add -i', it can be helpful to pipe the output of
'git diff --cached' into 'vc-chlog --stdin'.  However, if the
working directory also contains unrelated changes, then the tag
list might be wrong, because we try to recreate the old version
of the file from the copy in the working directory.  With the
new --dirty-workdir options, use 'vc-dwim --diff' to get back to
the state of the last commit.  From there, recreate the version
of the new file with the patch from stdin.

* vc-chlog.in: New option --dirty-workdir.
(func_help): Document it.
(func_extract_identifiers): If the work directory is dirty,
recreate the old file from 'vc-dwim --diff' rather than from the
patch in question; also, create a version of the new file based
on that plus the patch in question.
* doc/vc-dwim.texi (vc-chlog Invocation): Document the option.
* tests/Makefile.am (XFAIL_TESTS): Remove dirty-workdir.
* NEWS: Update.

Signed-off-by: Ralf Wildenhues <address@hidden>
---
 NEWS                |    2 ++
 doc/vc-dwim.texi    |    5 +++++
 tests/Makefile.am   |    3 ---
 tests/dirty-workdir |    2 +-
 vc-chlog.in         |   19 ++++++++++++++++---
 5 files changed, 24 insertions(+), 7 deletions(-)

diff --git a/NEWS b/NEWS
index ac5bd02..437000a 100644
--- a/NEWS
+++ b/NEWS
@@ -4,6 +4,8 @@ vc-dwim NEWS                                          -*- 
outline -*-
 
   vc-chlog can now handle two-word function names like "operator delete"
 
+  vc-chlog now accepts --dirty-workdir for 'git add -i' workflows.
+
 
 * Noteworthy changes in release 1.3 (2010-11-06) [stable]
 
diff --git a/doc/vc-dwim.texi b/doc/vc-dwim.texi
index 22a166b..79d0786 100644
--- a/doc/vc-dwim.texi
+++ b/doc/vc-dwim.texi
@@ -421,6 +421,11 @@ Wrap @file{ChangeLog} entry at @var{cols} instead of 72.
 Do not try to parse the names of functions or other identifiers
 that changed.
 
address@hidden --dirty-workdir
+Assume that the working directory has other changes unrelated to the
+patch (usually given with @option{--stdin}).  This will let the file
+be recreated from the version control index or cache, if any.
+
 @item --debug
 Inhibit temp file cleanup.
 
diff --git a/tests/Makefile.am b/tests/Makefile.am
index a3fd83c..1ceee3c 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -25,7 +25,4 @@ TESTS = \
   multiple-chlogs \
   dirty-workdir
 
-XFAIL_TESTS = \
-  dirty-workdir
-
 include $(srcdir)/check.mk
diff --git a/tests/dirty-workdir b/tests/dirty-workdir
index a9ef8fe..2e939b5 100644
--- a/tests/dirty-workdir
+++ b/tests/dirty-workdir
@@ -74,7 +74,7 @@ EOF
 # This will now mention the 'bar' function, although that is not
 # present in the commit at all.
 git diff --cached > diff
-run_vc_chlog diff
+run_vc_chlog diff --dirty-workdir
 grep '(foo)' stdout
 
 Exit 0
diff --git a/vc-chlog.in b/vc-chlog.in
index a5bee47..b1527e1 100755
--- a/vc-chlog.in
+++ b/vc-chlog.in
@@ -41,6 +41,7 @@ Options:
       --user-name NAME   use NAME as user name
       --width COLS       wrap ChangeLog entry at COLS instead of 72
       --no-functions     do not try to find the names of changed functions
+      --dirty-workdir    base off last version control copy, not working dir
 
       --debug            inhibit temp file cleanup
       --help             display this help and exit
@@ -72,6 +73,7 @@ PATCH="@PATCH@"
 : ${TMPDIR=/tmp}
 : ${INT_MAX=2147483647}
 : ${stdin=false}
+: ${dirty_workdir=false}
 : ${take_old_file_into_account=:}
 
 today=`date +%Y-%m-%d`
@@ -404,6 +406,8 @@ func_extract_identifiers ()
     basename=`func_basename "$file"`
     oldbase=oldfile-$nfile-$basename
     oldfile=$tmp/$oldbase
+    newbase=newfile-$nfile-$basename
+    newfile=$tmp/$newbase
     nidents=$tmp/nidents-$nfile
     oidents=$tmp/oidents-$nfile
 
@@ -413,14 +417,22 @@ func_extract_identifiers ()
     else
       : >"$oldfile"
     fi
-    func_diff_for_file "$oldbase" | func_apply_tmp_patch -p0 -R "$oldbase"
+    if $dirty_workdir; then
+      vc-dwim --diff "$file"
+    else
+      func_diff_for_file "$oldbase"
+    fi | func_apply_tmp_patch -p0 -R "$oldbase"
     # The file may be new, in which case $oldfile will be removed by patch.
     if test -f "$oldfile"; then
       func_taglist "$oldfile"
     fi >"$tagfile-old"
 
-    # Create the tag list from the new file.
-    if test -f "$file"; then
+    # Recreate the new file if needed, and the tag list from it.
+    if $dirty_workdir; then
+      cp "$oldfile" "$newfile"
+      func_diff_for_file "$oldbase" | func_apply_tmp_patch -p0 "$newbase"
+      func_taglist "$newfile"
+    elif test -f "$file"; then
       func_taglist "$file"
     fi >"$tagfile"
 
@@ -625,6 +637,7 @@ while test $# -gt 0; do
     --address)   email_address=$2; shift ;;
     --changelog) chlogs="$chlogs $2"; shift ;;
     --no-functions) find_functions=false ;;
+    --dirty-workdir) dirty_workdir=: ;;
     --stdin)     stdin=: ;;
     --tabsize)   tabstop=$2; shift ;;
     --width)     textwidth=$2; shift ;;
-- 
1.7.4.1.227.gadfe4




reply via email to

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