builtin/update-index.c: cleanup update_one
do_reupdate calls update_one with a cache_entry.name, there's no need for the extra sanitation / normalization that happens in prefix_path. cmd_update_index calls update_one with an already prefixed path, no need to prefix_path twice. Remove the extra prefix_path from update_one. Also remove the now unused 'prefix' and 'prefix_length' parameters. As of d089eba "setup: sanitize absolute and funny paths in get_pathspec()", prefix_path uncoditionally returns a copy, even if the passed in path isn't changed. Lets unconditionally free() the result. Signed-off-by: Karsten Blees <blees@dcon.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
e837af6134
commit
6bb69077b7
@ -274,36 +274,32 @@ static void chmod_path(int flip, const char *path)
|
|||||||
die("git update-index: cannot chmod %cx '%s'", flip, path);
|
die("git update-index: cannot chmod %cx '%s'", flip, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void update_one(const char *path, const char *prefix, int prefix_length)
|
static void update_one(const char *path)
|
||||||
{
|
{
|
||||||
const char *p = prefix_path(prefix, prefix_length, path);
|
if (!verify_path(path)) {
|
||||||
if (!verify_path(p)) {
|
|
||||||
fprintf(stderr, "Ignoring path %s\n", path);
|
fprintf(stderr, "Ignoring path %s\n", path);
|
||||||
goto free_return;
|
return;
|
||||||
}
|
}
|
||||||
if (mark_valid_only) {
|
if (mark_valid_only) {
|
||||||
if (mark_ce_flags(p, CE_VALID, mark_valid_only == MARK_FLAG))
|
if (mark_ce_flags(path, CE_VALID, mark_valid_only == MARK_FLAG))
|
||||||
die("Unable to mark file %s", path);
|
die("Unable to mark file %s", path);
|
||||||
goto free_return;
|
return;
|
||||||
}
|
}
|
||||||
if (mark_skip_worktree_only) {
|
if (mark_skip_worktree_only) {
|
||||||
if (mark_ce_flags(p, CE_SKIP_WORKTREE, mark_skip_worktree_only == MARK_FLAG))
|
if (mark_ce_flags(path, CE_SKIP_WORKTREE, mark_skip_worktree_only == MARK_FLAG))
|
||||||
die("Unable to mark file %s", path);
|
die("Unable to mark file %s", path);
|
||||||
goto free_return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (force_remove) {
|
if (force_remove) {
|
||||||
if (remove_file_from_cache(p))
|
if (remove_file_from_cache(path))
|
||||||
die("git update-index: unable to remove %s", path);
|
die("git update-index: unable to remove %s", path);
|
||||||
report("remove '%s'", path);
|
report("remove '%s'", path);
|
||||||
goto free_return;
|
return;
|
||||||
}
|
}
|
||||||
if (process_path(p))
|
if (process_path(path))
|
||||||
die("Unable to process path %s", path);
|
die("Unable to process path %s", path);
|
||||||
report("add '%s'", path);
|
report("add '%s'", path);
|
||||||
free_return:
|
|
||||||
if (p < path || p > path + strlen(path))
|
|
||||||
free((char *)p);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void read_index_info(int line_termination)
|
static void read_index_info(int line_termination)
|
||||||
@ -579,7 +575,7 @@ static int do_reupdate(int ac, const char **av,
|
|||||||
* or worse yet 'allow_replace', active_nr may decrease.
|
* or worse yet 'allow_replace', active_nr may decrease.
|
||||||
*/
|
*/
|
||||||
save_nr = active_nr;
|
save_nr = active_nr;
|
||||||
update_one(ce->name, NULL, 0);
|
update_one(ce->name);
|
||||||
if (save_nr != active_nr)
|
if (save_nr != active_nr)
|
||||||
goto redo;
|
goto redo;
|
||||||
}
|
}
|
||||||
@ -836,11 +832,10 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
|
|||||||
|
|
||||||
setup_work_tree();
|
setup_work_tree();
|
||||||
p = prefix_path(prefix, prefix_length, path);
|
p = prefix_path(prefix, prefix_length, path);
|
||||||
update_one(p, NULL, 0);
|
update_one(p);
|
||||||
if (set_executable_bit)
|
if (set_executable_bit)
|
||||||
chmod_path(set_executable_bit, p);
|
chmod_path(set_executable_bit, p);
|
||||||
if (p < path || p > path + strlen(path))
|
free((char *)p);
|
||||||
free((char *)p);
|
|
||||||
ctx.argc--;
|
ctx.argc--;
|
||||||
ctx.argv++;
|
ctx.argv++;
|
||||||
break;
|
break;
|
||||||
@ -879,11 +874,10 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
|
|||||||
strbuf_swap(&buf, &nbuf);
|
strbuf_swap(&buf, &nbuf);
|
||||||
}
|
}
|
||||||
p = prefix_path(prefix, prefix_length, buf.buf);
|
p = prefix_path(prefix, prefix_length, buf.buf);
|
||||||
update_one(p, NULL, 0);
|
update_one(p);
|
||||||
if (set_executable_bit)
|
if (set_executable_bit)
|
||||||
chmod_path(set_executable_bit, p);
|
chmod_path(set_executable_bit, p);
|
||||||
if (p < buf.buf || p > buf.buf + buf.len)
|
free((char *)p);
|
||||||
free((char *)p);
|
|
||||||
}
|
}
|
||||||
strbuf_release(&nbuf);
|
strbuf_release(&nbuf);
|
||||||
strbuf_release(&buf);
|
strbuf_release(&buf);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user