mv: unindent one level for directory move code
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Nguyễn Thái Ngọc Duy committed
Aug 10, 2014 at 09:29 UTC
b46b15dea01a898888fac977aeed6055a761c3ca
1 file changed
+21
-28
builtin/mv.c
+21
-28
@@ -171,43 +171,36 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
171
&& lstat(dst, &st) == 0)
172
bad = _("cannot move directory over file");
173
else if (src_is_dir) {
174
- int first = cache_name_pos(src, length);
174
+ int first = cache_name_pos(src, length), last;
175
176
if (first >= 0)
177
prepare_move_submodule(src, first,
178
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;
184
185
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 *));
191
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);
194
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;
202
}
203
+ argc += last - first;
204
}
205
} else if (cache_name_pos(src, length) < 0)
206
bad = _("not under version control");