entry: extract a header file for entry.c functions

The declarations of entry.c's public functions and structures currently reside in cache.h. Although not many, they contribute to the size of cache.h and, when changed, cause the unnecessary recompilation of modules that don't really use these functions. So let's move them to a new entry.h header. While at it let's also move a comment related to checkout_entry() from entry.c to entry.h as it's more useful to describe the function there. Original-patch-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Matheus Tavares <matheus.bernardino@usp.br> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Matheus Tavares committed Mar 23, 2021 at 11:19 UTC d052cc038270d1231a245d7ac6d60559123464d3
9 files changed +49 -32
apply.c
+1
@@ -21,6 +21,7 @@
21 #include "quote.h"
22 #include "rerere.h"
23 #include "apply.h"
24 +#include "entry.h"
25
26 struct gitdiff_data {
27 struct strbuf *root;
builtin/checkout-index.c
+1
@@ -11,6 +11,7 @@
11 #include "quote.h"
12 #include "cache-tree.h"
13 #include "parse-options.h"
14 +#include "entry.h"
15
16 #define CHECKOUT_ALL 4
17 static int nul_term_line;
builtin/checkout.c
+1
@@ -26,6 +26,7 @@
26 #include "unpack-trees.h"
27 #include "wt-status.h"
28 #include "xdiff-interface.h"
29 +#include "entry.h"
30
31 static const char * const checkout_usage[] = {
32 N_("git checkout [<options>] <branch>"),
builtin/difftool.c
+1
@@ -23,6 +23,7 @@
23 #include "lockfile.h"
24 #include "object-store.h"
25 #include "dir.h"
26 +#include "entry.h"
27
28 static int trust_exit_code;
29
builtin/stash.c
+1
@@ -15,6 +15,7 @@
15 #include "log-tree.h"
16 #include "diffcore.h"
17 #include "exec-cmd.h"
18 +#include "entry.h"
19
20 #define INCLUDE_ALL_FILES 2
21
cache.h
-24
@@ -1621,30 +1621,6 @@ const char *show_ident_date(const struct ident_split *id,
1621 */
1622 int ident_cmp(const struct ident_split *, const struct ident_split *);
1623
1624 -struct checkout {
1625 - struct index_state *istate;
1626 - const char *base_dir;
1627 - int base_dir_len;
1628 - struct delayed_checkout *delayed_checkout;
1629 - struct checkout_metadata meta;
1630 - unsigned force:1,
1631 - quiet:1,
1632 - not_new:1,
1633 - clone:1,
1634 - refresh_cache:1;
1635 -};
1636 -#define CHECKOUT_INIT { NULL, "" }
1637 -
1638 -#define TEMPORARY_FILENAME_LENGTH 25
1639 -int checkout_entry(struct cache_entry *ce, const struct checkout *state, char *topath, int *nr_checkouts);
1640 -void enable_delayed_checkout(struct checkout *state);
1641 -int finish_delayed_checkout(struct checkout *state, int *nr_checkouts);
1642 -/*
1643 - * Unlink the last component and schedule the leading directories for
1644 - * removal, such that empty directories get removed.
1645 - */
1646 -void unlink_entry(const struct cache_entry *ce);
1647 -
1624 struct cache_def {
1625 struct strbuf path;
1626 int flags;
entry.c
+1 -8
@@ -6,6 +6,7 @@
6 #include "submodule.h"
7 #include "progress.h"
8 #include "fsmonitor.h"
9 +#include "entry.h"
10
11 static void create_directories(const char *path, int path_len,
12 const struct checkout *state)
@@ -429,14 +430,6 @@ static void mark_colliding_entries(const struct checkout *state,
430 }
431 }
432
432 -/*
433 - * Write the contents from ce out to the working tree.
434 - *
435 - * When topath[] is not NULL, instead of writing to the working tree
436 - * file named by ce, a temporary file is created by this function and
437 - * its name is returned in topath[], which must be able to hold at
438 - * least TEMPORARY_FILENAME_LENGTH bytes long.
439 - */
433 int checkout_entry(struct cache_entry *ce, const struct checkout *state,
434 char *topath, int *nr_checkouts)
435 {
entry.h new
+42
@@ -0,0 +1,42 @@
1 +#ifndef ENTRY_H
2 +#define ENTRY_H
3 +
4 +#include "cache.h"
5 +#include "convert.h"
6 +
7 +struct checkout {
8 + struct index_state *istate;
9 + const char *base_dir;
10 + int base_dir_len;
11 + struct delayed_checkout *delayed_checkout;
12 + struct checkout_metadata meta;
13 + unsigned force:1,
14 + quiet:1,
15 + not_new:1,
16 + clone:1,
17 + refresh_cache:1;
18 +};
19 +#define CHECKOUT_INIT { NULL, "" }
20 +
21 +#define TEMPORARY_FILENAME_LENGTH 25
22 +/*
23 + * Write the contents from ce out to the working tree.
24 + *
25 + * When topath[] is not NULL, instead of writing to the working tree
26 + * file named by ce, a temporary file is created by this function and
27 + * its name is returned in topath[], which must be able to hold at
28 + * least TEMPORARY_FILENAME_LENGTH bytes long.
29 + */
30 +int checkout_entry(struct cache_entry *ce, const struct checkout *state,
31 + char *topath, int *nr_checkouts);
32 +
33 +void enable_delayed_checkout(struct checkout *state);
34 +int finish_delayed_checkout(struct checkout *state, int *nr_checkouts);
35 +
36 +/*
37 + * Unlink the last component and schedule the leading directories for
38 + * removal, such that empty directories get removed.
39 + */
40 +void unlink_entry(const struct cache_entry *ce);
41 +
42 +#endif /* ENTRY_H */
unpack-trees.c
+1
@@ -16,6 +16,7 @@
16 #include "fsmonitor.h"
17 #include "object-store.h"
18 #include "promisor-remote.h"
19 +#include "entry.h"
20
21 /*
22 * Error messages expected by scripts out of plumbing commands such as