36
return get_pathspec(prefix, result);
37
}
38
39
-static void show_list(const char *label, struct string_list *list)
40
-{
41
- if (list->nr > 0) {
42
- int i;
43
- printf("%s", label);
44
- for (i = 0; i < list->nr; i++)
45
- printf("%s%s", i > 0 ? ", " : "",
46
- list->items[i].string);
47
- putchar('\n');
48
- }
49
-}
50
-
39
static const char *add_slash(const char *path)
40
{
41
int len = strlen(path);
64
const char **source, **destination, **dest_path;
65
enum update_mode { BOTH = 0, WORKING_DIRECTORY, INDEX } *modes;
66
struct stat st;
79
- struct string_list overwritten = {NULL, 0, 0, 0};
67
struct string_list src_for_dst = {NULL, 0, 0, 0};
81
- struct string_list added = {NULL, 0, 0, 0};
82
- struct string_list deleted = {NULL, 0, 0, 0};
83
- struct string_list changed = {NULL, 0, 0, 0};
68
69
git_config(git_default_config, NULL);
70
169
* only files can overwrite each other:
170
* check both source and destination
171
*/
188
- if (S_ISREG(st.st_mode)) {
172
+ if (S_ISREG(st.st_mode) || S_ISLNK(st.st_mode)) {
173
fprintf(stderr, "Warning: %s;"
174
" will overwrite!\n",
175
bad);
176
bad = NULL;
193
- string_list_insert(dst, &overwritten);
177
} else
178
bad = "Cannot overwrite";
179
}
202
for (i = 0; i < argc; i++) {
203
const char *src = source[i], *dst = destination[i];
204
enum update_mode mode = modes[i];
205
+ int pos;
206
if (show_only || verbose)
207
printf("Renaming %s to %s\n", src, dst);
208
if (!show_only && mode != INDEX &&
212
if (mode == WORKING_DIRECTORY)
213
continue;
214
231
- assert(cache_name_pos(src, strlen(src)) >= 0);
232
-
233
- string_list_insert(src, &deleted);
234
- /* destination can be a directory with 1 file inside */
235
- if (string_list_has_string(&overwritten, dst))
236
- string_list_insert(dst, &changed);
237
- else
238
- string_list_insert(dst, &added);
215
+ pos = cache_name_pos(src, strlen(src));
216
+ assert(pos >= 0);
217
+ if (!show_only)
218
+ rename_cache_entry_at(pos, dst);
219
}
220
241
- if (show_only) {
242
- show_list("Changed : ", &changed);
243
- show_list("Adding : ", &added);
244
- show_list("Deleting : ", &deleted);
245
- } else {
246
- for (i = 0; i < changed.nr; i++) {
247
- const char *path = changed.items[i].string;
248
- int j = cache_name_pos(path, strlen(path));
249
- struct cache_entry *ce = active_cache[j];
250
-
251
- if (j < 0)
252
- die ("Huh? Cache entry for %s unknown?", path);
253
- refresh_cache_entry(ce, 0);
254
- }
255
-
256
- for (i = 0; i < added.nr; i++) {
257
- const char *path = added.items[i].string;
258
- if (add_file_to_cache(path, verbose ? ADD_CACHE_VERBOSE : 0))
259
- die("updating index entries failed");
260
- }
261
-
262
- for (i = 0; i < deleted.nr; i++)
263
- remove_file_from_cache(deleted.items[i].string);
264
-
265
- if (active_cache_changed) {
266
- if (write_cache(newfd, active_cache, active_nr) ||
267
- commit_locked_index(&lock_file))
268
- die("Unable to write new index file");
269
- }
221
+ if (active_cache_changed) {
222
+ if (write_cache(newfd, active_cache, active_nr) ||
223
+ commit_locked_index(&lock_file))
224
+ die("Unable to write new index file");
225
}
226
227
return 0;