From dbe44faadb87f88e092f3dac387f96070268137a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Scharfe?= Date: Tue, 19 May 2015 23:44:23 +0200 Subject: use file_exists() to check if a file exists in the worktree Call file_exists() instead of open-coding it. That's shorter, simpler and the intent becomes clearer. Signed-off-by: Rene Scharfe Signed-off-by: Junio C Hamano --- builtin/blame.c | 15 +++------------ builtin/rm.c | 3 +-- 2 files changed, 4 insertions(+), 14 deletions(-) (limited to 'builtin') diff --git a/builtin/blame.c b/builtin/blame.c index 06484c2e0e..91d4221f59 100644 --- a/builtin/blame.c +++ b/builtin/blame.c @@ -26,6 +26,7 @@ #include "userdiff.h" #include "line-range.h" #include "line-log.h" +#include "dir.h" static char blame_usage[] = N_("git blame [] [] [] [--] file"); @@ -2151,16 +2152,6 @@ static void sanity_check_refcnt(struct scoreboard *sb) } } -/* - * Used for the command line parsing; check if the path exists - * in the working tree. - */ -static int has_string_in_work_tree(const char *path) -{ - struct stat st; - return !lstat(path, &st); -} - static unsigned parse_score(const char *arg) { char *end; @@ -2655,14 +2646,14 @@ parse_done: if (argc < 2) usage_with_options(blame_opt_usage, options); path = add_prefix(prefix, argv[argc - 1]); - if (argc == 3 && !has_string_in_work_tree(path)) { /* (2b) */ + if (argc == 3 && !file_exists(path)) { /* (2b) */ path = add_prefix(prefix, argv[1]); argv[1] = argv[2]; } argv[argc - 1] = "--"; setup_work_tree(); - if (!has_string_in_work_tree(path)) + if (!file_exists(path)) die_errno("cannot stat path '%s'", path); } diff --git a/builtin/rm.c b/builtin/rm.c index 3304bff42a..80b972f92f 100644 --- a/builtin/rm.c +++ b/builtin/rm.c @@ -84,7 +84,6 @@ static int check_submodules_use_gitfiles(void) const char *name = list.entry[i].name; int pos; const struct cache_entry *ce; - struct stat st; pos = cache_name_pos(name, strlen(name)); if (pos < 0) { @@ -95,7 +94,7 @@ static int check_submodules_use_gitfiles(void) ce = active_cache[pos]; if (!S_ISGITLINK(ce->ce_mode) || - (lstat(ce->name, &st) < 0) || + !file_exists(ce->name) || is_empty_dir(name)) continue; -- cgit v1.2.3 From 5cd83e18851445cdc20d5842b53373fe15554ae9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Scharfe?= Date: Wed, 20 May 2015 00:13:26 +0200 Subject: clean: remove unused variable buf It had never been used. Signed-off-by: Rene Scharfe Signed-off-by: Junio C Hamano --- builtin/clean.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'builtin') diff --git a/builtin/clean.c b/builtin/clean.c index 98c103fa8b..a9eb7723e9 100644 --- a/builtin/clean.c +++ b/builtin/clean.c @@ -314,7 +314,6 @@ static void print_highlight_menu_stuff(struct menu_stuff *stuff, int **chosen) { struct string_list menu_list = STRING_LIST_INIT_DUP; struct strbuf menu = STRBUF_INIT; - struct strbuf buf = STRBUF_INIT; struct menu_item *menu_item; struct string_list_item *string_list_item; int i; @@ -363,7 +362,6 @@ static void print_highlight_menu_stuff(struct menu_stuff *stuff, int **chosen) pretty_print_menus(&menu_list); strbuf_release(&menu); - strbuf_release(&buf); string_list_clear(&menu_list, 0); } -- cgit v1.2.3