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 <tboegi@web.de> Mentored-by: Lars Schneider <larsxschneider@gmail.com> Mentored-by: Christian Couder <chriscool@tuxfamily.org> Signed-off-by: Pranit Bauva <pranit.bauva@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Pranit Bauva committed Jan 2, 2019 at 07:38 UTC e3b1e3bdc0aa5fa6a474874a2395ae0584b2aea7
3 files changed +18 -18
builtin/am.c
+2 -18
@@ -34,22 +34,6 @@
34 #include "packfile.h"
35 #include "repository.h"
36
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 -
37 /**
38 * Returns the length of the first line of msg.
39 */
@@ -1220,7 +1204,7 @@ static int parse_mail(struct am_state *state, const char *mail)
1204 goto finish;
1205 }
1206
1223 - if (is_empty_file(am_path(state, "patch"))) {
1207 + if (is_empty_or_missing_file(am_path(state, "patch"))) {
1208 printf_ln(_("Patch is empty."));
1209 die_user_resolve(state);
1210 }
@@ -1803,7 +1787,7 @@ next:
1787 resume = 0;
1788 }
1789
1806 - if (!is_empty_file(am_path(state, "rewritten"))) {
1790 + if (!is_empty_or_missing_file(am_path(state, "rewritten"))) {
1791 assert(state->rebasing);
1792 copy_notes_for_rebase(state);
1793 run_post_rewrite_hook(state);
cache.h
+3
@@ -1788,4 +1788,7 @@ void safe_create_dir(const char *dir, int share);
1788 */
1789 extern int print_sha1_ellipsis(void);
1790
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 +
1794 #endif /* CACHE_H */
wrapper.c
+13
@@ -690,3 +690,16 @@ int xgethostname(char *buf, size_t len)
690 buf[len - 1] = 0;
691 return ret;
692 }
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 +}