Skip to content

Commit b46b15d

Browse files
pcloudsgitster
authored andcommitted
mv: unindent one level for directory move code
Signed-off-by: Nguyễn Thái Ngọc Duy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e2b6cfa commit b46b15d

File tree

1 file changed

+21
-28
lines changed

1 file changed

+21
-28
lines changed

builtin/mv.c

Lines changed: 21 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -171,43 +171,36 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
171171
&& lstat(dst, &st) == 0)
172172
bad = _("cannot move directory over file");
173173
else if (src_is_dir) {
174-
int first = cache_name_pos(src, length);
174+
int first = cache_name_pos(src, length), last;
175175

176176
if (first >= 0)
177177
prepare_move_submodule(src, first,
178178
submodule_gitfile + i);
179-
else {
180-
int last;
179+
else if (index_range_of_same_dir(src, length,
180+
&first, &last) < 1)
181+
bad = _("source directory is empty");
182+
else { /* last - first >= 1 */
183+
int j, dst_len, n;
181184

182185
modes[i] = WORKING_DIRECTORY;
183-
index_range_of_same_dir(src, length, &first, &last);
184-
if (last - first < 1)
185-
bad = _("source directory is empty");
186-
else {
187-
int j, dst_len, n;
186+
n = argc + last - first;
187+
source = xrealloc(source, n * sizeof(char *));
188+
destination = xrealloc(destination, n * sizeof(char *));
189+
modes = xrealloc(modes, n * sizeof(enum update_mode));
190+
submodule_gitfile = xrealloc(submodule_gitfile, n * sizeof(char *));
188191

189-
n = argc + last - first;
190-
source = xrealloc(source, n * sizeof(char *));
191-
destination = xrealloc(destination, n * sizeof(char *));
192-
modes = xrealloc(modes, n * sizeof(enum update_mode));
193-
submodule_gitfile =
194-
xrealloc(submodule_gitfile, n * sizeof(char *));
192+
dst = add_slash(dst);
193+
dst_len = strlen(dst);
195194

196-
dst = add_slash(dst);
197-
dst_len = strlen(dst);
198-
199-
for (j = 0; j < last - first; j++) {
200-
const char *path =
201-
active_cache[first + j]->name;
202-
source[argc + j] = path;
203-
destination[argc + j] =
204-
prefix_path(dst, dst_len,
205-
path + length + 1);
206-
modes[argc + j] = INDEX;
207-
submodule_gitfile[argc + j] = NULL;
208-
}
209-
argc += last - first;
195+
for (j = 0; j < last - first; j++) {
196+
const char *path = active_cache[first + j]->name;
197+
source[argc + j] = path;
198+
destination[argc + j] =
199+
prefix_path(dst, dst_len, path + length + 1);
200+
modes[argc + j] = INDEX;
201+
submodule_gitfile[argc + j] = NULL;
210202
}
203+
argc += last - first;
211204
}
212205
} else if (cache_name_pos(src, length) < 0)
213206
bad = _("not under version control");

0 commit comments

Comments
 (0)