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

[PATCH] cleans up builtin-mv

From
DRDavid Rientjes <rientjes@google.com>
Date
Aug 18, 2006, 05:59 UTC
Message-ID
<Pine.LNX.4.63.0608172230470.25827@chino.corp.google.com>

Cleans up builtin-mv by removing a needless check of source's length, redefinition of source's length, and misuse of strlen call that was already assigned.

Signed-off-by: David Rientjes <rientjes@google.com>
---
 builtin-mv.c |   14 +++++++-------
 1 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/builtin-mv.c b/builtin-mv.c
index c0c8764..54c9262 100644
--- a/builtin-mv.c
+++ b/builtin-mv.c
@@ -126,7 +126,7 @@ int cmd_mv(int argc, const char **argv, 
 
 	/* Checking */
 	for (i = 0; i < count; i++) {
-		int length;
+		int length = strlen(source[i]);
 		const char *bad = NULL;
 
 		if (show_only)
@@ -137,14 +137,13 @@ int cmd_mv(int argc, const char **argv, 
 			bad = "bad source";
 
 		if (!bad &&
-		    (length = strlen(source[i])) >= 0 &&
 		    !strncmp(destination[i], source[i], length) &&
 		    (destination[i][length] == 0 || destination[i][length] == '/'))
 			bad = "can not move directory into itself";
 
 		if (S_ISDIR(st.st_mode)) {
 			const char *dir = source[i], *dest_dir = destination[i];
-			int first, last, len = strlen(dir);
+			int first, last;
 
 			if (lstat(dest_dir, &st) == 0) {
 				bad = "cannot move directory over file";
@@ -153,14 +152,15 @@ int cmd_mv(int argc, const char **argv, 
 
 			modes[i] = WORKING_DIRECTORY;
 
-			first = cache_name_pos(source[i], len);
+			first = cache_name_pos(source[i], length);
 			if (first >= 0)
 				die ("Huh? %s/ is in index?", dir);
 
 			first = -1 - first;
 			for (last = first; last < active_nr; last++) {
 				const char *path = active_cache[last]->name;
-				if (strncmp(path, dir, len) || path[len] != '/')
+				if (strncmp(path, dir, length) ||
+				    path[length] != '/')
 					break;
 			}
 
@@ -189,7 +189,7 @@ int cmd_mv(int argc, const char **argv, 
 					source[count + j] = path;
 					destination[count + j] =
 						prefix_path(dest_dir, dst_len,
-							path + len);
+							path + length);
 					modes[count + j] = INDEX;
 				}
 				count += last - first;
@@ -217,7 +217,7 @@ int cmd_mv(int argc, const char **argv, 
 			}
 		}
 
-		if (!bad && cache_name_pos(source[i], strlen(source[i])) < 0)
+		if (!bad && cache_name_pos(source[i], length) < 0)
 			bad = "not under version control";
 
 		if (!bad) {
-- 
1.4.2.rc4.g55c3-dirty
Next: David Rientjes
Message 1 of 8 in “cleans up builtin-mv”
  1. cleans up builtin-mvDavid Rientjes, Aug 18, 2006
  2. David RientjesAug 18, 2006
  3. Johannes SchindelinAug 18, 2006
  4. David RientjesAug 18, 2006
  5. Josef WeidendorferAug 18, 2006
  6. David RientjesAug 18, 2006
  7. Junio C HamanoAug 18, 2006
  8. Johannes SchindelinAug 19, 2006

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.