@matheusbsbs / matheus-bagliano / commits / b0d6e64629
Fork 0

read-tree --reset: update working tree file for conflicted paths.

The earlier "git reset --hard" simplification stopped removing leftover working tree files from a failed automerge, when switching back to the HEAD version that does not have the paths. This patch, instead of removing the unmerged paths from the index, drops them down to stage#0 but marks them with mode=0 (the same "to be deleted" marker we internally use for paths deleted by the merge). one_way_merge() function and the functions it calls already know what to do with them -- if the tree we are reading has the path the working tree file is overwritten, and if it doesn't the working tree file is removed. Signed-off-by: Junio C Hamano <junkio@cox.net>

Junio C Hamano committed Jun 3, 2006 at 01:49 UTC b0d6e64629aeba96e837972c0fda5e61eebb7ab1
1 file changed +14 -10
builtin-read-tree.c
+14 -10
@@ -751,25 +751,26 @@ static int oneway_merge(struct cache_entry **src)
751
752 static int read_cache_unmerged(void)
753 {
754 - int i, deleted;
754 + int i;
755 struct cache_entry **dst;
756 + struct cache_entry *last = NULL;
757
758 read_cache();
759 dst = active_cache;
759 - deleted = 0;
760 for (i = 0; i < active_nr; i++) {
761 struct cache_entry *ce = active_cache[i];
762 if (ce_stage(ce)) {
763 - deleted++;
763 + if (last && !strcmp(ce->name, last->name))
764 + continue;
765 invalidate_ce_path(ce);
765 - continue;
766 + last = ce;
767 + ce->ce_mode = 0;
768 + ce->ce_flags &= ~htons(CE_STAGEMASK);
769 }
767 - if (deleted)
768 - *dst = ce;
769 - dst++;
770 + *dst++ = ce;
771 }
771 - active_nr -= deleted;
772 - return deleted;
772 + active_nr = dst - active_cache;
773 + return !!last;
774 }
775
776 static void prime_cache_tree_rec(struct cache_tree *it, struct tree *tree)
@@ -850,7 +851,10 @@ int cmd_read_tree(int argc, const char **argv, char **envp)
851 continue;
852 }
853
853 - /* This differs from "-m" in that we'll silently ignore unmerged entries */
854 + /* This differs from "-m" in that we'll silently ignore
855 + * unmerged entries and overwrite working tree files that
856 + * correspond to them.
857 + */
858 if (!strcmp(arg, "--reset")) {
859 if (stage || merge)
860 usage(read_tree_usage);