Code

Fix reverting of unmerged status entries
authorJonas Fonseca <fonseca@diku.dk>
Tue, 3 Feb 2009 14:46:07 +0000 (15:46 +0100)
committerJonas Fonseca <fonseca@diku.dk>
Tue, 3 Feb 2009 15:21:55 +0000 (16:21 +0100)
... by using update-index --cacheinfo.

NEWS
tig.c

diff --git a/NEWS b/NEWS
index 59ad19e8035ae38f5ce3d44d455365e5599f54f8..7f8e98e406223a538ac5489708003b4efe90d312 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -27,6 +27,7 @@ Improvements:
 Bug fixes:
 
  - Tree view: fix memory corruption bug when updating.
+ - Status view: fix reverting of unmerged files.
  - Fix regression for non-UTF-8 locales corrupting the view data.
  - Fix regression parsing multiple spaces in ~/.tigrc.
 
diff --git a/tig.c b/tig.c
index 8fd5288f4a654660693dc95b8b447c501d66e4d6..27563e19670e252a8bf90b85416a30d8a15cdb12 100644 (file)
--- a/tig.c
+++ b/tig.c
@@ -4620,7 +4620,6 @@ status_get_diff(struct status *file, const char *buf, size_t bufsize)
 static bool
 status_run(struct view *view, const char *argv[], char status, enum line_type type)
 {
-       struct status *file = NULL;
        struct status *unmerged = NULL;
        char *buf;
        struct io io = {};
@@ -4631,6 +4630,8 @@ status_run(struct view *view, const char *argv[], char status, enum line_type ty
        add_line_data(view, NULL, type);
 
        while ((buf = io_get(&io, 0, TRUE))) {
+               struct status *file = unmerged;
+
                if (!file) {
                        file = calloc(1, sizeof(*file));
                        if (!file || !add_line_data(view, file, type))
@@ -4643,7 +4644,7 @@ status_run(struct view *view, const char *argv[], char status, enum line_type ty
                        if (status == 'A')
                                string_copy(file->old.rev, NULL_ID);
 
-               } else if (!file->status) {
+               } else if (!file->status || file == unmerged) {
                        if (!status_get_diff(file, buf, strlen(buf)))
                                goto error_out;
 
@@ -4653,19 +4654,11 @@ status_run(struct view *view, const char *argv[], char status, enum line_type ty
 
                        /* Collapse all 'M'odified entries that follow a
                         * associated 'U'nmerged entry. */
-                       if (file->status == 'U') {
-                               unmerged = file;
-
-                       } else if (unmerged) {
-                               int collapse = !strcmp(buf, unmerged->new.name);
-
+                       if (unmerged == file) {
+                               unmerged->status = 'U';
                                unmerged = NULL;
-                               if (collapse) {
-                                       free(file);
-                                       file = NULL;
-                                       view->lines--;
-                                       continue;
-                               }
+                       } else if (file->status == 'U') {
+                               unmerged = file;
                        }
                }
 
@@ -5104,13 +5097,20 @@ status_revert(struct status *status, enum line_type type, bool has_none)
                return FALSE;
 
        } else {
+               char mode[10] = "100644";
+               const char *reset_argv[] = {
+                       "git", "update-index", "--cacheinfo", mode,
+                               status->old.rev, status->old.name, NULL
+               };
                const char *checkout_argv[] = {
                        "git", "checkout", "--", status->old.name, NULL
                };
 
                if (!prompt_yesno("Are you sure you want to overwrite any changes?"))
                        return FALSE;
-               return run_io_fg(checkout_argv, opt_cdup);
+               string_format(mode, "%o", status->old.mode);
+               return (status->status != 'U' || run_io_fg(reset_argv, opt_cdup)) &&
+                       run_io_fg(checkout_argv, opt_cdup);
        }
 }