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

Re: [PATCH v2 6/8] mv: unindent one level for directory move code

From
Junio C Hamano <gitster@pobox.com>
Date
Aug 11, 2014, 18:47 UTC
Message-ID
<xmqq61hy7tii.fsf@gitster.dls.corp.google.com>
In-Reply-To
<1407637776-19794-7-git-send-email-pclouds@gmail.com>
Nguyễn Thái Ngọc Duy  <pclouds@gmail.com> writes:
Show 19 quoted lines
> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
> ---
>  builtin/mv.c | 47 +++++++++++++++++++++--------------------------
>  1 file changed, 21 insertions(+), 26 deletions(-)
>
> diff --git a/builtin/mv.c b/builtin/mv.c
> index dcfcb11..988945c 100644
> --- a/builtin/mv.c
> +++ b/builtin/mv.c
> @@ -171,42 +171,37 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
>  				&& lstat(dst, &st) == 0)
>  			bad = _("cannot move directory over file");
>  		else if (src_is_dir) {
> +			int first = cache_name_pos(src, length), last;
>  			if (first >= 0)
>  				prepare_move_submodule(src, first,
>  						       submodule_gitfile + i);
> +			else if (index_range_of_same_dir(src, length,
> +							 &first, &last) < 1) {

The function returns (last - first), so (last - first) < 1 holds inside this block, right?

>  				modes[i] = WORKING_DIRECTORY;
>  				if (last - first < 1)
>  					bad = _("source directory is empty");
Then do you need this conditional, or it is always bad here?

If it is always bad, then modes[i] do not need to be assigned to, either, I think.

Am I missing something?
> +			} else { /* last - first >= 1 */
> +				int j, dst_len, n;
> +				modes[i] = WORKING_DIRECTORY;
> +				n = argc + last - first;
> ...
Otherwise, perhaps squash this in?
diff --git a/builtin/mv.c b/builtin/mv.c
index bf513e0..bf784cb 100644
--- a/builtin/mv.c
+++ b/builtin/mv.c
@@ -172,15 +172,14 @@ 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), last;
+
 			if (first >= 0)
 				prepare_move_submodule(src, first,
 						       submodule_gitfile + i);
 			else if (index_range_of_same_dir(src, length,
-							 &first, &last) < 1) {
-				modes[i] = WORKING_DIRECTORY;
-				if (last - first < 1)
-					bad = _("source directory is empty");
-			} else { /* last - first >= 1 */
+							 &first, &last) < 1)
+				bad = _("source directory is empty");
+			else { /* last - first >= 1 */
 				int j, dst_len, n;
 
 				modes[i] = WORKING_DIRECTORY;
Previous: Nguyễn Thái Ngọc DuyNext: Duy Nguyen
Message 8 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.