Skip to content

Commit e3b1e3b

Browse files
pranitbauva1997gitster
authored andcommitted
wrapper: move is_empty_file() and rename it as is_empty_or_missing_file()
is_empty_file() can help to refactor a lot of code. This will be very helpful in porting "git bisect" to C. Suggested-by: Torsten Bögershausen <[email protected]> Mentored-by: Lars Schneider <[email protected]> Mentored-by: Christian Couder <[email protected]> Signed-off-by: Pranit Bauva <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 0f30233 commit e3b1e3b

File tree

3 files changed

+18
-18
lines changed

3 files changed

+18
-18
lines changed

builtin/am.c

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -34,22 +34,6 @@
3434
#include "packfile.h"
3535
#include "repository.h"
3636

37-
/**
38-
* Returns 1 if the file is empty or does not exist, 0 otherwise.
39-
*/
40-
static int is_empty_file(const char *filename)
41-
{
42-
struct stat st;
43-
44-
if (stat(filename, &st) < 0) {
45-
if (errno == ENOENT)
46-
return 1;
47-
die_errno(_("could not stat %s"), filename);
48-
}
49-
50-
return !st.st_size;
51-
}
52-
5337
/**
5438
* Returns the length of the first line of msg.
5539
*/
@@ -1220,7 +1204,7 @@ static int parse_mail(struct am_state *state, const char *mail)
12201204
goto finish;
12211205
}
12221206

1223-
if (is_empty_file(am_path(state, "patch"))) {
1207+
if (is_empty_or_missing_file(am_path(state, "patch"))) {
12241208
printf_ln(_("Patch is empty."));
12251209
die_user_resolve(state);
12261210
}
@@ -1803,7 +1787,7 @@ static void am_run(struct am_state *state, int resume)
18031787
resume = 0;
18041788
}
18051789

1806-
if (!is_empty_file(am_path(state, "rewritten"))) {
1790+
if (!is_empty_or_missing_file(am_path(state, "rewritten"))) {
18071791
assert(state->rebasing);
18081792
copy_notes_for_rebase(state);
18091793
run_post_rewrite_hook(state);

cache.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1788,4 +1788,7 @@ void safe_create_dir(const char *dir, int share);
17881788
*/
17891789
extern int print_sha1_ellipsis(void);
17901790

1791+
/* Return 1 if the file is empty or does not exists, 0 otherwise. */
1792+
extern int is_empty_or_missing_file(const char *filename);
1793+
17911794
#endif /* CACHE_H */

wrapper.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -690,3 +690,16 @@ int xgethostname(char *buf, size_t len)
690690
buf[len - 1] = 0;
691691
return ret;
692692
}
693+
694+
int is_empty_or_missing_file(const char *filename)
695+
{
696+
struct stat st;
697+
698+
if (stat(filename, &st) < 0) {
699+
if (errno == ENOENT)
700+
return 1;
701+
die_errno(_("could not stat %s"), filename);
702+
}
703+
704+
return !st.st_size;
705+
}

0 commit comments

Comments
 (0)