aboutsummaryrefslogtreecommitdiff
path: root/builtin/mv.c
diff options
context:
space:
mode:
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>2014-08-10 09:29:33 +0700
committerJunio C Hamano <gitster@pobox.com>2014-09-03 14:59:43 -0700
commite2b6cfa02e29c4a8f91ede15026b5eaa790de329 (patch)
tree1e3907ce32e4893551dfff856fb5ee572cc29caf /builtin/mv.c
parent42de4b169c5de9d3f22eb1f988aa5b69447951b2 (diff)
downloadgit-e2b6cfa02e29c4a8f91ede15026b5eaa790de329.tar.gz
git-e2b6cfa02e29c4a8f91ede15026b5eaa790de329.tar.xz
mv: move index search code out
"Huh?" is removed from die() message. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/mv.c')
-rw-r--r--builtin/mv.c42
1 files changed, 25 insertions, 17 deletions
diff --git a/builtin/mv.c b/builtin/mv.c
index 3b19ca26b..42a04d2b8 100644
--- a/builtin/mv.c
+++ b/builtin/mv.c
@@ -78,6 +78,29 @@ static void prepare_move_submodule(const char *src, int first,
strbuf_release(&submodule_dotgit);
}
+static int index_range_of_same_dir(const char *src, int length,
+ int *first_p, int *last_p)
+{
+ const char *src_w_slash = add_slash(src);
+ int first, last, len_w_slash = length + 1;
+
+ first = cache_name_pos(src_w_slash, len_w_slash);
+ if (first >= 0)
+ die(_("%.*s is in index"), len_w_slash, src_w_slash);
+
+ first = -1 - first;
+ for (last = first; last < active_nr; last++) {
+ const char *path = active_cache[last]->name;
+ if (strncmp(path, src_w_slash, len_w_slash))
+ break;
+ }
+ if (src_w_slash != src)
+ free((char *)src_w_slash);
+ *first_p = first;
+ *last_p = last;
+ return last - first;
+}
+
int cmd_mv(int argc, const char **argv, const char *prefix)
{
int i, gitmodules_modified = 0;
@@ -154,25 +177,10 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
prepare_move_submodule(src, first,
submodule_gitfile + i);
else {
- const char *src_w_slash = add_slash(src);
- int last, len_w_slash = length + 1;
+ int last;
modes[i] = WORKING_DIRECTORY;
-
- first = cache_name_pos(src_w_slash, len_w_slash);
- if (first >= 0)
- die (_("Huh? %.*s is in index?"),
- len_w_slash, src_w_slash);
-
- first = -1 - first;
- for (last = first; last < active_nr; last++) {
- const char *path = active_cache[last]->name;
- if (strncmp(path, src_w_slash, len_w_slash))
- break;
- }
- if (src_w_slash != src)
- free((char *)src_w_slash);
-
+ index_range_of_same_dir(src, length, &first, &last);
if (last - first < 1)
bad = _("source directory is empty");
else {