Merge branch 'jc/cache-unmerge'
authorJunio C Hamano <gitster@pobox.com>
Wed, 20 Jan 2010 22:44:31 +0000 (14:44 -0800)
committerJunio C Hamano <gitster@pobox.com>
Wed, 20 Jan 2010 22:46:35 +0000 (14:46 -0800)
* jc/cache-unmerge:
  rerere forget path: forget recorded resolution
  rerere: refactor rerere logic to make it independent from I/O
  rerere: remove silly 1024-byte line limit
  resolve-undo: teach "update-index --unresolve" to use resolve-undo info
  resolve-undo: "checkout -m path" uses resolve-undo information
  resolve-undo: allow plumbing to clear the information
  resolve-undo: basic tests
  resolve-undo: record resolved conflicts in a new index extension section
  builtin-merge.c: use standard active_cache macros

Conflicts:
builtin-ls-files.c
builtin-merge.c
builtin-rerere.c

1  2 
Makefile
builtin-checkout.c
builtin-ls-files.c
builtin-merge.c
builtin-read-tree.c
builtin-rerere.c
builtin-update-index.c
cache.h
read-cache.c
rerere.c
rerere.h

diff --cc Makefile
Simple merge
Simple merge
index 738215768ea701f0a35ed1e7bdc543779e6f4185,ef3a06889ab193b9e3aae679560f3eeaf300a8d5..b065061392718e4250d2c52dc3d53a0c1c7938e9
@@@ -37,7 -40,7 +40,8 @@@ static const char *tag_removed = ""
  static const char *tag_other = "";
  static const char *tag_killed = "";
  static const char *tag_modified = "";
 +static const char *tag_skip_worktree = "";
