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>maint
parent
0f30233a11
commit
e3b1e3bdc0
20
builtin/am.c
20
builtin/am.c
|
@ -34,22 +34,6 @@
|
||||||
#include "packfile.h"
|
#include "packfile.h"
|
||||||
#include "repository.h"
|
#include "repository.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.
|
* Returns the length of the first line of msg.
|
||||||
*/
|
*/
|
||||||
|
@ -1220,7 +1204,7 @@ static int parse_mail(struct am_state *state, const char *mail)
|
||||||
goto finish;
|
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."));
|
printf_ln(_("Patch is empty."));
|
||||||
die_user_resolve(state);
|
die_user_resolve(state);
|
||||||
}
|
}
|
||||||
|
@ -1803,7 +1787,7 @@ next:
|
||||||
resume = 0;
|
resume = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!is_empty_file(am_path(state, "rewritten"))) {
|
if (!is_empty_or_missing_file(am_path(state, "rewritten"))) {
|
||||||
assert(state->rebasing);
|
assert(state->rebasing);
|
||||||
copy_notes_for_rebase(state);
|
copy_notes_for_rebase(state);
|
||||||
run_post_rewrite_hook(state);
|
run_post_rewrite_hook(state);
|
||||||
|
|
3
cache.h
3
cache.h
|
@ -1788,4 +1788,7 @@ void safe_create_dir(const char *dir, int share);
|
||||||
*/
|
*/
|
||||||
extern int print_sha1_ellipsis(void);
|
extern int print_sha1_ellipsis(void);
|
||||||
|
|
||||||
|
/* 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 */
|
#endif /* CACHE_H */
|
||||||
|
|
13
wrapper.c
13
wrapper.c
|
@ -690,3 +690,16 @@ int xgethostname(char *buf, size_t len)
|
||||||
buf[len - 1] = 0;
|
buf[len - 1] = 0;
|
||||||
return ret;
|
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;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue