Skip to content

Commit 4ba5bb5

Browse files
committed
Merge branch 'rs/janitorial'
Code clean-up. * rs/janitorial: dir: remove unused variable sb clean: remove unused variable buf use file_exists() to check if a file exists in the worktree
2 parents f693bb0 + 22570b6 commit 4ba5bb5

File tree

7 files changed

+9
-26
lines changed

7 files changed

+9
-26
lines changed

builtin/blame.c

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "userdiff.h"
2727
#include "line-range.h"
2828
#include "line-log.h"
29+
#include "dir.h"
2930

3031
static char blame_usage[] = N_("git blame [<options>] [<rev-opts>] [<rev>] [--] <file>");
3132

@@ -2151,16 +2152,6 @@ static void sanity_check_refcnt(struct scoreboard *sb)
21512152
}
21522153
}
21532154

2154-
/*
2155-
* Used for the command line parsing; check if the path exists
2156-
* in the working tree.
2157-
*/
2158-
static int has_string_in_work_tree(const char *path)
2159-
{
2160-
struct stat st;
2161-
return !lstat(path, &st);
2162-
}
2163-
21642155
static unsigned parse_score(const char *arg)
21652156
{
21662157
char *end;
@@ -2656,14 +2647,14 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
26562647
if (argc < 2)
26572648
usage_with_options(blame_opt_usage, options);
26582649
path = add_prefix(prefix, argv[argc - 1]);
2659-
if (argc == 3 && !has_string_in_work_tree(path)) { /* (2b) */
2650+
if (argc == 3 && !file_exists(path)) { /* (2b) */
26602651
path = add_prefix(prefix, argv[1]);
26612652
argv[1] = argv[2];
26622653
}
26632654
argv[argc - 1] = "--";
26642655

26652656
setup_work_tree();
2666-
if (!has_string_in_work_tree(path))
2657+
if (!file_exists(path))
26672658
die_errno("cannot stat path '%s'", path);
26682659
}
26692660

builtin/clean.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,6 @@ static void print_highlight_menu_stuff(struct menu_stuff *stuff, int **chosen)
314314
{
315315
struct string_list menu_list = STRING_LIST_INIT_DUP;
316316
struct strbuf menu = STRBUF_INIT;
317-
struct strbuf buf = STRBUF_INIT;
318317
struct menu_item *menu_item;
319318
struct string_list_item *string_list_item;
320319
int i;
@@ -363,7 +362,6 @@ static void print_highlight_menu_stuff(struct menu_stuff *stuff, int **chosen)
363362
pretty_print_menus(&menu_list);
364363

365364
strbuf_release(&menu);
366-
strbuf_release(&buf);
367365
string_list_clear(&menu_list, 0);
368366
}
369367

builtin/rm.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ static int check_submodules_use_gitfiles(void)
8484
const char *name = list.entry[i].name;
8585
int pos;
8686
const struct cache_entry *ce;
87-
struct stat st;
8887

8988
pos = cache_name_pos(name, strlen(name));
9089
if (pos < 0) {
@@ -95,7 +94,7 @@ static int check_submodules_use_gitfiles(void)
9594
ce = active_cache[pos];
9695

9796
if (!S_ISGITLINK(ce->ce_mode) ||
98-
(lstat(ce->name, &st) < 0) ||
97+
!file_exists(ce->name) ||
9998
is_empty_dir(name))
10099
continue;
101100

dir.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,6 @@ int report_path_error(const char *ps_matched,
401401
/*
402402
* Make sure all pathspec matched; otherwise it is an error.
403403
*/
404-
struct strbuf sb = STRBUF_INIT;
405404
int num, errors = 0;
406405
for (num = 0; num < pathspec->nr; num++) {
407406
int other, found_dup;
@@ -433,7 +432,6 @@ int report_path_error(const char *ps_matched,
433432
pathspec->items[num].original);
434433
errors++;
435434
}
436-
strbuf_release(&sb);
437435
return errors;
438436
}
439437

merge-recursive.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,6 @@ static char *unique_path(struct merge_options *o, const char *path, const char *
611611
{
612612
struct strbuf newpath = STRBUF_INIT;
613613
int suffix = 0;
614-
struct stat st;
615614
size_t base_len;
616615

617616
strbuf_addf(&newpath, "%s~", path);
@@ -620,7 +619,7 @@ static char *unique_path(struct merge_options *o, const char *path, const char *
620619
base_len = newpath.len;
621620
while (string_list_has_string(&o->current_file_set, newpath.buf) ||
622621
string_list_has_string(&o->current_directory_set, newpath.buf) ||
623-
lstat(newpath.buf, &st) == 0) {
622+
file_exists(newpath.buf)) {
624623
strbuf_setlen(&newpath, base_len);
625624
strbuf_addf(&newpath, "_%d", suffix++);
626625
}

sha1_name.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "tree-walk.h"
77
#include "refs.h"
88
#include "remote.h"
9+
#include "dir.h"
910

1011
static int get_sha1_oneline(const char *, unsigned char *, struct commit_list *);
1112

@@ -1237,14 +1238,13 @@ static void diagnose_invalid_sha1_path(const char *prefix,
12371238
const char *object_name,
12381239
int object_name_len)
12391240
{
1240-
struct stat st;
12411241
unsigned char sha1[20];
12421242
unsigned mode;
12431243

12441244
if (!prefix)
12451245
prefix = "";
12461246

1247-
if (!lstat(filename, &st))
1247+
if (file_exists(filename))
12481248
die("Path '%s' exists on disk, but not in '%.*s'.",
12491249
filename, object_name_len, object_name);
12501250
if (errno == ENOENT || errno == ENOTDIR) {
@@ -1271,7 +1271,6 @@ static void diagnose_invalid_index_path(int stage,
12711271
const char *prefix,
12721272
const char *filename)
12731273
{
1274-
struct stat st;
12751274
const struct cache_entry *ce;
12761275
int pos;
12771276
unsigned namelen = strlen(filename);
@@ -1314,7 +1313,7 @@ static void diagnose_invalid_index_path(int stage,
13141313
ce_stage(ce), filename);
13151314
}
13161315

1317-
if (!lstat(filename, &st))
1316+
if (file_exists(filename))
13181317
die("Path '%s' exists on disk, but not in the index.", filename);
13191318
if (errno == ENOENT || errno == ENOTDIR)
13201319
die("Path '%s' does not exist (neither on disk nor in the index).",

submodule.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -891,7 +891,6 @@ int submodule_uses_gitfile(const char *path)
891891

892892
int ok_to_remove_submodule(const char *path)
893893
{
894-
struct stat st;
895894
ssize_t len;
896895
struct child_process cp = CHILD_PROCESS_INIT;
897896
const char *argv[] = {
@@ -904,7 +903,7 @@ int ok_to_remove_submodule(const char *path)
904903
struct strbuf buf = STRBUF_INIT;
905904
int ok_to_remove = 1;
906905

907-
if ((lstat(path, &st) < 0) || is_empty_dir(path))
906+
if (!file_exists(path) || is_empty_dir(path))
908907
return 1;
909908

910909
if (!submodule_uses_gitfile(path))

0 commit comments

Comments
 (0)