@@ -78,6 +78,29 @@ static void prepare_move_submodule(const char *src, int first,
78
78
strbuf_release (& submodule_dotgit );
79
79
}
80
80
81
+ static int index_range_of_same_dir (const char * src , int length ,
82
+ int * first_p , int * last_p )
83
+ {
84
+ const char * src_w_slash = add_slash (src );
85
+ int first , last , len_w_slash = length + 1 ;
86
+
87
+ first = cache_name_pos (src_w_slash , len_w_slash );
88
+ if (first >= 0 )
89
+ die (_ ("%.*s is in index" ), len_w_slash , src_w_slash );
90
+
91
+ first = -1 - first ;
92
+ for (last = first ; last < active_nr ; last ++ ) {
93
+ const char * path = active_cache [last ]-> name ;
94
+ if (strncmp (path , src_w_slash , len_w_slash ))
95
+ break ;
96
+ }
97
+ if (src_w_slash != src )
98
+ free ((char * )src_w_slash );
99
+ * first_p = first ;
100
+ * last_p = last ;
101
+ return last - first ;
102
+ }
103
+
81
104
int cmd_mv (int argc , const char * * argv , const char * prefix )
82
105
{
83
106
int i , gitmodules_modified = 0 ;
@@ -154,25 +177,10 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
154
177
prepare_move_submodule (src , first ,
155
178
submodule_gitfile + i );
156
179
else {
157
- const char * src_w_slash = add_slash (src );
158
- int last , len_w_slash = length + 1 ;
180
+ int last ;
159
181
160
182
modes [i ] = WORKING_DIRECTORY ;
161
-
162
- first = cache_name_pos (src_w_slash , len_w_slash );
163
- if (first >= 0 )
164
- die (_ ("Huh? %.*s is in index?" ),
165
- len_w_slash , src_w_slash );
166
-
167
- first = -1 - first ;
168
- for (last = first ; last < active_nr ; last ++ ) {
169
- const char * path = active_cache [last ]-> name ;
170
- if (strncmp (path , src_w_slash , len_w_slash ))
171
- break ;
172
- }
173
- if (src_w_slash != src )
174
- free ((char * )src_w_slash );
175
-
183
+ index_range_of_same_dir (src , length , & first , & last );
176
184
if (last - first < 1 )
177
185
bad = _ ("source directory is empty" );
178
186
else {
0 commit comments