2021-03-23 22:19:32 +08:00
|
|
|
#ifndef ENTRY_H
|
|
|
|
#define ENTRY_H
|
|
|
|
|
|
|
|
#include "convert.h"
|
|
|
|
|
2023-02-24 08:09:22 +08:00
|
|
|
struct cache_entry;
|
|
|
|
struct index_state;
|
|
|
|
|
2021-03-23 22:19:32 +08:00
|
|
|
struct checkout {
|
|
|
|
struct index_state *istate;
|
|
|
|
const char *base_dir;
|
|
|
|
int base_dir_len;
|
read-tree: add "--super-prefix" option, eliminate global
The "--super-prefix" option to "git" was initially added in [1] for
use with "ls-files"[2], and shortly thereafter "submodule--helper"[3]
and "grep"[4]. It wasn't until [5] that "read-tree" made use of it.
At the time [5] made sense, but since then we've made "ls-files"
recurse in-process in [6], "grep" in [7], and finally
"submodule--helper" in the preceding commits.
Let's also remove it from "read-tree", which allows us to remove the
option to "git" itself.
We can do this because the only remaining user of it is the submodule
API, which will now invoke "read-tree" with its new "--super-prefix"
option. It will only do so when the "submodule_move_head()" function
is called.
That "submodule_move_head()" function was then only invoked by
"read-tree" itself, but now rather than setting an environment
variable to pass "--super-prefix" between cmd_read_tree() we:
- Set a new "super_prefix" in "struct unpack_trees_options". The
"super_prefixed()" function in "unpack-trees.c" added in [5] will now
use this, rather than get_super_prefix() looking up the environment
variable we set earlier in the same process.
- Add the same field to the "struct checkout", which is only needed to
ferry the "super_prefix" in the "struct unpack_trees_options" all the
way down to the "entry.c" callers of "submodule_move_head()".
Those calls which used the super prefix all originated in
"cmd_read_tree()". The only other caller is the "unlink_entry()"
caller in "builtin/checkout.c", which now passes a "NULL".
1. 74866d75793 (git: make super-prefix option, 2016-10-07)
2. e77aa336f11 (ls-files: optionally recurse into submodules, 2016-10-07)
3. 89c86265576 (submodule helper: support super prefix, 2016-12-08)
4. 0281e487fd9 (grep: optionally recurse into submodules, 2016-12-16)
5. 3d415425c7b (unpack-trees: support super-prefix option, 2017-01-17)
6. 188dce131fa (ls-files: use repository object, 2017-06-22)
7. f9ee2fcdfa0 (grep: recurse in-process using 'struct repository', 2017-08-02)
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2022-12-20 20:39:56 +08:00
|
|
|
const char *super_prefix;
|
2021-03-23 22:19:32 +08:00
|
|
|
struct delayed_checkout *delayed_checkout;
|
|
|
|
struct checkout_metadata meta;
|
|
|
|
unsigned force:1,
|
|
|
|
quiet:1,
|
|
|
|
not_new:1,
|
|
|
|
clone:1,
|
|
|
|
refresh_cache:1;
|
|
|
|
};
|
2021-09-27 20:54:27 +08:00
|
|
|
#define CHECKOUT_INIT { .base_dir = "" }
|
2021-03-23 22:19:32 +08:00
|
|
|
|
|
|
|
#define TEMPORARY_FILENAME_LENGTH 25
|
|
|
|
/*
|
|
|
|
* Write the contents from ce out to the working tree.
|
|
|
|
*
|
|
|
|
* When topath[] is not NULL, instead of writing to the working tree
|
|
|
|
* file named by ce, a temporary file is created by this function and
|
|
|
|
* its name is returned in topath[], which must be able to hold at
|
|
|
|
* least TEMPORARY_FILENAME_LENGTH bytes long.
|
2021-03-23 22:19:36 +08:00
|
|
|
*
|
|
|
|
* With checkout_entry_ca(), callers can optionally pass a preloaded
|
|
|
|
* conv_attrs struct (to avoid reloading it), when ce refers to a
|
|
|
|
* regular file. If ca is NULL, the attributes will be loaded
|
|
|
|
* internally when (and if) needed.
|
2021-03-23 22:19:32 +08:00
|
|
|
*/
|
2021-03-23 22:19:36 +08:00
|
|
|
int checkout_entry_ca(struct cache_entry *ce, struct conv_attrs *ca,
|
|
|
|
const struct checkout *state, char *topath,
|
|
|
|
int *nr_checkouts);
|
|
|
|
static inline int checkout_entry(struct cache_entry *ce,
|
|
|
|
const struct checkout *state, char *topath,
|
|
|
|
int *nr_checkouts)
|
|
|
|
{
|
|
|
|
return checkout_entry_ca(ce, NULL, state, topath, nr_checkouts);
|
|
|
|
}
|
2021-03-23 22:19:32 +08:00
|
|
|
|
|
|
|
void enable_delayed_checkout(struct checkout *state);
|
2022-07-14 19:49:12 +08:00
|
|
|
int finish_delayed_checkout(struct checkout *state, int show_progress);
|
2021-03-23 22:19:32 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Unlink the last component and schedule the leading directories for
|
|
|
|
* removal, such that empty directories get removed.
|
read-tree: add "--super-prefix" option, eliminate global
The "--super-prefix" option to "git" was initially added in [1] for
use with "ls-files"[2], and shortly thereafter "submodule--helper"[3]
and "grep"[4]. It wasn't until [5] that "read-tree" made use of it.
At the time [5] made sense, but since then we've made "ls-files"
recurse in-process in [6], "grep" in [7], and finally
"submodule--helper" in the preceding commits.
Let's also remove it from "read-tree", which allows us to remove the
option to "git" itself.
We can do this because the only remaining user of it is the submodule
API, which will now invoke "read-tree" with its new "--super-prefix"
option. It will only do so when the "submodule_move_head()" function
is called.
That "submodule_move_head()" function was then only invoked by
"read-tree" itself, but now rather than setting an environment
variable to pass "--super-prefix" between cmd_read_tree() we:
- Set a new "super_prefix" in "struct unpack_trees_options". The
"super_prefixed()" function in "unpack-trees.c" added in [5] will now
use this, rather than get_super_prefix() looking up the environment
variable we set earlier in the same process.
- Add the same field to the "struct checkout", which is only needed to
ferry the "super_prefix" in the "struct unpack_trees_options" all the
way down to the "entry.c" callers of "submodule_move_head()".
Those calls which used the super prefix all originated in
"cmd_read_tree()". The only other caller is the "unlink_entry()"
caller in "builtin/checkout.c", which now passes a "NULL".
1. 74866d75793 (git: make super-prefix option, 2016-10-07)
2. e77aa336f11 (ls-files: optionally recurse into submodules, 2016-10-07)
3. 89c86265576 (submodule helper: support super prefix, 2016-12-08)
4. 0281e487fd9 (grep: optionally recurse into submodules, 2016-12-16)
5. 3d415425c7b (unpack-trees: support super-prefix option, 2017-01-17)
6. 188dce131fa (ls-files: use repository object, 2017-06-22)
7. f9ee2fcdfa0 (grep: recurse in-process using 'struct repository', 2017-08-02)
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2022-12-20 20:39:56 +08:00
|
|
|
*
|
|
|
|
* The "super_prefix" is either NULL, or the "--super-prefix" passed
|
|
|
|
* down from "read-tree" et al.
|
2021-03-23 22:19:32 +08:00
|
|
|
*/
|
read-tree: add "--super-prefix" option, eliminate global
The "--super-prefix" option to "git" was initially added in [1] for
use with "ls-files"[2], and shortly thereafter "submodule--helper"[3]
and "grep"[4]. It wasn't until [5] that "read-tree" made use of it.
At the time [5] made sense, but since then we've made "ls-files"
recurse in-process in [6], "grep" in [7], and finally
"submodule--helper" in the preceding commits.
Let's also remove it from "read-tree", which allows us to remove the
option to "git" itself.
We can do this because the only remaining user of it is the submodule
API, which will now invoke "read-tree" with its new "--super-prefix"
option. It will only do so when the "submodule_move_head()" function
is called.
That "submodule_move_head()" function was then only invoked by
"read-tree" itself, but now rather than setting an environment
variable to pass "--super-prefix" between cmd_read_tree() we:
- Set a new "super_prefix" in "struct unpack_trees_options". The
"super_prefixed()" function in "unpack-trees.c" added in [5] will now
use this, rather than get_super_prefix() looking up the environment
variable we set earlier in the same process.
- Add the same field to the "struct checkout", which is only needed to
ferry the "super_prefix" in the "struct unpack_trees_options" all the
way down to the "entry.c" callers of "submodule_move_head()".
Those calls which used the super prefix all originated in
"cmd_read_tree()". The only other caller is the "unlink_entry()"
caller in "builtin/checkout.c", which now passes a "NULL".
1. 74866d75793 (git: make super-prefix option, 2016-10-07)
2. e77aa336f11 (ls-files: optionally recurse into submodules, 2016-10-07)
3. 89c86265576 (submodule helper: support super prefix, 2016-12-08)
4. 0281e487fd9 (grep: optionally recurse into submodules, 2016-12-16)
5. 3d415425c7b (unpack-trees: support super-prefix option, 2017-01-17)
6. 188dce131fa (ls-files: use repository object, 2017-06-22)
7. f9ee2fcdfa0 (grep: recurse in-process using 'struct repository', 2017-08-02)
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2022-12-20 20:39:56 +08:00
|
|
|
void unlink_entry(const struct cache_entry *ce, const char *super_prefix);
|
2021-03-23 22:19:32 +08:00
|
|
|
|
2021-11-02 23:46:08 +08:00
|
|
|
void *read_blob_entry(const struct cache_entry *ce, size_t *size);
|
2021-03-23 22:19:33 +08:00
|
|
|
int fstat_checkout_output(int fd, const struct checkout *state, struct stat *st);
|
2021-03-23 22:19:34 +08:00
|
|
|
void update_ce_after_write(const struct checkout *state, struct cache_entry *ce,
|
|
|
|
struct stat *st);
|
2021-03-23 22:19:33 +08:00
|
|
|
|
2023-09-30 05:20:49 +08:00
|
|
|
/*
|
|
|
|
* Calls the correct function out of {unlink,rmdir}_or_warn based on
|
|
|
|
* the supplied file mode.
|
|
|
|
*/
|
|
|
|
int remove_or_warn(unsigned int mode, const char *path);
|
|
|
|
|
2021-03-23 22:19:32 +08:00
|
|
|
#endif /* ENTRY_H */
|