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

[PATCH v2 3/8] mv: split submodule move preparation code out

From
Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Date
Aug 10, 2014, 02:29 UTC
Message-ID
<1407637776-19794-4-git-send-email-pclouds@gmail.com>
In-Reply-To
<1407637776-19794-1-git-send-email-pclouds@gmail.com>
"Huh?" is removed from die() message.
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 builtin/mv.c | 35 +++++++++++++++++++++--------------
 1 file changed, 21 insertions(+), 14 deletions(-)
diff --git a/builtin/mv.c b/builtin/mv.c
index c48129e..524f4e5 100644
--- a/builtin/mv.c
+++ b/builtin/mv.c
@@ -61,6 +61,23 @@ static const char *add_slash(const char *path)
 static struct lock_file lock_file;
 #define SUBMODULE_WITH_GITDIR ((const char *)1)
 
+static void prepare_move_submodule(const char *src, int first,
+				   const char **submodule_gitfile)
+{
+	struct strbuf submodule_dotgit = STRBUF_INIT;
+	if (!S_ISGITLINK(active_cache[first]->ce_mode))
+		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"));
+	strbuf_addf(&submodule_dotgit, "%s/.git", src);
+	*submodule_gitfile = read_gitfile(submodule_dotgit.buf);
+	if (*submodule_gitfile)
+		*submodule_gitfile = xstrdup(*submodule_gitfile);
+	else
+		*submodule_gitfile = SUBMODULE_WITH_GITDIR;
+	strbuf_release(&submodule_dotgit);
+}
+
 int cmd_mv(int argc, const char **argv, const char *prefix)
 {
 	int i, gitmodules_modified = 0;
@@ -132,20 +149,10 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
 			bad = _("cannot move directory over file");
 		else if (src_is_dir) {
 			int first = cache_name_pos(src, length);
-			if (first >= 0) {
-				struct strbuf submodule_dotgit = STRBUF_INIT;
-				if (!S_ISGITLINK(active_cache[first]->ce_mode))
-					die (_("Huh? 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"));
-				strbuf_addf(&submodule_dotgit, "%s/.git", src);
-				submodule_gitfile[i] = read_gitfile(submodule_dotgit.buf);
-				if (submodule_gitfile[i])
-					submodule_gitfile[i] = xstrdup(submodule_gitfile[i]);
-				else
-					submodule_gitfile[i] = SUBMODULE_WITH_GITDIR;
-				strbuf_release(&submodule_dotgit);
-			} else {
+			if (first >= 0)
+				prepare_move_submodule(src, first,
+						       submodule_gitfile + i);
+			else {
 				const char *src_w_slash = add_slash(src);
 				int last, len_w_slash = length + 1;
 
-- 
2.1.0.rc0.78.gc0d8480
Previous: Nguyễn Thái Ngọc DuyNext: Nguyễn Thái Ngọc Duy
Message 4 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.