From: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
To: git@vger.kernel.org
Cc: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Subject: [PATCH 7/8] mv: unindent one level for directory move code
Date: Fri, 8 Aug 2014 20:11:01 +0700 [thread overview]
Message-ID: <1407503462-32632-8-git-send-email-pclouds@gmail.com> (raw)
In-Reply-To: <1407503462-32632-1-git-send-email-pclouds@gmail.com>
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 f8d65e2..a2e33b5 100644
--- a/builtin/mv.c
+++ b/builtin/mv.c
@@ -176,42 +176,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);
+ int first = cache_name_pos(src, length), last;
if (first >= 0)
prepare_move_submodule(src, first,
submodule_gitfile + i);
- else {
- int last;
-
+ else if (index_range_of_same_dir(src, length,
+ &first, &last) < 1) {
modes[i] = WORKING_DIRECTORY;
- index_range_of_same_dir(src, length, &first, &last);
if (last - first < 1)
bad = _("source directory is empty");
- else {
- int j, dst_len, n;
+ } else { /* last - first >= 1 */
+ int j, dst_len, n;
- n = argc + last - first;
- source = xrealloc(source, n * sizeof(char *));
- destination = xrealloc(destination, n * sizeof(char *));
- modes = xrealloc(modes, n * sizeof(enum update_mode));
- submodule_gitfile =
- xrealloc(submodule_gitfile, n * sizeof(char *));
+ modes[i] = WORKING_DIRECTORY;
+ n = argc + last - first;
+ source = xrealloc(source, n * sizeof(char *));
+ destination = xrealloc(destination, n * sizeof(char *));
+ modes = xrealloc(modes, n * sizeof(enum update_mode));
+ submodule_gitfile = xrealloc(submodule_gitfile, n * sizeof(char *));
- dst = add_slash(dst);
- dst_len = strlen(dst);
+ dst = add_slash(dst);
+ dst_len = strlen(dst);
- for (j = 0; j < last - first; j++) {
- const char *path =
- active_cache[first + j]->name;
- source[argc + j] = path;
- destination[argc + j] =
- prefix_path(dst, dst_len,
- path + length + 1);
- modes[argc + j] = INDEX;
- submodule_gitfile[argc + j] = NULL;
- }
- argc += last - first;
+ for (j = 0; j < last - first; j++) {
+ const char *path = active_cache[first + j]->name;
+ source[argc + j] = path;
+ destination[argc + j] =
+ prefix_path(dst, dst_len, path + length + 1);
+ modes[argc + j] = INDEX;
+ submodule_gitfile[argc + j] = NULL;
}
+ argc += last - first;
}
} else if (cache_name_pos(src, length) < 0)
bad = _("not under version control");
--
2.1.0.rc0.78.gc0d8480
next prev parent reply other threads:[~2014-08-08 13:11 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-08-08 13:10 [PATCH 0/8] builtin/mv.c cleanup Nguyễn Thái Ngọc Duy
2014-08-08 13:10 ` [PATCH 1/8] mv: mark strings for translations Nguyễn Thái Ngọc Duy
2014-08-08 13:10 ` [PATCH 2/8] mv: no "Huh?" to the user Nguyễn Thái Ngọc Duy
2014-08-08 17:48 ` Junio C Hamano
2014-08-08 13:10 ` [PATCH 3/8] mv: flatten error handling code block Nguyễn Thái Ngọc Duy
2014-08-08 17:54 ` Junio C Hamano
2014-08-08 13:10 ` [PATCH 4/8] mv: split submodule move preparation code out Nguyễn Thái Ngọc Duy
2014-08-08 13:10 ` [PATCH 5/8] mv: remove an "if" that's always true Nguyễn Thái Ngọc Duy
2014-08-08 13:11 ` [PATCH 6/8] mv: move index search code out Nguyễn Thái Ngọc Duy
2014-08-08 13:11 ` Nguyễn Thái Ngọc Duy [this message]
2014-08-08 13:11 ` [PATCH 8/8] mv: combine two if(s) 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=1407503462-32632-8-git-send-email-pclouds@gmail.com \
--to=pclouds@gmail.com \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
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;
as well as URLs for NNTP newsgroup(s).