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

Re: [PATCH 7/9] mv ":" ":" is like moving nothing from nowhere to nowhere

From
Nguyen Thai Ngoc Duy <pclouds@gmail.com>
Date
May 10, 2011, 13:30 UTC
Message-ID
<BANLkTinBv+aRfgdnFKM-=yedug+WtseXsQ@mail.gmail.com>
In-Reply-To
<1305006678-4051-8-git-send-email-gitster@pobox.com>
On Tue, May 10, 2011 at 12:51 PM, Junio C Hamano <gitster@pobox.com> wrote:
Show 16 quoted lines
> diff --git a/builtin/mv.c b/builtin/mv.c
> index 93e8995..38af9f0 100644
> --- a/builtin/mv.c
> +++ b/builtin/mv.c
> @@ -77,8 +77,12 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
>                die("index file corrupt");
>
>        source = copy_pathspec(prefix, argv, argc, 0);
> -       modes = xcalloc(argc, sizeof(enum update_mode));
> +       if (!source)
> +               die("copying from nowhere?");
> +       modes = xcalloc(count_pathspec(source), sizeof(enum update_mode));
>        dest_path = copy_pathspec(prefix, argv + argc, 1, 0);
> +       if (!dest_path)
> +               die("copying to nowhere?");
>

This command is interesting. Note to self: adding support for "git mv '*.c' to/there".

I think we could take get_pathspec() out of copy_pathspec() and call it just once (in case get_pathspec() or its successor does fancy things), something roughly like this

diff --git a/builtin/mv.c b/builtin/mv.c
index 40f33ca..a032789 100644
--- a/builtin/mv.c
+++ b/builtin/mv.c
@@ -32,7 +32,7 @@ static const char **copy_pathspec(const char
*prefix, const char **pathspec,
 			result[i] = base_name ? strdup(basename(it)) : it;
 		}
 	}
-	return get_pathspec(prefix, result);
+	return result;
 }

 static const char *add_slash(const char *path)
@@ -60,7 +60,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
 		OPT_BOOLEAN('k', NULL, &ignore_errors, "skip move/rename errors"),
 		OPT_END(),
 	};
-	const char **source, **destination, **dest_path;
+	const char **pathspec, **source, **destination, **dest_path;
 	enum update_mode { BOTH = 0, WORKING_DIRECTORY, INDEX } *modes;
 	struct stat st;
 	struct string_list src_for_dst = STRING_LIST_INIT_NODUP;
@@ -69,16 +69,20 @@ int cmd_mv(int argc, const char **argv, const char *prefix)

 	argc = parse_options(argc, argv, prefix, builtin_mv_options,
 			     builtin_mv_usage, 0);
-	if (--argc < 1)
+
+	pathspec = get_pathspec(prefix, argv);
+	argc = count_pathspec(pathspec);
+
+	if (--argc < 1 || !pathspec)
 		usage_with_options(builtin_mv_usage, builtin_mv_options);

 	newfd = hold_locked_index(&lock_file, 1);
 	if (read_cache() < 0)
 		die(_("index file corrupt"));

-	source = copy_pathspec(prefix, argv, argc, 0);
+	source = copy_pathspec(prefix, pathspec, argc, 0);
 	modes = xcalloc(argc, sizeof(enum update_mode));
-	dest_path = copy_pathspec(prefix, argv + argc, 1, 0);
+	dest_path = copy_pathspec(prefix, pathspec + argc, 1, 0);

 	if (dest_path[0][0] == '\0')
 		/* special case: "." was normalized to "" */
-- 
Duy
Previous: Junio C HamanoNext: Junio C Hamano
Message 19 of 28 in “t3703: add test cases for pathspec magic”
  1. t3703: add test cases for pathspec magicNguyễn Thái Ngọc Duy, May 7, 2011
  2. Junio C HamanoMay 7, 2011
  3. Nguyen Thai Ngoc DuyMay 8, 2011
  4. t3703, t4208: add test cases for magic pathspecNguyễn Thái Ngọc Duy, May 8, 2011
  5. Junio C HamanoMay 8, 2011
  6. Nguyen Thai Ngoc DuyMay 9, 2011
  7. Junio C HamanoMay 9, 2011
  8. Junio C HamanoMay 9, 2011
  9. 0/9 magic pathspec updatesJunio C Hamano, May 10, 2011
  10. 1/9 grep: use get_pathspec() correctlyJunio C Hamano, May 10, 2011
  11. 2/9 get_pathspec(): an empty ':' pathspec should stand aloneJunio C Hamano, May 10, 2011
  12. 3/9 count_pathspec(): return number of elements in pathspecJunio C Hamano, May 10, 2011
  13. Nguyen Thai Ngoc DuyMay 10, 2011
  14. 4/9 add ":" is a pathspec that is too wideJunio C Hamano, May 10, 2011
  15. 5/9 git rm ":" is like specifying nothingJunio C Hamano, May 10, 2011
  16. 6/9 clean ":" is like specifying nothingJunio C Hamano, May 10, 2011
  17. Thiago FarinaMay 10, 2011
  18. 7/9 mv ":" ":" is like moving nothing from nowhere to nowhereJunio C Hamano, May 10, 2011
  19. Nguyen Thai Ngoc DuyMay 10, 2011
  20. 8/9 checkout ":" is not giving any pathspecJunio C Hamano, May 10, 2011
  21. 9/9 t3703, t4208: add test cases for magic pathspecJunio C Hamano, May 10, 2011
  22. t3703: Skip tests using directory name ":" on WindowsJohannes Sixt, May 12, 2011
  23. Ævar Arnfjörð BjarmasonMay 29, 2011
  24. Junio C HamanoMay 29, 2011
  25. Ævar Arnfjörð BjarmasonMay 29, 2011
  26. Nguyen Thai Ngoc DuyMay 10, 2011
  27. Junio C HamanoMay 10, 2011
  28. Nguyen Thai Ngoc DuyMay 11, 2011

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.