public inbox for git@vger.kernel.org 
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox•com>
To: "Nguyễn Thái Ngọc Duy" <pclouds@gmail•com>
Cc: git@vger•kernel.org
Subject: Re: [PATCH v2 6/8] mv: unindent one level for directory move code
Date: Mon, 11 Aug 2014 11:47:49 -0700	[thread overview]
Message-ID: <xmqq61hy7tii.fsf@gitster.dls.corp.google.com> (raw)
In-Reply-To: 1407637776-19794-7-git-send-email-pclouds@gmail.com

Nguyễn Thái Ngọc Duy  <pclouds@gmail•com> writes:

> 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;

  reply	other threads:[~2014-08-11 18:48 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-08-10  2:29 [PATCH v2 0/8] builtin/mv.c cleanup Nguyễn Thái Ngọc Duy
2014-08-10  2:29 ` [PATCH v2 1/8] mv: mark strings for translations Nguyễn Thái Ngọc Duy
2014-08-10  2:29 ` [PATCH v2 2/8] mv: flatten error handling code block Nguyễn Thái Ngọc Duy
2014-08-10  2:29 ` [PATCH v2 3/8] mv: split submodule move preparation code out Nguyễn Thái Ngọc Duy
2014-08-10  2:29 ` [PATCH v2 4/8] mv: remove an "if" that's always true Nguyễn Thái Ngọc Duy
2014-08-10  2:29 ` [PATCH v2 5/8] mv: move index search code out Nguyễn Thái Ngọc Duy
2014-08-10  2:29 ` [PATCH v2 6/8] mv: unindent one level for directory move code Nguyễn Thái Ngọc Duy
2014-08-11 18:47   ` Junio C Hamano [this message]
2014-08-12 14:57     ` Duy Nguyen
2014-08-12 17:56       ` Junio C Hamano
2014-08-10  2:29 ` [PATCH v2 7/8] mv: combine two if(s) Nguyễn Thái Ngọc Duy
2014-08-10  2:29 ` [PATCH v2 8/8] mv: no SP between function name and the first opening parenthese Nguyễn Thái Ngọc Duy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqq61hy7tii.fsf@gitster.dls.corp.google.com \
    --to=gitster@pobox$(echo .)com \
    --cc=git@vger$(echo .)kernel.org \
    --cc=pclouds@gmail$(echo .)com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox