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

[PATCH v2 0/8] builtin/mv.c cleanup

From
Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Date
Aug 10, 2014, 02:29 UTC
Message-ID
<1407637776-19794-1-git-send-email-pclouds@gmail.com>

Interdiff on v1 below. I'm not going with MOVE_UP_BY_ONE because [1] seems to agree with the name CLOSE_GAP, but that should be a separate topic (touching more than just mv.c)

[1] http://thread.gmane.org/gmane.comp.version-control.git/243675/focus=244390
-- 8< --
diff --git a/builtin/mv.c b/builtin/mv.c
index 4eb420b..bf513e0 100644
--- a/builtin/mv.c
+++ b/builtin/mv.c
@@ -58,11 +58,6 @@ static const char *add_slash(const char *path)
 	return path;
 }
 
-static void move_up_one(void *p, int nmemb, int size)
-{
-	memmove(p, (char*)p + size, nmemb * size);
-}
-
 static struct lock_file lock_file;
 #define SUBMODULE_WITH_GITDIR ((const char *)1)
 
@@ -71,9 +66,9 @@ static void prepare_move_submodule(const char *src, int first,
 {
 	struct strbuf submodule_dotgit = STRBUF_INIT;
 	if (!S_ISGITLINK(active_cache[first]->ce_mode))
-		die (_("Directory %s is in index and no submodule?"), src);
+		die(_("Directory %s is in index and no submodule?"), src);
 	if (!is_staging_gitmodules_ok())
-		die (_("Please, stage your changes to .gitmodules or stash them to proceed"));
+		die(_("Please stage your changes to .gitmodules or stash them to proceed"));
 	strbuf_addf(&submodule_dotgit, "%s/.git", src);
 	*submodule_gitfile = read_gitfile(submodule_dotgit.buf);
 	if (*submodule_gitfile)
@@ -91,7 +86,7 @@ static int index_range_of_same_dir(const char *src, int length,
 
 	first = cache_name_pos(src_w_slash, len_w_slash);
 	if (first >= 0)
-		die (_("%.*s is in index"), len_w_slash, src_w_slash);
+		die(_("%.*s is in index"), len_w_slash, src_w_slash);
 
 	first = -1 - first;
 	for (last = first; last < active_nr; last++) {
@@ -235,14 +230,18 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
 		if (!bad)
 			continue;
 		if (!ignore_errors)
-			die (_("%s, source=%s, destination=%s"),
+			die(_("%s, source=%s, destination=%s"),
 			     bad, src, dst);
 		if (--argc > 0) {
 			int n = argc - i;
-			move_up_one(source + i, n, sizeof(*source));
-			move_up_one(destination + i, n, sizeof(*destination));
-			move_up_one(modes + i, n, sizeof(*modes));
-			move_up_one(submodule_gitfile + i, n, sizeof(*submodule_gitfile));
+			memmove(source + i, source + i + 1,
+				n * sizeof(char *));
+			memmove(destination + i, destination + i + 1,
+				n * sizeof(char *));
+			memmove(modes + i, modes + i + 1,
+				n * sizeof(enum update_mode));
+			memmove(submodule_gitfile + i, submodule_gitfile + i + 1,
+				n * sizeof(char *));
 			i--;
 		}
 	}
@@ -255,7 +254,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
 			printf(_("Renaming %s to %s\n"), src, dst);
 		if (!show_only && mode != INDEX) {
 			if (rename(src, dst) < 0 && !ignore_errors)
-				die_errno (_("renaming '%s' failed"), src);
+				die_errno(_("renaming '%s' failed"), src);
 			if (submodule_gitfile[i]) {
 				if (submodule_gitfile[i] != SUBMODULE_WITH_GITDIR)
 					connect_work_tree_and_git_dir(dst, submodule_gitfile[i]);
@@ -278,7 +277,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
 
 	if (active_cache_changed &&
 	    write_locked_index(&the_index, &lock_file, COMMIT_LOCK))
-			die(_("Unable to write new index file"));
+		die(_("Unable to write new index file"));
 
 	return 0;
 }
-- 8< --

Nguyễn Thái Ngọc Duy (8):
  mv: mark strings for translations
  mv: flatten error handling code block
  mv: split submodule move preparation code out
  mv: remove an "if" that's always true
  mv: move index search code out
  mv: unindent one level for directory move code
  mv: combine two if(s)
  mv: no SP between function name and the first opening parenthese

 builtin/mv.c | 171 +++++++++++++++++++++++++++++------------------------------
 1 file changed, 85 insertions(+), 86 deletions(-)
-- 
2.1.0.rc0.78.gc0d8480
Next: Nguyễn Thái Ngọc Duy
Message 1 of 12 in “builtin/mv.c cleanup”
  1. 0/8 builtin/mv.c cleanupNguyễn Thái Ngọc Duy, Aug 10, 2014
  2. 1/8 mv: mark strings for translationsNguyễn Thái Ngọc Duy, Aug 10, 2014
  3. 2/8 mv: flatten error handling code blockNguyễn Thái Ngọc Duy, Aug 10, 2014
  4. 3/8 mv: split submodule move preparation code outNguyễn Thái Ngọc Duy, Aug 10, 2014
  5. 4/8 mv: remove an "if" that's always trueNguyễn Thái Ngọc Duy, Aug 10, 2014
  6. 5/8 mv: move index search code outNguyễn Thái Ngọc Duy, Aug 10, 2014
  7. 6/8 mv: unindent one level for directory move codeNguyễn Thái Ngọc Duy, Aug 10, 2014
  8. Junio C HamanoAug 11, 2014
  9. Duy NguyenAug 12, 2014
  10. Junio C HamanoAug 12, 2014
  11. 7/8 mv: combine two if(s)Nguyễn Thái Ngọc Duy, Aug 10, 2014
  12. 8/8 mv: no SP between function name and the first opening parentheseNguyễn Thái Ngọc Duy, Aug 10, 2014

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.