git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v12 06/13] wrapper: move is_empty_file() and rename it as is_empty_or_missing_file()

From
Pranit Bauva <pranit.bauva@gmail.com>
Date
Aug 10, 2016, 21:57 UTC
Message-ID
<010201567675ae57-614652e4-7e6c-4451-a4cf-aa73922fe552-000000@eu-west-1.amazonses.com>
In-Reply-To
<010201567675adc1-17e27495-6b36-40d1-836d-814da029fcc4-000000@eu-west-1.amazonses.com>

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>
---
 builtin/am.c | 20 ++------------------
 cache.h      |  3 +++
 wrapper.c    | 13 +++++++++++++
 3 files changed, 18 insertions(+), 18 deletions(-)
diff --git a/builtin/am.c b/builtin/am.c
index 3dfe70b..6ee158f 100644
--- a/builtin/am.c
+++ b/builtin/am.c
@@ -30,22 +30,6 @@
 #include "mailinfo.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)
@@ -1323,7 +1307,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. Was it split wrong?"));
 		die_user_resolve(state);
 	}
@@ -1911,7 +1895,7 @@ static void am_run(struct am_state *state, int resume)
 		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 6049f86..91e2f81 100644
--- a/cache.h
+++ b/cache.h
@@ -1870,4 +1870,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 5dc4e15..e70e4d1 100644
--- a/wrapper.c
+++ b/wrapper.c
@@ -696,3 +696,16 @@ void sleep_millisec(int millisec)
 {
 	poll(NULL, 0, millisec);
 }
+
+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;
+}

--
https://github.com/git/git/pull/281
Previous: Pranit Bauva
Message 22 of 22 in “bisect--helper: use OPT_CMDMODE instead of OPT_BOOL”
  1. 01/13 bisect--helper: use OPT_CMDMODE instead of OPT_BOOLPranit Bauva, Aug 10, 2016
  2. 10/13 bisect--helper: `check_and_set_terms` shell function in CPranit Bauva, Aug 10, 2016
  3. 03/13 bisect--helper: `write_terms` shell function in CPranit Bauva, Aug 10, 2016
  4. 07/13 bisect--helper: `bisect_reset` shell function in CPranit Bauva, Aug 10, 2016
  5. 02/13 bisect: rewrite `check_term_format` shell function in CPranit Bauva, Aug 10, 2016
  6. 13/13 bisect--helper: `bisect_start` shell function partially in CPranit Bauva, Aug 10, 2016
  7. Junio C HamanoAug 12, 2016
  8. Pranit BauvaAug 13, 2016
  9. Christian CouderAug 13, 2016
  10. Pranit BauvaAug 13, 2016
  11. 12/13 bisect--helper: `get_terms` & `bisect_terms` shell function in CPranit Bauva, Aug 10, 2016
  12. 04/13 bisect--helper: `bisect_clean_state` shell function in CPranit Bauva, Aug 10, 2016
  13. Junio C HamanoAug 12, 2016
  14. 08/13 bisect--helper: `is_expected_rev` & `check_expected_revs` shell function in CPranit Bauva, Aug 10, 2016
  15. 05/13 t6030: explicitly test for bisection cleanupPranit Bauva, Aug 10, 2016
  16. Pranit BauvaAug 10, 2016
  17. 09/13 bisect--helper: `bisect_write` shell function in CPranit Bauva, Aug 10, 2016
  18. 11/13 bisect--helper: `bisect_next_check` & bisect_voc shell function in CPranit Bauva, Aug 10, 2016
  19. Junio C HamanoAug 12, 2016
  20. Junio C HamanoAug 12, 2016
  21. Pranit BauvaAug 13, 2016
  22. 06/13 wrapper: move is_empty_file() and rename it as is_empty_or_missing_file()Pranit Bauva, Aug 10, 2016

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.