In tricky cases (e.g., adding a function) it can be much more
convenient to edit diffs produced by the “patience diff” algorithm.
Now one can, with the 'git add -e --patience' command.

Still todo: update the ‘git add’ man page to explain the new option.

Signed-off-by: Jonathan Nieder <[email protected]>
---
... and a new test would be nice here, too.

Anyway, that’s it --- Junio C Hamano and Johannes Schindelin already
did all the hard work by writing git-add--interactive and the
patience diff driver for xdiff, respectively.

Sorry to fill up your inbox and the bug log.  Still, I hope the
patches are useful.  If you’d like to try a .deb with these patches
applied, let me know and I can build one.

Good night,
Jonathan

 builtin-add.c |   10 +++++++---
 1 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/builtin-add.c b/builtin-add.c
index 72d116f..fa5f4c7 100644
--- a/builtin-add.c
+++ b/builtin-add.c
@@ -10,6 +10,7 @@
 #include "cache-tree.h"
 #include "run-command.h"
 #include "parse-options.h"
+#include "xdiff-interface.h"
 #include "diff.h"
 #include "diffcore.h"
 #include "revision.h"
@@ -257,7 +258,8 @@ int interactive_add(int argc, const char **argv,
                                   pathspec);
 }
 
-static int edit_patch(int argc, const char **argv, const char *prefix)
+static int edit_patch(int argc, const char **argv,
+               const char *prefix, int patience)
 {
        char *file = xstrdup(git_path("ADD_EDIT.patch"));
        const char *apply_argv[] = { "apply", "--recount", "--cached",
@@ -277,6 +279,8 @@ static int edit_patch(int argc, const char **argv, const 
char *prefix)
 
        argc = setup_revisions(argc, argv, &rev, NULL);
        rev.diffopt.output_format = DIFF_FORMAT_PATCH;
+       if (patience)
+               DIFF_XDL_SET(&rev.diffopt, PATIENCE_DIFF);
        out = open(file, O_CREAT | O_WRONLY, 0644);
        if (out < 0)
                die ("Could not open '%s' for writing.", file);
@@ -318,7 +322,7 @@ static struct option builtin_add_options[] = {
        OPT_BOOLEAN('i', "interactive", &add_interactive, "interactive 
picking"),
        OPT_BOOLEAN('p', "patch", &patch_interactive, "interactive patching"),
        OPT_BOOLEAN('e', "edit", &edit_interactive, "edit current diff and 
apply"),
-       OPT_BOOLEAN( 0 , "patience", &patience, "use \"patience diff\" 
algorithm for -i"),
+       OPT_BOOLEAN( 0 , "patience", &patience, "use \"patience diff\" 
algorithm when making diffs"),
        OPT_BOOLEAN('f', "force", &ignored_too, "allow adding otherwise ignored 
files"),
        OPT_BOOLEAN('u', "update", &take_worktree_changes, "update tracked 
files"),
        OPT_BOOLEAN('N', "intent-to-add", &intent_to_add, "record only the fact 
that the path will be added later"),
@@ -378,7 +382,7 @@ int cmd_add(int argc, const char **argv, const char *prefix)
                exit(interactive_add(argc - 1, argv + 1, prefix, patience));
 
        if (edit_interactive)
-               return(edit_patch(argc, argv, prefix));
+               return(edit_patch(argc, argv, prefix, patience));
        argc--;
        argv++;
 
-- 
1.7.0.183.g328ba




-- 
To UNSUBSCRIBE, email to [email protected]
with a subject of "unsubscribe". Trouble? Contact [email protected]

Reply via email to