Thread (3 messages) flat view 3 messages, 2 authors, 2016-06-15

Re: Simplify "git reset --hard"

From: Linus Torvalds <torvalds@osdl.org>
Date: 2016-06-15 22:42:26
Subsystem: the rest · Maintainer: Linus Torvalds

Possibly related (same subject, not in this thread)


On Mon, 15 May 2006, Linus Torvalds wrote:
Ack. On the other hand, I wonder if it might not make sense to have this 
part potentially depend on the "--reset" flag.

That way you wouldn't even have to apologize for it.
Ie, something like this..

This should allow a two-way or three-way merge to akso ignore any dirty 
state when you use "--reset", because they use "verify_uptodate()", which 
now would set the CD_UPDATE flag on the ce rather than complain about it 
being different (if it survives the merge, of course - often it won't, but 
then we won't care).

This is all totally untested, of course.

		Linus

----
diff --git a/read-tree.c b/read-tree.c
index 7c83031..f2d674c 100644
--- a/read-tree.c
+++ b/read-tree.c
@@ -13,6 +13,7 @@ #include "cache-tree.h"
 #include <sys/time.h>
 #include <signal.h>
 
+static int reset = 0;
 static int merge = 0;
 static int update = 0;
 static int index_only = 0;
@@ -419,6 +420,10 @@ static void verify_uptodate(struct cache
 			return;
 		errno = 0;
 	}
+	if (reset) {
+		ce->ce_flags |= htons(CE_UPDATE);
+		return;
+	}
 	if (errno == ENOENT)
 		return;
 	die("Entry '%s' not uptodate. Cannot merge.", ce->name);
@@ -723,6 +728,11 @@ static int oneway_merge(struct cache_ent
 		return deleted_entry(old, NULL);
 	}
 	if (old && same(old, a)) {
+		if (reset) {
+			struct stat st;
+			if (lstat(old->name, &st) || ce_match_stat(old, &st, 1))
+				old->ce_flags |= htons(CE_UPDATE);
+		}
 		return keep_entry(old);
 	}
 	return merged_entry(a, NULL);
@@ -790,7 +800,7 @@ static struct cache_file cache_file;
 
 int main(int argc, char **argv)
 {
-	int i, newfd, reset, stage = 0;
+	int i, newfd, stage = 0;
 	unsigned char sha1[20];
 	merge_fn_t fn = NULL;
 
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help