[PATCH] cleans up builtin-mv

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
---
 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

-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]