wrapper: reduce scope of remove_or_warn()

remove_or_warn() is only used by entry.c and apply.c, but it is currently declared and defined in wrapper.{h,c}, so it has a scope much greater than it needs. This needlessly large scope also causes wrapper.c to need to include object.h, when this file is largely unconcerned with Git objects. Move remove_or_warn() to entry.{h,c}. The file apply.c still has access to it, since it already includes entry.h for another reason. Signed-off-by: Calvin Wan <calvinwan@google.com> Signed-off-by: Jonathan Tan <jonathantanmy@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Calvin Wan committed Sep 29, 2023 at 14:20 UTC afd2a1d5f1fc371fe1fda0ed07e0f2f27100fbab
4 files changed +11 -11
entry.c
+5
@@ -581,3 +581,8 @@ void unlink_entry(const struct cache_entry *ce, const char *super_prefix)
581 return;
582 schedule_dir_for_removal(ce->name, ce_namelen(ce));
583 }
584 +
585 +int remove_or_warn(unsigned int mode, const char *file)
586 +{
587 + return S_ISGITLINK(mode) ? rmdir_or_warn(file) : unlink_or_warn(file);
588 +}
entry.h
+6
@@ -62,4 +62,10 @@ int fstat_checkout_output(int fd, const struct checkout *state, struct stat *st)
62 void update_ce_after_write(const struct checkout *state, struct cache_entry *ce,
63 struct stat *st);
64
65 +/*
66 + * Calls the correct function out of {unlink,rmdir}_or_warn based on
67 + * the supplied file mode.
68 + */
69 +int remove_or_warn(unsigned int mode, const char *path);
70 +
71 #endif /* ENTRY_H */
wrapper.c
-6
@@ -5,7 +5,6 @@
5 #include "abspath.h"
6 #include "config.h"
7 #include "gettext.h"
8 -#include "object.h"
8 #include "repository.h"
9 #include "strbuf.h"
10 #include "trace2.h"
@@ -632,11 +631,6 @@ int rmdir_or_warn(const char *file)
631 return warn_if_unremovable("rmdir", file, rmdir(file));
632 }
633
635 -int remove_or_warn(unsigned int mode, const char *file)
636 -{
637 - return S_ISGITLINK(mode) ? rmdir_or_warn(file) : unlink_or_warn(file);
638 -}
639 -
634 static int access_error_is_ok(int err, unsigned flag)
635 {
636 return (is_missing_file_error(err) ||
wrapper.h
-5
@@ -106,11 +106,6 @@ int unlink_or_msg(const char *file, struct strbuf *err);
106 * not exist.
107 */
108 int rmdir_or_warn(const char *path);
109 -/*
110 - * Calls the correct function out of {unlink,rmdir}_or_warn based on
111 - * the supplied file mode.
112 - */
113 -int remove_or_warn(unsigned int mode, const char *path);
109
110 /*
111 * Call access(2), but warn for any error except "missing file"