+ static const char *tag_resolve_undo = "";
  
  static void show_dir_entry(const char *tag, struct dir_entry *ent)
  {
@@@ -497,7 -528,7 +535,8 @@@ int cmd_ls_files(int argc, const char *
                tag_modified = "C ";
                tag_other = "? ";
                tag_killed = "K ";
 +              tag_skip_worktree = "S ";
+               tag_resolve_undo = "U ";
        }
        if (show_modified || show_others || show_deleted || (dir.flags & DIR_SHOW_IGNORED) || show_killed)
                require_work_tree = 1;
diff --cc builtin-merge.c
index 6f1311414b6ba6c956cdc75a4afc0ed361a0f92d,6bc2f7af08ab94a5af8cd619d18dbe2244143c8b..9f60ffa2cd32fd78c04d81135cee42b584627e7c
@@@ -849,21 -848,12 +850,22 @@@ int cmd_merge(int argc, const char **ar
        const char *best_strategy = NULL, *wt_strategy = NULL;
        struct commit_list **remotes = &remoteheads;
  
 -      if (file_exists(git_path("MERGE_HEAD")))
 -              die("You have not concluded your merge. (MERGE_HEAD exists)");
 -      if (read_cache_unmerged())
 -              die("You are in the middle of a conflicted merge."
 -                              " (index unmerged)");
 +      if (read_cache_unmerged()) {
 +              die_resolve_conflict("merge");
 +      }
 +      if (file_exists(git_path("MERGE_HEAD"))) {
 +              /*
 +               * There is no unmerged entry, don't advise 'git
 +               * add/rm <file>', just 'git commit'.
 +               */
 +              if (advice_resolve_conflict)
 +                      die("You have not concluded your merge (MERGE_HEAD exists).\n"
 +                          "Please, commit your changes before you can merge.");
 +              else
 +                      die("You have not concluded your merge (MERGE_HEAD exists).");
 +      }
 +
+       resolve_undo_clear();
        /*
         * Check if we are _not_ on a detached HEAD, i.e. if there is a
         * current branch.
Simple merge
index 5028138898bf0d95d969ea19b85d23af129912d0,0253abf9b698ed10a8df5c21ef07c93b8e6460dc..25f507a2f1df89919d966b7f586fd57d9c57a227
@@@ -103,24 -103,17 +103,27 @@@ static int diff_two(const char *file1, 
  int cmd_rerere(int argc, const char **argv, const char *prefix)
  {
        struct string_list merge_rr = { NULL, 0, 0, 1 };
 -      int i, fd;
 -
 +      int i, fd, flags = 0;
 +
 +      if (2 < argc) {
 +              if (!strcmp(argv[1], "-h"))
 +                      usage(git_rerere_usage);
 +              if (!strcmp(argv[1], "--rerere-autoupdate"))
 +                      flags = RERERE_AUTOUPDATE;
 +              else if (!strcmp(argv[1], "--no-rerere-autoupdate"))
 +                      flags = RERERE_NOAUTOUPDATE;
 +              if (flags) {
 +                      argc--;
 +                      argv++;
 +              }
 +      }
        if (argc < 2)
 -              return rerere();
 +              return rerere(flags);
  
 -      if (!strcmp(argv[1], "-h"))
 -              usage(git_rerere_usage);
 -      else if (!strcmp(argv[1], "forget"))
++      if (!strcmp(argv[1], "forget"))
+               return rerere_forget(argv + 2);
 -      fd = setup_rerere(&merge_rr);
 +      fd = setup_rerere(&merge_rr, flags);
        if (fd < 0)
                return 0;
  
Simple merge
diff --cc cache.h
Simple merge
diff --cc read-cache.c
index f4512967b8393e7934812e667d42a97f4d67ba8c,9e0fb04075e19bab4dc70b494b7c5e45712dacef..edd995943d6741a67322e2967dcacd2121511494
  #include "diffcore.h"
  #include "revision.h"
  #include "blob.h"
+ #include "resolve-undo.h"
  
 +static struct cache_entry *refresh_cache_entry(struct cache_entry *ce, int really);
 +
  /* Index extensions.
   *
   * The first letter should be 'A'..'Z' for extensions that are not
diff --cc rerere.c
index e0ac5bcaed7da9cfdff10afc9d1ebb8c27f7ba9f,d92990a6bba01c321bb67bd07287772075f6994a..70d0f7afffe983e6c70ad8494b095c1292393745
+++ b/rerere.c
@@@ -394,3 -518,52 +520,52 @@@ int rerere(int flags
                return 0;
        return do_plain_rerere(&merge_rr, fd);
  }
 -      fd = setup_rerere(&merge_rr);
+ static int rerere_forget_one_path(const char *path, struct string_list *rr)
+ {
+       const char *filename;
+       char *hex;
+       unsigned char sha1[20];
+       int ret;
+       ret = handle_cache(path, sha1, NULL);
+       if (ret < 1)
+               return error("Could not parse conflict hunks in '%s'", path);
+       hex = xstrdup(sha1_to_hex(sha1));
+       filename = rerere_path(hex, "postimage");
+       if (unlink(filename))
+               return (errno == ENOENT
+                       ? error("no remembered resolution for %s", path)
+                       : error("cannot unlink %s: %s", filename, strerror(errno)));
+       handle_cache(path, sha1, rerere_path(hex, "preimage"));
+       fprintf(stderr, "Updated preimage for '%s'\n", path);
+       string_list_insert(path, rr)->util = hex;
+       fprintf(stderr, "Forgot resolution for %s\n", path);
+       return 0;
+ }
+ int rerere_forget(const char **pathspec)
+ {
+       int i, fd;
+       struct string_list conflict = { NULL, 0, 0, 1 };
+       struct string_list merge_rr = { NULL, 0, 0, 1 };
+       if (read_cache() < 0)
+               return error("Could not read index");
++      fd = setup_rerere(&merge_rr, RERERE_NOAUTOUPDATE);
+       unmerge_cache(pathspec);
+       find_conflict(&conflict);
+       for (i = 0; i < conflict.nr; i++) {
+               struct string_list_item *it = &conflict.items[i];
+               if (!match_pathspec(pathspec, it->string, strlen(it->string),
+                                   0, NULL))
+                       continue;
+               rerere_forget_one_path(it->string, &merge_rr);
+       }
+       return write_rr(&merge_rr, fd);
+ }
diff --cc rerere.h
index 10a94a4ea10aa4c7a1ba4ea8397b82f1278afc9d,36560ff2f5501105049e2220f959721104fc4922..eaa9004dcdbb2f0dfd446e1ac68237c6dff18530
+++ b/rerere.h
@@@ -3,15 -3,10 +3,16 @@@
  
  #include "string-list.h"
  
 -extern int setup_rerere(struct string_list *);
 -extern int rerere(void);
 +#define RERERE_AUTOUPDATE   01
 +#define RERERE_NOAUTOUPDATE 02
 +
 +extern int setup_rerere(struct string_list *, int);
 +extern int rerere(int);
  extern const char *rerere_path(const char *hex, const char *file);
  extern int has_rerere_resolution(const char *hex);
+ extern int rerere_forget(const char **);
  
 +#define OPT_RERERE_AUTOUPDATE(v) OPT_UYN(0, "rerere-autoupdate", (v), \
 +      "update the index with reused conflict resolution if possible")
 +
  #endif