Skip to content

Commit 6bb6907

Browse files
kbleesgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e837af6 commit 6bb6907

File tree

1 file changed

+15
-21
lines changed

1 file changed

+15
-21
lines changed

builtin/update-index.c

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -274,36 +274,32 @@ static void chmod_path(int flip, const char *path)
274274
die("git update-index: cannot chmod %cx '%s'", flip, path);
275275
}
276276

277-
static void update_one(const char *path, const char *prefix, int prefix_length)
277+
static void update_one(const char *path)
278278
{
279-
const char *p = prefix_path(prefix, prefix_length, path);
280-
if (!verify_path(p)) {
279+
if (!verify_path(path)) {
281280
fprintf(stderr, "Ignoring path %s\n", path);
282-
goto free_return;
281+
return;
283282
}
284283
if (mark_valid_only) {
285-
if (mark_ce_flags(p, CE_VALID, mark_valid_only == MARK_FLAG))
284+
if (mark_ce_flags(path, CE_VALID, mark_valid_only == MARK_FLAG))
286285
die("Unable to mark file %s", path);
287-
goto free_return;
286+
return;
288287
}
289288
if (mark_skip_worktree_only) {
290-
if (mark_ce_flags(p, CE_SKIP_WORKTREE, mark_skip_worktree_only == MARK_FLAG))
289+
if (mark_ce_flags(path, CE_SKIP_WORKTREE, mark_skip_worktree_only == MARK_FLAG))
291290
die("Unable to mark file %s", path);
292-
goto free_return;
291+
return;
293292
}
294293

295294
if (force_remove) {
296-
if (remove_file_from_cache(p))
295+
if (remove_file_from_cache(path))
297296
die("git update-index: unable to remove %s", path);
298297
report("remove '%s'", path);
299-
goto free_return;
298+
return;
300299
}
301-
if (process_path(p))
300+
if (process_path(path))
302301
die("Unable to process path %s", path);
303302
report("add '%s'", path);
304-
free_return:
305-
if (p < path || p > path + strlen(path))
306-
free((char *)p);
307303
}
308304

309305
static void read_index_info(int line_termination)
@@ -579,7 +575,7 @@ static int do_reupdate(int ac, const char **av,
579575
* or worse yet 'allow_replace', active_nr may decrease.
580576
*/
581577
save_nr = active_nr;
582-
update_one(ce->name, NULL, 0);
578+
update_one(ce->name);
583579
if (save_nr != active_nr)
584580
goto redo;
585581
}
@@ -836,11 +832,10 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
836832

837833
setup_work_tree();
838834
p = prefix_path(prefix, prefix_length, path);
839-
update_one(p, NULL, 0);
835+
update_one(p);
840836
if (set_executable_bit)
841837
chmod_path(set_executable_bit, p);
842-
if (p < path || p > path + strlen(path))
843-
free((char *)p);
838+
free((char *)p);
844839
ctx.argc--;
845840
ctx.argv++;
846841
break;
@@ -879,11 +874,10 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
879874
strbuf_swap(&buf, &nbuf);
880875
}
881876
p = prefix_path(prefix, prefix_length, buf.buf);
882-
update_one(p, NULL, 0);
877+
update_one(p);
883878
if (set_executable_bit)
884879
chmod_path(set_executable_bit, p);
885-
if (p < buf.buf || p > buf.buf + buf.len)
886-
free((char *)p);
880+
free((char *)p);
887881
}
888882
strbuf_release(&nbuf);
889883
strbuf_release(&buf);

0 commit comments

Comments
 (0)