git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] reset: trivial refactoring

From
Felipe Contreras <felipe.contreras@gmail.com>
Date
Jun 13, 2013, 18:15 UTC
Message-ID
<1371147305-20771-1-git-send-email-felipe.contreras@gmail.com>

After commit 3fde386 (reset [--mixed]: use diff-based reset whether or not pathspec was given), some code can't be reached, and other code can be moved to the 'reset_type == MIXED' check.

Let's remove the check that can't be reached, and move the code is specific to MIXED.

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 builtin/reset.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)
diff --git a/builtin/reset.c b/builtin/reset.c
index 6032131..68739ba 100644
--- a/builtin/reset.c
+++ b/builtin/reset.c
@@ -82,7 +82,7 @@ static int reset_index(const unsigned char *sha1, int reset_type, int quiet)
 	if (unpack_trees(nr, desc, &opts))
 		return -1;
 
-	if (reset_type == MIXED || reset_type == HARD) {
+	if (reset_type == HARD) {
 		tree = parse_tree_indirect(sha1);
 		prime_cache_tree(&active_cache_tree, tree);
 	}
@@ -323,8 +323,11 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
 		struct lock_file *lock = xcalloc(1, sizeof(struct lock_file));
 		int newfd = hold_locked_index(lock, 1);
 		if (reset_type == MIXED) {
+			int flags = quiet ? REFRESH_QUIET : REFRESH_IN_PORCELAIN;
 			if (read_from_tree(pathspec, sha1))
 				return 1;
+			refresh_index(&the_index, flags, NULL, NULL,
+				      _("Unstaged changes after reset:"));
 		} else {
 			int err = reset_index(sha1, reset_type, quiet);
 			if (reset_type == KEEP && !err)
@@ -333,12 +336,6 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
 				die(_("Could not reset index file to revision '%s'."), rev);
 		}
 
-		if (reset_type == MIXED) { /* Report what has not been updated. */
-			int flags = quiet ? REFRESH_QUIET : REFRESH_IN_PORCELAIN;
-			refresh_index(&the_index, flags, NULL, NULL,
-				      _("Unstaged changes after reset:"));
-		}
-
 		if (write_cache(newfd, active_cache, active_nr) ||
 		    commit_locked_index(lock))
 			die(_("Could not write new index file."));
-- 
1.8.3.698.g079b096
Next: Martin von Zweigbergk
Message 1 of 4 in “reset: trivial refactoring”
  1. reset: trivial refactoringFelipe Contreras, Jun 13, 2013
  2. Martin von ZweigbergkJun 13, 2013
  3. Felipe ContrerasJun 13, 2013
  4. Junio C HamanoJun 13, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.