82
83
#define SUBMODULE_WITH_GITDIR ((const char *)1)
84
85
-static void prepare_move_submodule(const char *src, int first,
86
- const char **submodule_gitfile)
85
+static const char *submodule_gitfile_path(const char *src, int first)
86
{
87
struct strbuf submodule_dotgit = STRBUF_INIT;
88
+ const char *path;
89
+
90
if (!S_ISGITLINK(the_repository->index->cache[first]->ce_mode))
91
die(_("Directory %s is in index and no submodule?"), src);
92
if (!is_staging_gitmodules_ok(the_repository->index))
93
die(_("Please stage your changes to .gitmodules or stash them to proceed"));
94
+
95
strbuf_addf(&submodule_dotgit, "%s/.git", src);
94
- *submodule_gitfile = read_gitfile(submodule_dotgit.buf);
95
- if (*submodule_gitfile)
96
- *submodule_gitfile = xstrdup(*submodule_gitfile);
97
- else
98
- *submodule_gitfile = SUBMODULE_WITH_GITDIR;
96
+
97
+ path = read_gitfile(submodule_dotgit.buf);
98
strbuf_release(&submodule_dotgit);
99
+ if (path)
100
+ return path;
101
+ return SUBMODULE_WITH_GITDIR;
102
}
103
104
static int index_range_of_same_dir(const char *src, int length,
172
struct strvec sources = STRVEC_INIT;
173
struct strvec dest_paths = STRVEC_INIT;
174
struct strvec destinations = STRVEC_INIT;
173
- const char **submodule_gitfile;
175
+ struct strvec submodule_gitfiles_to_free = STRVEC_INIT;
176
+ const char **submodule_gitfiles;
177
char *dst_w_slash = NULL;
178
const char **src_dir = NULL;
179
int src_dir_nr = 0, src_dir_alloc = 0;
211
flags = 0;
212
internal_prefix_pathspec(&dest_paths, prefix, argv + argc, 1, flags);
213
dst_w_slash = add_slash(dest_paths.v[0]);
211
- submodule_gitfile = xcalloc(argc, sizeof(char *));
214
+ submodule_gitfiles = xcalloc(argc, sizeof(char *));
215
216
if (dest_paths.v[0][0] == '\0')
217
/* special case: "." was normalized to "" */
309
int first = index_name_pos(the_repository->index, src, length), last;
310
311
if (first >= 0) {
309
- prepare_move_submodule(src, first,
310
- submodule_gitfile + i);
312
+ const char *path = submodule_gitfile_path(src, first);
313
+ if (path != SUBMODULE_WITH_GITDIR)
314
+ path = strvec_push(&submodule_gitfiles_to_free, path);
315
+ submodule_gitfiles[i] = path;
316
goto act_on_entry;
317
} else if (index_range_of_same_dir(src, length,
318
&first, &last) < 1) {
328
329
n = argc + last - first;
330
REALLOC_ARRAY(modes, n);
326
- REALLOC_ARRAY(submodule_gitfile, n);
331
+ REALLOC_ARRAY(submodule_gitfiles, n);
332
333
dst_with_slash = add_slash(dst);
334
dst_with_slash_len = strlen(dst_with_slash);
343
344
memset(modes + argc + j, 0, sizeof(enum update_mode));
345
modes[argc + j] |= ce_skip_worktree(ce) ? SPARSE : INDEX;
341
- submodule_gitfile[argc + j] = NULL;
346
+ submodule_gitfiles[argc + j] = NULL;
347
348
free(prefixed_path);
349
}
432
strvec_remove(&sources, i);
433
strvec_remove(&destinations, i);
434
MOVE_ARRAY(modes + i, modes + i + 1, n);
430
- MOVE_ARRAY(submodule_gitfile + i,
431
- submodule_gitfile + i + 1, n);
435
+ MOVE_ARRAY(submodule_gitfiles + i,
436
+ submodule_gitfiles + i + 1, n);
437
i--;
438
}
439
}
467
continue;
468
die_errno(_("renaming '%s' failed"), src);
469
}
465
- if (submodule_gitfile[i]) {
470
+ if (submodule_gitfiles[i]) {
471
if (!update_path_in_gitmodules(src, dst))
472
gitmodules_modified = 1;
468
- if (submodule_gitfile[i] != SUBMODULE_WITH_GITDIR)
473
+ if (submodule_gitfiles[i] != SUBMODULE_WITH_GITDIR)
474
connect_work_tree_and_git_dir(dst,
470
- submodule_gitfile[i],
475
+ submodule_gitfiles[i],
476
1);
477
}
478
578
strvec_clear(&sources);
579
strvec_clear(&dest_paths);
580
strvec_clear(&destinations);
576
- free(submodule_gitfile);
581
+ strvec_clear(&submodule_gitfiles_to_free);
582
+ free(submodule_gitfiles);
583
free(modes);
584
return ret;
585
}