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>
Karsten Blees committed
Nov 14, 2013 at 20:24 UTC
6bb69077b74b792ddef66e372c86e66dea8e449b
1 file changed
+15
-21
builtin/update-index.c
+15
-21
@@ -274,36 +274,32 @@ static void chmod_path(int flip, const char *path)
274
die("git update-index: cannot chmod %cx '%s'", flip, path);
275
}
276
277
-static void update_one(const char *path, const char *prefix, int prefix_length)
277
+static void update_one(const char *path)
278
{
279
- const char *p = prefix_path(prefix, prefix_length, path);
280
- if (!verify_path(p)) {
279
+ if (!verify_path(path)) {
280
fprintf(stderr, "Ignoring path %s\n", path);
282
- goto free_return;
281
+ return;
282
}
283
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))
285
die("Unable to mark file %s", path);
287
- goto free_return;
286
+ return;
287
}
288
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))
290
die("Unable to mark file %s", path);
292
- goto free_return;
291
+ return;
292
}
293
294
if (force_remove) {
296
- if (remove_file_from_cache(p))
295
+ if (remove_file_from_cache(path))
296
die("git update-index: unable to remove %s", path);
297
report("remove '%s'", path);
299
- goto free_return;
298
+ return;
299
}
301
- if (process_path(p))
300
+ if (process_path(path))
301
die("Unable to process path %s", path);
302
report("add '%s'", path);
304
- free_return:
305
- if (p < path || p > path + strlen(path))
306
- free((char *)p);
303
}
304
305
static void read_index_info(int line_termination)
@@ -579,7 +575,7 @@ static int do_reupdate(int ac, const char **av,
575
* or worse yet 'allow_replace', active_nr may decrease.
576
*/
577
save_nr = active_nr;
582
- update_one(ce->name, NULL, 0);
578
+ update_one(ce->name);
579
if (save_nr != active_nr)
580
goto redo;
581
}
@@ -836,11 +832,10 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
832
833
setup_work_tree();
834
p = prefix_path(prefix, prefix_length, path);
839
- update_one(p, NULL, 0);
835
+ update_one(p);
836
if (set_executable_bit)
837
chmod_path(set_executable_bit, p);
842
- if (p < path || p > path + strlen(path))
843
- free((char *)p);
838
+ free((char *)p);
839
ctx.argc--;
840
ctx.argv++;
841
break;
@@ -879,11 +874,10 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
874
strbuf_swap(&buf, &nbuf);
875
}
876
p = prefix_path(prefix, prefix_length, buf.buf);
882
- update_one(p, NULL, 0);
877
+ update_one(p);
878
if (set_executable_bit)
879
chmod_path(set_executable_bit, p);
885
- if (p < buf.buf || p > buf.buf + buf.len)
886
- free((char *)p);
880
+ free((char *)p);
881
}
882
strbuf_release(&nbuf);
883
strbuf_release(&buf);