@@ -171,43 +171,36 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
171
171
&& lstat (dst , & st ) == 0 )
172
172
bad = _ ("cannot move directory over file" );
173
173
else if (src_is_dir ) {
174
- int first = cache_name_pos (src , length );
174
+ int first = cache_name_pos (src , length ), last ;
175
175
176
176
if (first >= 0 )
177
177
prepare_move_submodule (src , first ,
178
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 ;
181
184
182
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 * )) ;
188
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 );
195
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 ;
210
202
}
203
+ argc += last - first ;
211
204
}
212
205
} else if (cache_name_pos (src , length ) < 0 )
213
206
bad = _ ("not under version control" );
0 commit comments