summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPranit Bauva <pranit.bauva@gmail.com>2017-10-27 15:06:37 +0000
committerJunio C Hamano <gitster@pobox.com>2017-10-28 02:08:32 +0900
commit8874ae1a3a8ee0882b123c2c3614db0216adf999 (patch)
treef96be9f279fd7361bd394683d81960a6506dd1e8
parentda4ac60ad4ba1faaf7090eea900a7985f59893c2 (diff)
downloadgit-8874ae1a3a8ee0882b123c2c3614db0216adf999.tar.gz
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>
-rw-r--r--builtin/am.c20
-rw-r--r--cache.h3
-rw-r--r--wrapper.c13
3 files changed, 18 insertions, 18 deletions
diff --git a/builtin/am.c b/builtin/am.c
index d7513f5375..3e081499ac 100644
--- a/builtin/am.c
+++ b/builtin/am.c
@@ -34,22 +34,6 @@
#include "packfile.h"
/**
- * Returns 1 if the file is empty or does not exist, 0 otherwise.
- */
-static int is_empty_file(const char *filename)
-{
- struct stat st;
-
- if (stat(filename, &st) < 0) {
- if (errno == ENOENT)
- return 1;
- die_errno(_("could not stat %s"), filename);
- }
-
- return !st.st_size;
-}
-
-/**
* Returns the length of the first line of msg.
*/
static int linelen(const char *msg)
@@ -1298,7 +1282,7 @@ static int parse_mail(struct am_state *state, const char *mail)
goto finish;
}
- if (is_empty_file(am_path(state, "patch"))) {
+ if (is_empty_or_missing_file(am_path(state, "patch"))) {
printf_ln(_("Patch is empty."));
die_user_resolve(state);
}
@@ -1881,7 +1865,7 @@ next:
resume = 0;
}
- if (!is_empty_file(am_path(state, "rewritten"))) {
+ if (!is_empty_or_missing_file(am_path(state, "rewritten"))) {
assert(state->rebasing);
copy_notes_for_rebase(state);
run_post_rewrite_hook(state);
diff --git a/cache.h b/cache.h
index 6440e2bf21..832ee94555 100644
--- a/cache.h
+++ b/cache.h
@@ -1919,4 +1919,7 @@ void sleep_millisec(int millisec);
*/
void safe_create_dir(const char *dir, int share);
+/* Return 1 if the file is empty or does not exists, 0 otherwise. */
+extern int is_empty_or_missing_file(const char *filename);
+
#endif /* CACHE_H */
diff --git a/wrapper.c b/wrapper.c
index 61aba0b5c1..21c0fee2db 100644
--- a/wrapper.c
+++ b/wrapper.c
@@ -690,3 +690,16 @@ int xgethostname(char *buf, size_t len)
buf[len - 1] = 0;
return ret;
}
+
+int is_empty_or_missing_file(const char *filename)
+{
+ struct stat st;
+
+ if (stat(filename, &st) < 0) {
+ if (errno == ENOENT)
+ return 1;
+ die_errno(_("could not stat %s"), filename);
+ }
+
+ return !st.st_size;
+}