repository object
cover repository object
Given the vast interest expressed when I sent out my RFC series I decided it would be worth it to invest more time to making a repository object a reality.
This series is an extension of the last series I sent out (in that ls-files is converted to working on submodules in-process using repository objects instead of spawning a child process to do the work). The big difference from the RFC series is that I went through and did the work to migrate key repository state from global variables in 'environment.c' to being stored in a repository object itself. I migrated the bits of state that seemed reasonable for this series, there is still a lot of global state which could be migrated in the future.
I do think that we need to be slightly cautious about moving global state into the repository object though, I don't want 'struct repo' to simply become a kitchen sink where everything gets dumped. But this is just a warning for the future.
Since this is a v1 I'm fairly certain that it still has a lot of rough edges (like I think I need to write better commit messages, and we should probably have more comments documenting object fields/contract) but I want to get the review process started sooner rather than later since I'm sure people will have opinions (e.g. should it be called 'struct repo' or 'struct repository'?!).
So here it is! Thank you so much for taking the time review this, any and all comments would be appreciated.
- Brandon
Patches [01-14] -> Introducing the Repository object and migrating some state
to be stored in 'the_repository'.
Patches [15-31] -> Converting ls-files to use 'struct repo' in order to recurse
submodules in-process.
Brandon Williams (31):
config: create config.h
config: don't include config.h by default
config: don't implicitly use gitdir
setup: don't perform lazy initialization of repository state
environment: remove namespace_len variable
repo: introduce the repository object
environment: place key repository state in the_repository
environment: store worktree in the_repository
setup: add comment indicating a hack
config: migrate the_configset to the_repository
repo: add index_state to struct repo
submodule-config: store the_submodule_cache in the_repository
repo: add repo_read_gitmodules
submodule: convert is_submodule_initialized to work on a repository
convert: convert get_cached_convert_stats_ascii to take an index
convert: convert crlf_to_git to take an index
convert: convert convert_to_git_filter_fd to take an index
convert: convert convert_to_git to take an index
convert: convert renormalize_buffer to take an index
tree: convert read_tree to take an index parameter
ls-files: convert overlay_tree_on_cache to take an index
ls-files: convert write_eolinfo to take an index
ls-files: convert show_killed_files to take an index
ls-files: convert show_other_files to take an index
ls-files: convert show_ru_info to take an index
ls-files: convert ce_excluded to take an index
ls-files: convert prune_cache to take an index
ls-files: convert show_files to take an index
ls-files: factor out debug info into a function
ls-files: factor out tag calculation
ls-files: use repository object
Makefile | 1 + advice.c | 1 + alias.c | 1 + apply.c | 3 +- archive-tar.c | 1 + archive-zip.c | 1 + archive.c | 1 + attr.c | 1 + bisect.c | 1 + branch.c | 1 + builtin/add.c | 1 + builtin/am.c | 1 + builtin/blame.c | 3 +- builtin/branch.c | 1 + builtin/cat-file.c | 1 + builtin/check-attr.c | 1 + builtin/check-ignore.c | 1 + builtin/check-mailmap.c | 1 + builtin/checkout-index.c | 1 + builtin/checkout.c | 1 + builtin/clean.c | 1 + builtin/clone.c | 1 + builtin/column.c | 1 + builtin/commit-tree.c | 1 + builtin/commit.c | 4 +- builtin/config.c | 3 + builtin/count-objects.c | 1 + builtin/describe.c | 1 + builtin/diff-files.c | 1 + builtin/diff-index.c | 1 + builtin/diff-tree.c | 1 + builtin/diff.c | 1 + builtin/difftool.c | 1 + builtin/fast-export.c | 1 + builtin/fetch.c | 1 + builtin/fmt-merge-msg.c | 1 + builtin/for-each-ref.c | 1 + builtin/fsck.c | 1 + builtin/gc.c | 1 + builtin/grep.c | 4 +- builtin/hash-object.c | 1 + builtin/help.c | 1 + builtin/index-pack.c | 1 + builtin/init-db.c | 1 + builtin/log.c | 1 + builtin/ls-files.c | 343 ++++++++++++++++----------------- builtin/ls-tree.c | 1 + builtin/merge-base.c | 1 + builtin/merge-file.c | 1 + builtin/merge.c | 1 + builtin/mv.c | 1 + builtin/name-rev.c | 1 + builtin/notes.c | 1 + builtin/pack-objects.c | 1 + builtin/patch-id.c | 1 + builtin/pull.c | 1 + builtin/push.c | 1 + builtin/read-tree.c | 1 + builtin/rebase--helper.c | 1 + builtin/receive-pack.c | 1 + builtin/reflog.c | 1 + builtin/remote.c | 1 + builtin/repack.c | 1 + builtin/replace.c | 1 + builtin/rerere.c | 1 + builtin/reset.c | 1 + builtin/rev-list.c | 1 + builtin/rev-parse.c | 1 + builtin/revert.c | 1 + builtin/rm.c | 1 + builtin/send-pack.c | 1 + builtin/shortlog.c | 1 + builtin/show-branch.c | 1 + builtin/stripspace.c | 1 + builtin/submodule--helper.c | 10 +- builtin/symbolic-ref.c | 1 + builtin/tag.c | 1 + builtin/unpack-file.c | 1 + builtin/unpack-objects.c | 1 + builtin/update-index.c | 1 + builtin/update-ref.c | 1 + builtin/update-server-info.c | 1 + builtin/var.c | 1 + builtin/verify-commit.c | 1 + builtin/verify-pack.c | 1 + builtin/verify-tag.c | 1 + builtin/worktree.c | 1 + builtin/write-tree.c | 1 + cache.h | 196 +------------------ color.c | 1 + column.c | 1 + combine-diff.c | 2 +- config.c | 186 +++++++++++------- config.h | 204 ++++++++++++++++++++ connect.c | 1 + convert.c | 32 +-- convert.h | 19 +- credential-cache--daemon.c | 1 + credential.c | 1 + daemon.c | 1 + diff.c | 7 +- dir.c | 3 +- environment.c | 101 +++------- fast-import.c | 1 + fetch-pack.c | 1 + git.c | 3 +- gpg-interface.c | 1 + graph.c | 1 + grep.c | 1 + help.c | 1 + http-backend.c | 1 + http-fetch.c | 1 + http.c | 1 + ident.c | 1 + imap-send.c | 1 + ll-merge.c | 3 +- log-tree.c | 1 + mailinfo.c | 1 + merge-recursive.c | 5 +- notes-utils.c | 1 + notes.c | 1 + pager.c | 1 + parse-options.c | 1 + path.c | 11 +- pathspec.c | 1 + pretty.c | 1 + prompt.c | 1 + read-cache.c | 1 + refs.c | 1 + refs/files-backend.c | 1 + remote-curl.c | 1 + remote.c | 1 + repo.c | 192 ++++++++++++++++++ repo.h | 45 +++++ rerere.c | 1 + send-pack.c | 1 + sequencer.c | 1 + setup.c | 34 ++++ sha1_file.c | 7 +- sha1_name.c | 1 + submodule-config.c | 72 +++++-- submodule-config.h | 10 + submodule.c | 22 +-- submodule.h | 3 +- t/helper/test-config.c | 1 + t/helper/test-submodule-config.c | 1 + t/t3007-ls-files-recurse-submodules.sh | 39 ++++ trailer.c | 1 + transport.c | 1 + tree.c | 28 ++- tree.h | 3 +- unpack-trees.c | 1 + upload-pack.c | 1 + userdiff.c | 1 + versioncmp.c | 1 + wrapper.c | 1 + xdiff-interface.c | 1 + 157 files changed, 1130 insertions(+), 593 deletions(-) create mode 100644 config.h create mode 100644 repo.c create mode 100644 repo.h
Signature · 1 line
2.13.0.506.g27d5fe0cd-goog
PATCH 1/31 config: create config.h
Move all config related declarations from cache.h to a new config.h header file. This makes cache.h smaller and allows for the opportunity in a following patch to only include config.h when needed.
--- cache.h | 190 +------------------------------------------------------------ config.h | 194 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 195 insertions(+), 189 deletions(-) create mode 100644 config.h
cache.h +1 -189
@@ -11,6 +11,7 @@#include "string-list.h" #include "pack-revindex.h" #include "hash.h" +#include "config.h" #ifndef platform_SHA_CTX/*
@@ -1866,188 +1867,9 @@ extern int packed_object_info(struct packed_git *pack, off_t offset, struct obje/* Dumb servers support */ extern int update_server_info (int ); -/* git_config_parse_key() returns these negated: */ -#define CONFIG_INVALID_KEY 1 -#define CONFIG_NO_SECTION_OR_NAME 2 -/* git_config_set_gently(), git_config_set_multivar_gently() return the above or these: */ -#define CONFIG_NO_LOCK -1 -#define CONFIG_INVALID_FILE 3 -#define CONFIG_NO_WRITE 4 -#define CONFIG_NOTHING_SET 5 -#define CONFIG_INVALID_PATTERN 6 -#define CONFIG_GENERIC_ERROR 7 - -#define CONFIG_REGEX_NONE ((void *)1) - -struct git_config_source { -unsigned int use_stdin:1 ; -const char *file; -const char *blob; -}; - -enum config_origin_type { -CONFIG_ORIGIN_BLOB , -CONFIG_ORIGIN_FILE , -CONFIG_ORIGIN_STDIN , -CONFIG_ORIGIN_SUBMODULE_BLOB , -CONFIG_ORIGIN_CMDLINE -}; - -struct config_options { -unsigned int respect_includes :1 ; -const char *git_dir; -}; - -typedef int (*config_fn_t )(const char *,const char *,void *); -extern int git_default_config (const char *,const char *,void *); -extern int git_config_from_file (config_fn_t fn,const char *,void *); -extern int git_config_from_mem (config_fn_t fn,const enum config_origin_type , -const char *name,const char *buf,size_t len,void *data); -extern int git_config_from_blob_sha1 (config_fn_t fn,const char *name, -const unsigned char *sha1,void *data); -extern void git_config_push_parameter (const char *text); -extern int git_config_from_parameters (config_fn_t fn,void *data); -extern void read_early_config (config_fn_t cb,void *data); -extern void git_config (config_fn_t fn,void *); -extern int git_config_with_options (config_fn_t fn,void *, -struct git_config_source *config_source, -const struct config_options *opts); -extern int git_parse_ulong (const char *,unsigned long *); -extern int git_parse_maybe_bool (const char *); -extern int git_config_int (const char *,const char *); -extern int64_t git_config_int64 (const char *,const char *); -extern unsigned long git_config_ulong (const char *,const char *); -extern ssize_t git_config_ssize_t (const char *,const char *); -extern int git_config_bool_or_int (const char *,const char *,int *); -extern int git_config_bool (const char *,const char *); -extern int git_config_maybe_bool (const char *,const char *); -extern int git_config_string (const char **,const char *,const char *); -extern int git_config_pathname (const char **,const char *,const char *); -extern int git_config_set_in_file_gently (const char *,const char *,const char *); -extern void git_config_set_in_file (const char *,const char *,const char *); -extern int git_config_set_gently (const char *,const char *); -extern void git_config_set (const char *,const char *); -extern int git_config_parse_key (const char *,char **,int *); -extern int git_config_key_is_valid (const char *key); -extern int git_config_set_multivar_gently (const char *,const char *,const char *,int ); -extern void git_config_set_multivar (const char *,const char *,const char *,int ); -extern int git_config_set_multivar_in_file_gently (const char *,const char *,const char *,const char *,int ); -extern void git_config_set_multivar_in_file (const char *,const char *,const char *,const char *,int ); -extern int git_config_rename_section (const char *,const char *); -extern int git_config_rename_section_in_file (const char *,const char *,const char *); -extern const char *git_etc_gitconfig (void ); -extern int git_env_bool (const char *,int ); -extern unsigned long git_env_ulong (const char *,unsigned long ); -extern int git_config_system (void ); -extern int config_error_nonbool (const char *); -#if defined(__GNUC__) -#define config_error_nonbool (s) (config_error_nonbool(s), const_error()) -#endif extern const char *get_log_output_encoding (void );extern const char *get_commit_output_encoding (void ); -extern int git_config_parse_parameter (const char *,config_fn_t fn,void *data); - -enum config_scope { -CONFIG_SCOPE_UNKNOWN =0 , -CONFIG_SCOPE_SYSTEM , -CONFIG_SCOPE_GLOBAL , -CONFIG_SCOPE_REPO , -CONFIG_SCOPE_CMDLINE , -}; - -extern enum config_scope current_config_scope (void ); -extern const char *current_config_origin_type (void ); -extern const char *current_config_name (void ); - -struct config_include_data { -int depth; -config_fn_t fn; -void *data; -const struct config_options *opts; -}; -#define CONFIG_INCLUDE_INIT { 0 } -extern int git_config_include (const char *name,const char *value,void *data); - -/* -* Match and parse a config key of the form: -* -* section.(subsection.)?key -* -* (i.e., what gets handed to a config_fn_t). The caller provides the section; -* we return -1 if it does not match, 0 otherwise. The subsection and key -* out-parameters are filled by the function (and *subsection is NULL if it is -* missing). -* -* If the subsection pointer-to-pointer passed in is NULL, returns 0 only if -* there is no subsection at all. -*/ -extern int parse_config_key (const char *var, -const char *section, -const char **subsection,int *subsection_len, -const char **key); - -struct config_set_element { -struct hashmap_entry ent; -char *key; -struct string_list value_list; -}; - -struct configset_list_item { -struct config_set_element *e; -int value_index; -}; - -/* -* the contents of the list are ordered according to their -* position in the config files and order of parsing the files. -* (i.e. key-value pair at the last position of .git/config will -* be at the last item of the list) -*/ -struct configset_list { -struct configset_list_item *items; -unsigned int nr, alloc; -}; - -struct config_set { -struct hashmap config_hash; -int hash_initialized; -struct configset_list list; -}; - -extern void git_configset_init (struct config_set *cs); -extern int git_configset_add_file (struct config_set *cs,const char *filename); -extern int git_configset_get_value (struct config_set *cs,const char *key,const char **value); -extern const struct string_list *git_configset_get_value_multi (struct config_set *cs,const char *key); -extern void git_configset_clear (struct config_set *cs); -extern int git_configset_get_string_const (struct config_set *cs,const char *key,const char **dest); -extern int git_configset_get_string (struct config_set *cs,const char *key,char **dest); -extern int git_configset_get_int (struct config_set *cs,const char *key,int *dest); -extern int git_configset_get_ulong (struct config_set *cs,const char *key,unsigned long *dest); -extern int git_configset_get_bool (struct config_set *cs,const char *key,int *dest); -extern int git_configset_get_bool_or_int (struct config_set *cs,const char *key,int *is_bool,int *dest); -extern int git_configset_get_maybe_bool (struct config_set *cs,const char *key,int *dest); -extern int git_configset_get_pathname (struct config_set *cs,const char *key,const char **dest); - -extern int git_config_get_value (const char *key,const char **value); -extern const struct string_list *git_config_get_value_multi (const char *key); -extern void git_config_clear (void ); -extern void git_config_iter (config_fn_t fn,void *data); -extern int git_config_get_string_const (const char *key,const char **dest); -extern int git_config_get_string (const char *key,char **dest); -extern int git_config_get_int (const char *key,int *dest); -extern int git_config_get_ulong (const char *key,unsigned long *dest); -extern int git_config_get_bool (const char *key,int *dest); -extern int git_config_get_bool_or_int (const char *key,int *is_bool,int *dest); -extern int git_config_get_maybe_bool (const char *key,int *dest); -extern int git_config_get_pathname (const char *key,const char **dest); -extern int git_config_get_untracked_cache (void ); -extern int git_config_get_split_index (void ); -extern int git_config_get_max_percent_split_change (void ); - -/* This dies if the configured or default date is in the future */ -extern int git_config_get_expiry (const char *key,const char **output); -/* * This is a hack for test programs like test-dump-untracked-cache to * ensure that they do not modify the untracked cache when reading it.
@@ -2055,16 +1877,6 @@ extern int git_config_get_expiry(const char *key, const char **output);*/ extern int ignore_untracked_cache_config; -struct key_value_info { -const char *filename; -int linenr; -enum config_origin_type origin_type; -enum config_scope scope; -}; - -extern NORETURN void git_die_config(const char *key, const char *err, ...) __attribute__((format(printf, 2, 3))); -extern NORETURN void git_die_config_linenr(const char *key, const char *filename, int linenr); -extern int committer_ident_sufficiently_given (void );extern int author_ident_sufficiently_given (void );
config.h new file +194 -0
194 lines not on this page · raw message
Signature · 1 line
2.13.0.506.g27d5fe0cd-goog
PATCH 2/31 config: don't include config.h by default
In reply to Brandon WilliamsStop including config.h by default in cache.h. Instead only include config.h in those files which require use of the config system.
--- advice.c | 1 + alias.c | 1 + apply.c | 1 + archive-tar.c | 1 + archive-zip.c | 1 + archive.c | 1 + attr.c | 1 + bisect.c | 1 + branch.c | 1 + builtin/add.c | 1 + builtin/am.c | 1 + builtin/blame.c | 1 + builtin/branch.c | 1 + builtin/cat-file.c | 1 + builtin/check-attr.c | 1 + builtin/check-ignore.c | 1 + builtin/check-mailmap.c | 1 + builtin/checkout-index.c | 1 + builtin/checkout.c | 1 + builtin/clean.c | 1 + builtin/clone.c | 1 + builtin/column.c | 1 + builtin/commit-tree.c | 1 + builtin/commit.c | 1 + builtin/config.c | 1 + builtin/count-objects.c | 1 + builtin/describe.c | 1 + builtin/diff-files.c | 1 + builtin/diff-index.c | 1 + builtin/diff-tree.c | 1 + builtin/diff.c | 1 + builtin/difftool.c | 1 + builtin/fast-export.c | 1 + builtin/fetch.c | 1 + builtin/fmt-merge-msg.c | 1 + builtin/for-each-ref.c | 1 + builtin/fsck.c | 1 + builtin/gc.c | 1 + builtin/grep.c | 1 + builtin/hash-object.c | 1 + builtin/help.c | 1 + builtin/index-pack.c | 1 + builtin/init-db.c | 1 + builtin/log.c | 1 + builtin/ls-files.c | 1 + builtin/ls-tree.c | 1 + builtin/merge-base.c | 1 + builtin/merge-file.c | 1 + builtin/merge.c | 1 + builtin/mv.c | 1 + builtin/name-rev.c | 1 + builtin/notes.c | 1 + builtin/pack-objects.c | 1 + builtin/patch-id.c | 1 + builtin/pull.c | 1 + builtin/push.c | 1 + builtin/read-tree.c | 1 + builtin/rebase--helper.c | 1 + builtin/receive-pack.c | 1 + builtin/reflog.c | 1 + builtin/remote.c | 1 + builtin/repack.c | 1 + builtin/replace.c | 1 + builtin/rerere.c | 1 + builtin/reset.c | 1 + builtin/rev-list.c | 1 + builtin/rev-parse.c | 1 + builtin/revert.c | 1 + builtin/rm.c | 1 + builtin/send-pack.c | 1 + builtin/shortlog.c | 1 + builtin/show-branch.c | 1 + builtin/stripspace.c | 1 + builtin/submodule--helper.c | 1 + builtin/symbolic-ref.c | 1 + builtin/tag.c | 1 + builtin/unpack-file.c | 1 + builtin/unpack-objects.c | 1 + builtin/update-index.c | 1 + builtin/update-ref.c | 1 + builtin/update-server-info.c | 1 + builtin/var.c | 1 + builtin/verify-commit.c | 1 + builtin/verify-pack.c | 1 + builtin/verify-tag.c | 1 + builtin/worktree.c | 1 + builtin/write-tree.c | 1 + cache.h | 1 - color.c | 1 + column.c | 1 + config.c | 1 + connect.c | 1 + convert.c | 1 + credential-cache--daemon.c | 1 + credential.c | 1 + daemon.c | 1 + diff.c | 1 + dir.c | 1 + environment.c | 1 + fast-import.c | 1 + fetch-pack.c | 1 + git.c | 1 + gpg-interface.c | 1 + graph.c | 1 + grep.c | 1 + help.c | 1 + http-backend.c | 1 + http-fetch.c | 1 + http.c | 1 + ident.c | 1 + imap-send.c | 1 + ll-merge.c | 1 + log-tree.c | 1 + mailinfo.c | 1 + merge-recursive.c | 1 + notes-utils.c | 1 + notes.c | 1 + pager.c | 1 + parse-options.c | 1 + pathspec.c | 1 + pretty.c | 1 + prompt.c | 1 + read-cache.c | 1 + refs.c | 1 + refs/files-backend.c | 1 + remote-curl.c | 1 + remote.c | 1 + rerere.c | 1 + send-pack.c | 1 + sequencer.c | 1 + setup.c | 1 + sha1_file.c | 1 + sha1_name.c | 1 + submodule-config.c | 1 + submodule.c | 1 + t/helper/test-config.c | 1 + t/helper/test-submodule-config.c | 1 + trailer.c | 1 + transport.c | 1 + unpack-trees.c | 1 + upload-pack.c | 1 + userdiff.c | 1 + versioncmp.c | 1 + wrapper.c | 1 + xdiff-interface.c | 1 + 145 files changed, 144 insertions(+), 1 deletion(-)
advice.c +1 -0
@@ -1,4 +1,5 @@#include "cache.h" +#include "config.h" int advice_push_update_rejected =1 ;int advice_push_non_ff_current =1 ;
alias.c +1 -0
@@ -1,4 +1,5 @@#include "cache.h" +#include "config.h" char *alias_lookup (const char *alias) {
apply.c +1 -0
@@ -8,6 +8,7 @@*/ #include "cache.h" +#include "config.h" #include "blob.h" #include "delta.h" #include "diff.h"
archive-tar.c +1 -0
@@ -2,6 +2,7 @@* Copyright (c) 2005, 2006 Rene Scharfe */ #include "cache.h" +#include "config.h" #include "tar.h" #include "archive.h" #include "streaming.h"
archive-zip.c +1 -0
@@ -2,6 +2,7 @@* Copyright (c) 2006 Rene Scharfe */ #include "cache.h" +#include "config.h" #include "archive.h" #include "streaming.h" #include "utf8.h"
archive.c +1 -0
@@ -1,4 +1,5 @@#include "cache.h" +#include "config.h" #include "refs.h" #include "commit.h" #include "tree-walk.h"
attr.c +1 -0
@@ -9,6 +9,7 @@#define NO_THE_INDEX_COMPATIBILITY_MACROS #include "cache.h" +#include "config.h" #include "exec_cmd.h" #include "attr.h" #include "dir.h"
bisect.c +1 -0
@@ -1,4 +1,5 @@#include "cache.h" +#include "config.h" #include "commit.h" #include "diff.h" #include "revision.h"
branch.c +1 -0
@@ -1,5 +1,6 @@#include "git-compat-util.h" #include "cache.h" +#include "config.h" #include "branch.h" #include "refs.h" #include "remote.h"
builtin/add.c +1 -0
@@ -4,6 +4,7 @@* Copyright (C) 2006 Linus Torvalds */ #include "cache.h" +#include "config.h" #include "builtin.h" #include "lockfile.h" #include "dir.h"
builtin/am.c +1 -0
@@ -4,6 +4,7 @@* Based on git-am.sh by Junio C Hamano. */ #include "cache.h" +#include "config.h" #include "builtin.h" #include "exec_cmd.h" #include "parse-options.h"
builtin/blame.c +1 -0
@@ -6,6 +6,7 @@*/ #include "cache.h" +#include "config.h" #include "refs.h" #include "builtin.h" #include "blob.h"
builtin/branch.c +1 -0
@@ -6,6 +6,7 @@*/ #include "cache.h" +#include "config.h" #include "color.h" #include "refs.h" #include "commit.h"
builtin/cat-file.c +1 -0
@@ -4,6 +4,7 @@* Copyright (C) Linus Torvalds, 2005 */ #include "cache.h" +#include "config.h" #include "builtin.h" #include "parse-options.h" #include "userdiff.h"
builtin/check-attr.c +1 -0
@@ -1,5 +1,6 @@#include "builtin.h" #include "cache.h" +#include "config.h" #include "attr.h" #include "quote.h" #include "parse-options.h"
builtin/check-ignore.c +1 -0
@@ -1,5 +1,6 @@#include "builtin.h" #include "cache.h" +#include "config.h" #include "dir.h" #include "quote.h" #include "pathspec.h"
builtin/check-mailmap.c +1 -0
@@ -1,4 +1,5 @@#include "builtin.h" +#include "config.h" #include "mailmap.h" #include "parse-options.h" #include "string-list.h"
builtin/checkout-index.c +1 -0
@@ -5,6 +5,7 @@* */ #include "builtin.h" +#include "config.h" #include "lockfile.h" #include "quote.h" #include "cache-tree.h"
builtin/checkout.c +1 -0
@@ -1,4 +1,5 @@#include "builtin.h" +#include "config.h" #include "lockfile.h" #include "parse-options.h" #include "refs.h"
builtin/clean.c +1 -0
@@ -8,6 +8,7 @@#include "builtin.h" #include "cache.h" +#include "config.h" #include "dir.h" #include "parse-options.h" #include "string-list.h"
builtin/clone.c +1 -0
@@ -9,6 +9,7 @@*/ #include "builtin.h" +#include "config.h" #include "lockfile.h" #include "parse-options.h" #include "fetch-pack.h"
builtin/column.c +1 -0
@@ -1,5 +1,6 @@#include "builtin.h" #include "cache.h" +#include "config.h" #include "strbuf.h" #include "parse-options.h" #include "string-list.h"
builtin/commit-tree.c +1 -0
@@ -4,6 +4,7 @@* Copyright (C) Linus Torvalds, 2005 */ #include "cache.h" +#include "config.h" #include "commit.h" #include "tree.h" #include "builtin.h"
builtin/commit.c +1 -0
@@ -6,6 +6,7 @@*/ #include "cache.h" +#include "config.h" #include "lockfile.h" #include "cache-tree.h" #include "color.h"
builtin/config.c +1 -0
@@ -1,5 +1,6 @@#include "builtin.h" #include "cache.h" +#include "config.h" #include "color.h" #include "parse-options.h" #include "urlmatch.h"
builtin/count-objects.c +1 -0
@@ -5,6 +5,7 @@*/ #include "cache.h" +#include "config.h" #include "dir.h" #include "builtin.h" #include "parse-options.h"
builtin/describe.c +1 -0
@@ -1,4 +1,5 @@#include "cache.h" +#include "config.h" #include "lockfile.h" #include "commit.h" #include "tag.h"
builtin/diff-files.c +1 -0
@@ -4,6 +4,7 @@* Copyright (C) Linus Torvalds, 2005 */ #include "cache.h" +#include "config.h" #include "diff.h" #include "commit.h" #include "revision.h"
builtin/diff-index.c +1 -0
@@ -1,4 +1,5 @@#include "cache.h" +#include "config.h" #include "diff.h" #include "commit.h" #include "revision.h"
builtin/diff-tree.c +1 -0
@@ -1,4 +1,5 @@#include "cache.h" +#include "config.h" #include "diff.h" #include "commit.h" #include "log-tree.h"
builtin/diff.c +1 -0
@@ -4,6 +4,7 @@* Copyright (c) 2006 Junio C Hamano */ #include "cache.h" +#include "config.h" #include "lockfile.h" #include "color.h" #include "commit.h"
builtin/difftool.c +1 -0
@@ -12,6 +12,7 @@* Copyright (C) 2016 Johannes Schindelin */ #include "cache.h" +#include "config.h" #include "builtin.h" #include "run-command.h" #include "exec_cmd.h"
builtin/fast-export.c +1 -0
@@ -5,6 +5,7 @@*/ #include "builtin.h" #include "cache.h" +#include "config.h" #include "refs.h" #include "commit.h" #include "object.h"
builtin/fetch.c +1 -0
@@ -2,6 +2,7 @@* "git fetch" */ #include "cache.h" +#include "config.h" #include "refs.h" #include "commit.h" #include "builtin.h"
builtin/fmt-merge-msg.c +1 -0
@@ -1,5 +1,6 @@#include "builtin.h" #include "cache.h" +#include "config.h" #include "refs.h" #include "commit.h" #include "diff.h"
builtin/for-each-ref.c +1 -0
@@ -1,5 +1,6 @@#include "builtin.h" #include "cache.h" +#include "config.h" #include "refs.h" #include "object.h" #include "parse-options.h"
builtin/fsck.c +1 -0
@@ -1,5 +1,6 @@#include "builtin.h" #include "cache.h" +#include "config.h" #include "commit.h" #include "tree.h" #include "blob.h"
builtin/gc.c +1 -0
@@ -11,6 +11,7 @@*/ #include "builtin.h" +#include "config.h" #include "tempfile.h" #include "lockfile.h" #include "parse-options.h"
builtin/grep.c +1 -0
@@ -4,6 +4,7 @@* Copyright (c) 2006 Junio C Hamano */ #include "cache.h" +#include "config.h" #include "blob.h" #include "tree.h" #include "commit.h"
builtin/hash-object.c +1 -0
@@ -5,6 +5,7 @@* Copyright (C) Junio C Hamano, 2005 */ #include "builtin.h" +#include "config.h" #include "blob.h" #include "quote.h" #include "parse-options.h"
builtin/help.c +1 -0
@@ -2,6 +2,7 @@* Builtin help command */ #include "cache.h" +#include "config.h" #include "builtin.h" #include "exec_cmd.h" #include "parse-options.h"
builtin/index-pack.c +1 -0
@@ -1,4 +1,5 @@#include "builtin.h" +#include "config.h" #include "delta.h" #include "pack.h" #include "csum-file.h"
builtin/init-db.c +1 -0
@@ -4,6 +4,7 @@* Copyright (C) Linus Torvalds, 2005 */ #include "cache.h" +#include "config.h" #include "refs.h" #include "builtin.h" #include "exec_cmd.h"
builtin/log.c +1 -0
@@ -5,6 +5,7 @@* 2006 Junio Hamano */ #include "cache.h" +#include "config.h" #include "refs.h" #include "color.h" #include "commit.h"
builtin/ls-files.c +1 -0
@@ -6,6 +6,7 @@* Copyright (C) Linus Torvalds, 2005 */ #include "cache.h" +#include "config.h" #include "quote.h" #include "dir.h" #include "builtin.h"
builtin/ls-tree.c +1 -0
@@ -4,6 +4,7 @@* Copyright (C) Linus Torvalds, 2005 */ #include "cache.h" +#include "config.h" #include "blob.h" #include "tree.h" #include "commit.h"
builtin/merge-base.c +1 -0
@@ -1,5 +1,6 @@#include "builtin.h" #include "cache.h" +#include "config.h" #include "commit.h" #include "refs.h" #include "diff.h"
builtin/merge-file.c +1 -0
@@ -1,5 +1,6 @@#include "builtin.h" #include "cache.h" +#include "config.h" #include "xdiff/xdiff.h" #include "xdiff-interface.h" #include "parse-options.h"
builtin/merge.c +1 -0
@@ -7,6 +7,7 @@*/ #include "cache.h" +#include "config.h" #include "parse-options.h" #include "builtin.h" #include "lockfile.h"
builtin/mv.c +1 -0
@@ -4,6 +4,7 @@* Copyright (C) 2006 Johannes Schindelin */ #include "builtin.h" +#include "config.h" #include "pathspec.h" #include "lockfile.h" #include "dir.h"
builtin/name-rev.c +1 -0
@@ -1,5 +1,6 @@#include "builtin.h" #include "cache.h" +#include "config.h" #include "commit.h" #include "tag.h" #include "refs.h"
builtin/notes.c +1 -0
@@ -8,6 +8,7 @@*/ #include "cache.h" +#include "config.h" #include "builtin.h" #include "notes.h" #include "blob.h"
builtin/pack-objects.c +1 -0
@@ -1,5 +1,6 @@#include "builtin.h" #include "cache.h" +#include "config.h" #include "attr.h" #include "object.h" #include "blob.h"
builtin/patch-id.c +1 -0
@@ -1,4 +1,5 @@#include "builtin.h" +#include "config.h" static void flush_current_id (int patchlen,struct object_id *id,struct object_id *result) {
builtin/pull.c +1 -0
@@ -6,6 +6,7 @@* Fetch one or more remote refs and merge it/them into the current HEAD. */ #include "cache.h" +#include "config.h" #include "builtin.h" #include "parse-options.h" #include "exec_cmd.h"
builtin/push.c +1 -0
@@ -2,6 +2,7 @@* "git push" */ #include "cache.h" +#include "config.h" #include "refs.h" #include "run-command.h" #include "builtin.h"
builtin/read-tree.c +1 -0
@@ -5,6 +5,7 @@*/ #include "cache.h" +#include "config.h" #include "lockfile.h" #include "object.h" #include "tree.h"
builtin/rebase--helper.c +1 -0
@@ -1,5 +1,6 @@#include "builtin.h" #include "cache.h" +#include "config.h" #include "parse-options.h" #include "sequencer.h"
builtin/receive-pack.c +1 -0
@@ -1,4 +1,5 @@#include "builtin.h" +#include "config.h" #include "lockfile.h" #include "pack.h" #include "refs.h"
builtin/reflog.c +1 -0
@@ -1,4 +1,5 @@#include "builtin.h" +#include "config.h" #include "lockfile.h" #include "commit.h" #include "refs.h"
builtin/remote.c +1 -0
@@ -1,4 +1,5 @@#include "builtin.h" +#include "config.h" #include "parse-options.h" #include "transport.h" #include "remote.h"
builtin/repack.c +1 -0
@@ -1,5 +1,6 @@#include "builtin.h" #include "cache.h" +#include "config.h" #include "dir.h" #include "parse-options.h" #include "run-command.h"
builtin/replace.c +1 -0
@@ -9,6 +9,7 @@*/ #include "cache.h" +#include "config.h" #include "builtin.h" #include "refs.h" #include "parse-options.h"
builtin/rerere.c +1 -0
@@ -1,5 +1,6 @@#include "builtin.h" #include "cache.h" +#include "config.h" #include "dir.h" #include "parse-options.h" #include "string-list.h"
builtin/reset.c +1 -0
@@ -8,6 +8,7 @@* Copyright (c) 2005, 2006 Linus Torvalds and Junio C Hamano */ #include "builtin.h" +#include "config.h" #include "lockfile.h" #include "tag.h" #include "object.h"
builtin/rev-list.c +1 -0
@@ -1,4 +1,5 @@#include "cache.h" +#include "config.h" #include "commit.h" #include "diff.h" #include "revision.h"
builtin/rev-parse.c +1 -0
@@ -4,6 +4,7 @@* Copyright (C) Linus Torvalds, 2005 */ #include "cache.h" +#include "config.h" #include "commit.h" #include "refs.h" #include "quote.h"
builtin/revert.c +1 -0
@@ -1,4 +1,5 @@#include "cache.h" +#include "config.h" #include "builtin.h" #include "parse-options.h" #include "diff.h"
builtin/rm.c +1 -0
@@ -4,6 +4,7 @@* Copyright (C) Linus Torvalds 2006 */ #include "builtin.h" +#include "config.h" #include "lockfile.h" #include "dir.h" #include "cache-tree.h"
builtin/send-pack.c +1 -0
@@ -1,4 +1,5 @@#include "builtin.h" +#include "config.h" #include "commit.h" #include "refs.h" #include "pkt-line.h"
builtin/shortlog.c +1 -0
@@ -1,5 +1,6 @@#include "builtin.h" #include "cache.h" +#include "config.h" #include "commit.h" #include "diff.h" #include "string-list.h"
builtin/show-branch.c +1 -0
@@ -1,4 +1,5 @@#include "cache.h" +#include "config.h" #include "commit.h" #include "refs.h" #include "builtin.h"
builtin/stripspace.c +1 -0
@@ -1,5 +1,6 @@#include "builtin.h" #include "cache.h" +#include "config.h" #include "parse-options.h" #include "strbuf.h"
builtin/submodule--helper.c +1 -0
@@ -1,5 +1,6 @@#include "builtin.h" #include "cache.h" +#include "config.h" #include "parse-options.h" #include "quote.h" #include "pathspec.h"
builtin/symbolic-ref.c +1 -0
@@ -1,4 +1,5 @@#include "builtin.h" +#include "config.h" #include "cache.h" #include "refs.h" #include "parse-options.h"
builtin/tag.c +1 -0
@@ -7,6 +7,7 @@*/ #include "cache.h" +#include "config.h" #include "builtin.h" #include "refs.h" #include "tag.h"
builtin/unpack-file.c +1 -0
@@ -1,4 +1,5 @@#include "builtin.h" +#include "config.h" static char *create_temp_file (unsigned char *sha1) {
builtin/unpack-objects.c +1 -0
@@ -1,5 +1,6 @@#include "builtin.h" #include "cache.h" +#include "config.h" #include "object.h" #include "delta.h" #include "pack.h"
builtin/update-index.c +1 -0
@@ -4,6 +4,7 @@* Copyright (C) Linus Torvalds, 2005 */ #include "cache.h" +#include "config.h" #include "lockfile.h" #include "quote.h" #include "cache-tree.h"
builtin/update-ref.c +1 -0
@@ -1,4 +1,5 @@#include "cache.h" +#include "config.h" #include "refs.h" #include "builtin.h" #include "parse-options.h"
builtin/update-server-info.c +1 -0
@@ -1,4 +1,5 @@#include "cache.h" +#include "config.h" #include "builtin.h" #include "parse-options.h"
builtin/var.c +1 -0
@@ -4,6 +4,7 @@* Copyright (C) Eric Biederman, 2005 */ #include "builtin.h" +#include "config.h" static const char var_usage[] ="git var (-l | <variable>)" ;
builtin/verify-commit.c +1 -0
@@ -6,6 +6,7 @@* Based on git-verify-tag */ #include "cache.h" +#include "config.h" #include "builtin.h" #include "commit.h" #include "run-command.h"
builtin/verify-pack.c +1 -0
@@ -1,5 +1,6 @@#include "builtin.h" #include "cache.h" +#include "config.h" #include "run-command.h" #include "parse-options.h"
builtin/verify-tag.c +1 -0
@@ -6,6 +6,7 @@* Based on git-verify-tag.sh */ #include "cache.h" +#include "config.h" #include "builtin.h" #include "tag.h" #include "run-command.h"
builtin/worktree.c +1 -0
@@ -1,4 +1,5 @@#include "cache.h" +#include "config.h" #include "builtin.h" #include "dir.h" #include "parse-options.h"
builtin/write-tree.c +1 -0
@@ -5,6 +5,7 @@*/ #include "builtin.h" #include "cache.h" +#include "config.h" #include "tree.h" #include "cache-tree.h" #include "parse-options.h"
cache.h +0 -1
@@ -11,7 +11,6 @@#include "string-list.h" #include "pack-revindex.h" #include "hash.h" -#include "config.h" #ifndef platform_SHA_CTX/*
color.c +1 -0
@@ -1,4 +1,5 @@#include "cache.h" +#include "config.h" #include "color.h" static int git_use_color_default =GIT_COLOR_AUTO ;
column.c +1 -0
@@ -1,4 +1,5 @@#include "cache.h" +#include "config.h" #include "column.h" #include "string-list.h" #include "parse-options.h"
config.c +1 -0
@@ -6,6 +6,7 @@* */ #include "cache.h" +#include "config.h" #include "lockfile.h" #include "exec_cmd.h" #include "strbuf.h"
connect.c +1 -0
@@ -1,5 +1,6 @@#include "git-compat-util.h" #include "cache.h" +#include "config.h" #include "pkt-line.h" #include "quote.h" #include "refs.h"
convert.c +1 -0
@@ -1,4 +1,5 @@#include "cache.h" +#include "config.h" #include "attr.h" #include "run-command.h" #include "quote.h"
credential-cache--daemon.c +1 -0
@@ -1,4 +1,5 @@#include "cache.h" +#include "config.h" #include "tempfile.h" #include "credential.h" #include "unix-socket.h"
credential.c +1 -0
@@ -1,4 +1,5 @@#include "cache.h" +#include "config.h" #include "credential.h" #include "string-list.h" #include "run-command.h"
daemon.c +1 -0
@@ -1,4 +1,5 @@#include "cache.h" +#include "config.h" #include "pkt-line.h" #include "run-command.h" #include "strbuf.h"
diff.c +1 -0
@@ -2,6 +2,7 @@* Copyright (C) 2005 Junio C Hamano */ #include "cache.h" +#include "config.h" #include "tempfile.h" #include "quote.h" #include "diff.h"
dir.c +1 -0
@@ -9,6 +9,7 @@*/ #define NO_THE_INDEX_COMPATIBILITY_MACROS #include "cache.h" +#include "config.h" #include "dir.h" #include "attr.h" #include "refs.h"
environment.c +1 -0
@@ -8,6 +8,7 @@* are. */ #include "cache.h" +#include "config.h" #include "refs.h" #include "fmt-merge-msg.h" #include "commit.h"
fast-import.c +1 -0
@@ -154,6 +154,7 @@ Format of STDIN stream:#include "builtin.h" #include "cache.h" +#include "config.h" #include "lockfile.h" #include "object.h" #include "blob.h"
fetch-pack.c +1 -0
@@ -1,4 +1,5 @@#include "cache.h" +#include "config.h" #include "lockfile.h" #include "refs.h" #include "pkt-line.h"
git.c +1 -0
@@ -1,4 +1,5 @@#include "builtin.h" +#include "config.h" #include "exec_cmd.h" #include "help.h" #include "run-command.h"
gpg-interface.c +1 -0
@@ -1,4 +1,5 @@#include "cache.h" +#include "config.h" #include "run-command.h" #include "strbuf.h" #include "gpg-interface.h"
graph.c +1 -0
@@ -1,4 +1,5 @@#include "cache.h" +#include "config.h" #include "commit.h" #include "color.h" #include "graph.h"
grep.c +1 -0
@@ -1,4 +1,5 @@#include "cache.h" +#include "config.h" #include "grep.h" #include "userdiff.h" #include "xdiff-interface.h"
help.c +1 -0
@@ -1,4 +1,5 @@#include "cache.h" +#include "config.h" #include "builtin.h" #include "exec_cmd.h" #include "run-command.h"
http-backend.c +1 -0
@@ -1,4 +1,5 @@#include "cache.h" +#include "config.h" #include "refs.h" #include "pkt-line.h" #include "object.h"
http-fetch.c +1 -0
@@ -1,4 +1,5 @@#include "cache.h" +#include "config.h" #include "exec_cmd.h" #include "http.h" #include "walker.h"
http.c +1 -0
@@ -1,5 +1,6 @@#include "git-compat-util.h" #include "http.h" +#include "config.h" #include "pack.h" #include "sideband.h" #include "run-command.h"
ident.c +1 -0
@@ -6,6 +6,7 @@* Copyright (C) 2005 Linus Torvalds */ #include "cache.h" +#include "config.h" static struct strbuf git_default_name =STRBUF_INIT ;static struct strbuf git_default_email =STRBUF_INIT ;
imap-send.c +1 -0
@@ -23,6 +23,7 @@*/ #include "cache.h" +#include "config.h" #include "credential.h" #include "exec_cmd.h" #include "run-command.h"
ll-merge.c +1 -0
@@ -5,6 +5,7 @@*/ #include "cache.h" +#include "config.h" #include "attr.h" #include "xdiff-interface.h" #include "run-command.h"
log-tree.c +1 -0
@@ -1,4 +1,5 @@#include "cache.h" +#include "config.h" #include "diff.h" #include "commit.h" #include "tag.h"
mailinfo.c +1 -0
@@ -1,4 +1,5 @@#include "cache.h" +#include "config.h" #include "utf8.h" #include "strbuf.h" #include "mailinfo.h"
merge-recursive.c +1 -0
@@ -4,6 +4,7 @@* The thieves were Alex Riesen and Johannes Schindelin, in June/July 2006 */ #include "cache.h" +#include "config.h" #include "advice.h" #include "lockfile.h" #include "cache-tree.h"
notes-utils.c +1 -0
@@ -1,4 +1,5 @@#include "cache.h" +#include "config.h" #include "commit.h" #include "refs.h" #include "notes-utils.h"
notes.c +1 -0
@@ -1,4 +1,5 @@#include "cache.h" +#include "config.h" #include "notes.h" #include "blob.h" #include "tree.h"
pager.c +1 -0
@@ -1,4 +1,5 @@#include "cache.h" +#include "config.h" #include "run-command.h" #include "sigchain.h"
parse-options.c +1 -0
@@ -1,6 +1,7 @@#include "git-compat-util.h" #include "parse-options.h" #include "cache.h" +#include "config.h" #include "commit.h" #include "color.h" #include "utf8.h"
pathspec.c +1 -0
@@ -1,5 +1,6 @@#define NO_THE_INDEX_COMPATIBILITY_MACROS #include "cache.h" +#include "config.h" #include "dir.h" #include "pathspec.h" #include "attr.h"
pretty.c +1 -0
@@ -1,4 +1,5 @@#include "cache.h" +#include "config.h" #include "commit.h" #include "utf8.h" #include "diff.h"
prompt.c +1 -0
@@ -1,4 +1,5 @@#include "cache.h" +#include "config.h" #include "run-command.h" #include "strbuf.h" #include "prompt.h"
read-cache.c +1 -0
@@ -5,6 +5,7 @@*/ #define NO_THE_INDEX_COMPATIBILITY_MACROS #include "cache.h" +#include "config.h" #include "tempfile.h" #include "lockfile.h" #include "cache-tree.h"
refs.c +1 -0
@@ -3,6 +3,7 @@*/ #include "cache.h" +#include "config.h" #include "hashmap.h" #include "lockfile.h" #include "iterator.h"
refs/files-backend.c +1 -0
@@ -1,4 +1,5 @@#include "../cache.h" +#include "../config.h" #include "../refs.h" #include "refs-internal.h" #include "ref-cache.h"
remote-curl.c +1 -0
@@ -1,4 +1,5 @@#include "cache.h" +#include "config.h" #include "remote.h" #include "strbuf.h" #include "walker.h"
remote.c +1 -0
@@ -1,4 +1,5 @@#include "cache.h" +#include "config.h" #include "remote.h" #include "refs.h" #include "commit.h"
rerere.c +1 -0
@@ -1,4 +1,5 @@#include "cache.h" +#include "config.h" #include "lockfile.h" #include "string-list.h" #include "rerere.h"
send-pack.c +1 -0
@@ -1,4 +1,5 @@#include "builtin.h" +#include "config.h" #include "commit.h" #include "refs.h" #include "pkt-line.h"
sequencer.c +1 -0
@@ -1,4 +1,5 @@#include "cache.h" +#include "config.h" #include "lockfile.h" #include "sequencer.h" #include "dir.h"
setup.c +1 -0
@@ -1,4 +1,5 @@#include "cache.h" +#include "config.h" #include "dir.h" #include "string-list.h"
sha1_file.c +1 -0
@@ -7,6 +7,7 @@* creation etc. */ #include "cache.h" +#include "config.h" #include "string-list.h" #include "lockfile.h" #include "delta.h"
sha1_name.c +1 -0
@@ -1,4 +1,5 @@#include "cache.h" +#include "config.h" #include "tag.h" #include "commit.h" #include "tree.h"
submodule-config.c +1 -0
@@ -1,4 +1,5 @@#include "cache.h" +#include "config.h" #include "submodule-config.h" #include "submodule.h" #include "strbuf.h"
submodule.c +1 -0
@@ -1,4 +1,5 @@#include "cache.h" +#include "config.h" #include "submodule-config.h" #include "submodule.h" #include "dir.h"
t/helper/test-config.c +1 -0
@@ -1,4 +1,5 @@#include "cache.h" +#include "config.h" #include "string-list.h" /*
t/helper/test-submodule-config.c +1 -0
@@ -1,4 +1,5 @@#include "cache.h" +#include "config.h" #include "submodule-config.h" #include "submodule.h"
trailer.c +1 -0
@@ -1,4 +1,5 @@#include "cache.h" +#include "config.h" #include "string-list.h" #include "run-command.h" #include "commit.h"
transport.c +1 -0
@@ -1,4 +1,5 @@#include "cache.h" +#include "config.h" #include "transport.h" #include "run-command.h" #include "pkt-line.h"
unpack-trees.c +1 -0
@@ -1,5 +1,6 @@#define NO_THE_INDEX_COMPATIBILITY_MACROS #include "cache.h" +#include "config.h" #include "dir.h" #include "tree.h" #include "tree-walk.h"
upload-pack.c +1 -0
@@ -1,4 +1,5 @@#include "cache.h" +#include "config.h" #include "refs.h" #include "pkt-line.h" #include "sideband.h"
userdiff.c +1 -0
@@ -1,4 +1,5 @@#include "cache.h" +#include "config.h" #include "userdiff.h" #include "attr.h"
versioncmp.c +1 -0
@@ -1,4 +1,5 @@#include "cache.h" +#include "config.h" #include "string-list.h" /*
wrapper.c +1 -0
@@ -2,6 +2,7 @@* Various trivial helper wrappers around standard functions */ #include "cache.h" +#include "config.h" static void do_nothing (size_t size) {
xdiff-interface.c +1 -0
@@ -1,4 +1,5 @@#include "cache.h" +#include "config.h" #include "xdiff-interface.h" #include "xdiff/xtypes.h" #include "xdiff/xdiffi.h"
Signature · 1 line
2.13.0.506.g27d5fe0cd-goog
PATCH 5/31 environment: remove namespace_len variable
In reply to Brandon WilliamsUse 'skip_prefix' instead of 'starts_with' so that we can drop the need to keep around 'namespace_len'.
--- environment.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
environment.c +4 -5
@@ -98,7 +98,6 @@ char *git_work_tree_cfg;static char *work_tree;static const char *namespace; -static size_t namespace_len;static const char *super_prefix;
@@ -190,7 +189,6 @@ void setup_git_env(void) git_replace_ref_base =xstrdup (replace_ref_base ? replace_ref_base :"refs/replace/" ); namespace =expand_namespace (getenv (GIT_NAMESPACE_ENVIRONMENT )); - namespace_len =strlen (namespace); shallow_file =getenv (GIT_SHALLOW_FILE_ENVIRONMENT );if (shallow_file)set_alternate_shallow_file (shallow_file,0 );
@@ -231,9 +229,10 @@ const char *get_git_namespace(void)const char *strip_namespace (const char *namespaced_ref) { -if (!starts_with (namespaced_ref,get_git_namespace ())) -return NULL ; -return namespaced_ref + namespace_len; +const char *out; +if (skip_prefix (namespaced_ref,get_git_namespace (), &out)) +return out; +return NULL ; }const char *get_super_prefix (void )
Signature · 1 line
2.13.0.506.g27d5fe0cd-goog
PATCH 6/31 repo: introduce the repository object
In reply to Brandon WilliamsIntroduce the repository object 'struct repo' which can be used hold all state pertaining to a git repository.
The aim of object-ifying the repository is to (1) make the code base more readable and easier to reason about and (2) allow for working on multiple repositories, specifically submodules, within the same process.
TODO: Add more motivating points for adding a repository object?
--- Makefile | 1 + cache.h | 1 + environment.c | 2 +- repo.c | 124 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ repo.h | 25 ++++++++++++ 5 files changed, 152 insertions(+), 1 deletion(-) create mode 100644 repo.c create mode 100644 repo.h
Makefile +1 -0
@@ -821,6 +821,7 @@ LIB_OBJS += refs/ref-cache.o LIB_OBJS += ref-filter.o LIB_OBJS += remote.o LIB_OBJS += replace_object.o +LIB_OBJS += repo.o LIB_OBJS += rerere.o LIB_OBJS += resolve-undo.o LIB_OBJS += revision.o
cache.h +1 -0
@@ -483,6 +483,7 @@ extern char *get_graft_file(void);extern int set_git_dir (const char *path);extern int get_common_dir_noenv (struct strbuf *sb,const char *gitdir);extern int get_common_dir (struct strbuf *sb,const char *gitdir); +extern char *expand_namespace (const char *raw_namespace);extern const char *get_git_namespace (void );extern const char *strip_namespace (const char *namespaced_ref);extern const char *get_super_prefix (void );
environment.c +1 -1
@@ -127,7 +127,7 @@ const char * const local_repo_env[] = { NULL }; -static char *expand_namespace (const char *raw_namespace) +char *expand_namespace (const char *raw_namespace) {struct strbuf buf =STRBUF_INIT ;struct strbuf **components, **c;
repo.c new file +124 -0
124 lines not on this page · raw message
repo.h new file +25 -0
@@ -0,0 +1,25 @@ +#ifndef REPO_H +#define REPO_H + +struct repo { +/* Environment */ +char *gitdir; +char *commondir; +char *objectdir; +char *index_file; +char *graft_file; +char *namespace; + +/* Configurations */ +unsigned ignore_env:1 ; +/* Indicates if a repository has a different 'commondir' from 'gitdir' */ +unsigned different_commondir:1 ; +}; + +extern struct repo the_repository; + +extern void repo_set_gitdir (struct repo *repo,const char *path); +extern int repo_init (struct repo *repo,const char *path); +extern void repo_clear (struct repo *repo); + +#endif /* REPO_H */
Signature · 1 line
2.13.0.506.g27d5fe0cd-goog
PATCH 3/31 config: don't implicitly use gitdir
In reply to Brandon WilliamsCommit 2185fde56 (config: handle conditional include when $GIT_DIR is not set up) added a 'git_dir' field to the config_options struct. Let's use this option field explicitly all the time instead of occasionally falling back to calling 'git_pathdup("config")' to get the path to the local repository configuration. This allows 'go_git_config_sequence()' to not implicitly rely on global repository state.
--- builtin/config.c | 2 ++ config.c | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-)
builtin/config.c +2 -0
@@ -539,6 +539,8 @@ int cmd_config(int argc, const char **argv, const char *prefix) config_options.respect_includes = !given_config_source.file; else config_options.respect_includes = respect_includes_opt; +if (have_git_dir ()) + config_options.git_dir =get_git_common_dir ();if (end_null) { term ='\0' ;
config.c +2 -2
@@ -1548,8 +1548,6 @@ static int do_git_config_sequence(const struct config_options *opts,if (opts->git_dir) repo_config =mkpathdup ("%s/config" , opts->git_dir); -else if (have_git_dir ()) - repo_config =git_pathdup ("config" );else repo_config =NULL ;
@@ -1613,6 +1611,8 @@ static void git_config_raw(config_fn_t fn, void *data)struct config_options opts = {0 }; opts.respect_includes =1 ; +if (have_git_dir ()) + opts.git_dir =get_git_common_dir ();if (git_config_with_options (fn, data,NULL , &opts) <0 )/* * git_config_with_options() normally returns only
Signature · 1 line
2.13.0.506.g27d5fe0cd-goog
PATCH 8/31 environment: store worktree in the_repository
In reply to Brandon WilliamsMigrate 'work_tree' to be stored in 'the_repository'.
--- environment.c | 9 ++++----- repo.c | 7 +++++++ repo.h | 2 ++ 3 files changed, 13 insertions(+), 5 deletions(-)
environment.c +4 -5
@@ -96,7 +96,6 @@ int ignore_untracked_cache_config;/* This is set by setup_git_dir_gently() and/or git_default_config() */ char *git_work_tree_cfg; -static char *work_tree;static const char *super_prefix;
@@ -220,19 +219,19 @@ void set_git_work_tree(const char *new_work_tree) {if (git_work_tree_initialized) { new_work_tree =real_path (new_work_tree); -if (strcmp (new_work_tree, work_tree)) +if (strcmp (new_work_tree, the_repository.worktree))die ("internal error: work tree has already been set\n" "Current worktree: %s\nNew worktree: %s" , - work_tree, new_work_tree); + the_repository.worktree, new_work_tree);return ; } git_work_tree_initialized =1 ; - work_tree =real_pathdup (new_work_tree,1 ); +repo_set_worktree (&the_repository, new_work_tree); }const char *get_git_work_tree (void ) { -return work_tree; +return the_repository.worktree; }char *get_object_directory (void )
repo.c +7 -0
@@ -84,6 +84,11 @@ void repo_set_gitdir(struct repo *repo, const char *path)repo_setup_env (repo); } +void repo_set_worktree (struct repo *repo,const char *path) +{ + repo->worktree =real_pathdup (path,1 ); +} +int repo_init (struct repo *repo,const char *gitdir) {int error =0 ;
@@ -121,4 +126,6 @@ int repo_init(struct repo *repo, const char *gitdir)void repo_clear (struct repo *repo) {repo_clear_env (repo); +free (repo->worktree); + repo->worktree =NULL ; }
repo.h +2 -0
@@ -9,6 +9,7 @@ struct repo {char *index_file;char *graft_file;char *namespace; +char *worktree;/* Configurations */ unsigned ignore_env:1;
@@ -19,6 +20,7 @@ struct repo {extern struct repo the_repository;extern void repo_set_gitdir (struct repo *repo,const char *path); +extern void repo_set_worktree (struct repo *repo,const char *path);extern int repo_init (struct repo *repo,const char *path);extern void repo_clear (struct repo *repo);
Signature · 1 line
2.13.0.506.g27d5fe0cd-goog
PATCH 13/31 repo: add repo_read_gitmodules
In reply to Brandon WilliamsTeach the repo object to be able to populate the submodule_cache by reading the repository's gitmodules file.
--- repo.c | 14 ++++++++++++++ repo.h | 1 + 2 files changed, 15 insertions(+)
repo.c +14 -0
@@ -116,6 +116,20 @@ void repo_read_index(struct repo *repo)die (_ ("failure reading index" )); } +static int gitmodules_cb (const char *var,const char *value,void *data) +{ +struct repo *repo = data; +return submodule_config_option (repo, var, value); +} + +void repo_read_gitmodules (struct repo *repo) +{ +char *gitmodules_path =xstrfmt ("%s/.gitmodules" , repo->worktree); + +git_config_from_file (gitmodules_cb, gitmodules_path, repo); +free (gitmodules_path); +} +int repo_init (struct repo *repo,const char *gitdir) {int error =0 ;
repo.h +1 -0
@@ -37,6 +37,7 @@ extern void repo_set_gitdir(struct repo *repo, const char *path);extern void repo_set_worktree (struct repo *repo,const char *path);extern void repo_read_config (struct repo *repo);extern void repo_read_index (struct repo *repo); +extern void repo_read_gitmodules (struct repo *repo);extern int repo_init (struct repo *repo,const char *path);extern void repo_clear (struct repo *repo);
Signature · 1 line
2.13.0.506.g27d5fe0cd-goog
PATCH 11/31 repo: add index_state to struct repo
In reply to Brandon Williams--- repo.c | 17 +++++++++++++++++ repo.h | 3 +++ 2 files changed, 20 insertions(+)
repo.c +17 -0
@@ -104,6 +104,17 @@ void repo_read_config(struct repo *repo)git_config_with_options (config_set_callback, repo->config,NULL , &opts); } +void repo_read_index (struct repo *repo) +{ +if (!repo->index) + repo->index =xcalloc (1 ,sizeof (struct index_state )); +else +discard_index (repo->index); + +if (read_index_from (repo->index, repo->index_file) <0 ) +die (_ ("failure reading index" )); +} +int repo_init (struct repo *repo,const char *gitdir) {int error =0 ;
@@ -149,4 +160,10 @@ void repo_clear(struct repo *repo)free (repo->config); repo->config =NULL ; } + +if (repo->index) { +discard_index (repo->index); +free (repo->index); + repo->index =NULL ; + } }
repo.h +3 -0
@@ -2,6 +2,7 @@#define REPO_H struct config_set ; +struct index_state ;struct repo {/* Environment */
@@ -20,6 +21,7 @@ struct repo {* ~/.gitconfig, XDG config file and the global /etc/gitconfig) */ struct config_set *config; +struct index_state *index;/* Configurations */ unsigned ignore_env:1;
@@ -32,6 +34,7 @@ extern struct repo the_repository;extern void repo_set_gitdir (struct repo *repo,const char *path);extern void repo_set_worktree (struct repo *repo,const char *path);extern void repo_read_config (struct repo *repo); +extern void repo_read_index (struct repo *repo);extern int repo_init (struct repo *repo,const char *path);extern void repo_clear (struct repo *repo);
Signature · 1 line
2.13.0.506.g27d5fe0cd-goog
PATCH 7/31 environment: place key repository state in the_repository
In reply to Brandon WilliamsMigrate 'git_dir', 'git_common_dir', 'git_object_dir', 'git_index_file', 'git_graft_file', and 'namespace' to be stored in 'the_repository'.
--- cache.h | 1 - environment.c | 65 ++++++++++++++--------------------------------------------- path.c | 11 +++++----- setup.c | 17 ++++++++++++++-- 4 files changed, 36 insertions(+), 58 deletions(-)
cache.h +0 -1
@@ -769,7 +769,6 @@ extern int core_apply_sparse_checkout;extern int precomposed_unicode;extern int protect_hfs;extern int protect_ntfs; -extern int git_db_env, git_index_env, git_graft_env, git_common_dir_env;/* * Include broken refs in all ref iterations, which will
environment.c +15 -50
141 lines not on this page · raw message
path.c +6 -5
@@ -2,6 +2,7 @@* Utilities for paths and pathnames */ #include "cache.h" +#include "repo.h" #include "strbuf.h" #include "string-list.h" #include "dir.h"
@@ -355,7 +356,7 @@ void report_linked_checkout_garbage(void)const struct common_dir *p;int len; -if (!git_common_dir_env) +if (!the_repository.different_commondir)return ;strbuf_addf (&sb,"%s/" ,get_git_dir ()); len = sb.len;
@@ -374,17 +375,17 @@ void report_linked_checkout_garbage(void)static void adjust_git_path (struct strbuf *buf,int git_dir_len) {const char *base = buf->buf + git_dir_len; -if (git_graft_env &&is_dir_file (base,"info" ,"grafts" )) +if (is_dir_file (base,"info" ,"grafts" ))strbuf_splice (buf,0 , buf->len,get_graft_file (),strlen (get_graft_file ())); -else if (git_index_env && !strcmp (base,"index" )) +else if (!strcmp (base,"index" ))strbuf_splice (buf,0 , buf->len,get_index_file (),strlen (get_index_file ())); -else if (git_db_env &&dir_prefix (base,"objects" )) +else if (dir_prefix (base,"objects" ))replace_dir (buf, git_dir_len +7 ,get_object_directory ());else if (git_hooks_path &&dir_prefix (base,"hooks" ))replace_dir (buf, git_dir_len +5 , git_hooks_path); -else if (git_common_dir_env) +else if (the_repository.different_commondir)update_common_dir (buf, git_dir_len,NULL ); }
setup.c +15 -2
@@ -1,4 +1,5 @@#include "cache.h" +#include "repo.h" #include "config.h" #include "dir.h" #include "string-list.h"
@@ -376,6 +377,11 @@ void setup_work_tree(void)if (getenv (GIT_WORK_TREE_ENVIRONMENT ))setenv (GIT_WORK_TREE_ENVIRONMENT ,"." ,1 ); +/* +* NEEDSWORK: this call can essentially be set_git_dir(get_git_dir()) +* which can cause some problems when trying to free the old value of +* gitdir. +*/ set_git_dir (remove_leading_path (git_dir, work_tree)); initialized =1 ; }
@@ -1074,8 +1080,15 @@ const char *setup_git_directory_gently(int *nongit_ok)* the user has set GIT_DIR. It may be beneficial to disallow bogus * GIT_DIR values at some point in the future. */ -if (startup_info->have_repository ||getenv (GIT_DIR_ENVIRONMENT )) -setup_git_env (); +if (startup_info->have_repository ||getenv (GIT_DIR_ENVIRONMENT )) { +if (!the_repository.gitdir) { +const char *gitdir =getenv (GIT_DIR_ENVIRONMENT ); +if (!gitdir) + gitdir =DEFAULT_GIT_DIR_ENVIRONMENT ; +repo_set_gitdir (&the_repository, gitdir); +setup_git_env (); + } + }strbuf_release (&dir);strbuf_release (&gitdir);
Signature · 1 line
2.13.0.506.g27d5fe0cd-goog
PATCH 12/31 submodule-config: store the_submodule_cache in the_repository
In reply to Brandon WilliamsRefactor how 'the_submodule_cache' is handled so that it can be stored inside of a repository object. Also migrate 'the_submodule_cache' to be stored in 'the_repository'.
--- repo.c | 6 +++++ repo.h | 2 ++ submodule-config.c | 71 ++++++++++++++++++++++++++++++++++++++++-------------- submodule-config.h | 10 ++++++++ 4 files changed, 71 insertions(+), 18 deletions(-)
repo.c +6 -0
@@ -1,6 +1,7 @@#include "cache.h" #include "repo.h" #include "config.h" +#include "submodule-config.h" /* * This may be the wrong place for this.
@@ -166,4 +167,9 @@ void repo_clear(struct repo *repo)free (repo->index); repo->index =NULL ; } + +if (repo->submodule_cache) { +submodule_cache_free (repo->submodule_cache); + repo->submodule_cache =NULL ; + } }
repo.h +2 -0
@@ -3,6 +3,7 @@struct config_set ;struct index_state ; +struct submodule_cache ;struct repo {/* Environment */
@@ -22,6 +23,7 @@ struct repo {*/ struct config_set *config;struct index_state *index; +struct submodule_cache *submodule_cache;/* Configurations */ unsigned ignore_env:1;
submodule-config.c +53 -18
142 lines not on this page · raw message
submodule-config.h +10 -0
@@ -22,14 +22,24 @@ struct submodule {int recommend_shallow; }; +struct submodule_cache ; +struct repo ; + +extern void submodule_cache_free (struct submodule_cache *cache); +extern int parse_fetch_recurse_submodules_arg (const char *opt,const char *arg);extern int parse_update_recurse_submodules_arg (const char *opt,const char *arg);extern int parse_push_recurse_submodules_arg (const char *opt,const char *arg);extern int parse_submodule_config_option (const char *var,const char *value); +extern int submodule_config_option (struct repo *repository, +const char *var,const char *value);extern const struct submodule *submodule_from_name (const unsigned char *commit_or_tree,const char *name);extern const struct submodule *submodule_from_path (const unsigned char *commit_or_tree,const char *path); +extern const struct submodule *submodule_from_cache (struct repo *repository, +const unsigned char *treeish_name, +const char *key);extern int gitmodule_sha1_from_commit (const unsigned char *commit_sha1,unsigned char *gitmodules_sha1,struct strbuf *rev);
Signature · 1 line
2.13.0.506.g27d5fe0cd-goog
PATCH 14/31 submodule: convert is_submodule_initialized to work on a repository
In reply to Brandon WilliamsConvert 'is_submodule_initialized()' to take a repository object and while we're at it, lets rename the function to 'is_submodule_active()' and remove the NEEDSWORK comment.
--- builtin/grep.c | 3 ++- builtin/submodule--helper.c | 9 +++++---- config.c | 12 ++++++------ config.h | 9 +++++++++ submodule.c | 21 +++++++++------------ submodule.h | 3 ++- 6 files changed, 33 insertions(+), 24 deletions(-)
builtin/grep.c +2 -1
@@ -4,6 +4,7 @@* Copyright (c) 2006 Junio C Hamano */ #include "cache.h" +#include "repo.h" #include "config.h" #include "blob.h" #include "tree.h"
@@ -626,7 +627,7 @@ static int grep_submodule_launch(struct grep_opt *opt,static int grep_submodule (struct grep_opt *opt,const unsigned char *sha1,const char *filename,const char *path) { -if (!is_submodule_initialized (path)) +if (!is_submodule_active (&the_repository, path))return 0 ;if (!is_submodule_populated_gently (path,NULL )) {/*
builtin/submodule--helper.c +5 -4
@@ -1,4 +1,5 @@#include "builtin.h" +#include "repo.h" #include "cache.h" #include "config.h" #include "parse-options.h"
@@ -280,7 +281,7 @@ static void module_list_active(struct module_list *list)for (i =0 ; i < list->nr; i++) {const struct cache_entry *ce = list->entries[i]; -if (!is_submodule_initialized (ce->name)) +if (!is_submodule_active (&the_repository, ce->name))continue ; ALLOC_GROW(active_modules.entries,
@@ -362,7 +363,7 @@ static void init_submodule(const char *path, const char *prefix, int quiet)* * Set active flag for the submodule being initialized */ -if (!is_submodule_initialized (path)) { +if (!is_submodule_active (&the_repository, path)) {strbuf_reset (&sb);strbuf_addf (&sb,"submodule.%s.active" , sub->name);git_config_set_gently (sb.buf,"true" );
@@ -817,7 +818,7 @@ static int prepare_to_clone_next_submodule(const struct cache_entry *ce, }/* Check if the submodule has been initialized. */ -if (!is_submodule_initialized (ce->name)) { +if (!is_submodule_active (&the_repository, ce->name)) {next_submodule_warn_missing (suc, out, displaypath); goto cleanup; }
@@ -1193,7 +1194,7 @@ static int is_active(int argc, const char **argv, const char *prefix)gitmodules_config (); -return !is_submodule_initialized (argv[1 ]); +return !is_submodule_active (&the_repository, argv[1 ]); }#define SUPPORT_SUPER_PREFIX (1<<0)
config.c +6 -6
@@ -1885,8 +1885,8 @@ static int repo_config_get_value(struct repo *repository,return git_configset_get_value (repository->config, key, value); } -static const struct string_list *repo_config_get_value_multi (struct repo *repository, -const char *key) +const struct string_list *repo_config_get_value_multi (struct repo *repository, +const char *key) {git_config_check_init (repository);return git_configset_get_value_multi (repository->config, key);
@@ -1903,8 +1903,8 @@ static int repo_config_get_string_const(struct repo *repository,return ret; } -static int repo_config_get_string (struct repo *repository, -const char *key,char **dest) +int repo_config_get_string (struct repo *repository, +const char *key,char **dest) {git_config_check_init (repository);return repo_config_get_string_const (repository, key, (const char **)dest);
@@ -1924,8 +1924,8 @@ static int repo_config_get_ulong(struct repo *repository,return git_configset_get_ulong (repository->config, key, dest); } -static int repo_config_get_bool (struct repo *repository, -const char *key,int *dest) +int repo_config_get_bool (struct repo *repository, +const char *key,int *dest) {git_config_check_init (repository);return git_configset_get_bool (repository->config, key, dest);
config.h +9 -0
@@ -163,6 +163,15 @@ extern int git_configset_get_bool_or_int(struct config_set *cs, const char *key,extern int git_configset_get_maybe_bool (struct config_set *cs,const char *key,int *dest);extern int git_configset_get_pathname (struct config_set *cs,const char *key,const char **dest); +struct repo ; + +extern const struct string_list *repo_config_get_value_multi (struct repo *repository, +const char *key); +extern int repo_config_get_string (struct repo *repository, +const char *key,char **dest); +extern int repo_config_get_bool (struct repo *repository, +const char *key,int *dest); +extern int git_config_get_value (const char *key,const char **value);extern const struct string_list *git_config_get_value_multi (const char *key);extern void git_config_clear (void );
submodule.c +9 -12
@@ -1,4 +1,5 @@#include "cache.h" +#include "repo.h" #include "config.h" #include "submodule-config.h" #include "submodule.h"
@@ -215,21 +216,17 @@ void gitmodules_config_sha1(const unsigned char *commit_sha1) }/* -* NEEDSWORK: With the addition of different configuration options to determine -* if a submodule is of interests, the validity of this function's name comes -* into question. Once the dust has settled and more concrete terminology is -* decided upon, come up with a more proper name for this function. One -* potential candidate could be 'is_submodule_active()'. -* * Determine if a submodule has been initialized at a given 'path' */ -int is_submodule_initialized (const char *path) +int is_submodule_active (struct repo *repo,const char *path) {int ret =0 ;char *key =NULL ;char *value =NULL ;const struct string_list *sl; -const struct submodule *module =submodule_from_path (null_sha1, path); +const struct submodule *module; + + module =submodule_from_cache (repo, null_sha1, path);/* early return if there isn't a path->module mapping */ if (!module)
@@ -237,14 +234,14 @@ int is_submodule_initialized(const char *path)/* submodule.<name>.active is set */ key =xstrfmt ("submodule.%s.active" , module->name); -if (!git_config_get_bool (key, &ret)) { +if (!repo_config_get_bool (repo, key, &ret)) {free (key);return ret; }free (key);/* submodule.active is set */ - sl =git_config_get_value_multi ("submodule.active" ); + sl =repo_config_get_value_multi (repo,"submodule.active" );if (sl) {struct pathspec ps;struct argv_array args =ARGV_ARRAY_INIT ;
@@ -264,7 +261,7 @@ int is_submodule_initialized(const char *path)/* fallback to checking if the URL is set */ key =xstrfmt ("submodule.%s.url" , module->name); - ret = !git_config_get_string (key, &value); + ret = !repo_config_get_string (repo, key, &value);free (value);free (key);
@@ -1469,7 +1466,7 @@ int submodule_move_head(const char *path,const struct submodule *sub;int *error_code_ptr, error_code; -if (!is_submodule_initialized (path)) +if (!is_submodule_active (&the_repository, path))return 0 ;if (flags &SUBMODULE_MOVE_HEAD_FORCE )
submodule.h +2 -1
@@ -1,6 +1,7 @@#ifndef SUBMODULE_H #define SUBMODULE_H +struct repo ;struct diff_options ;struct argv_array ;struct oid_array ;
@@ -41,7 +42,7 @@ extern void set_diffopt_flags_from_submodule_config(struct diff_options *,extern int submodule_config (const char *var,const char *value,void *cb);extern void gitmodules_config (void );extern void gitmodules_config_sha1 (const unsigned char *commit_sha1); -extern int is_submodule_initialized (const char *path); +extern int is_submodule_active (struct repo *repo,const char *path);/* * Determine if a submodule has been populated at a given 'path' by checking if * the <path>/.git resolves to a valid git repository.
Signature · 1 line
2.13.0.506.g27d5fe0cd-goog
PATCH 16/31 convert: convert crlf_to_git to take an index
In reply to Brandon Williams--- convert.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)
convert.c +8 -6
@@ -219,13 +219,13 @@ static void check_safe_crlf(const char *path, enum crlf_action crlf_action, } } -static int has_cr_in_index (const char *path) +static int has_cr_in_index (const struct index_state *istate,const char *path) {unsigned long sz;void *data;int has_cr; - data =read_blob_data_from_cache (path, &sz); + data =read_blob_data_from_index (istate, path, &sz);if (!data)return 0 ; has_cr =memchr (data,'\r' , sz) !=NULL ;
@@ -255,7 +255,8 @@ static int will_convert_lf_to_crlf(size_t len, struct text_stat *stats, } -static int crlf_to_git (const char *path,const char *src,size_t len, +static int crlf_to_git (const struct index_state *istate, +const char *path,const char *src,size_t len,struct strbuf *buf,enum crlf_action crlf_action,enum safe_crlf checksafe) {
@@ -287,7 +288,8 @@ static int crlf_to_git(const char *path, const char *src, size_t len,* unless we want to renormalize in a merge or * cherry-pick. */ -if ((checksafe !=SAFE_CRLF_RENORMALIZE ) &&has_cr_in_index (path)) +if ((checksafe !=SAFE_CRLF_RENORMALIZE ) && +has_cr_in_index (istate, path)) convert_crlf_into_lf =0 ; } if ((checksafe == SAFE_CRLF_WARN ||
@@ -1099,7 +1101,7 @@ int convert_to_git(const char *path, const char *src, size_t len, src = dst->buf; len = dst->len; } - ret |=crlf_to_git (path, src, len, dst, ca.crlf_action, checksafe); + ret |=crlf_to_git (&the_index, path, src, len, dst, ca.crlf_action, checksafe);if (ret && dst) { src = dst->buf; len = dst->len;
@@ -1119,7 +1121,7 @@ void convert_to_git_filter_fd(const char *path, int fd, struct strbuf *dst,if (!apply_filter (path,NULL ,0 , fd, dst, ca.drv,CAP_CLEAN ))die ("%s: clean filter '%s' failed" , path, ca.drv->name); -crlf_to_git (path, dst->buf, dst->len, dst, ca.crlf_action, checksafe); +crlf_to_git (&the_index, path, dst->buf, dst->len, dst, ca.crlf_action, checksafe);ident_to_git (path, dst->buf, dst->len, dst, ca.ident); }
Signature · 1 line
2.13.0.506.g27d5fe0cd-goog
PATCH 15/31 convert: convert get_cached_convert_stats_ascii to take an index
In reply to Brandon Williams--- builtin/ls-files.c | 3 ++- convert.c | 5 +++-- convert.h | 5 ++++- 3 files changed, 9 insertions(+), 4 deletions(-)
builtin/ls-files.c +2 -1
@@ -64,7 +64,8 @@ static void write_eolinfo(const struct cache_entry *ce, const char *path)const char *w_txt ="" ;const char *a_txt =get_convert_attr_ascii (path);if (ce &&S_ISREG (ce->ce_mode)) - i_txt =get_cached_convert_stats_ascii (ce->name); + i_txt =get_cached_convert_stats_ascii (&the_index, + ce->name);if (!lstat (path, &st) &&S_ISREG (st.st_mode)) w_txt =get_wt_convert_stats_ascii (path);printf ("i/%-5s w/%-5s attr/%-17s\t" , i_txt, w_txt, a_txt);
convert.c +3 -2
@@ -135,11 +135,12 @@ static const char *gather_convert_stats_ascii(const char *data, unsigned long si } } -const char *get_cached_convert_stats_ascii (const char *path) +const char *get_cached_convert_stats_ascii (const struct index_state *istate, +const char *path) {const char *ret;unsigned long sz; -void *data =read_blob_data_from_cache (path, &sz); +void *data =read_blob_data_from_index (istate, path, &sz); ret =gather_convert_stats_ascii (data, sz);free (data);return ret;
convert.h +4 -1
@@ -4,6 +4,8 @@#ifndef CONVERT_H #define CONVERT_H +struct index_state ; +enum safe_crlf {SAFE_CRLF_FALSE =0 , SAFE_CRLF_FAIL = 1,
@@ -33,7 +35,8 @@ enum eol { };extern enum eol core_eol; -extern const char *get_cached_convert_stats_ascii (const char *path); +extern const char *get_cached_convert_stats_ascii (const struct index_state *istate, +const char *path);extern const char *get_wt_convert_stats_ascii (const char *path);extern const char *get_convert_attr_ascii (const char *path);
Signature · 1 line
2.13.0.506.g27d5fe0cd-goog
PATCH 19/31 convert: convert renormalize_buffer to take an index
In reply to Brandon Williams--- convert.c | 6 ++++-- convert.h | 3 ++- ll-merge.c | 2 +- merge-recursive.c | 4 ++-- 4 files changed, 9 insertions(+), 6 deletions(-)
convert.c +4 -2
@@ -1,3 +1,4 @@ +#define NO_THE_INDEX_COMPATIBILITY_MACROS #include "cache.h" #include "config.h" #include "attr.h"
@@ -1166,14 +1167,15 @@ int convert_to_working_tree(const char *path, const char *src, size_t len, strucreturn convert_to_working_tree_internal (path, src, len, dst,0 ); } -int renormalize_buffer (const char *path,const char *src,size_t len,struct strbuf *dst) +int renormalize_buffer (const struct index_state *istate,const char *path, +const char *src,size_t len,struct strbuf *dst) {int ret =convert_to_working_tree_internal (path, src, len, dst,1 );if (ret) { src = dst->buf; len = dst->len; } -return ret |convert_to_git (&the_index, path, src, len, dst,SAFE_CRLF_RENORMALIZE ); +return ret |convert_to_git (istate, path, src, len, dst,SAFE_CRLF_RENORMALIZE ); }/*****************************************************************
convert.h +2 -1
@@ -46,7 +46,8 @@ extern int convert_to_git(const struct index_state *istate, struct strbuf *dst, enum safe_crlf checksafe);extern int convert_to_working_tree (const char *path,const char *src,size_t len,struct strbuf *dst); -extern int renormalize_buffer (const char *path,const char *src,size_t len, +extern int renormalize_buffer (const struct index_state *istate, +const char *path,const char *src,size_t len,struct strbuf *dst);static inline int would_convert_to_git (const struct index_state *istate,const char *path)
ll-merge.c +1 -1
@@ -340,7 +340,7 @@ static const struct ll_merge_driver *find_ll_merge_driver(const char *merge_attrstatic void normalize_file (mmfile_t *mm,const char *path) {struct strbuf strbuf =STRBUF_INIT ; -if (renormalize_buffer (path, mm->ptr, mm->size, &strbuf)) { +if (renormalize_buffer (&the_index, path, mm->ptr, mm->size, &strbuf)) {free (mm->ptr); mm->size = strbuf.len; mm->ptr =strbuf_detach (&strbuf,NULL );
merge-recursive.c +2 -2
@@ -1640,8 +1640,8 @@ static int blob_unchanged(struct merge_options *opt,* performed. Comparison can be skipped if both files are * unchanged since their sha1s have already been compared. */ -if (renormalize_buffer (path, o.buf, o.len, &o) | -renormalize_buffer (path, a.buf, a.len, &a)) +if (renormalize_buffer (&the_index, path, o.buf, o.len, &o) | +renormalize_buffer (&the_index, path, a.buf, a.len, &a)) ret = (o.len == a.len && !memcmp (o.buf, a.buf, o.len)); error_return:
Signature · 1 line
2.13.0.506.g27d5fe0cd-goog
PATCH 22/31 ls-files: convert write_eolinfo to take an index
In reply to Brandon Williams--- builtin/ls-files.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-)
builtin/ls-files.c +6 -7
@@ -54,17 +54,16 @@ static const char *tag_modified = "";static const char *tag_skip_worktree ="" ;static const char *tag_resolve_undo ="" ; -static void write_eolinfo (const struct cache_entry *ce,const char *path) +static void write_eolinfo (const struct index_state *istate, +const struct cache_entry *ce,const char *path) { -if (!show_eol) -return ; -else { +if (show_eol) {struct stat st;const char *i_txt ="" ;const char *w_txt ="" ;const char *a_txt =get_convert_attr_ascii (path);if (ce &&S_ISREG (ce->ce_mode)) - i_txt =get_cached_convert_stats_ascii (&the_index, + i_txt =get_cached_convert_stats_ascii (istate, ce->name);if (!lstat (path, &st) &&S_ISREG (st.st_mode)) w_txt =get_wt_convert_stats_ascii (path);
@@ -106,7 +105,7 @@ static void show_dir_entry(const char *tag, struct dir_entry *ent)return ;fputs (tag, stdout); -write_eolinfo (NULL , ent->name); +write_eolinfo (NULL ,NULL , ent->name);write_name (ent->name); }
@@ -276,7 +275,7 @@ static void show_ce_entry(const char *tag, const struct cache_entry *ce)find_unique_abbrev (ce->oid.hash, abbrev), ce_stage(ce)); } -write_eolinfo (ce, ce->name); +write_eolinfo (&the_index, ce, ce->name);write_name (ce->name);if (debug_mode) {const struct stat_data *sd = &ce->ce_stat_data;
Signature · 1 line
2.13.0.506.g27d5fe0cd-goog
PATCH 21/31 ls-files: convert overlay_tree_on_cache to take an index
In reply to Brandon Williams--- builtin/commit.c | 3 ++- builtin/ls-files.c | 15 ++++++++------- cache.h | 3 ++- 3 files changed, 12 insertions(+), 9 deletions(-)
builtin/commit.c +2 -1
@@ -254,7 +254,8 @@ static int list_paths(struct string_list *list, const char *with_tree,if (with_tree) {char *max_prefix =common_prefix (pattern); -overlay_tree_on_cache (with_tree, max_prefix ? max_prefix : prefix); +overlay_tree_on_index (&the_index, with_tree, + max_prefix ? max_prefix : prefix);free (max_prefix); }
builtin/ls-files.c +8 -7
@@ -432,7 +432,8 @@ static int get_common_prefix_len(const char *common_prefix)* that were given from the command line. We are not * going to write this index out. */ -void overlay_tree_on_cache (const char *tree_name,const char *prefix) +void overlay_tree_on_index (struct index_state *istate, +const char *tree_name,const char *prefix) {struct tree *tree;struct object_id oid;
@@ -447,8 +448,8 @@ void overlay_tree_on_cache(const char *tree_name, const char *prefix)die ("bad tree-ish %s" , tree_name);/* Hoist the unmerged entries up to stage #3 to make room */ -for (i =0 ; i < active_nr; i++) { -struct cache_entry *ce = active_cache[i]; +for (i =0 ; i < istate->cache_nr; i++) { +struct cache_entry *ce = istate->cache[i];if (!ce_stage (ce))continue ; ce->ce_flags |=CE_STAGEMASK ;
@@ -461,11 +462,11 @@ void overlay_tree_on_cache(const char *tree_name, const char *prefix) PATHSPEC_PREFER_CWD, prefix, matchbuf); }else memset (&pathspec,0 ,sizeof (pathspec)); -if (read_tree (tree,1 , &pathspec, &the_index)) +if (read_tree (tree,1 , &pathspec, istate))die ("unable to read tree entries %s" , tree_name); -for (i =0 ; i < active_nr; i++) { -struct cache_entry *ce = active_cache[i]; +for (i =0 ; i < istate->cache_nr; i++) { +struct cache_entry *ce = istate->cache[i];switch (ce_stage (ce)) {case 0 : last_stage0 = ce;
@@ -680,7 +681,7 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix)*/ if (show_stage || show_unmerged)die ("ls-files --with-tree is incompatible with -s or -u" ); -overlay_tree_on_cache (with_tree, max_prefix); +overlay_tree_on_index (&the_index, with_tree, max_prefix); }show_files (&dir);if (show_resolve_undo)
cache.h +2 -1
@@ -1993,7 +1993,8 @@ extern int ws_blank_line(const char *line, int len, unsigned ws_rule);#define ws_tab_width (rule) ((rule) & WS_TAB_WIDTH_MASK)/* ls-files */ -void overlay_tree_on_cache (const char *tree_name,const char *prefix); +void overlay_tree_on_index (struct index_state *istate, +const char *tree_name,const char *prefix);char *alias_lookup (const char *alias);int split_cmdline (char *cmdline,const char ***argv);
Signature · 1 line
2.13.0.506.g27d5fe0cd-goog
PATCH 20/31 tree: convert read_tree to take an index parameter
In reply to Brandon Williams--- builtin/ls-files.c | 2 +- tree.c | 28 ++++++++++++++++++---------- tree.h | 3 ++- 3 files changed, 21 insertions(+), 12 deletions(-)
builtin/ls-files.c +1 -1
@@ -461,7 +461,7 @@ void overlay_tree_on_cache(const char *tree_name, const char *prefix) PATHSPEC_PREFER_CWD, prefix, matchbuf); }else memset (&pathspec,0 ,sizeof (pathspec)); -if (read_tree (tree,1 , &pathspec)) +if (read_tree (tree,1 , &pathspec, &the_index))die ("unable to read tree entries %s" , tree_name);for (i =0 ; i < active_nr; i++) {
tree.c +18 -10
@@ -1,3 +1,4 @@ +#define NO_THE_INDEX_COMPATIBILITY_MACROS #include "cache.h" #include "cache-tree.h" #include "tree.h"
@@ -8,7 +9,11 @@const char *tree_type ="tree" ; -static int read_one_entry_opt (const unsigned char *sha1,const char *base,int baselen,const char *pathname,unsigned mode,int stage,int opt) +static int read_one_entry_opt (struct index_state *istate, +const unsigned char *sha1, +const char *base,int baselen, +const char *pathname, +unsigned mode,int stage,int opt) {int len;unsigned int size;
@@ -27,14 +32,15 @@ static int read_one_entry_opt(const unsigned char *sha1, const char *base, int bmemcpy (ce->name, base, baselen);memcpy (ce->name + baselen, pathname, len+1 );hashcpy (ce->oid.hash, sha1); -return add_cache_entry (ce, opt); +return add_index_entry (istate, ce, opt); }static int read_one_entry (const unsigned char *sha1,struct strbuf *base,const char *pathname,unsigned mode,int stage,void *context) { -return read_one_entry_opt (sha1, base->buf, base->len, pathname, +struct index_state *istate = context; +return read_one_entry_opt (istate, sha1, base->buf, base->len, pathname, mode, stage,ADD_CACHE_OK_TO_ADD |ADD_CACHE_SKIP_DFCHECK ); }
@@ -47,7 +53,8 @@ static int read_one_entry_quick(const unsigned char *sha1, struct strbuf *base, const char *pathname, unsigned mode, int stage, void *context) { - return read_one_entry_opt(sha1, base->buf, base->len, pathname, + struct index_state *istate = context; +return read_one_entry_opt (istate, sha1, base->buf, base->len, pathname, mode, stage,ADD_CACHE_JUST_APPEND ); }
@@ -144,7 +151,8 @@ static int cmp_cache_name_compare(const void *a_, const void *b_) ce2->name, ce2->ce_namelen, ce_stage(ce2)); } -int read_tree (struct tree *tree,int stage,struct pathspec *match) +int read_tree (struct tree *tree,int stage,struct pathspec *match, +struct index_state *istate) {read_tree_fn_t fn =NULL ;int i, err;
@@ -164,23 +172,23 @@ int read_tree(struct tree *tree, int stage, struct pathspec *match)* do it the original slow way, otherwise, append and then * sort at the end. */ -for (i =0 ; !fn && i < active_nr; i++) { -const struct cache_entry *ce = active_cache[i]; +for (i =0 ; !fn && i < istate->cache_nr; i++) { +const struct cache_entry *ce = istate->cache[i];if (ce_stage (ce) == stage) fn = read_one_entry; }if (!fn) fn = read_one_entry_quick; - err =read_tree_recursive (tree,"" ,0 , stage, match, fn,NULL ); + err =read_tree_recursive (tree,"" ,0 , stage, match, fn, istate);if (fn == read_one_entry || err)return err;/* * Sort the cache entry -- we need to nuke the cache tree, though. */ -cache_tree_free (&active_cache_tree); -QSORT (active_cache, active_nr, cmp_cache_name_compare); +cache_tree_free (&istate->cache_tree); +QSORT (istate->cache, istate->cache_nr, cmp_cache_name_compare);return 0 ; }
tree.h +2 -1
@@ -34,6 +34,7 @@ extern int read_tree_recursive(struct tree *tree, int stage, const struct pathspec *pathspec, read_tree_fn_t fn, void *context); -extern int read_tree (struct tree *tree,int stage,struct pathspec *pathspec); +extern int read_tree (struct tree *tree,int stage,struct pathspec *pathspec, +struct index_state *istate);#endif /* TREE_H */
Signature · 1 line
2.13.0.506.g27d5fe0cd-goog
PATCH 18/31 convert: convert convert_to_git to take an index
In reply to Brandon Williams--- apply.c | 2 +- builtin/blame.c | 2 +- combine-diff.c | 2 +- convert.c | 7 ++++--- convert.h | 8 +++++--- diff.c | 6 +++--- dir.c | 2 +- sha1_file.c | 4 ++-- 8 files changed, 18 insertions(+), 15 deletions(-)
apply.c +1 -1
@@ -2268,7 +2268,7 @@ static int read_old_data(struct stat *st, const char *path, struct strbuf *buf)case S_IFREG :if (strbuf_read_file (buf, path, st->st_size) != st->st_size)return error (_ ("unable to open or read %s" ), path); -convert_to_git (path, buf->buf, buf->len, buf,0 ); +convert_to_git (&the_index, path, buf->buf, buf->len, buf,0 );return 0 ;default :return -1 ;
builtin/blame.c +1 -1
@@ -2384,7 +2384,7 @@ static struct commit *fake_working_tree_commit(struct diff_options *opt,if (strbuf_read (&buf,0 ,0 ) <0 )die_errno ("failed to read from stdin" ); } -convert_to_git (path, buf.buf, buf.len, &buf,0 ); +convert_to_git (&the_index, path, buf.buf, buf.len, &buf,0 ); origin->file.ptr = buf.buf; origin->file.size = buf.len;pretend_sha1_file (buf.buf, buf.len,OBJ_BLOB , origin->blob_oid.hash);
combine-diff.c +1 -1
@@ -1053,7 +1053,7 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,if (is_file) {struct strbuf buf =STRBUF_INIT ; -if (convert_to_git (elem->path, result, len, &buf, safe_crlf)) { +if (convert_to_git (&the_index, elem->path, result, len, &buf, safe_crlf)) {free (result); result =strbuf_detach (&buf, &len); result_size = len;
convert.c +4 -3
@@ -1085,7 +1085,8 @@ const char *get_convert_attr_ascii(const char *path)return "" ; } -int convert_to_git (const char *path,const char *src,size_t len, +int convert_to_git (const struct index_state *istate, +const char *path,const char *src,size_t len,struct strbuf *dst,enum safe_crlf checksafe) {int ret =0 ;
@@ -1101,7 +1102,7 @@ int convert_to_git(const char *path, const char *src, size_t len, src = dst->buf; len = dst->len; } - ret |=crlf_to_git (&the_index, path, src, len, dst, ca.crlf_action, checksafe); + ret |=crlf_to_git (istate, path, src, len, dst, ca.crlf_action, checksafe);if (ret && dst) { src = dst->buf; len = dst->len;
@@ -1172,7 +1173,7 @@ int renormalize_buffer(const char *path, const char *src, size_t len, struct str src = dst->buf; len = dst->len; } -return ret |convert_to_git (path, src, len, dst,SAFE_CRLF_RENORMALIZE ); +return ret |convert_to_git (&the_index, path, src, len, dst,SAFE_CRLF_RENORMALIZE ); }/*****************************************************************
convert.h +5 -3
@@ -41,15 +41,17 @@ extern const char *get_wt_convert_stats_ascii(const char *path);extern const char *get_convert_attr_ascii (const char *path);/* returns 1 if *dst was used */ -extern int convert_to_git (const char *path,const char *src,size_t len, +extern int convert_to_git (const struct index_state *istate, +const char *path,const char *src,size_t len,struct strbuf *dst,enum safe_crlf checksafe);extern int convert_to_working_tree (const char *path,const char *src,size_t len,struct strbuf *dst);extern int renormalize_buffer (const char *path,const char *src,size_t len,struct strbuf *dst); -static inline int would_convert_to_git (const char *path) +static inline int would_convert_to_git (const struct index_state *istate, +const char *path) { -return convert_to_git (path,NULL ,0 ,NULL ,0 ); +return convert_to_git (istate, path,NULL ,0 ,NULL ,0 ); }/* Precondition: would_convert_to_git_filter_fd(path) == true */ extern void convert_to_git_filter_fd(const struct index_state *istate,
diff.c +3 -3
@@ -2756,7 +2756,7 @@ static int reuse_worktree_file(const char *name, const unsigned char *sha1, int* Similarly, if we'd have to convert the file contents anyway, that * makes the optimization not worthwhile. */ -if (!want_file &&would_convert_to_git (name)) +if (!want_file &&would_convert_to_git (&the_index, name))return 0 ; len =strlen (name);
@@ -2878,7 +2878,7 @@ int diff_populate_filespec(struct diff_filespec *s, unsigned int flags)* point if the path requires us to run the content * conversion. */ -if (size_only && !would_convert_to_git (s->path)) +if (size_only && !would_convert_to_git (&the_index, s->path))return 0 ;/*
@@ -2905,7 +2905,7 @@ int diff_populate_filespec(struct diff_filespec *s, unsigned int flags)/* * Convert from working tree format to canonical git format */ -if (convert_to_git (s->path, s->data, s->size, &buf, crlf_warn)) { +if (convert_to_git (&the_index, s->path, s->data, s->size, &buf, crlf_warn)) {size_t size =0 ;munmap (s->data, s->size); s->should_munmap =0 ;
dir.c +1 -1
@@ -796,7 +796,7 @@ static int add_excludes(const char *fname, const char *base, int baselen, (pos = index_name_pos(istate, fname, strlen(fname))) >= 0 && !ce_stage(istate->cache[pos]) && ce_uptodate(istate->cache[pos]) && - !would_convert_to_git(fname)) + !would_convert_to_git(istate, fname))hashcpy (sha1_stat->sha1, istate->cache[pos]->oid.hash); else
sha1_file.c +2 -2
@@ -3547,7 +3547,7 @@ static int index_mem(unsigned char *sha1, void *buf, size_t size,*/ if ((type ==OBJ_BLOB ) && path) {struct strbuf nbuf =STRBUF_INIT ; -if (convert_to_git (path, buf, size, &nbuf, +if (convert_to_git (&the_index, path, buf, size, &nbuf, write_object ? safe_crlf :SAFE_CRLF_FALSE )) { buf =strbuf_detach (&nbuf, &size); re_allocated =1 ;
@@ -3669,7 +3669,7 @@ int index_fd(unsigned char *sha1, int fd, struct stat *st,else if (!S_ISREG (st->st_mode)) ret =index_pipe (sha1, fd, type, path, flags);else if (st->st_size <= big_file_threshold || type !=OBJ_BLOB || - (path &&would_convert_to_git (path))) + (path &&would_convert_to_git (&the_index, path))) ret =index_core (sha1, fd,xsize_t (st->st_size), type, path, flags);else
Signature · 1 line
2.13.0.506.g27d5fe0cd-goog
PATCH 28/31 ls-files: convert show_files to take an index
In reply to Brandon Williams--- builtin/ls-files.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-)
builtin/ls-files.c +12 -12
@@ -329,7 +329,7 @@ static int ce_excluded(struct dir_struct *dir, struct index_state *istate,return is_excluded (dir, istate, ce->name, &dtype); } -static void show_files (struct dir_struct *dir) +static void show_files (struct index_state *istate,struct dir_struct *dir) {int i;
@@ -337,17 +337,17 @@ static void show_files(struct dir_struct *dir)if (show_others || show_killed) {if (!show_others) dir->flags |=DIR_COLLECT_KILLED_ONLY ; -fill_directory (dir, &the_index, &pathspec); +fill_directory (dir, istate, &pathspec);if (show_others) -show_other_files (&the_index, dir); +show_other_files (istate, dir);if (show_killed) -show_killed_files (&the_index, dir); +show_killed_files (istate, dir); }if (show_cached || show_stage) { -for (i =0 ; i < active_nr; i++) { -const struct cache_entry *ce = active_cache[i]; +for (i =0 ; i < istate->cache_nr; i++) { +const struct cache_entry *ce = istate->cache[i];if ((dir->flags &DIR_SHOW_IGNORED ) && - !ce_excluded (dir, &the_index, ce)) + !ce_excluded (dir, istate, ce))continue ;if (show_unmerged && !ce_stage (ce))continue ;
@@ -358,12 +358,12 @@ static void show_files(struct dir_struct *dir) } }if (show_deleted || show_modified) { -for (i =0 ; i < active_nr; i++) { -const struct cache_entry *ce = active_cache[i]; +for (i =0 ; i < istate->cache_nr; i++) { +const struct cache_entry *ce = istate->cache[i];struct stat st;int err;if ((dir->flags &DIR_SHOW_IGNORED ) && - !ce_excluded (dir, &the_index, ce)) + !ce_excluded (dir, istate, ce))continue ;if (ce->ce_flags &CE_UPDATE )continue ;
@@ -372,7 +372,7 @@ static void show_files(struct dir_struct *dir) err =lstat (ce->name, &st);if (show_deleted && err)show_ce_entry (tag_removed, ce); -if (show_modified &&ce_modified (ce, &st,0 )) +if (show_modified &&ie_modified (istate, ce, &st,0 ))show_ce_entry (tag_modified, ce); } }
@@ -686,7 +686,7 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix)die ("ls-files --with-tree is incompatible with -s or -u" );overlay_tree_on_index (&the_index, with_tree, max_prefix); } -show_files (&dir); +show_files (&the_index, &dir);if (show_resolve_undo)show_ru_info (&the_index);
Signature · 1 line
2.13.0.506.g27d5fe0cd-goog
PATCH 25/31 ls-files: convert show_ru_info to take an index
In reply to Brandon Williams--- builtin/ls-files.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
builtin/ls-files.c +4 -4
@@ -293,14 +293,14 @@ static void show_ce_entry(const char *tag, const struct cache_entry *ce)strbuf_release (&name); } -static void show_ru_info (void ) +static void show_ru_info (const struct index_state *istate) {struct string_list_item *item; -if (!the_index.resolve_undo) +if (!istate->resolve_undo)return ; -for_each_string_list_item (item, the_index.resolve_undo) { +for_each_string_list_item (item, istate->resolve_undo) {const char *path = item->string;struct resolve_undo_info *ui = item->util;int i, len;
@@ -686,7 +686,7 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix) }show_files (&dir);if (show_resolve_undo) -show_ru_info (); +show_ru_info (&the_index);if (ps_matched) {int bad;
Signature · 1 line
2.13.0.506.g27d5fe0cd-goog
PATCH 24/31 ls-files: convert show_other_files to take an index
In reply to Brandon Williams--- builtin/ls-files.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
builtin/ls-files.c +4 -3
@@ -109,13 +109,14 @@ static void show_dir_entry(const char *tag, struct dir_entry *ent)write_name (ent->name); } -static void show_other_files (struct dir_struct *dir) +static void show_other_files (const struct index_state *istate, +const struct dir_struct *dir) {int i;for (i =0 ; i < dir->nr; i++) {struct dir_entry *ent = dir->entries[i]; -if (!cache_name_is_other (ent->name, ent->len)) +if (!index_name_is_other (istate, ent->name, ent->len))continue ;show_dir_entry (tag_other, ent); }
@@ -337,7 +338,7 @@ static void show_files(struct dir_struct *dir) dir->flags |=DIR_COLLECT_KILLED_ONLY ;fill_directory (dir, &the_index, &pathspec);if (show_others) -show_other_files (dir); +show_other_files (&the_index, dir);if (show_killed)show_killed_files (&the_index, dir); }
Signature · 1 line
2.13.0.506.g27d5fe0cd-goog
PATCH 30/31 ls-files: factor out tag calculation
In reply to Brandon Williams--- builtin/ls-files.c | 41 +++++++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 16 deletions(-)
builtin/ls-files.c +25 -16
@@ -94,6 +94,30 @@ static void write_name(const char *name)strbuf_release (&full_name); } +static const char *get_tag (const struct cache_entry *ce,const char *tag) +{ +static char alttag[4 ]; + +if (tag && *tag && show_valid_bit && (ce->ce_flags &CE_VALID )) { +memcpy (alttag, tag,3 ); + +if (isalpha (tag[0 ])) { + alttag[0 ] =tolower (tag[0 ]); + }else if (tag[0 ] =='?' ) { + alttag[0 ] ='!' ; + }else { + alttag[0 ] ='v' ; + alttag[1 ] = tag[0 ]; + alttag[2 ] =' ' ; + alttag[3 ] =0 ; + } + + tag = alttag; + } + +return tag; +} +static void print_debug (const struct cache_entry *ce) {if (debug_mode) {
@@ -264,22 +288,7 @@ static void show_ce_entry(const char *tag, const struct cache_entry *ce) len, ps_matched, S_ISDIR(ce->ce_mode) || S_ISGITLINK(ce->ce_mode))) { -if (tag && *tag && show_valid_bit && - (ce->ce_flags &CE_VALID )) { -static char alttag[4 ]; -memcpy (alttag, tag,3 ); -if (isalpha (tag[0 ])) - alttag[0 ] =tolower (tag[0 ]); -else if (tag[0 ] =='?' ) - alttag[0 ] ='!' ; -else { - alttag[0 ] ='v' ; - alttag[1 ] = tag[0 ]; - alttag[2 ] =' ' ; - alttag[3 ] =0 ; - } - tag = alttag; - } + tag =get_tag (ce, tag);if (!show_stage) {fputs (tag, stdout);
Signature · 1 line
2.13.0.506.g27d5fe0cd-goog
PATCH 29/31 ls-files: factor out debug info into a function
In reply to Brandon Williams--- builtin/ls-files.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-)
builtin/ls-files.c +14 -9
@@ -94,6 +94,19 @@ static void write_name(const char *name)strbuf_release (&full_name); } +static void print_debug (const struct cache_entry *ce) +{ +if (debug_mode) { +const struct stat_data *sd = &ce->ce_stat_data; + +printf (" ctime: %d:%d\n" , sd->sd_ctime.sec, sd->sd_ctime.nsec); +printf (" mtime: %d:%d\n" , sd->sd_mtime.sec, sd->sd_mtime.nsec); +printf (" dev: %d\tino: %d\n" , sd->sd_dev, sd->sd_ino); +printf (" uid: %d\tgid: %d\n" , sd->sd_uid, sd->sd_gid); +printf (" size: %d\tflags: %x\n" , sd->sd_size, ce->ce_flags); + } +} +static void show_dir_entry (const char *tag,struct dir_entry *ent) {int len = max_prefix_len;
@@ -279,15 +292,7 @@ static void show_ce_entry(const char *tag, const struct cache_entry *ce) }write_eolinfo (&the_index, ce, ce->name);write_name (ce->name); -if (debug_mode) { -const struct stat_data *sd = &ce->ce_stat_data; - -printf (" ctime: %d:%d\n" , sd->sd_ctime.sec, sd->sd_ctime.nsec); -printf (" mtime: %d:%d\n" , sd->sd_mtime.sec, sd->sd_mtime.nsec); -printf (" dev: %d\tino: %d\n" , sd->sd_dev, sd->sd_ino); -printf (" uid: %d\tgid: %d\n" , sd->sd_uid, sd->sd_gid); -printf (" size: %d\tflags: %x\n" , sd->sd_size, ce->ce_flags); - } +print_debug (ce); }strbuf_release (&name);
Signature · 1 line
2.13.0.506.g27d5fe0cd-goog
PATCH 31/31 ls-files: use repository object
In reply to Brandon WilliamsConvert ls-files to use a repository struct and recurse submodules inprocess.
--- builtin/ls-files.c | 211 ++++++++++++++------------------- git.c | 2 +- repo.c | 3 + repo.h | 1 + t/t3007-ls-files-recurse-submodules.sh | 39 ++++++ 5 files changed, 135 insertions(+), 121 deletions(-)
builtin/ls-files.c +91 -120
@@ -5,6 +5,7 @@* * Copyright (C) Linus Torvalds, 2005 */ +#define NO_THE_INDEX_COMPATIBILITY_MACROS #include "cache.h" #include "config.h" #include "quote.h"
@@ -17,6 +18,7 @@#include "pathspec.h" #include "run-command.h" #include "submodule.h" +#include "repo.h" static int abbrev;static int show_deleted;
@@ -32,10 +34,8 @@ static int line_terminator = '\n';static int debug_mode;static int show_eol;static int recurse_submodules; -static struct argv_array submodule_options =ARGV_ARRAY_INIT ;static const char *prefix; -static const char *super_prefix;static int max_prefix_len;static int prefix_len;static struct pathspec pathspec;
@@ -73,25 +73,12 @@ static void write_eolinfo(const struct index_state *istate,static void write_name (const char *name) { -/* -* Prepend the super_prefix to name to construct the full_name to be -* written. -*/ -struct strbuf full_name =STRBUF_INIT ; -if (super_prefix) { -strbuf_addstr (&full_name, super_prefix); -strbuf_addstr (&full_name, name); - name = full_name.buf; - } -/* * With "--full-name", prefix_len=0; this caller needs to pass * an empty string in that case (a NULL is good for ""). */ write_name_quoted_relative (name, prefix_len ? prefix :NULL , stdout, line_terminator); - -strbuf_release (&full_name); }static const char *get_tag (const struct cache_entry *ce,const char *tag)
@@ -210,101 +197,59 @@ static void show_killed_files(const struct index_state *istate, } } -/* -* Compile an argv_array with all of the options supported by --recurse_submodules -*/ -static void compile_submodule_options (const char **argv, -const struct dir_struct *dir, -int show_tag) -{ -if (line_terminator =='\0' ) -argv_array_push (&submodule_options,"-z" ); -if (show_tag) -argv_array_push (&submodule_options,"-t" ); -if (show_valid_bit) -argv_array_push (&submodule_options,"-v" ); -if (show_cached) -argv_array_push (&submodule_options,"--cached" ); -if (show_eol) -argv_array_push (&submodule_options,"--eol" ); -if (debug_mode) -argv_array_push (&submodule_options,"--debug" ); - -/* Add Pathspecs */ -argv_array_push (&submodule_options,"--" ); -for (; *argv; argv++) -argv_array_push (&submodule_options, *argv); -} +static void show_files (struct repo *repo,struct dir_struct *dir); -/** -* Recursively call ls-files on a submodule -*/ -static void show_gitlink (const struct cache_entry *ce) +static void show_submodule (const struct repo *superproject, +struct dir_struct *dir,const char *path) { -struct child_process cp =CHILD_PROCESS_INIT ; -int status; -char *dir; - -prepare_submodule_repo_env (&cp.env_array); -argv_array_push (&cp.env_array,GIT_DIR_ENVIRONMENT ); - -if (prefix_len) -argv_array_pushf (&cp.env_array,"%s=%s" , -GIT_TOPLEVEL_PREFIX_ENVIRONMENT , - prefix); -argv_array_pushf (&cp.args,"--super-prefix=%s%s/" , - super_prefix ? super_prefix :"" , - ce->name); -argv_array_push (&cp.args,"ls-files" ); -argv_array_push (&cp.args,"--recurse-submodules" ); - -/* add supported options */ -argv_array_pushv (&cp.args, submodule_options.argv); - - cp.git_cmd =1 ; - dir =mkpathdup ("%s/%s" ,get_git_work_tree (), ce->name); - cp.dir = dir; - status =run_command (&cp); -free (dir); -if (status) -exit (status); +struct repo submodule; +char *gitdir =mkpathdup ("%s/%s" , superproject->worktree, path); +repo_init (&submodule, gitdir); + +repo_read_index (&submodule); +repo_read_gitmodules (&submodule); + +if (superproject->submodule_prefix) + submodule.submodule_prefix =xstrfmt ("%s%s/" , superproject->submodule_prefix, path); +else + submodule.submodule_prefix =xstrfmt ("%s/" , path); +show_files (&submodule, dir); + +repo_clear (&submodule); +free (gitdir); } -static void show_ce_entry (const char *tag,const struct cache_entry *ce) +static void show_ce (struct repo *repo,struct dir_struct *dir, +const struct cache_entry *ce,const char *fullname, +const char *tag) { -struct strbuf name =STRBUF_INIT ; -int len = max_prefix_len; -if (super_prefix) -strbuf_addstr (&name, super_prefix); -strbuf_addstr (&name, ce->name); - -if (len >ce_namelen (ce)) +if (max_prefix_len >strlen (fullname))die ("git ls-files: internal error - cache entry not superset of prefix" );if (recurse_submodules &&S_ISGITLINK (ce->ce_mode) && -submodule_path_match (&pathspec, name.buf, ps_matched)) { -show_gitlink (ce); - }else if (match_pathspec (&pathspec, name.buf, name.len, - len, ps_matched, +submodule_path_match (&pathspec, fullname, ps_matched) && +is_submodule_active (repo, ce->name)) { +show_submodule (repo, dir, ce->name); + }else if (match_pathspec (&pathspec, fullname,strlen (fullname), + max_prefix_len, ps_matched,S_ISDIR (ce->ce_mode) ||S_ISGITLINK (ce->ce_mode))) { tag =get_tag (ce, tag); -if (!show_stage) { -fputs (tag, stdout); - }else { +if (show_stage) {printf ("%s%06o %s %d\t" , tag, ce->ce_mode,find_unique_abbrev (ce->oid.hash, abbrev),ce_stage (ce)); + }else { +fputs (tag, stdout); } -write_eolinfo (&the_index, ce, ce->name); -write_name (ce->name); + +write_eolinfo (repo->index, ce, fullname); +write_name (fullname);print_debug (ce); } - -strbuf_release (&name); }static void show_ru_info (const struct index_state *istate)
@@ -337,59 +282,80 @@ static void show_ru_info(const struct index_state *istate) }static int ce_excluded (struct dir_struct *dir,struct index_state *istate, -const struct cache_entry *ce) +const char *fullname,const struct cache_entry *ce) {int dtype =ce_to_dtype (ce); -return is_excluded (dir, istate, ce->name, &dtype); +return is_excluded (dir, istate, fullname, &dtype); } -static void show_files (struct index_state *istate,struct dir_struct *dir) +static void construct_fullname (struct strbuf *out,const struct repo *repo, +const struct cache_entry *ce) +{ +strbuf_reset (out); +if (repo->submodule_prefix) +strbuf_addstr (out, repo->submodule_prefix); +strbuf_addstr (out, ce->name); + +} + +static void show_files (struct repo *repo,struct dir_struct *dir) {int i; +struct strbuf fullname =STRBUF_INIT ;/* For cached/deleted files we don't need to even do the readdir */ if (show_others || show_killed) {if (!show_others) dir->flags |=DIR_COLLECT_KILLED_ONLY ; -fill_directory (dir, istate, &pathspec); +fill_directory (dir, repo->index, &pathspec);if (show_others) -show_other_files (istate, dir); +show_other_files (repo->index, dir);if (show_killed) -show_killed_files (istate, dir); +show_killed_files (repo->index, dir); }if (show_cached || show_stage) { -for (i =0 ; i < istate->cache_nr; i++) { -const struct cache_entry *ce = istate->cache[i]; +for (i =0 ; i < repo->index->cache_nr; i++) { +const struct cache_entry *ce = repo->index->cache[i]; + +construct_fullname (&fullname, repo, ce); +if ((dir->flags &DIR_SHOW_IGNORED ) && - !ce_excluded (dir, istate, ce)) + !ce_excluded (dir, repo->index, fullname.buf, ce))continue ;if (show_unmerged && !ce_stage (ce))continue ;if (ce->ce_flags &CE_UPDATE )continue ; -show_ce_entry (ce_stage (ce) ? tag_unmerged : - (ce_skip_worktree (ce) ? tag_skip_worktree : tag_cached), ce); +show_ce (repo, dir, ce, fullname.buf, +ce_stage (ce) ? tag_unmerged : + (ce_skip_worktree (ce) ? tag_skip_worktree : + tag_cached)); } }if (show_deleted || show_modified) { -for (i =0 ; i < istate->cache_nr; i++) { -const struct cache_entry *ce = istate->cache[i]; +for (i =0 ; i < repo->index->cache_nr; i++) { +const struct cache_entry *ce = repo->index->cache[i];struct stat st;int err; + +construct_fullname (&fullname, repo, ce); +if ((dir->flags &DIR_SHOW_IGNORED ) && - !ce_excluded (dir, istate, ce)) + !ce_excluded (dir, repo->index, fullname.buf, ce))continue ;if (ce->ce_flags &CE_UPDATE )continue ;if (ce_skip_worktree (ce))continue ; - err =lstat (ce->name, &st); + err =lstat (fullname.buf, &st);if (show_deleted && err) -show_ce_entry (tag_removed, ce); -if (show_modified &&ie_modified (istate, ce, &st,0 )) -show_ce_entry (tag_modified, ce); +show_ce (repo, dir, ce, fullname.buf, tag_removed); +if (show_modified &&ie_modified (repo->index, ce, &st,0 )) +show_ce (repo, dir, ce, fullname.buf, tag_modified); } } + +strbuf_release (&fullname); }/*
@@ -544,7 +510,7 @@ static int option_parse_exclude_standard(const struct option *opt,int cmd_ls_files (int argc,const char **argv,const char *cmd_prefix) {int require_work_tree =0 , show_tag =0 , i; -const char *max_prefix; +char *max_prefix;struct dir_struct dir;struct exclude_list *el;struct string_list exclude_list =STRING_LIST_INIT_NODUP ;
@@ -614,11 +580,9 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix) prefix = cmd_prefix;if (prefix) prefix_len =strlen (prefix); - super_prefix =get_super_prefix ();git_config (git_default_config,NULL ); -if (read_cache () <0 ) -die ("index file corrupt" ); +repo_read_index (&the_repository); argc =parse_options (argc, argv, prefix, builtin_ls_files_options, ls_files_usage,0 );
@@ -650,12 +614,14 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix)if (require_work_tree && !is_inside_work_tree ())setup_work_tree (); -if (recurse_submodules) -compile_submodule_options (argv, &dir, show_tag); +if (recurse_submodules) { +repo_read_gitmodules (&the_repository); + }if (recurse_submodules && (show_stage || show_deleted || show_others || show_unmerged || - show_killed || show_modified || show_resolve_undo || with_tree)) + show_killed || show_modified || show_resolve_undo || with_tree || + show_eol))die ("ls-files --recurse-submodules unsupported mode" );if (recurse_submodules && error_unmatch)
@@ -669,7 +635,10 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix)/* * Find common prefix for all pathspec's * This is used as a performance optimization which unfortunately cannot -* be done when recursing into submodules +* be done when recursing into submodules because when a pathspec is +* given which spans repository boundaries you can't simply remove the +* submodule entry because the pathspec may match something inside the +* submodule. */ if (recurse_submodules) max_prefix =NULL ;
@@ -677,7 +646,7 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix) max_prefix =common_prefix (&pathspec); max_prefix_len =get_common_prefix_len (max_prefix); -prune_index (&the_index, max_prefix, max_prefix_len); +prune_index (the_repository.index, max_prefix, max_prefix_len);/* Treat unmatching pathspec elements as errors */ if (pathspec.nr && error_unmatch)
@@ -698,11 +667,13 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix)*/ if (show_stage || show_unmerged)die ("ls-files --with-tree is incompatible with -s or -u" ); -overlay_tree_on_index (&the_index, with_tree, max_prefix); +overlay_tree_on_index (the_repository.index, with_tree, max_prefix); } -show_files (&the_index, &dir); + +show_files (&the_repository, &dir); +if (show_resolve_undo) -show_ru_info (&the_index); +show_ru_info (the_repository.index);if (ps_matched) {int bad;
git.c +1 -1
@@ -442,7 +442,7 @@ static struct cmd_struct commands[] = { { "init-db", cmd_init_db }, { "interpret-trailers", cmd_interpret_trailers, RUN_SETUP_GENTLY }, { "log", cmd_log, RUN_SETUP }, - { "ls-files", cmd_ls_files, RUN_SETUP | SUPPORT_SUPER_PREFIX }, + { "ls-files", cmd_ls_files, RUN_SETUP }, { "ls-remote", cmd_ls_remote, RUN_SETUP_GENTLY }, { "ls-tree", cmd_ls_tree, RUN_SETUP }, { "mailinfo", cmd_mailinfo, RUN_SETUP_GENTLY },
repo.c +3 -0
@@ -154,6 +154,7 @@ int repo_init(struct repo *repo, const char *gitdir) }repo_set_gitdir (repo, resolved_gitdir); +repo_set_worktree (repo, gitdir);/* NEEDSWORK: Verify repository format version */
@@ -169,6 +170,8 @@ void repo_clear(struct repo *repo)repo_clear_env (repo);free (repo->worktree); repo->worktree =NULL ; +free (repo->submodule_prefix); + repo->submodule_prefix =NULL ;if (repo->config) {git_configset_clear (repo->config);
repo.h +1 -0
@@ -14,6 +14,7 @@ struct repo {char *graft_file;char *namespace;char *worktree; +char *submodule_prefix;/* Subsystems */ /*
t/t3007-ls-files-recurse-submodules.sh +39 -0
@@ -135,6 +135,45 @@ test_expect_success '--recurse-submodules and pathspecs setup' ' test_cmp expect actual ' +test_expect_success 'inactive submodule' ' + test_when_finished "git config --bool submodule.submodule.active true" && + test_when_finished "git -C submodule config --bool submodule.subsub.active true" && + git config --bool submodule.submodule.active "false" && + + cat >expect <<-\EOF && + .gitmodules + a + b/b + h.txt + sib/file + sub/file + submodule + EOF + + git ls-files --recurse-submodules >actual && + test_cmp expect actual && + + git config --bool submodule.submodule.active "true" && + git -C submodule config --bool submodule.subsub.active "false" && + + cat >expect <<-\EOF && + .gitmodules + a + b/b + h.txt + sib/file + sub/file + submodule/.gitmodules + submodule/c + submodule/f.TXT + submodule/g.txt + submodule/subsub + EOF + + git ls-files --recurse-submodules >actual && + test_cmp expect actual +' + test_expect_success '--recurse-submodules and pathspecs' ' cat >expect <<-\EOF && h.txt
Signature · 1 line
2.13.0.506.g27d5fe0cd-goog
PATCH 23/31 ls-files: convert show_killed_files to take an index
In reply to Brandon Williams--- builtin/ls-files.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-)
builtin/ls-files.c +11 -10
@@ -121,7 +121,8 @@ static void show_other_files(struct dir_struct *dir) } } -static void show_killed_files (struct dir_struct *dir) +static void show_killed_files (const struct index_state *istate, +const struct dir_struct *dir) {int i;for (i =0 ; i < dir->nr; i++) {
@@ -135,29 +136,29 @@ static void show_killed_files(struct dir_struct *dir)/* If ent->name is prefix of an entry in the * cache, it will be killed. */ - pos =cache_name_pos (ent->name, ent->len); + pos =index_name_pos (istate, ent->name, ent->len);if (0 <= pos)die ("BUG: killed-file %.*s not found" , ent->len, ent->name); pos = -pos -1 ; -while (pos < active_nr && -ce_stage (active_cache[pos])) +while (pos < istate->cache_nr && +ce_stage (istate->cache[pos])) pos++;/* skip unmerged */ -if (active_nr <= pos) +if (istate->cache_nr <= pos)break ;/* pos points at a name immediately after * ent->name in the cache. Does it expect * ent->name to be a directory? */ - len =ce_namelen (active_cache[pos]); + len =ce_namelen (istate->cache[pos]);if ((ent->len < len) && - !strncmp (active_cache[pos]->name, + !strncmp (istate->cache[pos]->name, ent->name, ent->len) && - active_cache[pos]->name[ent->len] =='/' ) + istate->cache[pos]->name[ent->len] =='/' ) killed =1 ;break ; } -if (0 <=cache_name_pos (ent->name, sp - ent->name)) { +if (0 <=index_name_pos (istate, ent->name, sp - ent->name)) {/* If any of the leading directories in * ent->name is registered in the cache, * ent->name will be killed.
@@ -338,7 +339,7 @@ static void show_files(struct dir_struct *dir)if (show_others)show_other_files (dir);if (show_killed) -show_killed_files (dir); +show_killed_files (&the_index, dir); }if (show_cached || show_stage) {for (i =0 ; i < active_nr; i++) {
Signature · 1 line
2.13.0.506.g27d5fe0cd-goog
PATCH 27/31 ls-files: convert prune_cache to take an index
In reply to Brandon Williams--- builtin/ls-files.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-)
builtin/ls-files.c +8 -7
@@ -381,30 +381,31 @@ static void show_files(struct dir_struct *dir)/* * Prune the index to only contain stuff starting with "prefix" */ -static void prune_cache (const char *prefix,size_t prefixlen) +static void prune_index (struct index_state *istate, +const char *prefix,size_t prefixlen) {int pos;unsigned int first, last;if (!prefix)return ; - pos =cache_name_pos (prefix, prefixlen); + pos =index_name_pos (istate, prefix, prefixlen);if (pos <0 ) pos = -pos-1 ; first = pos; - last = active_nr; + last = istate->cache_nr;while (last > first) {int next = (last + first) >>1 ; -const struct cache_entry *ce = active_cache[next]; +const struct cache_entry *ce = istate->cache[next];if (!strncmp (ce->name, prefix, prefixlen)) { first = next+1 ;continue ; } last = next; } -memmove (active_cache, active_cache + pos, +memmove (istate->cache, istate->cache + pos, (last - pos) *sizeof (struct cache_entry *)); - active_nr = last - pos; + istate->cache_nr = last - pos; }static int get_common_prefix_len (const char *common_prefix)
@@ -662,7 +663,7 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix) max_prefix =common_prefix (&pathspec); max_prefix_len =get_common_prefix_len (max_prefix); -prune_cache (max_prefix, max_prefix_len); +prune_index (&the_index, max_prefix, max_prefix_len);/* Treat unmatching pathspec elements as errors */ if (pathspec.nr && error_unmatch)
Signature · 1 line
2.13.0.506.g27d5fe0cd-goog
PATCH 26/31 ls-files: convert ce_excluded to take an index
In reply to Brandon Williams--- builtin/ls-files.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
builtin/ls-files.c +5 -4
@@ -322,10 +322,11 @@ static void show_ru_info(const struct index_state *istate) } } -static int ce_excluded (struct dir_struct *dir,const struct cache_entry *ce) +static int ce_excluded (struct dir_struct *dir,struct index_state *istate, +const struct cache_entry *ce) {int dtype =ce_to_dtype (ce); -return is_excluded (dir, &the_index, ce->name, &dtype); +return is_excluded (dir, istate, ce->name, &dtype); }static void show_files (struct dir_struct *dir)
@@ -346,7 +347,7 @@ static void show_files(struct dir_struct *dir)for (i =0 ; i < active_nr; i++) {const struct cache_entry *ce = active_cache[i];if ((dir->flags &DIR_SHOW_IGNORED ) && - !ce_excluded (dir, ce)) + !ce_excluded (dir, &the_index, ce))continue ;if (show_unmerged && !ce_stage (ce))continue ;
@@ -362,7 +363,7 @@ static void show_files(struct dir_struct *dir)struct stat st;int err;if ((dir->flags &DIR_SHOW_IGNORED ) && - !ce_excluded (dir, ce)) + !ce_excluded (dir, &the_index, ce))continue ;if (ce->ce_flags &CE_UPDATE )continue ;
Signature · 1 line
2.13.0.506.g27d5fe0cd-goog
PATCH 17/31 convert: convert convert_to_git_filter_fd to take an index
In reply to Brandon Williams--- convert.c | 5 +++-- convert.h | 3 ++- sha1_file.c | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-)
convert.c +3 -2
@@ -1109,7 +1109,8 @@ int convert_to_git(const char *path, const char *src, size_t len,return ret |ident_to_git (path, src, len, dst, ca.ident); } -void convert_to_git_filter_fd (const char *path,int fd,struct strbuf *dst, +void convert_to_git_filter_fd (const struct index_state *istate, +const char *path,int fd,struct strbuf *dst,enum safe_crlf checksafe) {struct conv_attrs ca;
@@ -1121,7 +1122,7 @@ void convert_to_git_filter_fd(const char *path, int fd, struct strbuf *dst,if (!apply_filter (path,NULL ,0 , fd, dst, ca.drv,CAP_CLEAN ))die ("%s: clean filter '%s' failed" , path, ca.drv->name); -crlf_to_git (&the_index, path, dst->buf, dst->len, dst, ca.crlf_action, checksafe); +crlf_to_git (istate, path, dst->buf, dst->len, dst, ca.crlf_action, checksafe);ident_to_git (path, dst->buf, dst->len, dst, ca.ident); }
convert.h +2 -1
@@ -52,7 +52,8 @@ static inline int would_convert_to_git(const char *path)return convert_to_git (path,NULL ,0 ,NULL ,0 ); }/* Precondition: would_convert_to_git_filter_fd(path) == true */ -extern void convert_to_git_filter_fd (const char *path,int fd, +extern void convert_to_git_filter_fd (const struct index_state *istate, +const char *path,int fd,struct strbuf *dst,enum safe_crlf checksafe);extern int would_convert_to_git_filter_fd (const char *path);
sha1_file.c +1 -1
@@ -3581,7 +3581,7 @@ static int index_stream_convert_blob(unsigned char *sha1, int fd,assert (path);assert (would_convert_to_git_filter_fd (path)); -convert_to_git_filter_fd (path, fd, &sbuf, +convert_to_git_filter_fd (&the_index, path, fd, &sbuf, write_object ? safe_crlf :SAFE_CRLF_FALSE );if (write_object)
Signature · 1 line
2.13.0.506.g27d5fe0cd-goog
PATCH 10/31 config: migrate the_configset to the_repository
In reply to Brandon WilliamsMigrate the default config to be stored within 'the_repository'.
--- config.c | 185 ++++++++++++++++++++++++++++++++++++++------------------------- config.h | 1 + repo.c | 21 ++++++++ repo.h | 11 ++++ 4 files changed, 146 insertions(+), 72 deletions(-)
config.c +113 -72
@@ -7,6 +7,7 @@*/ #include "cache.h" #include "config.h" +#include "repo.h" #include "lockfile.h" #include "exec_cmd.h" #include "strbuf.h"
@@ -72,13 +73,6 @@ static int core_compression_seen;static int pack_compression_seen;static int zlib_compression_seen; -/* -* Default config_set that contains key-value pairs from the usual set of config -* config files (i.e repo specific .git/config, user wide ~/.gitconfig, XDG -* config file and the global /etc/gitconfig) -*/ -static struct config_set the_config_set; -static int config_file_fgetc (struct config_source *conf) {return getc_unlocked (conf->u.file);
@@ -1606,28 +1600,6 @@ int git_config_with_options(config_fn_t fn, void *data,return do_git_config_sequence (opts, fn, data); } -static void git_config_raw (config_fn_t fn,void *data) -{ -struct config_options opts = {0 }; - - opts.respect_includes =1 ; -if (have_git_dir ()) - opts.git_dir =get_git_common_dir (); -if (git_config_with_options (fn, data,NULL , &opts) <0 ) -/* -* git_config_with_options() normally returns only -* zero, as most errors are fatal, and -* non-fatal potential errors are guarded by "if" -* statements that are entered only when no error is -* possible. -* -* If we ever encounter a non-fatal error, it means -* something went really wrong and we should stop -* immediately. -*/ -die (_ ("unknown error occurred while reading the configuration files" )); -} -static void configset_iter (struct config_set *cs,config_fn_t fn,void *data) {int i, value_index;
@@ -1676,14 +1648,6 @@ void read_early_config(config_fn_t cb, void *data)strbuf_release (&buf); } -static void git_config_check_init (void ); - -void git_config (config_fn_t fn,void *data) -{ -git_config_check_init (); -configset_iter (&the_config_set, fn, data); -} -static struct config_set_element *configset_find_element (struct config_set *cs,const char *key) {struct config_set_element k;
@@ -1782,7 +1746,7 @@ void git_configset_clear(struct config_set *cs) cs->list.items =NULL ; } -static int config_set_callback (const char *key,const char *value,void *cb) +int config_set_callback (const char *key,const char *value,void *cb) {struct config_set *cs = cb;configset_add_value (cs, key, value);
@@ -1893,87 +1857,164 @@ int git_configset_get_pathname(struct config_set *cs, const char *key, const chareturn 1 ; } -static void git_config_check_init (void ) +/* Functions use to read configuration from a repository */ +static void git_config_check_init (struct repo *repository) { -if (the_config_set.hash_initialized) +if (repository->config && repository->config->hash_initialized)return ; -git_configset_init (&the_config_set); -git_config_raw (config_set_callback, &the_config_set); +repo_read_config (repository); } -void git_config_clear (void ) +static void repo_config_clear (struct repo *repository) { -if (!the_config_set.hash_initialized) +if (!repository->config || !repository->config->hash_initialized)return ; -git_configset_clear (&the_config_set); +git_configset_clear (repository->config); } -int git_config_get_value (const char *key,const char **value) +static void repo_config (struct repo *repository,config_fn_t fn,void *data) { -git_config_check_init (); -return git_configset_get_value (&the_config_set, key, value); +git_config_check_init (repository); +configset_iter (repository->config, fn, data); } -const struct string_list *git_config_get_value_multi (const char *key) +static int repo_config_get_value (struct repo *repository, +const char *key,const char **value) { -git_config_check_init (); -return git_configset_get_value_multi (&the_config_set, key); +git_config_check_init (repository); +return git_configset_get_value (repository->config, key, value); } -int git_config_get_string_const (const char *key,const char **dest) +static const struct string_list *repo_config_get_value_multi (struct repo *repository, +const char *key) +{ +git_config_check_init (repository); +return git_configset_get_value_multi (repository->config, key); +} + +static int repo_config_get_string_const (struct repo *repository, +const char *key,const char **dest) {int ret; -git_config_check_init (); - ret =git_configset_get_string_const (&the_config_set, key, dest); +git_config_check_init (repository); + ret =git_configset_get_string_const (repository->config, key, dest);if (ret <0 )git_die_config (key,NULL );return ret; } +static int repo_config_get_string (struct repo *repository, +const char *key,char **dest) +{ +git_config_check_init (repository); +return repo_config_get_string_const (repository, key, (const char **)dest); +} + +static int repo_config_get_int (struct repo *repository, +const char *key,int *dest) +{ +git_config_check_init (repository); +return git_configset_get_int (repository->config, key, dest); +} + +static int repo_config_get_ulong (struct repo *repository, +const char *key,unsigned long *dest) +{ +git_config_check_init (repository); +return git_configset_get_ulong (repository->config, key, dest); +} + +static int repo_config_get_bool (struct repo *repository, +const char *key,int *dest) +{ +git_config_check_init (repository); +return git_configset_get_bool (repository->config, key, dest); +} + +static int repo_config_get_bool_or_int (struct repo *repository, +const char *key,int *is_bool,int *dest) +{ +git_config_check_init (repository); +return git_configset_get_bool_or_int (repository->config, key, is_bool, dest); +} + +static int repo_config_get_maybe_bool (struct repo *repository, +const char *key,int *dest) +{ +git_config_check_init (repository); +return git_configset_get_maybe_bool (repository->config, key, dest); +} + +static int repo_config_get_pathname (struct repo *repository, +const char *key,const char **dest) +{ +int ret; +git_config_check_init (repository); + ret =git_configset_get_pathname (repository->config, key, dest); +if (ret <0 ) +git_die_config (key,NULL ); +return ret; +} + +/* Functions used historically to read configuration from 'the_repository' */ +void git_config (config_fn_t fn,void *data) +{ +repo_config (&the_repository, fn, data); +} + +void git_config_clear (void ) +{ +repo_config_clear (&the_repository); +} + +int git_config_get_value (const char *key,const char **value) +{ +return repo_config_get_value (&the_repository, key, value); +} + +const struct string_list *git_config_get_value_multi (const char *key) +{ +return repo_config_get_value_multi (&the_repository, key); +} + +int git_config_get_string_const (const char *key,const char **dest) +{ +return repo_config_get_string_const (&the_repository, key, dest); +} +int git_config_get_string (const char *key,char **dest) { -git_config_check_init (); -return git_config_get_string_const (key, (const char **)dest); +return repo_config_get_string (&the_repository, key, dest); }int git_config_get_int (const char *key,int *dest) { -git_config_check_init (); -return git_configset_get_int (&the_config_set, key, dest); +return repo_config_get_int (&the_repository, key, dest); }int git_config_get_ulong (const char *key,unsigned long *dest) { -git_config_check_init (); -return git_configset_get_ulong (&the_config_set, key, dest); +return repo_config_get_ulong (&the_repository, key, dest); }int git_config_get_bool (const char *key,int *dest) { -git_config_check_init (); -return git_configset_get_bool (&the_config_set, key, dest); +return repo_config_get_bool (&the_repository, key, dest); }int git_config_get_bool_or_int (const char *key,int *is_bool,int *dest) { -git_config_check_init (); -return git_configset_get_bool_or_int (&the_config_set, key, is_bool, dest); +return repo_config_get_bool_or_int (&the_repository, key, is_bool, dest); }int git_config_get_maybe_bool (const char *key,int *dest) { -git_config_check_init (); -return git_configset_get_maybe_bool (&the_config_set, key, dest); +return repo_config_get_maybe_bool (&the_repository, key, dest); }int git_config_get_pathname (const char *key,const char **dest) { -int ret; -git_config_check_init (); - ret =git_configset_get_pathname (&the_config_set, key, dest); -if (ret <0 ) -git_die_config (key,NULL ); -return ret; +return repo_config_get_pathname (&the_repository, key, dest); }int git_config_get_expiry (const char *key,const char **output)
config.h +1 -0
@@ -149,6 +149,7 @@ struct config_set { };extern void git_configset_init (struct config_set *cs); +extern int config_set_callback (const char *key,const char *value,void *cb);extern int git_configset_add_file (struct config_set *cs,const char *filename);extern int git_configset_get_value (struct config_set *cs,const char *key,const char **value);extern const struct string_list *git_configset_get_value_multi (struct config_set *cs,const char *key);
repo.c +21 -0
@@ -1,5 +1,6 @@#include "cache.h" #include "repo.h" +#include "config.h" /* * This may be the wrong place for this.
@@ -89,6 +90,20 @@ void repo_set_worktree(struct repo *repo, const char *path) repo->worktree =real_pathdup (path,1 ); } +void repo_read_config (struct repo *repo) +{ +struct config_options opts = {1 , repo->commondir }; + +if (!repo->config) + repo->config =xcalloc (1 ,sizeof (struct config_set )); +else +git_configset_clear (repo->config); + +git_configset_init (repo->config); + +git_config_with_options (config_set_callback, repo->config,NULL , &opts); +} +int repo_init (struct repo *repo,const char *gitdir) {int error =0 ;
@@ -128,4 +143,10 @@ void repo_clear(struct repo *repo)repo_clear_env (repo);free (repo->worktree); repo->worktree =NULL ; + +if (repo->config) { +git_configset_clear (repo->config); +free (repo->config); + repo->config =NULL ; + } }
repo.h +11 -0
@@ -1,6 +1,8 @@ #ifndef REPO_H #define REPO_H +struct config_set; + struct repo { /* Environment */ char *gitdir;
@@ -11,6 +13,14 @@ struct repo {char *namespace;char *worktree; +/* Subsystems */ +/* +* Repository's config which contains key-value pairs from the usual +* set of config config files (i.e repo specific .git/config, user wide +* ~/.gitconfig, XDG config file and the global /etc/gitconfig) +*/ +struct config_set *config; +/* Configurations */ unsigned ignore_env:1;/* Indicates if a repository has a different 'commondir' from 'gitdir' */
@@ -21,6 +31,7 @@ extern struct repo the_repository;extern void repo_set_gitdir (struct repo *repo,const char *path);extern void repo_set_worktree (struct repo *repo,const char *path); +extern void repo_read_config (struct repo *repo);extern int repo_init (struct repo *repo,const char *path);extern void repo_clear (struct repo *repo);
Signature · 1 line
2.13.0.506.g27d5fe0cd-goog
PATCH 4/31 setup: don't perform lazy initialization of repository state
In reply to Brandon WilliamsUnder some circumstances (bogus GIT_DIR value or the discovered gitdir is '.git') 'setup_git_directory()' won't initialize key repository state. This leads to inconsistent state after running the setup code. To account for this inconsistent state, lazy initialization is done once a caller asks for the repository's gitdir or some other piece of repository state. This is confusing and can be error prone.
Instead let's tighten the expected outcome of 'setup_git_directory()' and ensure that it initializes repository state in all cases that would have been handled by lazy initialization.
This also lets us drop the requirement to have 'have_git_dir()' check if the environment variable GIT_DIR was set as that will be handled by the end of the setup code.
--- cache.h | 2 ++ environment.c | 17 ++++++++--------- setup.c | 14 ++++++++++++++ 3 files changed, 24 insertions(+), 9 deletions(-)
cache.h +2 -0
@@ -462,6 +462,8 @@ static inline enum object_type object_type(unsigned int mode)*/ extern const char *const local_repo_env[]; +extern void setup_git_env (void ); +/* * Returns true iff we have a configured git repository (either via * setup_git_directory, or in the environment via $GIT_DIR).
environment.c +8 -9
@@ -160,7 +160,7 @@ static char *git_path_from_env(const char *envvar, const char *git_dir,return xstrdup (value); } -static void setup_git_env (void ) +void setup_git_env (void ) {struct strbuf sb =STRBUF_INIT ;const char *gitfile;
@@ -205,28 +205,27 @@ int is_bare_repository(void)int have_git_dir (void ) {return startup_info->have_repository - || git_dir - ||getenv (GIT_DIR_ENVIRONMENT ); + || git_dir; }const char *get_git_dir (void ) {if (!git_dir) -setup_git_env (); +BUG ("git environment hasn't been setup" );return git_dir; }const char *get_git_common_dir (void ) {if (!git_dir) -setup_git_env (); +BUG ("git environment hasn't been setup" );return git_common_dir; }const char *get_git_namespace (void ) {if (!namespace) -setup_git_env (); +BUG ("git environment hasn't been setup" );return namespace; }
@@ -276,7 +275,7 @@ const char *get_git_work_tree(void)char *get_object_directory (void ) {if (!git_object_dir) -setup_git_env (); +BUG ("git environment hasn't been setup" );return git_object_dir; }
@@ -316,14 +315,14 @@ int odb_pack_keep(const char *name)char *get_index_file (void ) {if (!git_index_file) -setup_git_env (); +BUG ("git environment hasn't been setup" );return git_index_file; }char *get_graft_file (void ) {if (!git_graft_file) -setup_git_env (); +BUG ("git environment hasn't been setup" );return git_graft_file; }
setup.c +14 -0
@@ -1063,6 +1063,20 @@ const char *setup_git_directory_gently(int *nongit_ok) startup_info->have_repository = !nongit_ok || !*nongit_ok; startup_info->prefix = prefix; +/* +* Not all paths through the setup code will call 'set_git_dir()' (which +* directly sets up the environment) so in order to guarantee that the +* environment is in a consistent state after setup, explicitly setup +* the environment if we have a repository. +* +* NEEDSWORK: currently we allow bogus GIT_DIR values to be set in some +* code paths so we also need to explicitly setup the environment if +* the user has set GIT_DIR. It may be beneficial to disallow bogus +* GIT_DIR values at some point in the future. +*/ +if (startup_info->have_repository ||getenv (GIT_DIR_ENVIRONMENT )) +setup_git_env (); +strbuf_release (&dir);strbuf_release (&gitdir);
Signature · 1 line
2.13.0.506.g27d5fe0cd-goog
PATCH 9/31 setup: add comment indicating a hack
In reply to Brandon Williams'GIT_TOPLEVEL_PREFIX_ENVIRONMENT' was added in (b58a68c1c setup: allow for prefix to be passed to git commands) to aid in fixing a bug where 'ls-files' and 'grep' were not able to properly recurse when called from within a subdirectory. Add a 'NEEDSWORK' comment indicating that this envvar should be removed once 'ls-files' and 'grep' can recurse in-process.
--- setup.c | 6 ++++++ 1 file changed, 6 insertions(+)
setup.c +6 -0
@@ -1057,6 +1057,12 @@ const char *setup_git_directory_gently(int *nongit_ok)die ("BUG: unhandled setup_git_directory_1() result" ); } +/* +* NEEDSWORK: This was a hack in order to get ls-files and grep to have +* properly formated output when recursing submodules. Once ls-files +* and grep have been changed to perform this recursing in-process this +* needs to be removed. +*/ env_prefix =getenv (GIT_TOPLEVEL_PREFIX_ENVIRONMENT );if (env_prefix) prefix = env_prefix;
Signature · 1 line
2.13.0.506.g27d5fe0cd-goog
Quoted 11 lines · Brandon Williams
Given the vast interest expressed when I sent out my RFC series I decided it would be worth it to invest more time to making a repository object a reality.
This series is an extension of the last series I sent out (in that ls-files is converted to working on submodules in-process using repository objects instead of spawning a child process to do the work). The big difference from the RFC series is that I went through and did the work to migrate key repository state from global variables in '
environment.c' to being stored in a repository object itself. I migrated the bits of state that seemed reasonable for this series, there is still a lot of global state which could be migrated in the future.
Quoted 4 lines
I do think that we need to be slightly cautious about moving global state into the repository object though, I don't want 'struct repo' to simply become a kitchen sink where everything gets dumped. But this is just a warning for the future.
Or in other words:
You want to have another struct e.g. 'the_command_line_arguments', which would carry the verbosity/color options for example as they are not related to a repo object, but to the current command being run?
Quoted 5 lines
Since this is a v1 I'm fairly certain that it still has a lot of rough edges (like I think I need to write better commit messages, and we should probably have more comments documenting object fields/contract) but I want to get the review process started sooner rather than later since I'm sure people will have opinions (e.g. should it be called 'struct repo' or 'struct repository'?!).
IMHO this is the most obvious, but bikesheddable part of the series. ;) Keep it short as everyone knows what a 'repo' is.
Quoted 17 lines · Stefan Beller
Quoted 11 lines · Brandon Williams
Given the vast interest expressed when I sent out my RFC series I decided it would be worth it to invest more time to making a repository object a reality.
This series is an extension of the last series I sent out (in that ls-files is converted to working on submodules in-process using repository objects instead of spawning a child process to do the work). The big difference from the RFC series is that I went through and did the work to migrate key repository state from global variables in '
environment.c' to being stored in a repository object itself. I migrated the bits of state that seemed reasonable for this series, there is still a lot of global state which could be migrated in the future.Quoted 4 lines
I do think that we need to be slightly cautious about moving global state into the repository object though, I don't want 'struct repo' to simply become a kitchen sink where everything gets dumped. But this is just a warning for the future.
Quoted 4 lines
Or in other words:
You want to have another struct e.g. 'the_command_line_arguments', which would carry the verbosity/color options for example as they are not related to a repo object, but to the current command being run?
Yes exactly. Library code that needs to operate on a repository would then be able to take arguments like:
some_library_function(struct repo *repo, struct lib_opts *ops)
Much like how the grep machinery takes a grep_opts struct.
Quoted 8 lines
Quoted 6 lines
Since this is a v1 I'm fairly certain that it still has a lot of rough edges (like I think I need to write better commit messages, and we should probably have more comments documenting object fields/contract) but I want to get the review process started sooner rather than later since I'm sure people will have opinions (e.g. should it be called 'struct repo' or 'struct repository'?!).
IMHO this is the most obvious, but bikesheddable part of the series. ;)
I know, that's why I mentioned it ;)
Quoted 1 line
Keep it short as everyone knows what a 'repo' is.
Signature · 1 line
Brandon Williams
Quoted 25 lines · Brandon Williams
Given the vast interest expressed when I sent out my RFC series I decided it would be worth it to invest more time to making a repository object a reality.
This series is an extension of the last series I sent out (in that ls-files is converted to working on submodules in-process using repository objects instead of spawning a child process to do the work). The big difference from the RFC series is that I went through and did the work to migrate key repository state from global variables in '
environment.c' to being stored in a repository object itself. I migrated the bits of state that seemed reasonable for this series, there is still a lot of global state which could be migrated in the future.I do think that we need to be slightly cautious about moving global state into the repository object though, I don't want 'struct repo' to simply become a kitchen sink where everything gets dumped. But this is just a warning for the future.
Since this is a v1 I'm fairly certain that it still has a lot of rough edges (like I think I need to write better commit messages, and we should probably have more comments documenting object fields/contract) but I want to get the review process started sooner rather than later since I'm sure people will have opinions (e.g. should it be called 'struct repo' or 'struct repository'?!).
So here it is! Thank you so much for taking the time review this, any and all comments would be appreciated.
Quoted 7 lines
- Brandon
Patches [01-14] -> Introducing the Repository object and migrating some state
to be stored in 'the_repository'.Patches [15-31] -> Converting ls-files to use 'struct repo' in order to recurse
submodules in-process.
For those who don't like reviewing patches in email form, you can find this series at:
https://github.com/bmwill/git/tree/repository-object
Signature · 1 line
Brandon Williams
Quoted 4 lines · Brandon Williams
For those who don't like reviewing patches in email form, you can find this series at:
https://github.com/bmwill/git/tree/repository-object
I was just asking Brandon for a remote to pull these patches from.
As I was looking at the very first patch, I'd like to lobby for trying out origin/sb/diff-color-moved, as it will tell you about code movements. :)
Thanks,
Stefan
Re: [PATCH 04/31] setup: don't perform lazy initialization of repository state
In reply to Brandon WilliamsQuoted 10 lines · Brandon Williams
Under some circumstances (bogus
GIT_DIRvalue or the discovered gitdir is '.git') 'setup_git_directory()' won't initialize key repository state. This leads to inconsistent state after running the setup code. To account for this inconsistent state, lazy initialization is done once a caller asks for the repository's gitdir or some other piece of repository state. This is confusing and can be error prone.Instead let's tighten the expected outcome of '
setup_git_directory()' and ensure that it initializes repository state in all cases that would have been handled by lazy initialization.
Lazy init is usually there for a reason. (As in: it took too long to perform it at all times, so it has been optimized to only perform the init when needed).
Reading the code of setup_git_env, this is the additional cost incurred to us:
* reading a file ('git_dir' to determine if it is a gitlink or actual directory)
* reading another file to determine the commondir
* some environment variable reading (<10).
Reading the environment should be fast, though in the implementation of libc that I just looked up, it is still a linear search, so O(n) with n the number of environment variables. (No actual syscalls though.)
I would think that this is ok as it incurs not much cost. Maybe the lazyloading implementation was just a habit of the contributors at the time.
Quoted 4 lines
const char
*get_git_dir(void){ if (!git_dir)-
setup_git_env();
NEEDSWORK: eventually (say after release 2.16)
we can remove all these
if (!git_dir)
BUG(...);calls. I will read on, as maybe this series touches this further
Re: [PATCH 05/31] environment: remove namespace_len variable
In reply to Brandon WilliamsQuoted 2 lines · Brandon Williams
Use '
skip_prefix' instead of 'starts_with' so that we can drop the need to keep around 'namespace_len'.
Looks correct.
Performance wise:
The strip_namespace function is only called from {receive/upload}-pack and http-backend, so all network operations, whose actual operations should far outweight the tiny CPU saving that this reverts. We should be fine?
Quoted 42 lines
Signed-off-by Brandon Williams <[email protected]>--- environment.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)environment.c +4
-6@@ -98,7 +98,6 @@ char *git_work_tree_cfg;static char *work_tree;static const char *namespace; -static size_t namespace_len;static const char *super_prefix;@@ -190,7 +189,6 @@ void setup_git_env(void) git_replace_ref_base =xstrdup (replace_ref_base ? replace_ref_base :"refs/replace/" ); namespace =expand_namespace (getenv (GIT_NAMESPACE_ENVIRONMENT )); - namespace_len =strlen (namespace); shallow_file =getenv (GIT_SHALLOW_FILE_ENVIRONMENT );if (shallow_file)set_alternate_shallow_file (shallow_file,0 );@@ -231,9 +229,10 @@ const char *get_git_namespace(void)const char *strip_namespace (const char *namespaced_ref) { -if (!starts_with (namespaced_ref,get_git_namespace ())) -return NULL ; -return namespaced_ref + namespace_len; +const char *out; +if (skip_prefix (namespaced_ref,get_git_namespace (), &out)) +return out; +return NULL ; }const char *get_super_prefix (void ) --2.13.0.506.g27d5fe0cd-goog
Re: [PATCH 06/31] repo: introduce the repository object
In reply to Brandon WilliamsQuoted 8 lines · Brandon Williams
Introduce the repository object 'struct repo' which can be used hold all state pertaining to a git repository.
The aim of object-ifying the repository is to (1) make the code base more readable and easier to reason about and (2) allow for working on multiple repositories, specifically submodules, within the same process.
TODO: Add more motivating points for adding a repository object?
Yes please (or delete this line).
https://public-inbox.org/git/alpine.DEB.2.21.1.1705221501540.3610@virtualbox/
repo.c line 6
Quoted 8 lines
+++
b/repo.crepo.c new file +6
-0@@ -0,0 +1,124 @@ +#include "cache.h" +#include "repo.h" + +/* +* This may be the wrong place for this. +* It may be better to go in env.c or setup for the time being?
In env.c we say:
/*
* We put all the git config variables in this same object
* file, so that programs can link against the config parser
* without having to link against all the rest of git. *
* In particular, no need to bring in libz etc unless needed,
* even if you might want to know where the git directory etc
* are.
*/
And setup.c only has a few variables that matter there locally. So I would think having 'the_repository' in repo.c is acceptable.
Quoted 53 lines
repo.c new file +53
-0+*/ +struct repo the_repository; + +static char *git_path_from_env (const char *envvar,const char *git_dir, +const char *path,int fromenv) +{ +if (fromenv) { +const char *value =getenv (envvar); +if (value) +return xstrdup (value); + } + +return xstrfmt ("%s/%s" , git_dir, path); +} + +static int find_common_dir (struct strbuf *sb,const char *gitdir,int fromenv) +{ +if (fromenv) { +const char *value =getenv (GIT_COMMON_DIR_ENVIRONMENT ); +if (value) { +strbuf_addstr (sb, value); +return 1 ; + } + } + +return get_common_dir_noenv (sb, gitdir); +} + +/* called after setting gitdir */ +static void repo_setup_env (struct repo *repo) +{ +struct strbuf sb =STRBUF_INIT ; + +if (!repo->gitdir) +BUG ("gitdir wasn't set before setting up the environment" ); + + repo->different_commondir =find_common_dir (&sb, repo->gitdir, + !repo->ignore_env); + repo->commondir =strbuf_detach (&sb,NULL ); + repo->objectdir =git_path_from_env (DB_ENVIRONMENT , repo->commondir, +"objects" , !repo->ignore_env); + repo->index_file =git_path_from_env (INDEX_ENVIRONMENT , repo->gitdir, +"index" , !repo->ignore_env); + repo->graft_file =git_path_from_env (GRAFT_ENVIRONMENT , repo->commondir, +"info/grafts" , !repo->ignore_env); + repo->namespace =expand_namespace (repo->ignore_env ?NULL : +getenv (GIT_NAMESPACE_ENVIRONMENT )); +} + +static void repo_clear_env (struct repo *repo) +{ +free (repo->gitdir); + repo->gitdir =NULL ;
repo.c line 69
Quoted 10 lines
repo.c new file +10
-0+free (repo->commondir); + repo->commondir =NULL ; +free (repo->objectdir); + repo->objectdir =NULL ; +free (repo->index_file); + repo->index_file =NULL ; +free (repo->graft_file); + repo->graft_file =NULL ; +free (repo->namespace); + repo->namespace =NULL ;
I wonder if we can defer the NULL assignments torepo_clear, where we would just do amemset(repo, 0, sizeof(struct repo));
repo.c line 112
Quoted 4 lines
repo.c new file +4
-0+ +repo_set_gitdir (repo, resolved_gitdir); + +/* NEEDSWORK: Verify repository format version */
Care to elaborate on this? I do not understand why we would want to check the format version here?
repo.h line 23
Quoted 4 lines
repo.h new file +4
-0+ +extern void repo_set_gitdir (struct repo *repo,const char *path); +extern int repo_init (struct repo *repo,const char *path); +extern void repo_clear (struct repo *repo);
The init and clear method seem obvious to me, but what do we need the repo_set_gitdir for externally? I would assume the repo auto-discovers its gitdir on its own?
Quoted 6 lines · Stefan Beller
Quoted 4 lines · Brandon Williams
For those who don't like reviewing patches in email form, you can find this series at:
https://github.com/bmwill/git/tree/repository-object
Quoted 7 lines
I was just asking Brandon for a remote to pull these patches from.
As I was looking at the very first patch, I'd like to lobby for trying out origin/sb/diff-color-moved, as it will tell you about code movements. :)
Thanks,
Stefan
Yep, I'll be doing so.
Thanks,
Jake
Re: [PATCH 31/31] ls-files: use repository object
In reply to Brandon WilliamsQuoted 15 lines · Brandon Williams
Convert ls-files to use a repository struct and recurse submodules inprocess.
Signed-off-by Brandon Williams <[email protected]>builtin/ls-files.c +8
-0+static void show_submodule (const struct repo *superproject, +struct dir_struct *dir,const char *path) { +struct repo submodule; +char *gitdir =mkpathdup ("%s/%s" , superproject->worktree, path); +repo_init (&submodule, gitdir); + +repo_read_index (&submodule); +repo_read_gitmodules (&submodule);
builtin/ls-files.c static void show_killed_files(const struct index_state *istate, · line 220
Quoted 10 lines
builtin/ls-files.c +9
-0+ +if (superproject->submodule_prefix) + submodule.submodule_prefix =xstrfmt ("%s%s/" , superproject->submodule_prefix, path); +else + submodule.submodule_prefix =xstrfmt ("%s/" , path); +show_files (&submodule, dir); + +repo_clear (&submodule); +free (gitdir); }
I like how it seems easy now to do work in another repository. :)
git.c static struct cmd_struct commands[] = { · line 445
Quoted 2 lines
git.c +1
-1- { "ls-files", cmd_ls_files, RUN_SETUP | SUPPORT_SUPER_PREFIX }, + { "ls-files", cmd_ls_files, RUN_SETUP },
With this step, we can get rid of SUPPORT_SUPER_PREFIX eventually.
I do not have comments on the patches in the middle, but they cleared up some of the questions that I asked in the early patches.
Thanks,
Stefan
Re: [PATCH 05/31] environment: remove namespace_len variable
In reply to Stefan BellerQuoted 11 lines · Stefan Beller
Quoted 2 lines · Brandon Williams
Use '
skip_prefix' instead of 'starts_with' so that we can drop the need to keep around 'namespace_len'.Looks correct.
Performance wise:
Thestrip_namespacefunction is only called from {receive/upload}-pack and http-backend, so all network operations, whose actual operations should far outweight the tiny CPU saving that this reverts. We should be fine?
Actually there should be zero performance degradation with this change (maybe a very small improvement) because both functions need to do a char by char comparison, just skip_prefix returns a pointer into the string with the prefix already stripped. So no need to do a strlen() calculation on 'namespace' as well as no additon operation adding 'namespace_len' to 'namespaced_ref'.
Quoted 43 lines
Quoted 43 lines
Signed-off-by Brandon Williams <[email protected]>--- environment.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)environment.c +4
-6@@ -98,7 +98,6 @@ char *git_work_tree_cfg;static char *work_tree;static const char *namespace; -static size_t namespace_len;static const char *super_prefix;@@ -190,7 +189,6 @@ void setup_git_env(void) git_replace_ref_base =xstrdup (replace_ref_base ? replace_ref_base :"refs/replace/" ); namespace =expand_namespace (getenv (GIT_NAMESPACE_ENVIRONMENT )); - namespace_len =strlen (namespace); shallow_file =getenv (GIT_SHALLOW_FILE_ENVIRONMENT );if (shallow_file)set_alternate_shallow_file (shallow_file,0 );@@ -231,9 +229,10 @@ const char *get_git_namespace(void)const char *strip_namespace (const char *namespaced_ref) { -if (!starts_with (namespaced_ref,get_git_namespace ())) -return NULL ; -return namespaced_ref + namespace_len; +const char *out; +if (skip_prefix (namespaced_ref,get_git_namespace (), &out)) +return out; +return NULL ; }const char *get_super_prefix (void ) --2.13.0.506.g27d5fe0cd-goog
Signature · 1 line
Brandon Williams
Re: [PATCH 04/31] setup: don't perform lazy initialization of repository state
In reply to Stefan BellerQuoted 8 lines · Stefan Beller
Quoted 7 lines · Brandon Williams
Under some circumstances (bogus
GIT_DIRvalue or the discovered gitdir is '.git') 'setup_git_directory()' won't initialize key repository state. This leads to inconsistent state after running the setup code. To account for this inconsistent state, lazy initialization is done once a caller asks for the repository's gitdir or some other piece of repository state. This is confusing and can be error prone.
Quoted 6 lines
Quoted 3 lines
Instead let's tighten the expected outcome of '
setup_git_directory()' and ensure that it initializes repository state in all cases that would have been handled by lazy initialization.Lazy init is usually there for a reason. (As in: it took too long to perform it at all times, so it has been optimized to only perform the init when needed).
In the case of setup_git_env(), I think it was less about doing work and more that we didn't want to have to do explicit setup in each program. But over the years we've moved away from that, and in fact if you hit the lazy initialization these days you'll generally BUG() anyway.
_But_ I suspect there are still some cases you'd need to handle. For instance, it's still OK to skip calling setup_git_directory() if you've got $GIT_DIR in the environment (which is why we have have_git_dir() instead of checking startup_info->have_repository).
I think it would be nice to do away with that, too, but we're not quite there yet (and if I am reading this patch correctly, we'd probably hit these BUGs in such cases).
-Peff
Re: [PATCH 04/31] setup: don't perform lazy initialization of repository state
Quoted 22 lines · Jeff King
Quoted 8 lines · Stefan Beller
Quoted 7 lines · Brandon Williams
Under some circumstances (bogus
GIT_DIRvalue or the discovered gitdir is '.git') 'setup_git_directory()' won't initialize key repository state. This leads to inconsistent state after running the setup code. To account for this inconsistent state, lazy initialization is done once a caller asks for the repository's gitdir or some other piece of repository state. This is confusing and can be error prone.Quoted 6 lines
Quoted 3 lines
Instead let's tighten the expected outcome of '
setup_git_directory()' and ensure that it initializes repository state in all cases that would have been handled by lazy initialization.Lazy init is usually there for a reason. (As in: it took too long to perform it at all times, so it has been optimized to only perform the init when needed).
In the case of
setup_git_env(), I think it was less about doing work and more that we didn't want to have to do explicit setup in each program. But over the years we've moved away from that, and in fact if you hit the lazy initialization these days you'll generallyBUG()anyway.
Quoted 4 lines
_But_ I suspect there are still some cases you'd need to handle. For instance, it's still OK to skip calling
setup_git_directory()if you've got $GIT_DIR in the environment (which is why we havehave_git_dir()instead of checkingstartup_info->have_repository).
Yes there are a couple places that rely on the lazy initialization but that's not due to setup not being run. Rather it has to do with GIT_DIR being set to a bogus directory so when setup is run gently it does nothing. Then at a later point in time the command tries to access files in the gitdir (which triggers lazy init of the git environment).
So I think that explicitly doing the 'lazy init' portion (which ensures that the env gets setup even if GIT_DIR is bogus) at the end of setup should be sufficient, least it seems to be so though perhaps we can't rely on our tests to tell us that.
Quoted 6 lines
I think it would be nice to do away with that, too, but we're not quite there yet (and if I am reading this patch correctly, we'd probably hit these BUGs in such cases).
-Peff
Signature · 1 line
Brandon Williams
Re: [PATCH 31/31] ls-files: use repository object
In reply to Stefan BellerQuoted 20 lines · Stefan Beller
Quoted 19 lines · Brandon Williams
Convert ls-files to use a repository struct and recurse submodules inprocess.
Signed-off-by Brandon Williams <[email protected]>builtin/ls-files.c +12
-0+static void show_submodule (const struct repo *superproject, +struct dir_struct *dir,const char *path) { +struct repo submodule; +char *gitdir =mkpathdup ("%s/%s" , superproject->worktree, path); +repo_init (&submodule, gitdir); + +repo_read_index (&submodule); +repo_read_gitmodules (&submodule); + +if (superproject->submodule_prefix) + submodule.submodule_prefix =xstrfmt ("%s%s/" , superproject->submodule_prefix, path); +else
Quoted 8 lines
builtin/ls-files.c static void show_killed_files(const struct index_state *istate, · line 220
Quoted 6 lines
builtin/ls-files.c +5
-0+ submodule.submodule_prefix =xstrfmt ("%s/" , path); +show_files (&submodule, dir); + +repo_clear (&submodule); +free (gitdir); }I like how it seems easy now to do work in another repository. :)
It really does make working with another repo easy! No more compiling argv options and spawning child processes :D
Quoted 5 lines
git.c static struct cmd_struct commands[] = { · line 445
Quoted 3 lines
git.c +1
-1- { "ls-files", cmd_ls_files, RUN_SETUP | SUPPORT_SUPER_PREFIX }, + { "ls-files", cmd_ls_files, RUN_SETUP },With this step, we can get rid of
SUPPORT_SUPER_PREFIXeventually.
Yes Ideally most of the little hacks I introduced when originally teaching ls-files and grep to recurse could be removed.
Quoted 6 lines
I do not have comments on the patches in the middle, but they cleared up some of the questions that I asked in the early patches.
Thanks,
Stefan
Signature · 1 line
Brandon Williams
Re: [PATCH 06/31] repo: introduce the repository object
In reply to Stefan BellerQuoted 33 lines · Stefan Beller
Quoted 8 lines · Brandon Williams
Introduce the repository object 'struct repo' which can be used hold all state pertaining to a git repository.
The aim of object-ifying the repository is to (1) make the code base more readable and easier to reason about and (2) allow for working on multiple repositories, specifically submodules, within the same process.
TODO: Add more motivating points for adding a repository object?
Yes please (or delete this line).
https://public-inbox.org/git/alpine.DEB.2.21.1.1705221501540.3610@virtualbox/repo.c line 6
Quoted 8 lines
+++
b/repo.crepo.c new file +6
-0@@ -0,0 +1,124 @@ +#include "cache.h" +#include "repo.h" + +/* +* This may be the wrong place for this. +* It may be better to go in env.c or setup for the time being? In
env.cwe say:
/*
* We put all the git config variables in this same object
* file, so that programs can link against the config parser
* without having to link against all the rest of git. *
* In particular, no need to bring in libz etc unless needed,
* even if you might want to know where the git directory etc
* are.
*/
Quoted 2 lines
And
setup.conly has a few variables that matter there locally. So I would think having 'the_repository' inrepo.cis acceptable.
And perhaps (far down the road) 'the_repoository' could be removed such that builtin commands take a pointer to a repo object as a parameter.
Quoted 60 lines
Quoted 60 lines
repo.c new file +59
-0+*/ +struct repo the_repository; + +static char *git_path_from_env (const char *envvar,const char *git_dir, +const char *path,int fromenv) +{ +if (fromenv) { +const char *value =getenv (envvar); +if (value) +return xstrdup (value); + } + +return xstrfmt ("%s/%s" , git_dir, path); +} + +static int find_common_dir (struct strbuf *sb,const char *gitdir,int fromenv) +{ +if (fromenv) { +const char *value =getenv (GIT_COMMON_DIR_ENVIRONMENT ); +if (value) { +strbuf_addstr (sb, value); +return 1 ; + } + } + +return get_common_dir_noenv (sb, gitdir); +} + +/* called after setting gitdir */ +static void repo_setup_env (struct repo *repo) +{ +struct strbuf sb =STRBUF_INIT ; + +if (!repo->gitdir) +BUG ("gitdir wasn't set before setting up the environment" ); + + repo->different_commondir =find_common_dir (&sb, repo->gitdir, + !repo->ignore_env); + repo->commondir =strbuf_detach (&sb,NULL ); + repo->objectdir =git_path_from_env (DB_ENVIRONMENT , repo->commondir, +"objects" , !repo->ignore_env); + repo->index_file =git_path_from_env (INDEX_ENVIRONMENT , repo->gitdir, +"index" , !repo->ignore_env); + repo->graft_file =git_path_from_env (GRAFT_ENVIRONMENT , repo->commondir, +"info/grafts" , !repo->ignore_env); + repo->namespace =expand_namespace (repo->ignore_env ?NULL : +getenv (GIT_NAMESPACE_ENVIRONMENT )); +} + +static void repo_clear_env (struct repo *repo) +{ +free (repo->gitdir); + repo->gitdir =NULL ; +free (repo->commondir); + repo->commondir =NULL ; +free (repo->objectdir); + repo->objectdir =NULL ; +free (repo->index_file); + repo->index_file =NULL ;
Quoted 9 lines
repo.c line 69
Quoted 4 lines
repo.c new file +4
-0+free (repo->graft_file); + repo->graft_file =NULL ; +free (repo->namespace); + repo->namespace =NULL ;I wonder if we can defer the NULL assignments to
repo_clear, where we would just do amemset(repo, 0, sizeof(struct repo));
Yeah perhaps, clearing the env should either be done when setting gitdir again (so setting up the env will happen again and we don't need to clear the fields) or clearing the struct as a whole so using memset would work.
Quoted 7 lines
repo.c line 112
Quoted 4 lines
repo.c new file +4
-0+ +repo_set_gitdir (repo, resolved_gitdir); + +/* NEEDSWORK: Verify repository format version */ Care to elaborate on this? I do not understand why we would want to check the format version here?
When opening up a repository git needs to check if it understands the repository format and all extensions. If it doesn't git needs to bail out and not operate on the repository. So a part of initializing a repo object would be to verify that it understands the repository format version.
Quoted 9 lines
repo.h line 23
Quoted 5 lines
repo.h new file +4
-0+ +extern void repo_set_gitdir (struct repo *repo,const char *path); +extern int repo_init (struct repo *repo,const char *path); +extern void repo_clear (struct repo *repo);The init and clear method seem obvious to me, but what do we need the
repo_set_gitdirfor externally? I would assume the repo auto-discovers its gitdir on its own?
Well I didn't completely overhaul the setup code in this series so I really just hooked into where the setup code already sets the gitdir, hence why this function is exposed atm.
Signature · 1 line
Brandon Williams
Re: [PATCH 04/31] setup: don't perform lazy initialization of repository state
In reply to Brandon WilliamsQuoted 16 lines · Brandon Williams
Quoted 9 lines
In the case of
setup_git_env(), I think it was less about doing work and more that we didn't want to have to do explicit setup in each program. But over the years we've moved away from that, and in fact if you hit the lazy initialization these days you'll generallyBUG()anyway._But_ I suspect there are still some cases you'd need to handle. For instance, it's still OK to skip calling
setup_git_directory()if you've got $GIT_DIR in the environment (which is why we havehave_git_dir()instead of checkingstartup_info->have_repository).Yes there are a couple places that rely on the lazy initialization but that's not due to setup not being run. Rather it has to do with
GIT_DIRbeing set to a bogus directory so when setup is run gently it does nothing. Then at a later point in time the command tries to access files in the gitdir (which triggers lazy init of the git environment).
Quoted 4 lines
So I think that explicitly doing the 'lazy init' portion (which ensures that the env gets setup even if
GIT_DIRis bogus) at the end of setup should be sufficient, least it seems to be so though perhaps we can't rely on our tests to tell us that.
In have_git_dir() we do:
int have_git_dir(void)
{
return startup_info->have_repository
|| git_dir
|| getenv(GIT_DIR_ENVIRONMENT);}
and generally call that right before calling a function that might do setup_git_env(). We can assume that if have_repository is set that we have an actual git_dir (we can check all of the assignment spots and verify that they always set it in tandem with the global git_dir). And obviously if git_dir is set, we're good.
But if that third condition ever triggers, it's because we're relying on the lazy setup to copy it into git_dir. And if I understand correctly, that would turn into a BUG with your patch.
I guess my question is: does that third condition actually trigger in practice? I added those conditions in b9605bc4f (config: only read .git/config from configured repos, 2016-09-12). I remember there being some reason for needing those back then, but the commit message doesn't say. But if I remove them and just check have_repository (either on top of that commit or on top of the current master) the tests all still pass.
So I'm not sure at this point what the case was that motivated it, or if it really was just an abundance of caution. But if there is such a case, I suspect it's broken by your patch series.
I'm not sure we have a good way to find out, though. Like the current BUG() in setup_git_env, I think we'll just have to cook the patches for a long time, see if anybody triggers it, and deal with it on a case by case basis.
I do kind of wonder if we should simplify have_git_dir(), if those other conditions aren't actually triggering.
-Peff
Re: [PATCH 06/31] repo: introduce the repository object
In reply to Brandon WilliamsQuoted 8 lines
Quoted 7 lines
repo.c line 112
Quoted 4 lines
repo.c new file +4
-0+ +repo_set_gitdir (repo, resolved_gitdir); + +/* NEEDSWORK: Verify repository format version */ Care to elaborate on this? I do not understand why we would want to check the format version here?
Quoted 5 lines
When opening up a repository git needs to check if it understands the repository format and all extensions. If it doesn't git needs to bail out and not operate on the repository. So a part of initializing a repo object would be to verify that it understands the repository format version.
Ah yes. Conceptually I understand why and what the repo format version check is. At the time of asking the question I was confused whether this is the right place, but after some thought this is the best place to put it.
And this NEEDSWORK is really just telling the reader that it needs to be moved here, not copied. (That was another brain fart I had upon reading this comment).
Thanks,
Stefan
Re: [PATCH 04/31] setup: don't perform lazy initialization of repository state
In reply to Jeff KingQuoted 42 lines · Jeff King
Quoted 16 lines · Brandon Williams
Quoted 9 lines
In the case of
setup_git_env(), I think it was less about doing work and more that we didn't want to have to do explicit setup in each program. But over the years we've moved away from that, and in fact if you hit the lazy initialization these days you'll generallyBUG()anyway._But_ I suspect there are still some cases you'd need to handle. For instance, it's still OK to skip calling
setup_git_directory()if you've got $GIT_DIR in the environment (which is why we havehave_git_dir()instead of checkingstartup_info->have_repository).Yes there are a couple places that rely on the lazy initialization but that's not due to setup not being run. Rather it has to do with
GIT_DIRbeing set to a bogus directory so when setup is run gently it does nothing. Then at a later point in time the command tries to access files in the gitdir (which triggers lazy init of the git environment).Quoted 4 lines
So I think that explicitly doing the 'lazy init' portion (which ensures that the env gets setup even if
GIT_DIRis bogus) at the end of setup should be sufficient, least it seems to be so though perhaps we can't rely on our tests to tell us that.In
have_git_dir()we do:int
have_git_dir(void){ return startup_info->have_repository || git_dir || getenv(GIT_DIR_ENVIRONMENT);}
and generally call that right before calling a function that might do
setup_git_env(). We can assume that ifhave_repositoryis set that we have an actualgit_dir(we can check all of the assignment spots and verify that they always set it in tandem with the globalgit_dir). And obviously ifgit_diris set, we're good.But if that third condition ever triggers, it's because we're relying on the lazy setup to copy it into
git_dir. And if I understand correctly, that would turn into a BUG with your patch.
Quoted 7 lines
I guess my question is: does that third condition actually trigger in practice? I added those conditions in
b9605bc4f(config: only read .git/config from configured repos, 2016-09-12). I remember there being some reason for needing those back then, but the commit message doesn't say. But if I remove them and just checkhave_repository(either on top of that commit or on top of the current master) the tests all still pass.
The only instance I saw the third condition trigger was when GIT_DIR was set to a bogus gitdir so when reading the early config a bogus gitdir/config file was attempted to be read resulting in a noop. If GIT_DIR is set to a valid gitdir then the other condition in read_early_config (which does repository discovery itself) would correctly catch and read from the repository's config.
Quoted 5 lines
So I'm not sure at this point what the case was that motivated it, or if it really was just an abundance of caution. But if there is such a case, I suspect it's broken by your patch series.
Quoted 7 lines
I'm not sure we have a good way to find out, though. Like the current
BUG()insetup_git_env, I think we'll just have to cook the patches for a long time, see if anybody triggers it, and deal with it on a case by case basis.I do kind of wonder if we should simplify
have_git_dir(), if those other conditions aren't actually triggering.
If this ends up being that big of an issue I'm sure that it would be easy to adapt this and revert to doing lazy-init. I just saw how clunky it is and was trying to work to start the process of cleaning it up so that the code becomes easier to reason about. It seemed to make things easier for me to package them in a struct at least (and reason about how the config system would work once stored in a repository struct).
Signature · 1 line
Brandon Williams
Re: [PATCH 03/31] config: don't implicitly use gitdir
In reply to Brandon WilliamsHi Brandon,
Quoted 6 lines · Brandon Williams
Commit
2185fde56(config: handle conditional include when $GIT_DIR is not set up) added a 'git_dir' field to theconfig_optionsstruct. Let's use this option field explicitly all the time instead of occasionally falling back to calling 'git_pathdup("config")' to get the path to the local repository configuration. This allows 'go_git_config_sequence()' to not implicitly rely on global repository state.
Oh wow. git_pathdup()...
Sadly, I lack the time to review the entire patch series, but this here change definitely looks correct to me.
Thanks,
Dscho
Re: [PATCH 03/31] config: don't implicitly use gitdir
Quoted 11 lines · Johannes Schindelin
Hi Brandon,
Quoted 6 lines · Brandon Williams
Commit
2185fde56(config: handle conditional include when $GIT_DIR is not set up) added a 'git_dir' field to theconfig_optionsstruct. Let's use this option field explicitly all the time instead of occasionally falling back to calling 'git_pathdup("config")' to get the path to the local repository configuration. This allows 'go_git_config_sequence()' to not implicitly rely on global repository state.
Quoted 4 lines
Oh wow.
git_pathdup()...Sadly, I lack the time to review the entire patch series, but this here change definitely looks correct to me.
Thanks for taking a look. I understand you don't have time to review the series in whole but I should also mention that patch 04/31 may be of interest to you as it deals with setup being slightly more robust and since you've spent a great deal of time in that bit of code any input would be nice. Last prod I promise ;)
Signature · 1 line
Brandon Williams
Re: [PATCH 03/31] config: don't implicitly use gitdir
Hi Brandon,
Quoted 13 lines · Brandon Williams
Quoted 12 lines · Johannes Schindelin
Quoted 6 lines · Brandon Williams
Commit
2185fde56(config: handle conditional include when $GIT_DIR is not set up) added a 'git_dir' field to theconfig_optionsstruct. Let's use this option field explicitly all the time instead of occasionally falling back to calling 'git_pathdup("config")' to get the path to the local repository configuration. This allows 'go_git_config_sequence()' to not implicitly rely on global repository state.Oh wow.
git_pathdup()...
Quoted 8 lines
Quoted 2 lines
Sadly, I lack the time to review the entire patch series, but this here change definitely looks correct to me.
Thanks for taking a look. I understand you don't have time to review the series in whole but I should also mention that patch 04/31 may be of interest to you as it deals with setup being slightly more robust and since you've spent a great deal of time in that bit of code any input would be nice. Last prod I promise ;)
I had a quick look over the patch and I like the direction.
I also briefly scanned the discussion and have to admit that I am not knee-deep in those exceptional code paths that do strange^Wuncommon things, so I feel a bit unqualified to comment about those.
Ciao,
Dscho
Re: [PATCH 03/31] config: don't implicitly use gitdir
Quoted 26 lines · Johannes Schindelin
Hi Brandon,
Quoted 13 lines · Brandon Williams
Quoted 12 lines · Johannes Schindelin
Quoted 6 lines · Brandon Williams
Commit
2185fde56(config: handle conditional include when $GIT_DIR is not set up) added a 'git_dir' field to theconfig_optionsstruct. Let's use this option field explicitly all the time instead of occasionally falling back to calling 'git_pathdup("config")' to get the path to the local repository configuration. This allows 'go_git_config_sequence()' to not implicitly rely on global repository state.Oh wow.
git_pathdup()...Quoted 8 lines
Quoted 2 lines
Sadly, I lack the time to review the entire patch series, but this here change definitely looks correct to me.
Thanks for taking a look. I understand you don't have time to review the series in whole but I should also mention that patch 04/31 may be of interest to you as it deals with setup being slightly more robust and since you've spent a great deal of time in that bit of code any input would be nice. Last prod I promise ;)
Quoted 5 lines
I had a quick look over the patch and I like the direction.
I also briefly scanned the discussion and have to admit that I am not knee-deep in those exceptional code paths that do strange^Wuncommon things, so I feel a bit unqualified to comment about those.
All good, thanks for looking!
Signature · 1 line
Brandon Williams
PATCH v2 1/32 config: create config.h
In reply to Brandon WilliamsMove all config related declarations from cache.h to a new config.h header file. This makes cache.h smaller and allows for the opportunity in a following patch to only include config.h when needed.
--- cache.h | 190 +------------------------------------------------------------ config.h | 194 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 195 insertions(+), 189 deletions(-) create mode 100644 config.h
cache.h +1 -189
@@ -11,6 +11,7 @@#include "string-list.h" #include "pack-revindex.h" #include "hash.h" +#include "config.h" #ifndef platform_SHA_CTX/*
@@ -1866,188 +1867,9 @@ extern int packed_object_info(struct packed_git *pack, off_t offset, struct obje/* Dumb servers support */ extern int update_server_info (int ); -/* git_config_parse_key() returns these negated: */ -#define CONFIG_INVALID_KEY 1 -#define CONFIG_NO_SECTION_OR_NAME 2 -/* git_config_set_gently(), git_config_set_multivar_gently() return the above or these: */ -#define CONFIG_NO_LOCK -1 -#define CONFIG_INVALID_FILE 3 -#define CONFIG_NO_WRITE 4 -#define CONFIG_NOTHING_SET 5 -#define CONFIG_INVALID_PATTERN 6 -#define CONFIG_GENERIC_ERROR 7 - -#define CONFIG_REGEX_NONE ((void *)1) - -struct git_config_source { -unsigned int use_stdin:1 ; -const char *file; -const char *blob; -}; - -enum config_origin_type { -CONFIG_ORIGIN_BLOB , -CONFIG_ORIGIN_FILE , -CONFIG_ORIGIN_STDIN , -CONFIG_ORIGIN_SUBMODULE_BLOB , -CONFIG_ORIGIN_CMDLINE -}; - -struct config_options { -unsigned int respect_includes :1 ; -const char *git_dir; -}; - -typedef int (*config_fn_t )(const char *,const char *,void *); -extern int git_default_config (const char *,const char *,void *); -extern int git_config_from_file (config_fn_t fn,const char *,void *); -extern int git_config_from_mem (config_fn_t fn,const enum config_origin_type , -const char *name,const char *buf,size_t len,void *data); -extern int git_config_from_blob_sha1 (config_fn_t fn,const char *name, -const unsigned char *sha1,void *data); -extern void git_config_push_parameter (const char *text); -extern int git_config_from_parameters (config_fn_t fn,void *data); -extern void read_early_config (config_fn_t cb,void *data); -extern void git_config (config_fn_t fn,void *); -extern int git_config_with_options (config_fn_t fn,void *, -struct git_config_source *config_source, -const struct config_options *opts); -extern int git_parse_ulong (const char *,unsigned long *); -extern int git_parse_maybe_bool (const char *); -extern int git_config_int (const char *,const char *); -extern int64_t git_config_int64 (const char *,const char *); -extern unsigned long git_config_ulong (const char *,const char *); -extern ssize_t git_config_ssize_t (const char *,const char *); -extern int git_config_bool_or_int (const char *,const char *,int *); -extern int git_config_bool (const char *,const char *); -extern int git_config_maybe_bool (const char *,const char *); -extern int git_config_string (const char **,const char *,const char *); -extern int git_config_pathname (const char **,const char *,const char *); -extern int git_config_set_in_file_gently (const char *,const char *,const char *); -extern void git_config_set_in_file (const char *,const char *,const char *); -extern int git_config_set_gently (const char *,const char *); -extern void git_config_set (const char *,const char *); -extern int git_config_parse_key (const char *,char **,int *); -extern int git_config_key_is_valid (const char *key); -extern int git_config_set_multivar_gently (const char *,const char *,const char *,int ); -extern void git_config_set_multivar (const char *,const char *,const char *,int ); -extern int git_config_set_multivar_in_file_gently (const char *,const char *,const char *,const char *,int ); -extern void git_config_set_multivar_in_file (const char *,const char *,const char *,const char *,int ); -extern int git_config_rename_section (const char *,const char *); -extern int git_config_rename_section_in_file (const char *,const char *,const char *); -extern const char *git_etc_gitconfig (void ); -extern int git_env_bool (const char *,int ); -extern unsigned long git_env_ulong (const char *,unsigned long ); -extern int git_config_system (void ); -extern int config_error_nonbool (const char *); -#if defined(__GNUC__) -#define config_error_nonbool (s) (config_error_nonbool(s), const_error()) -#endif extern const char *get_log_output_encoding (void );extern const char *get_commit_output_encoding (void ); -extern int git_config_parse_parameter (const char *,config_fn_t fn,void *data); - -enum config_scope { -CONFIG_SCOPE_UNKNOWN =0 , -CONFIG_SCOPE_SYSTEM , -CONFIG_SCOPE_GLOBAL , -CONFIG_SCOPE_REPO , -CONFIG_SCOPE_CMDLINE , -}; - -extern enum config_scope current_config_scope (void ); -extern const char *current_config_origin_type (void ); -extern const char *current_config_name (void ); - -struct config_include_data { -int depth; -config_fn_t fn; -void *data; -const struct config_options *opts; -}; -#define CONFIG_INCLUDE_INIT { 0 } -extern int git_config_include (const char *name,const char *value,void *data); - -/* -* Match and parse a config key of the form: -* -* section.(subsection.)?key -* -* (i.e., what gets handed to a config_fn_t). The caller provides the section; -* we return -1 if it does not match, 0 otherwise. The subsection and key -* out-parameters are filled by the function (and *subsection is NULL if it is -* missing). -* -* If the subsection pointer-to-pointer passed in is NULL, returns 0 only if -* there is no subsection at all. -*/ -extern int parse_config_key (const char *var, -const char *section, -const char **subsection,int *subsection_len, -const char **key); - -struct config_set_element { -struct hashmap_entry ent; -char *key; -struct string_list value_list; -}; - -struct configset_list_item { -struct config_set_element *e; -int value_index; -}; - -/* -* the contents of the list are ordered according to their -* position in the config files and order of parsing the files. -* (i.e. key-value pair at the last position of .git/config will -* be at the last item of the list) -*/ -struct configset_list { -struct configset_list_item *items; -unsigned int nr, alloc; -}; - -struct config_set { -struct hashmap config_hash; -int hash_initialized; -struct configset_list list; -}; - -extern void git_configset_init (struct config_set *cs); -extern int git_configset_add_file (struct config_set *cs,const char *filename); -extern int git_configset_get_value (struct config_set *cs,const char *key,const char **value); -extern const struct string_list *git_configset_get_value_multi (struct config_set *cs,const char *key); -extern void git_configset_clear (struct config_set *cs); -extern int git_configset_get_string_const (struct config_set *cs,const char *key,const char **dest); -extern int git_configset_get_string (struct config_set *cs,const char *key,char **dest); -extern int git_configset_get_int (struct config_set *cs,const char *key,int *dest); -extern int git_configset_get_ulong (struct config_set *cs,const char *key,unsigned long *dest); -extern int git_configset_get_bool (struct config_set *cs,const char *key,int *dest); -extern int git_configset_get_bool_or_int (struct config_set *cs,const char *key,int *is_bool,int *dest); -extern int git_configset_get_maybe_bool (struct config_set *cs,const char *key,int *dest); -extern int git_configset_get_pathname (struct config_set *cs,const char *key,const char **dest); - -extern int git_config_get_value (const char *key,const char **value); -extern const struct string_list *git_config_get_value_multi (const char *key); -extern void git_config_clear (void ); -extern void git_config_iter (config_fn_t fn,void *data); -extern int git_config_get_string_const (const char *key,const char **dest); -extern int git_config_get_string (const char *key,char **dest); -extern int git_config_get_int (const char *key,int *dest); -extern int git_config_get_ulong (const char *key,unsigned long *dest); -extern int git_config_get_bool (const char *key,int *dest); -extern int git_config_get_bool_or_int (const char *key,int *is_bool,int *dest); -extern int git_config_get_maybe_bool (const char *key,int *dest); -extern int git_config_get_pathname (const char *key,const char **dest); -extern int git_config_get_untracked_cache (void ); -extern int git_config_get_split_index (void ); -extern int git_config_get_max_percent_split_change (void ); - -/* This dies if the configured or default date is in the future */ -extern int git_config_get_expiry (const char *key,const char **output); -/* * This is a hack for test programs like test-dump-untracked-cache to * ensure that they do not modify the untracked cache when reading it.
@@ -2055,16 +1877,6 @@ extern int git_config_get_expiry(const char *key, const char **output);*/ extern int ignore_untracked_cache_config; -struct key_value_info { -const char *filename; -int linenr; -enum config_origin_type origin_type; -enum config_scope scope; -}; - -extern NORETURN void git_die_config(const char *key, const char *err, ...) __attribute__((format(printf, 2, 3))); -extern NORETURN void git_die_config_linenr(const char *key, const char *filename, int linenr); -extern int committer_ident_sufficiently_given (void );extern int author_ident_sufficiently_given (void );
config.h new file +194 -0
194 lines not on this page · raw message
Signature · 1 line
2.13.1.508.gb3defc5cc-goog
PATCH v2 2/32 config: remove git_config_iter
In reply to Brandon WilliamsSince there is no implementation of the function 'git_config_iter' lets stop exporting it and remove the prototype from config.h.
--- config.h | 1 - 1 file changed, 1 deletion(-)
config.h +0 -1
@@ -165,7 +165,6 @@ extern int git_configset_get_pathname(struct config_set *cs, const char *key, coextern int git_config_get_value (const char *key,const char **value);extern const struct string_list *git_config_get_value_multi (const char *key);extern void git_config_clear (void ); -extern void git_config_iter (config_fn_t fn,void *data);extern int git_config_get_string_const (const char *key,const char **dest);extern int git_config_get_string (const char *key,char **dest);extern int git_config_get_int (const char *key,int *dest);
Signature · 1 line
2.13.1.508.gb3defc5cc-goog
v2 cover repository object
In reply to Brandon WilliamsWhen I sent out my RFC series there seemed to be a lot of interest but I haven't seen many people jump to review this series. Despite lack of review I wanted to get out another version which includes some changes to fix things that were bugging me about the series. Hopfully this v2 will prod some more people to take a look.
The meat of the series is really from 04-15 and patch 32 which converts ls-files to recurse using a repository object. So if you're pressed for time you can focus on those patches.
You can find this series at: https://github.com/bmwill/git/tree/repository-object
What's different in v2:
* 'struct repo' has been renamed 'struct repository'. Really just an aesthetic change and it looks more "official" without having a shortened name.
* Better commit messages on a few of the patches which were soarly lacking.
* I found that 'git_config_iter' was being exported without an implementation so I added a patch to remove it.
* repo_init is a bit cleaner and is written in such a way to not call 'die()', instead it returns a non-zero return value upon failure.
Thanks for your help!
Brandon Williams (32):
config: create config.h
config: remove git_config_iter
config: don't include config.h by default
config: don't implicitly use gitdir
setup: don't perform lazy initialization of repository state
environment: remove namespace_len variable
repository: introduce the repository object
environment: place key repository state in the_repository
environment: store worktree in the_repository
setup: add comment indicating a hack
config: read config from a repository object
repository: add index_state to struct repo
submodule-config: store the_submodule_cache in the_repository
submodule: add repo_read_gitmodules
submodule: convert is_submodule_initialized to work on a repository
convert: convert get_cached_convert_stats_ascii to take an index
convert: convert crlf_to_git to take an index
convert: convert convert_to_git_filter_fd to take an index
convert: convert convert_to_git to take an index
convert: convert renormalize_buffer to take an index
tree: convert read_tree to take an index parameter
ls-files: convert overlay_tree_on_cache to take an index
ls-files: convert write_eolinfo to take an index
ls-files: convert show_killed_files to take an index
ls-files: convert show_other_files to take an index
ls-files: convert show_ru_info to take an index
ls-files: convert ce_excluded to take an index
ls-files: convert prune_cache to take an index
ls-files: convert show_files to take an index
ls-files: factor out debug info into a function
ls-files: factor out tag calculation
ls-files: use repository object
Makefile | 1 + advice.c | 1 + alias.c | 1 + apply.c | 3 +- archive-tar.c | 1 + archive-zip.c | 1 + archive.c | 1 + attr.c | 1 + bisect.c | 1 + branch.c | 1 + builtin/add.c | 1 + builtin/am.c | 1 + builtin/blame.c | 3 +- builtin/branch.c | 1 + builtin/cat-file.c | 1 + builtin/check-attr.c | 1 + builtin/check-ignore.c | 1 + builtin/check-mailmap.c | 1 + builtin/checkout-index.c | 1 + builtin/checkout.c | 1 + builtin/clean.c | 1 + builtin/clone.c | 1 + builtin/column.c | 1 + builtin/commit-tree.c | 1 + builtin/commit.c | 4 +- builtin/config.c | 3 + builtin/count-objects.c | 1 + builtin/describe.c | 1 + builtin/diff-files.c | 1 + builtin/diff-index.c | 1 + builtin/diff-tree.c | 1 + builtin/diff.c | 1 + builtin/difftool.c | 1 + builtin/fast-export.c | 1 + builtin/fetch.c | 1 + builtin/fmt-merge-msg.c | 1 + builtin/for-each-ref.c | 1 + builtin/fsck.c | 1 + builtin/gc.c | 1 + builtin/grep.c | 4 +- builtin/hash-object.c | 1 + builtin/help.c | 1 + builtin/index-pack.c | 1 + builtin/init-db.c | 1 + builtin/log.c | 1 + builtin/ls-files.c | 330 ++++++++++++++++----------------- builtin/ls-tree.c | 1 + builtin/merge-base.c | 1 + builtin/merge-file.c | 1 + builtin/merge.c | 1 + builtin/mv.c | 1 + builtin/name-rev.c | 1 + builtin/notes.c | 1 + builtin/pack-objects.c | 1 + builtin/patch-id.c | 1 + builtin/pull.c | 1 + builtin/push.c | 1 + builtin/read-tree.c | 1 + builtin/rebase--helper.c | 1 + builtin/receive-pack.c | 1 + builtin/reflog.c | 1 + builtin/remote.c | 1 + builtin/repack.c | 1 + builtin/replace.c | 1 + builtin/rerere.c | 1 + builtin/reset.c | 1 + builtin/rev-list.c | 1 + builtin/rev-parse.c | 1 + builtin/revert.c | 1 + builtin/rm.c | 1 + builtin/send-pack.c | 1 + builtin/shortlog.c | 1 + builtin/show-branch.c | 1 + builtin/stripspace.c | 1 + builtin/submodule--helper.c | 10 +- builtin/symbolic-ref.c | 1 + builtin/tag.c | 1 + builtin/unpack-file.c | 1 + builtin/unpack-objects.c | 1 + builtin/update-index.c | 1 + builtin/update-ref.c | 1 + builtin/update-server-info.c | 1 + builtin/var.c | 1 + builtin/verify-commit.c | 1 + builtin/verify-pack.c | 1 + builtin/verify-tag.c | 1 + builtin/worktree.c | 1 + builtin/write-tree.c | 1 + cache.h | 196 +------------------- color.c | 1 + column.c | 1 + combine-diff.c | 2 +- config.c | 210 ++++++++++++++------- config.h | 217 ++++++++++++++++++++++ connect.c | 1 + convert.c | 32 ++-- convert.h | 19 +- credential-cache--daemon.c | 1 + credential.c | 1 + daemon.c | 1 + diff.c | 7 +- dir.c | 3 +- environment.c | 101 ++++------ fast-import.c | 1 + fetch-pack.c | 1 + git.c | 3 +- gpg-interface.c | 1 + graph.c | 1 + grep.c | 1 + help.c | 1 + http-backend.c | 1 + http-fetch.c | 1 + http.c | 1 + ident.c | 1 + imap-send.c | 1 + ll-merge.c | 3 +- log-tree.c | 1 + mailinfo.c | 1 + merge-recursive.c | 5 +- notes-utils.c | 1 + notes.c | 1 + pager.c | 1 + parse-options.c | 1 + path.c | 11 +- pathspec.c | 1 + pretty.c | 1 + prompt.c | 1 + read-cache.c | 1 + refs.c | 1 + refs/files-backend.c | 1 + remote-curl.c | 1 + remote.c | 1 + repository.c | 216 +++++++++++++++++++++ repository.h | 45 +++++ rerere.c | 1 + send-pack.c | 1 + sequencer.c | 1 + setup.c | 34 ++++ sha1_file.c | 7 +- sha1_name.c | 1 + submodule-config.c | 71 +++++-- submodule-config.h | 10 + submodule.c | 36 ++-- submodule.h | 4 +- t/helper/test-config.c | 1 + t/helper/test-submodule-config.c | 1 + t/t3007-ls-files-recurse-submodules.sh | 39 ++++ trailer.c | 1 + transport.c | 1 + tree.c | 28 ++- tree.h | 3 +- unpack-trees.c | 1 + upload-pack.c | 1 + userdiff.c | 1 + versioncmp.c | 1 + wrapper.c | 1 + xdiff-interface.c | 1 + 157 files changed, 1199 insertions(+), 586 deletions(-) create mode 100644 config.h create mode 100644 repository.c create mode 100644 repository.h
Signature · 1 line
2.13.1.508.gb3defc5cc-goog
PATCH v2 4/32 config: don't implicitly use gitdir
Commit 2185fde56 (config: handle conditional include when $GIT_DIR is not set up) added a 'git_dir' field to the config_options struct. Let's use this option field explicitly all the time instead of occasionally falling back to calling 'git_pathdup("config")' to get the path to the local repository configuration. This allows 'do_git_config_sequence()' to not implicitly rely on global repository state.
--- builtin/config.c | 2 ++ config.c | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-)
builtin/config.c +2 -0
@@ -539,6 +539,8 @@ int cmd_config(int argc, const char **argv, const char *prefix) config_options.respect_includes = !given_config_source.file; else config_options.respect_includes = respect_includes_opt; +if (have_git_dir ()) + config_options.git_dir =get_git_common_dir ();if (end_null) { term ='\0' ;
config.c +2 -2
@@ -1548,8 +1548,6 @@ static int do_git_config_sequence(const struct config_options *opts,if (opts->git_dir) repo_config =mkpathdup ("%s/config" , opts->git_dir); -else if (have_git_dir ()) - repo_config =git_pathdup ("config" );else repo_config =NULL ;
@@ -1613,6 +1611,8 @@ static void git_config_raw(config_fn_t fn, void *data)struct config_options opts = {0 }; opts.respect_includes =1 ; +if (have_git_dir ()) + opts.git_dir =get_git_common_dir ();if (git_config_with_options (fn, data,NULL , &opts) <0 )/* * git_config_with_options() normally returns only
Signature · 1 line
2.13.1.508.gb3defc5cc-goog
PATCH v2 3/32 config: don't include config.h by default
In reply to Brandon WilliamsStop including config.h by default in cache.h. Instead only include config.h in those files which require use of the config system.
--- advice.c | 1 + alias.c | 1 + apply.c | 1 + archive-tar.c | 1 + archive-zip.c | 1 + archive.c | 1 + attr.c | 1 + bisect.c | 1 + branch.c | 1 + builtin/add.c | 1 + builtin/am.c | 1 + builtin/blame.c | 1 + builtin/branch.c | 1 + builtin/cat-file.c | 1 + builtin/check-attr.c | 1 + builtin/check-ignore.c | 1 + builtin/check-mailmap.c | 1 + builtin/checkout-index.c | 1 + builtin/checkout.c | 1 + builtin/clean.c | 1 + builtin/clone.c | 1 + builtin/column.c | 1 + builtin/commit-tree.c | 1 + builtin/commit.c | 1 + builtin/config.c | 1 + builtin/count-objects.c | 1 + builtin/describe.c | 1 + builtin/diff-files.c | 1 + builtin/diff-index.c | 1 + builtin/diff-tree.c | 1 + builtin/diff.c | 1 + builtin/difftool.c | 1 + builtin/fast-export.c | 1 + builtin/fetch.c | 1 + builtin/fmt-merge-msg.c | 1 + builtin/for-each-ref.c | 1 + builtin/fsck.c | 1 + builtin/gc.c | 1 + builtin/grep.c | 1 + builtin/hash-object.c | 1 + builtin/help.c | 1 + builtin/index-pack.c | 1 + builtin/init-db.c | 1 + builtin/log.c | 1 + builtin/ls-files.c | 1 + builtin/ls-tree.c | 1 + builtin/merge-base.c | 1 + builtin/merge-file.c | 1 + builtin/merge.c | 1 + builtin/mv.c | 1 + builtin/name-rev.c | 1 + builtin/notes.c | 1 + builtin/pack-objects.c | 1 + builtin/patch-id.c | 1 + builtin/pull.c | 1 + builtin/push.c | 1 + builtin/read-tree.c | 1 + builtin/rebase--helper.c | 1 + builtin/receive-pack.c | 1 + builtin/reflog.c | 1 + builtin/remote.c | 1 + builtin/repack.c | 1 + builtin/replace.c | 1 + builtin/rerere.c | 1 + builtin/reset.c | 1 + builtin/rev-list.c | 1 + builtin/rev-parse.c | 1 + builtin/revert.c | 1 + builtin/rm.c | 1 + builtin/send-pack.c | 1 + builtin/shortlog.c | 1 + builtin/show-branch.c | 1 + builtin/stripspace.c | 1 + builtin/submodule--helper.c | 1 + builtin/symbolic-ref.c | 1 + builtin/tag.c | 1 + builtin/unpack-file.c | 1 + builtin/unpack-objects.c | 1 + builtin/update-index.c | 1 + builtin/update-ref.c | 1 + builtin/update-server-info.c | 1 + builtin/var.c | 1 + builtin/verify-commit.c | 1 + builtin/verify-pack.c | 1 + builtin/verify-tag.c | 1 + builtin/worktree.c | 1 + builtin/write-tree.c | 1 + cache.h | 1 - color.c | 1 + column.c | 1 + config.c | 1 + connect.c | 1 + convert.c | 1 + credential-cache--daemon.c | 1 + credential.c | 1 + daemon.c | 1 + diff.c | 1 + dir.c | 1 + environment.c | 1 + fast-import.c | 1 + fetch-pack.c | 1 + git.c | 1 + gpg-interface.c | 1 + graph.c | 1 + grep.c | 1 + help.c | 1 + http-backend.c | 1 + http-fetch.c | 1 + http.c | 1 + ident.c | 1 + imap-send.c | 1 + ll-merge.c | 1 + log-tree.c | 1 + mailinfo.c | 1 + merge-recursive.c | 1 + notes-utils.c | 1 + notes.c | 1 + pager.c | 1 + parse-options.c | 1 + pathspec.c | 1 + pretty.c | 1 + prompt.c | 1 + read-cache.c | 1 + refs.c | 1 + refs/files-backend.c | 1 + remote-curl.c | 1 + remote.c | 1 + rerere.c | 1 + send-pack.c | 1 + sequencer.c | 1 + setup.c | 1 + sha1_file.c | 1 + sha1_name.c | 1 + submodule-config.c | 1 + submodule.c | 1 + t/helper/test-config.c | 1 + t/helper/test-submodule-config.c | 1 + trailer.c | 1 + transport.c | 1 + unpack-trees.c | 1 + upload-pack.c | 1 + userdiff.c | 1 + versioncmp.c | 1 + wrapper.c | 1 + xdiff-interface.c | 1 + 145 files changed, 144 insertions(+), 1 deletion(-)
advice.c +1 -0
@@ -1,4 +1,5 @@#include "cache.h" +#include "config.h" int advice_push_update_rejected =1 ;int advice_push_non_ff_current =1 ;
alias.c +1 -0
@@ -1,4 +1,5 @@#include "cache.h" +#include "config.h" char *alias_lookup (const char *alias) {
apply.c +1 -0
@@ -8,6 +8,7 @@*/ #include "cache.h" +#include "config.h" #include "blob.h" #include "delta.h" #include "diff.h"
archive-tar.c +1 -0
@@ -2,6 +2,7 @@* Copyright (c) 2005, 2006 Rene Scharfe */ #include "cache.h" +#include "config.h" #include "tar.h" #include "archive.h" #include "streaming.h"
archive-zip.c +1 -0
@@ -2,6 +2,7 @@* Copyright (c) 2006 Rene Scharfe */ #include "cache.h" +#include "config.h" #include "archive.h" #include "streaming.h" #include "utf8.h"
archive.c +1 -0
@@ -1,4 +1,5 @@#include "cache.h" +#include "config.h" #include "refs.h" #include "commit.h" #include "tree-walk.h"
attr.c +1 -0
@@ -9,6 +9,7 @@#define NO_THE_INDEX_COMPATIBILITY_MACROS #include "cache.h" +#include "config.h" #include "exec_cmd.h" #include "attr.h" #include "dir.h"
bisect.c +1 -0
@@ -1,4 +1,5 @@#include "cache.h" +#include "config.h" #include "commit.h" #include "diff.h" #include "revision.h"
branch.c +1 -0
@@ -1,5 +1,6 @@#include "git-compat-util.h" #include "cache.h" +#include "config.h" #include "branch.h" #include "refs.h" #include "remote.h"
builtin/add.c +1 -0
@@ -4,6 +4,7 @@* Copyright (C) 2006 Linus Torvalds */ #include "cache.h" +#include "config.h" #include "builtin.h" #include "lockfile.h" #include "dir.h"
builtin/am.c +1 -0
@@ -4,6 +4,7 @@* Based on git-am.sh by Junio C Hamano. */ #include "cache.h" +#include "config.h" #include "builtin.h" #include "exec_cmd.h" #include "parse-options.h"
builtin/blame.c +1 -0
@@ -6,6 +6,7 @@*/ #include "cache.h" +#include "config.h" #include "refs.h" #include "builtin.h" #include "blob.h"
builtin/branch.c +1 -0
@@ -6,6 +6,7 @@*/ #include "cache.h" +#include "config.h" #include "color.h" #include "refs.h" #include "commit.h"
builtin/cat-file.c +1 -0
@@ -4,6 +4,7 @@* Copyright (C) Linus Torvalds, 2005 */ #include "cache.h" +#include "config.h" #include "builtin.h" #include "parse-options.h" #include "userdiff.h"
builtin/check-attr.c +1 -0
@@ -1,5 +1,6 @@#include "builtin.h" #include "cache.h" +#include "config.h" #include "attr.h" #include "quote.h" #include "parse-options.h"
builtin/check-ignore.c +1 -0
@@ -1,5 +1,6 @@#include "builtin.h" #include "cache.h" +#include "config.h" #include "dir.h" #include "quote.h" #include "pathspec.h"
builtin/check-mailmap.c +1 -0
@@ -1,4 +1,5 @@#include "builtin.h" +#include "config.h" #include "mailmap.h" #include "parse-options.h" #include "string-list.h"
builtin/checkout-index.c +1 -0
@@ -5,6 +5,7 @@* */ #include "builtin.h" +#include "config.h" #include "lockfile.h" #include "quote.h" #include "cache-tree.h"
builtin/checkout.c +1 -0
@@ -1,4 +1,5 @@#include "builtin.h" +#include "config.h" #include "lockfile.h" #include "parse-options.h" #include "refs.h"
builtin/clean.c +1 -0
@@ -8,6 +8,7 @@#include "builtin.h" #include "cache.h" +#include "config.h" #include "dir.h" #include "parse-options.h" #include "string-list.h"
builtin/clone.c +1 -0
@@ -9,6 +9,7 @@*/ #include "builtin.h" +#include "config.h" #include "lockfile.h" #include "parse-options.h" #include "fetch-pack.h"
builtin/column.c +1 -0
@@ -1,5 +1,6 @@#include "builtin.h" #include "cache.h" +#include "config.h" #include "strbuf.h" #include "parse-options.h" #include "string-list.h"
builtin/commit-tree.c +1 -0
@@ -4,6 +4,7 @@* Copyright (C) Linus Torvalds, 2005 */ #include "cache.h" +#include "config.h" #include "commit.h" #include "tree.h" #include "builtin.h"
builtin/commit.c +1 -0
@@ -6,6 +6,7 @@*/ #include "cache.h" +#include "config.h" #include "lockfile.h" #include "cache-tree.h" #include "color.h"
builtin/config.c +1 -0
@@ -1,5 +1,6 @@#include "builtin.h" #include "cache.h" +#include "config.h" #include "color.h" #include "parse-options.h" #include "urlmatch.h"
builtin/count-objects.c +1 -0
@@ -5,6 +5,7 @@*/ #include "cache.h" +#include "config.h" #include "dir.h" #include "builtin.h" #include "parse-options.h"
builtin/describe.c +1 -0
@@ -1,4 +1,5 @@#include "cache.h" +#include "config.h" #include "lockfile.h" #include "commit.h" #include "tag.h"
builtin/diff-files.c +1 -0
@@ -4,6 +4,7 @@* Copyright (C) Linus Torvalds, 2005 */ #include "cache.h" +#include "config.h" #include "diff.h" #include "commit.h" #include "revision.h"
builtin/diff-index.c +1 -0
@@ -1,4 +1,5 @@#include "cache.h" +#include "config.h" #include "diff.h" #include "commit.h" #include "revision.h"
builtin/diff-tree.c +1 -0
@@ -1,4 +1,5 @@#include "cache.h" +#include "config.h" #include "diff.h" #include "commit.h" #include "log-tree.h"
builtin/diff.c +1 -0
@@ -4,6 +4,7 @@* Copyright (c) 2006 Junio C Hamano */ #include "cache.h" +#include "config.h" #include "lockfile.h" #include "color.h" #include "commit.h"
builtin/difftool.c +1 -0
@@ -12,6 +12,7 @@* Copyright (C) 2016 Johannes Schindelin */ #include "cache.h" +#include "config.h" #include "builtin.h" #include "run-command.h" #include "exec_cmd.h"
builtin/fast-export.c +1 -0
@@ -5,6 +5,7 @@*/ #include "builtin.h" #include "cache.h" +#include "config.h" #include "refs.h" #include "commit.h" #include "object.h"
builtin/fetch.c +1 -0
@@ -2,6 +2,7 @@* "git fetch" */ #include "cache.h" +#include "config.h" #include "refs.h" #include "commit.h" #include "builtin.h"
builtin/fmt-merge-msg.c +1 -0
@@ -1,5 +1,6 @@#include "builtin.h" #include "cache.h" +#include "config.h" #include "refs.h" #include "commit.h" #include "diff.h"
builtin/for-each-ref.c +1 -0
@@ -1,5 +1,6 @@#include "builtin.h" #include "cache.h" +#include "config.h" #include "refs.h" #include "object.h" #include "parse-options.h"
builtin/fsck.c +1 -0
@@ -1,5 +1,6 @@#include "builtin.h" #include "cache.h" +#include "config.h" #include "commit.h" #include "tree.h" #include "blob.h"
builtin/gc.c +1 -0
@@ -11,6 +11,7 @@*/ #include "builtin.h" +#include "config.h" #include "tempfile.h" #include "lockfile.h" #include "parse-options.h"
builtin/grep.c +1 -0
@@ -4,6 +4,7 @@* Copyright (c) 2006 Junio C Hamano */ #include "cache.h" +#include "config.h" #include "blob.h" #include "tree.h" #include "commit.h"
builtin/hash-object.c +1 -0
@@ -5,6 +5,7 @@* Copyright (C) Junio C Hamano, 2005 */ #include "builtin.h" +#include "config.h" #include "blob.h" #include "quote.h" #include "parse-options.h"
builtin/help.c +1 -0
@@ -2,6 +2,7 @@* Builtin help command */ #include "cache.h" +#include "config.h" #include "builtin.h" #include "exec_cmd.h" #include "parse-options.h"
builtin/index-pack.c +1 -0
@@ -1,4 +1,5 @@#include "builtin.h" +#include "config.h" #include "delta.h" #include "pack.h" #include "csum-file.h"
builtin/init-db.c +1 -0
@@ -4,6 +4,7 @@* Copyright (C) Linus Torvalds, 2005 */ #include "cache.h" +#include "config.h" #include "refs.h" #include "builtin.h" #include "exec_cmd.h"
builtin/log.c +1 -0
@@ -5,6 +5,7 @@* 2006 Junio Hamano */ #include "cache.h" +#include "config.h" #include "refs.h" #include "color.h" #include "commit.h"
builtin/ls-files.c +1 -0
@@ -6,6 +6,7 @@* Copyright (C) Linus Torvalds, 2005 */ #include "cache.h" +#include "config.h" #include "quote.h" #include "dir.h" #include "builtin.h"
builtin/ls-tree.c +1 -0
@@ -4,6 +4,7 @@* Copyright (C) Linus Torvalds, 2005 */ #include "cache.h" +#include "config.h" #include "blob.h" #include "tree.h" #include "commit.h"
builtin/merge-base.c +1 -0
@@ -1,5 +1,6 @@#include "builtin.h" #include "cache.h" +#include "config.h" #include "commit.h" #include "refs.h" #include "diff.h"
builtin/merge-file.c +1 -0
@@ -1,5 +1,6 @@#include "builtin.h" #include "cache.h" +#include "config.h" #include "xdiff/xdiff.h" #include "xdiff-interface.h" #include "parse-options.h"
builtin/merge.c +1 -0
@@ -7,6 +7,7 @@*/ #include "cache.h" +#include "config.h" #include "parse-options.h" #include "builtin.h" #include "lockfile.h"
builtin/mv.c +1 -0
@@ -4,6 +4,7 @@* Copyright (C) 2006 Johannes Schindelin */ #include "builtin.h" +#include "config.h" #include "pathspec.h" #include "lockfile.h" #include "dir.h"
builtin/name-rev.c +1 -0
@@ -1,5 +1,6 @@#include "builtin.h" #include "cache.h" +#include "config.h" #include "commit.h" #include "tag.h" #include "refs.h"
builtin/notes.c +1 -0
@@ -8,6 +8,7 @@*/ #include "cache.h" +#include "config.h" #include "builtin.h" #include "notes.h" #include "blob.h"
builtin/pack-objects.c +1 -0
@@ -1,5 +1,6 @@#include "builtin.h" #include "cache.h" +#include "config.h" #include "attr.h" #include "object.h" #include "blob.h"
builtin/patch-id.c +1 -0
@@ -1,4 +1,5 @@#include "builtin.h" +#include "config.h" static void flush_current_id (int patchlen,struct object_id *id,struct object_id *result) {
builtin/pull.c +1 -0
@@ -6,6 +6,7 @@* Fetch one or more remote refs and merge it/them into the current HEAD. */ #include "cache.h" +#include "config.h" #include "builtin.h" #include "parse-options.h" #include "exec_cmd.h"
builtin/push.c +1 -0
@@ -2,6 +2,7 @@* "git push" */ #include "cache.h" +#include "config.h" #include "refs.h" #include "run-command.h" #include "builtin.h"
builtin/read-tree.c +1 -0
@@ -5,6 +5,7 @@*/ #include "cache.h" +#include "config.h" #include "lockfile.h" #include "object.h" #include "tree.h"
builtin/rebase--helper.c +1 -0
@@ -1,5 +1,6 @@#include "builtin.h" #include "cache.h" +#include "config.h" #include "parse-options.h" #include "sequencer.h"
builtin/receive-pack.c +1 -0
@@ -1,4 +1,5 @@#include "builtin.h" +#include "config.h" #include "lockfile.h" #include "pack.h" #include "refs.h"
builtin/reflog.c +1 -0
@@ -1,4 +1,5 @@#include "builtin.h" +#include "config.h" #include "lockfile.h" #include "commit.h" #include "refs.h"
builtin/remote.c +1 -0
@@ -1,4 +1,5 @@#include "builtin.h" +#include "config.h" #include "parse-options.h" #include "transport.h" #include "remote.h"
builtin/repack.c +1 -0
@@ -1,5 +1,6 @@#include "builtin.h" #include "cache.h" +#include "config.h" #include "dir.h" #include "parse-options.h" #include "run-command.h"
builtin/replace.c +1 -0
@@ -9,6 +9,7 @@*/ #include "cache.h" +#include "config.h" #include "builtin.h" #include "refs.h" #include "parse-options.h"
builtin/rerere.c +1 -0
@@ -1,5 +1,6 @@#include "builtin.h" #include "cache.h" +#include "config.h" #include "dir.h" #include "parse-options.h" #include "string-list.h"
builtin/reset.c +1 -0
@@ -8,6 +8,7 @@* Copyright (c) 2005, 2006 Linus Torvalds and Junio C Hamano */ #include "builtin.h" +#include "config.h" #include "lockfile.h" #include "tag.h" #include "object.h"
builtin/rev-list.c +1 -0
@@ -1,4 +1,5 @@#include "cache.h" +#include "config.h" #include "commit.h" #include "diff.h" #include "revision.h"
builtin/rev-parse.c +1 -0
@@ -4,6 +4,7 @@* Copyright (C) Linus Torvalds, 2005 */ #include "cache.h" +#include "config.h" #include "commit.h" #include "refs.h" #include "quote.h"
builtin/revert.c +1 -0
@@ -1,4 +1,5 @@#include "cache.h" +#include "config.h" #include "builtin.h" #include "parse-options.h" #include "diff.h"
builtin/rm.c +1 -0
@@ -4,6 +4,7 @@* Copyright (C) Linus Torvalds 2006 */ #include "builtin.h" +#include "config.h" #include "lockfile.h" #include "dir.h" #include "cache-tree.h"
builtin/send-pack.c +1 -0
@@ -1,4 +1,5 @@#include "builtin.h" +#include "config.h" #include "commit.h" #include "refs.h" #include "pkt-line.h"
builtin/shortlog.c +1 -0
@@ -1,5 +1,6 @@#include "builtin.h" #include "cache.h" +#include "config.h" #include "commit.h" #include "diff.h" #include "string-list.h"
builtin/show-branch.c +1 -0
@@ -1,4 +1,5 @@#include "cache.h" +#include "config.h" #include "commit.h" #include "refs.h" #include "builtin.h"
builtin/stripspace.c +1 -0
@@ -1,5 +1,6 @@#include "builtin.h" #include "cache.h" +#include "config.h" #include "parse-options.h" #include "strbuf.h"
builtin/submodule--helper.c +1 -0
@@ -1,5 +1,6 @@#include "builtin.h" #include "cache.h" +#include "config.h" #include "parse-options.h" #include "quote.h" #include "pathspec.h"
builtin/symbolic-ref.c +1 -0
@@ -1,4 +1,5 @@#include "builtin.h" +#include "config.h" #include "cache.h" #include "refs.h" #include "parse-options.h"
builtin/tag.c +1 -0
@@ -7,6 +7,7 @@*/ #include "cache.h" +#include "config.h" #include "builtin.h" #include "refs.h" #include "tag.h"
builtin/unpack-file.c +1 -0
@@ -1,4 +1,5 @@#include "builtin.h" +#include "config.h" static char *create_temp_file (unsigned char *sha1) {
builtin/unpack-objects.c +1 -0
@@ -1,5 +1,6 @@#include "builtin.h" #include "cache.h" +#include "config.h" #include "object.h" #include "delta.h" #include "pack.h"
builtin/update-index.c +1 -0
@@ -4,6 +4,7 @@* Copyright (C) Linus Torvalds, 2005 */ #include "cache.h" +#include "config.h" #include "lockfile.h" #include "quote.h" #include "cache-tree.h"
builtin/update-ref.c +1 -0
@@ -1,4 +1,5 @@#include "cache.h" +#include "config.h" #include "refs.h" #include "builtin.h" #include "parse-options.h"
builtin/update-server-info.c +1 -0
@@ -1,4 +1,5 @@#include "cache.h" +#include "config.h" #include "builtin.h" #include "parse-options.h"
builtin/var.c +1 -0
@@ -4,6 +4,7 @@* Copyright (C) Eric Biederman, 2005 */ #include "builtin.h" +#include "config.h" static const char var_usage[] ="git var (-l | <variable>)" ;
builtin/verify-commit.c +1 -0
@@ -6,6 +6,7 @@* Based on git-verify-tag */ #include "cache.h" +#include "config.h" #include "builtin.h" #include "commit.h" #include "run-command.h"
builtin/verify-pack.c +1 -0
@@ -1,5 +1,6 @@#include "builtin.h" #include "cache.h" +#include "config.h" #include "run-command.h" #include "parse-options.h"
builtin/verify-tag.c +1 -0
@@ -6,6 +6,7 @@* Based on git-verify-tag.sh */ #include "cache.h" +#include "config.h" #include "builtin.h" #include "tag.h" #include "run-command.h"
builtin/worktree.c +1 -0
@@ -1,4 +1,5 @@#include "cache.h" +#include "config.h" #include "builtin.h" #include "dir.h" #include "parse-options.h"
builtin/write-tree.c +1 -0
@@ -5,6 +5,7 @@*/ #include "builtin.h" #include "cache.h" +#include "config.h" #include "tree.h" #include "cache-tree.h" #include "parse-options.h"
cache.h +0 -1
@@ -11,7 +11,6 @@#include "string-list.h" #include "pack-revindex.h" #include "hash.h" -#include "config.h" #ifndef platform_SHA_CTX/*
color.c +1 -0
@@ -1,4 +1,5 @@#include "cache.h" +#include "config.h" #include "color.h" static int git_use_color_default =GIT_COLOR_AUTO ;
column.c +1 -0
@@ -1,4 +1,5 @@#include "cache.h" +#include "config.h" #include "column.h" #include "string-list.h" #include "parse-options.h"
config.c +1 -0
@@ -6,6 +6,7 @@* */ #include "cache.h" +#include "config.h" #include "lockfile.h" #include "exec_cmd.h" #include "strbuf.h"
connect.c +1 -0
@@ -1,5 +1,6 @@#include "git-compat-util.h" #include "cache.h" +#include "config.h" #include "pkt-line.h" #include "quote.h" #include "refs.h"
convert.c +1 -0
@@ -1,4 +1,5 @@#include "cache.h" +#include "config.h" #include "attr.h" #include "run-command.h" #include "quote.h"
credential-cache--daemon.c +1 -0
@@ -1,4 +1,5 @@#include "cache.h" +#include "config.h" #include "tempfile.h" #include "credential.h" #include "unix-socket.h"
credential.c +1 -0
@@ -1,4 +1,5 @@#include "cache.h" +#include "config.h" #include "credential.h" #include "string-list.h" #include "run-command.h"
daemon.c +1 -0
@@ -1,4 +1,5 @@#include "cache.h" +#include "config.h" #include "pkt-line.h" #include "run-command.h" #include "strbuf.h"
diff.c +1 -0
@@ -2,6 +2,7 @@* Copyright (C) 2005 Junio C Hamano */ #include "cache.h" +#include "config.h" #include "tempfile.h" #include "quote.h" #include "diff.h"
dir.c +1 -0
@@ -9,6 +9,7 @@*/ #define NO_THE_INDEX_COMPATIBILITY_MACROS #include "cache.h" +#include "config.h" #include "dir.h" #include "attr.h" #include "refs.h"
environment.c +1 -0
@@ -8,6 +8,7 @@* are. */ #include "cache.h" +#include "config.h" #include "refs.h" #include "fmt-merge-msg.h" #include "commit.h"
fast-import.c +1 -0
@@ -154,6 +154,7 @@ Format of STDIN stream:#include "builtin.h" #include "cache.h" +#include "config.h" #include "lockfile.h" #include "object.h" #include "blob.h"
fetch-pack.c +1 -0
@@ -1,4 +1,5 @@#include "cache.h" +#include "config.h" #include "lockfile.h" #include "refs.h" #include "pkt-line.h"
git.c +1 -0
@@ -1,4 +1,5 @@#include "builtin.h" +#include "config.h" #include "exec_cmd.h" #include "help.h" #include "run-command.h"
gpg-interface.c +1 -0
@@ -1,4 +1,5 @@#include "cache.h" +#include "config.h" #include "run-command.h" #include "strbuf.h" #include "gpg-interface.h"
graph.c +1 -0
@@ -1,4 +1,5 @@#include "cache.h" +#include "config.h" #include "commit.h" #include "color.h" #include "graph.h"
grep.c +1 -0
@@ -1,4 +1,5 @@#include "cache.h" +#include "config.h" #include "grep.h" #include "userdiff.h" #include "xdiff-interface.h"
help.c +1 -0
@@ -1,4 +1,5 @@#include "cache.h" +#include "config.h" #include "builtin.h" #include "exec_cmd.h" #include "run-command.h"
http-backend.c +1 -0
@@ -1,4 +1,5 @@#include "cache.h" +#include "config.h" #include "refs.h" #include "pkt-line.h" #include "object.h"
http-fetch.c +1 -0
@@ -1,4 +1,5 @@#include "cache.h" +#include "config.h" #include "exec_cmd.h" #include "http.h" #include "walker.h"
http.c +1 -0
@@ -1,5 +1,6 @@#include "git-compat-util.h" #include "http.h" +#include "config.h" #include "pack.h" #include "sideband.h" #include "run-command.h"
ident.c +1 -0
@@ -6,6 +6,7 @@* Copyright (C) 2005 Linus Torvalds */ #include "cache.h" +#include "config.h" static struct strbuf git_default_name =STRBUF_INIT ;static struct strbuf git_default_email =STRBUF_INIT ;
imap-send.c +1 -0
@@ -23,6 +23,7 @@*/ #include "cache.h" +#include "config.h" #include "credential.h" #include "exec_cmd.h" #include "run-command.h"
ll-merge.c +1 -0
@@ -5,6 +5,7 @@*/ #include "cache.h" +#include "config.h" #include "attr.h" #include "xdiff-interface.h" #include "run-command.h"
log-tree.c +1 -0
@@ -1,4 +1,5 @@#include "cache.h" +#include "config.h" #include "diff.h" #include "commit.h" #include "tag.h"
mailinfo.c +1 -0
@@ -1,4 +1,5 @@#include "cache.h" +#include "config.h" #include "utf8.h" #include "strbuf.h" #include "mailinfo.h"
merge-recursive.c +1 -0
@@ -4,6 +4,7 @@* The thieves were Alex Riesen and Johannes Schindelin, in June/July 2006 */ #include "cache.h" +#include "config.h" #include "advice.h" #include "lockfile.h" #include "cache-tree.h"
notes-utils.c +1 -0
@@ -1,4 +1,5 @@#include "cache.h" +#include "config.h" #include "commit.h" #include "refs.h" #include "notes-utils.h"
notes.c +1 -0
@@ -1,4 +1,5 @@#include "cache.h" +#include "config.h" #include "notes.h" #include "blob.h" #include "tree.h"
pager.c +1 -0
@@ -1,4 +1,5 @@#include "cache.h" +#include "config.h" #include "run-command.h" #include "sigchain.h"
parse-options.c +1 -0
@@ -1,6 +1,7 @@#include "git-compat-util.h" #include "parse-options.h" #include "cache.h" +#include "config.h" #include "commit.h" #include "color.h" #include "utf8.h"
pathspec.c +1 -0
@@ -1,5 +1,6 @@#define NO_THE_INDEX_COMPATIBILITY_MACROS #include "cache.h" +#include "config.h" #include "dir.h" #include "pathspec.h" #include "attr.h"
pretty.c +1 -0
@@ -1,4 +1,5 @@#include "cache.h" +#include "config.h" #include "commit.h" #include "utf8.h" #include "diff.h"
prompt.c +1 -0
@@ -1,4 +1,5 @@#include "cache.h" +#include "config.h" #include "run-command.h" #include "strbuf.h" #include "prompt.h"
read-cache.c +1 -0
@@ -5,6 +5,7 @@*/ #define NO_THE_INDEX_COMPATIBILITY_MACROS #include "cache.h" +#include "config.h" #include "tempfile.h" #include "lockfile.h" #include "cache-tree.h"
refs.c +1 -0
@@ -3,6 +3,7 @@*/ #include "cache.h" +#include "config.h" #include "hashmap.h" #include "lockfile.h" #include "iterator.h"
refs/files-backend.c +1 -0
@@ -1,4 +1,5 @@#include "../cache.h" +#include "../config.h" #include "../refs.h" #include "refs-internal.h" #include "ref-cache.h"
remote-curl.c +1 -0
@@ -1,4 +1,5 @@#include "cache.h" +#include "config.h" #include "remote.h" #include "strbuf.h" #include "walker.h"
remote.c +1 -0
@@ -1,4 +1,5 @@#include "cache.h" +#include "config.h" #include "remote.h" #include "refs.h" #include "commit.h"
rerere.c +1 -0
@@ -1,4 +1,5 @@#include "cache.h" +#include "config.h" #include "lockfile.h" #include "string-list.h" #include "rerere.h"
send-pack.c +1 -0
@@ -1,4 +1,5 @@#include "builtin.h" +#include "config.h" #include "commit.h" #include "refs.h" #include "pkt-line.h"
sequencer.c +1 -0
@@ -1,4 +1,5 @@#include "cache.h" +#include "config.h" #include "lockfile.h" #include "sequencer.h" #include "dir.h"
setup.c +1 -0
@@ -1,4 +1,5 @@#include "cache.h" +#include "config.h" #include "dir.h" #include "string-list.h"
sha1_file.c +1 -0
@@ -7,6 +7,7 @@* creation etc. */ #include "cache.h" +#include "config.h" #include "string-list.h" #include "lockfile.h" #include "delta.h"
sha1_name.c +1 -0
@@ -1,4 +1,5 @@#include "cache.h" +#include "config.h" #include "tag.h" #include "commit.h" #include "tree.h"
submodule-config.c +1 -0
@@ -1,4 +1,5 @@#include "cache.h" +#include "config.h" #include "submodule-config.h" #include "submodule.h" #include "strbuf.h"
submodule.c +1 -0
@@ -1,4 +1,5 @@#include "cache.h" +#include "config.h" #include "submodule-config.h" #include "submodule.h" #include "dir.h"
t/helper/test-config.c +1 -0
@@ -1,4 +1,5 @@#include "cache.h" +#include "config.h" #include "string-list.h" /*
t/helper/test-submodule-config.c +1 -0
@@ -1,4 +1,5 @@#include "cache.h" +#include "config.h" #include "submodule-config.h" #include "submodule.h"
trailer.c +1 -0
@@ -1,4 +1,5 @@#include "cache.h" +#include "config.h" #include "string-list.h" #include "run-command.h" #include "commit.h"
transport.c +1 -0
@@ -1,4 +1,5 @@#include "cache.h" +#include "config.h" #include "transport.h" #include "run-command.h" #include "pkt-line.h"
unpack-trees.c +1 -0
@@ -1,5 +1,6 @@#define NO_THE_INDEX_COMPATIBILITY_MACROS #include "cache.h" +#include "config.h" #include "dir.h" #include "tree.h" #include "tree-walk.h"
upload-pack.c +1 -0
@@ -1,4 +1,5 @@#include "cache.h" +#include "config.h" #include "refs.h" #include "pkt-line.h" #include "sideband.h"
userdiff.c +1 -0
@@ -1,4 +1,5 @@#include "cache.h" +#include "config.h" #include "userdiff.h" #include "attr.h"
versioncmp.c +1 -0
@@ -1,4 +1,5 @@#include "cache.h" +#include "config.h" #include "string-list.h" /*
wrapper.c +1 -0
@@ -2,6 +2,7 @@* Various trivial helper wrappers around standard functions */ #include "cache.h" +#include "config.h" static void do_nothing (size_t size) {
xdiff-interface.c +1 -0
@@ -1,4 +1,5 @@#include "cache.h" +#include "config.h" #include "xdiff-interface.h" #include "xdiff/xtypes.h" #include "xdiff/xdiffi.h"
Signature · 1 line
2.13.1.508.gb3defc5cc-goog
PATCH v2 5/32 setup: don't perform lazy initialization of repository state
In reply to Brandon WilliamsUnder some circumstances (bogus GIT_DIR value or the discovered gitdir is '.git') 'setup_git_directory()' won't initialize key repository state. This leads to inconsistent state after running the setup code. To account for this inconsistent state, lazy initialization is done once a caller asks for the repository's gitdir or some other piece of repository state. This is confusing and can be error prone.
Instead let's tighten the expected outcome of 'setup_git_directory()' and ensure that it initializes repository state in all cases that would have been handled by lazy initialization.
This also lets us drop the requirement to have 'have_git_dir()' check if the environment variable GIT_DIR was set as that will be handled by the end of the setup code.
--- cache.h | 2 ++ environment.c | 17 ++++++++--------- setup.c | 14 ++++++++++++++ 3 files changed, 24 insertions(+), 9 deletions(-)
cache.h +2 -0
@@ -462,6 +462,8 @@ static inline enum object_type object_type(unsigned int mode)*/ extern const char *const local_repo_env[]; +extern void setup_git_env (void ); +/* * Returns true iff we have a configured git repository (either via * setup_git_directory, or in the environment via $GIT_DIR).
environment.c +8 -9
@@ -160,7 +160,7 @@ static char *git_path_from_env(const char *envvar, const char *git_dir,return xstrdup (value); } -static void setup_git_env (void ) +void setup_git_env (void ) {struct strbuf sb =STRBUF_INIT ;const char *gitfile;
@@ -205,28 +205,27 @@ int is_bare_repository(void)int have_git_dir (void ) {return startup_info->have_repository - || git_dir - ||getenv (GIT_DIR_ENVIRONMENT ); + || git_dir; }const char *get_git_dir (void ) {if (!git_dir) -setup_git_env (); +BUG ("git environment hasn't been setup" );return git_dir; }const char *get_git_common_dir (void ) {if (!git_dir) -setup_git_env (); +BUG ("git environment hasn't been setup" );return git_common_dir; }const char *get_git_namespace (void ) {if (!namespace) -setup_git_env (); +BUG ("git environment hasn't been setup" );return namespace; }
@@ -276,7 +275,7 @@ const char *get_git_work_tree(void)char *get_object_directory (void ) {if (!git_object_dir) -setup_git_env (); +BUG ("git environment hasn't been setup" );return git_object_dir; }
@@ -316,14 +315,14 @@ int odb_pack_keep(const char *name)char *get_index_file (void ) {if (!git_index_file) -setup_git_env (); +BUG ("git environment hasn't been setup" );return git_index_file; }char *get_graft_file (void ) {if (!git_graft_file) -setup_git_env (); +BUG ("git environment hasn't been setup" );return git_graft_file; }
setup.c +14 -0
@@ -1063,6 +1063,20 @@ const char *setup_git_directory_gently(int *nongit_ok) startup_info->have_repository = !nongit_ok || !*nongit_ok; startup_info->prefix = prefix; +/* +* Not all paths through the setup code will call 'set_git_dir()' (which +* directly sets up the environment) so in order to guarantee that the +* environment is in a consistent state after setup, explicitly setup +* the environment if we have a repository. +* +* NEEDSWORK: currently we allow bogus GIT_DIR values to be set in some +* code paths so we also need to explicitly setup the environment if +* the user has set GIT_DIR. It may be beneficial to disallow bogus +* GIT_DIR values at some point in the future. +*/ +if (startup_info->have_repository ||getenv (GIT_DIR_ENVIRONMENT )) +setup_git_env (); +strbuf_release (&dir);strbuf_release (&gitdir);
Signature · 1 line
2.13.1.508.gb3defc5cc-goog
PATCH v2 7/32 repository: introduce the repository object
In reply to Brandon WilliamsIntroduce the repository object 'struct repository' which can be used to hold all state pertaining to a git repository.
Some of the benefits of object-ifying a repository are:
1. Make the code base more readable and easier to reason about.
2. Allow for working on multiple repositories, specifically submodules, within the same process. Currently the process for working on a submodule involves setting up an argv_array of options for a particular command and then launching a child process to execute the command in the context of the submodule. This is clunky and can require lots of little hacks in order to ensure correctness. Ideally it would be nice to simply pass a repository and an options struct to a command.
3. Eliminating reliance on global state will make it easier to enable the use of threading to improve performance.
--- Makefile | 1 + cache.h | 1 + environment.c | 2 +- repository.c | 171 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ repository.h | 25 +++++++++ 5 files changed, 199 insertions(+), 1 deletion(-) create mode 100644 repository.c create mode 100644 repository.h
Makefile +1 -0
@@ -821,6 +821,7 @@ LIB_OBJS += refs/ref-cache.o LIB_OBJS += ref-filter.o LIB_OBJS += remote.o LIB_OBJS += replace_object.o +LIB_OBJS += repository.o LIB_OBJS += rerere.o LIB_OBJS += resolve-undo.o LIB_OBJS += revision.o
cache.h +1 -0
@@ -483,6 +483,7 @@ extern char *get_graft_file(void);extern int set_git_dir (const char *path);extern int get_common_dir_noenv (struct strbuf *sb,const char *gitdir);extern int get_common_dir (struct strbuf *sb,const char *gitdir); +extern char *expand_namespace (const char *raw_namespace);extern const char *get_git_namespace (void );extern const char *strip_namespace (const char *namespaced_ref);extern const char *get_super_prefix (void );
environment.c +1 -1
@@ -127,7 +127,7 @@ const char * const local_repo_env[] = { NULL }; -static char *expand_namespace (const char *raw_namespace) +char *expand_namespace (const char *raw_namespace) {struct strbuf buf =STRBUF_INIT ;struct strbuf **components, **c;
repository.c new file +171 -0
171 lines not on this page · raw message
repository.h new file +25 -0
@@ -0,0 +1,25 @@ +#ifndef REPOSITORY_H +#define REPOSITORY_H + +struct repository { +/* Environment */ +char *gitdir; +char *commondir; +char *objectdir; +char *index_file; +char *graft_file; +char *namespace; + +/* Configurations */ +unsigned ignore_env:1 ; +/* Indicates if a repository has a different 'commondir' from 'gitdir' */ +unsigned different_commondir:1 ; +}; + +extern struct repository *the_repository; + +extern void repo_set_gitdir (struct repository *repo,const char *path); +extern int repo_init (struct repository *repo,const char *path); +extern void repo_clear (struct repository *repo); + +#endif /* REPOSITORY_H */
Signature · 1 line
2.13.1.508.gb3defc5cc-goog
PATCH v2 10/32 setup: add comment indicating a hack
In reply to Brandon Williams'GIT_TOPLEVEL_PREFIX_ENVIRONMENT' was added in (b58a68c1c setup: allow for prefix to be passed to git commands) to aid in fixing a bug where 'ls-files' and 'grep' were not able to properly recurse when called from within a subdirectory. Add a 'NEEDSWORK' comment indicating that this envvar should be removed once 'ls-files' and 'grep' can recurse in-process.
--- setup.c | 6 ++++++ 1 file changed, 6 insertions(+)
setup.c +6 -0
@@ -1057,6 +1057,12 @@ const char *setup_git_directory_gently(int *nongit_ok)die ("BUG: unhandled setup_git_directory_1() result" ); } +/* +* NEEDSWORK: This was a hack in order to get ls-files and grep to have +* properly formated output when recursing submodules. Once ls-files +* and grep have been changed to perform this recursing in-process this +* needs to be removed. +*/ env_prefix =getenv (GIT_TOPLEVEL_PREFIX_ENVIRONMENT );if (env_prefix) prefix = env_prefix;
Signature · 1 line
2.13.1.508.gb3defc5cc-goog
PATCH v2 6/32 environment: remove namespace_len variable
In reply to Brandon WilliamsUse 'skip_prefix' instead of 'starts_with' so that we can drop the need to keep around 'namespace_len'.
--- environment.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
environment.c +4 -5
@@ -98,7 +98,6 @@ char *git_work_tree_cfg;static char *work_tree;static const char *namespace; -static size_t namespace_len;static const char *super_prefix;
@@ -190,7 +189,6 @@ void setup_git_env(void) git_replace_ref_base =xstrdup (replace_ref_base ? replace_ref_base :"refs/replace/" ); namespace =expand_namespace (getenv (GIT_NAMESPACE_ENVIRONMENT )); - namespace_len =strlen (namespace); shallow_file =getenv (GIT_SHALLOW_FILE_ENVIRONMENT );if (shallow_file)set_alternate_shallow_file (shallow_file,0 );
@@ -231,9 +229,10 @@ const char *get_git_namespace(void)const char *strip_namespace (const char *namespaced_ref) { -if (!starts_with (namespaced_ref,get_git_namespace ())) -return NULL ; -return namespaced_ref + namespace_len; +const char *out; +if (skip_prefix (namespaced_ref,get_git_namespace (), &out)) +return out; +return NULL ; }const char *get_super_prefix (void )
Signature · 1 line
2.13.1.508.gb3defc5cc-goog
PATCH v2 9/32 environment: store worktree in the_repository
In reply to Brandon WilliamsMigrate 'work_tree' to be stored in 'the_repository'.
--- environment.c | 9 ++++----- repository.c | 12 ++++++++++++ repository.h | 3 +++ 3 files changed, 19 insertions(+), 5 deletions(-)
environment.c +4 -5
@@ -96,7 +96,6 @@ int ignore_untracked_cache_config;/* This is set by setup_git_dir_gently() and/or git_default_config() */ char *git_work_tree_cfg; -static char *work_tree;static const char *super_prefix;
@@ -220,19 +219,19 @@ void set_git_work_tree(const char *new_work_tree) {if (git_work_tree_initialized) { new_work_tree =real_path (new_work_tree); -if (strcmp (new_work_tree, work_tree)) +if (strcmp (new_work_tree, the_repository->worktree))die ("internal error: work tree has already been set\n" "Current worktree: %s\nNew worktree: %s" , - work_tree, new_work_tree); + the_repository->worktree, new_work_tree);return ; } git_work_tree_initialized =1 ; - work_tree =real_pathdup (new_work_tree,1 ); +repo_set_worktree (the_repository, new_work_tree); }const char *get_git_work_tree (void ) { -return work_tree; +return the_repository->worktree; }char *get_object_directory (void )
repository.c +12 -0
@@ -104,6 +104,16 @@ static int repo_init_gitdir(struct repository *repo, const char *gitdir)return ret; } +void repo_set_worktree (struct repository *repo,const char *path) +{ + repo->worktree =real_pathdup (path,1 ); +} + +char *repo_worktree_path (struct repository *repo,const char *path) +{ +return xstrfmt ("%s/%s" , repo->worktree, path); +} +static int verify_repo_format (struct repository_format *format,const char *commondir) {
@@ -166,6 +176,8 @@ static void repo_clear_env(struct repository *repo)void repo_clear (struct repository *repo) {repo_clear_env (repo); +free (repo->worktree); + repo->worktree =NULL ;memset (repo,0 ,sizeof (*repo)); }
repository.h +3 -0
@@ -9,6 +9,7 @@ struct repository {char *index_file;char *graft_file;char *namespace; +char *worktree;/* Configurations */ unsigned ignore_env:1;
@@ -19,6 +20,8 @@ struct repository {extern struct repository *the_repository;extern void repo_set_gitdir (struct repository *repo,const char *path); +extern void repo_set_worktree (struct repository *repo,const char *path); +extern char *repo_worktree_path (struct repository *repo,const char *path);extern int repo_init (struct repository *repo,const char *path);extern void repo_clear (struct repository *repo);
Signature · 1 line
2.13.1.508.gb3defc5cc-goog
PATCH v2 16/32 convert: convert get_cached_convert_stats_ascii to take an index
In reply to Brandon Williams--- builtin/ls-files.c | 3 ++- convert.c | 5 +++-- convert.h | 5 ++++- 3 files changed, 9 insertions(+), 4 deletions(-)
builtin/ls-files.c +2 -1
@@ -64,7 +64,8 @@ static void write_eolinfo(const struct cache_entry *ce, const char *path)const char *w_txt ="" ;const char *a_txt =get_convert_attr_ascii (path);if (ce &&S_ISREG (ce->ce_mode)) - i_txt =get_cached_convert_stats_ascii (ce->name); + i_txt =get_cached_convert_stats_ascii (&the_index, + ce->name);if (!lstat (path, &st) &&S_ISREG (st.st_mode)) w_txt =get_wt_convert_stats_ascii (path);printf ("i/%-5s w/%-5s attr/%-17s\t" , i_txt, w_txt, a_txt);
convert.c +3 -2
@@ -135,11 +135,12 @@ static const char *gather_convert_stats_ascii(const char *data, unsigned long si } } -const char *get_cached_convert_stats_ascii (const char *path) +const char *get_cached_convert_stats_ascii (const struct index_state *istate, +const char *path) {const char *ret;unsigned long sz; -void *data =read_blob_data_from_cache (path, &sz); +void *data =read_blob_data_from_index (istate, path, &sz); ret =gather_convert_stats_ascii (data, sz);free (data);return ret;
convert.h +4 -1
@@ -4,6 +4,8 @@#ifndef CONVERT_H #define CONVERT_H +struct index_state ; +enum safe_crlf {SAFE_CRLF_FALSE =0 , SAFE_CRLF_FAIL = 1,
@@ -33,7 +35,8 @@ enum eol { };extern enum eol core_eol; -extern const char *get_cached_convert_stats_ascii (const char *path); +extern const char *get_cached_convert_stats_ascii (const struct index_state *istate, +const char *path);extern const char *get_wt_convert_stats_ascii (const char *path);extern const char *get_convert_attr_ascii (const char *path);
Signature · 1 line
2.13.1.508.gb3defc5cc-goog
PATCH v2 14/32 submodule: add repo_read_gitmodules
In reply to Brandon WilliamsTeach the repo object to be able to populate the submodule_cache by reading the repository's gitmodules file.
--- submodule.c | 15 +++++++++++++++ submodule.h | 2 ++ 2 files changed, 17 insertions(+)
submodule.c +15 -0
@@ -1,4 +1,5 @@#include "cache.h" +#include "repository.h" #include "config.h" #include "submodule-config.h" #include "submodule.h"
@@ -202,6 +203,20 @@ void gitmodules_config(void) } } +static int gitmodules_cb (const char *var,const char *value,void *data) +{ +struct repository *repo = data; +return submodule_config_option (repo, var, value); +} + +void repo_read_gitmodules (struct repository *repo) +{ +char *gitmodules_path =repo_worktree_path (repo,".gitmodules" ); + +git_config_from_file (gitmodules_cb, gitmodules_path, repo); +free (gitmodules_path); +} +void gitmodules_config_sha1 (const unsigned char *commit_sha1) {struct strbuf rev =STRBUF_INIT ;
submodule.h +2 -0
@@ -1,6 +1,7 @@#ifndef SUBMODULE_H #define SUBMODULE_H +struct repository ;struct diff_options ;struct argv_array ;struct oid_array ;
@@ -40,6 +41,7 @@ extern void set_diffopt_flags_from_submodule_config(struct diff_options *, const char *path);extern int submodule_config (const char *var,const char *value,void *cb);extern void gitmodules_config (void ); +extern void repo_read_gitmodules (struct repository *repo);extern void gitmodules_config_sha1 (const unsigned char *commit_sha1);extern int is_submodule_initialized (const char *path);/*
Signature · 1 line
2.13.1.508.gb3defc5cc-goog
PATCH v2 19/32 convert: convert convert_to_git to take an index
In reply to Brandon Williams--- apply.c | 2 +- builtin/blame.c | 2 +- combine-diff.c | 2 +- convert.c | 7 ++++--- convert.h | 8 +++++--- diff.c | 6 +++--- dir.c | 2 +- sha1_file.c | 4 ++-- 8 files changed, 18 insertions(+), 15 deletions(-)
apply.c +1 -1
@@ -2268,7 +2268,7 @@ static int read_old_data(struct stat *st, const char *path, struct strbuf *buf)case S_IFREG :if (strbuf_read_file (buf, path, st->st_size) != st->st_size)return error (_ ("unable to open or read %s" ), path); -convert_to_git (path, buf->buf, buf->len, buf,0 ); +convert_to_git (&the_index, path, buf->buf, buf->len, buf,0 );return 0 ;default :return -1 ;
builtin/blame.c +1 -1
@@ -2384,7 +2384,7 @@ static struct commit *fake_working_tree_commit(struct diff_options *opt,if (strbuf_read (&buf,0 ,0 ) <0 )die_errno ("failed to read from stdin" ); } -convert_to_git (path, buf.buf, buf.len, &buf,0 ); +convert_to_git (&the_index, path, buf.buf, buf.len, &buf,0 ); origin->file.ptr = buf.buf; origin->file.size = buf.len;pretend_sha1_file (buf.buf, buf.len,OBJ_BLOB , origin->blob_oid.hash);
combine-diff.c +1 -1
@@ -1053,7 +1053,7 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,if (is_file) {struct strbuf buf =STRBUF_INIT ; -if (convert_to_git (elem->path, result, len, &buf, safe_crlf)) { +if (convert_to_git (&the_index, elem->path, result, len, &buf, safe_crlf)) {free (result); result =strbuf_detach (&buf, &len); result_size = len;
convert.c +4 -3
@@ -1085,7 +1085,8 @@ const char *get_convert_attr_ascii(const char *path)return "" ; } -int convert_to_git (const char *path,const char *src,size_t len, +int convert_to_git (const struct index_state *istate, +const char *path,const char *src,size_t len,struct strbuf *dst,enum safe_crlf checksafe) {int ret =0 ;
@@ -1101,7 +1102,7 @@ int convert_to_git(const char *path, const char *src, size_t len, src = dst->buf; len = dst->len; } - ret |=crlf_to_git (&the_index, path, src, len, dst, ca.crlf_action, checksafe); + ret |=crlf_to_git (istate, path, src, len, dst, ca.crlf_action, checksafe);if (ret && dst) { src = dst->buf; len = dst->len;
@@ -1172,7 +1173,7 @@ int renormalize_buffer(const char *path, const char *src, size_t len, struct str src = dst->buf; len = dst->len; } -return ret |convert_to_git (path, src, len, dst,SAFE_CRLF_RENORMALIZE ); +return ret |convert_to_git (&the_index, path, src, len, dst,SAFE_CRLF_RENORMALIZE ); }/*****************************************************************
convert.h +5 -3
@@ -41,15 +41,17 @@ extern const char *get_wt_convert_stats_ascii(const char *path);extern const char *get_convert_attr_ascii (const char *path);/* returns 1 if *dst was used */ -extern int convert_to_git (const char *path,const char *src,size_t len, +extern int convert_to_git (const struct index_state *istate, +const char *path,const char *src,size_t len,struct strbuf *dst,enum safe_crlf checksafe);extern int convert_to_working_tree (const char *path,const char *src,size_t len,struct strbuf *dst);extern int renormalize_buffer (const char *path,const char *src,size_t len,struct strbuf *dst); -static inline int would_convert_to_git (const char *path) +static inline int would_convert_to_git (const struct index_state *istate, +const char *path) { -return convert_to_git (path,NULL ,0 ,NULL ,0 ); +return convert_to_git (istate, path,NULL ,0 ,NULL ,0 ); }/* Precondition: would_convert_to_git_filter_fd(path) == true */ extern void convert_to_git_filter_fd(const struct index_state *istate,
diff.c +3 -3
@@ -2756,7 +2756,7 @@ static int reuse_worktree_file(const char *name, const unsigned char *sha1, int* Similarly, if we'd have to convert the file contents anyway, that * makes the optimization not worthwhile. */ -if (!want_file &&would_convert_to_git (name)) +if (!want_file &&would_convert_to_git (&the_index, name))return 0 ; len =strlen (name);
@@ -2878,7 +2878,7 @@ int diff_populate_filespec(struct diff_filespec *s, unsigned int flags)* point if the path requires us to run the content * conversion. */ -if (size_only && !would_convert_to_git (s->path)) +if (size_only && !would_convert_to_git (&the_index, s->path))return 0 ;/*
@@ -2905,7 +2905,7 @@ int diff_populate_filespec(struct diff_filespec *s, unsigned int flags)/* * Convert from working tree format to canonical git format */ -if (convert_to_git (s->path, s->data, s->size, &buf, crlf_warn)) { +if (convert_to_git (&the_index, s->path, s->data, s->size, &buf, crlf_warn)) {size_t size =0 ;munmap (s->data, s->size); s->should_munmap =0 ;
dir.c +1 -1
@@ -796,7 +796,7 @@ static int add_excludes(const char *fname, const char *base, int baselen, (pos = index_name_pos(istate, fname, strlen(fname))) >= 0 && !ce_stage(istate->cache[pos]) && ce_uptodate(istate->cache[pos]) && - !would_convert_to_git(fname)) + !would_convert_to_git(istate, fname))hashcpy (sha1_stat->sha1, istate->cache[pos]->oid.hash); else
sha1_file.c +2 -2
@@ -3547,7 +3547,7 @@ static int index_mem(unsigned char *sha1, void *buf, size_t size,*/ if ((type ==OBJ_BLOB ) && path) {struct strbuf nbuf =STRBUF_INIT ; -if (convert_to_git (path, buf, size, &nbuf, +if (convert_to_git (&the_index, path, buf, size, &nbuf, write_object ? safe_crlf :SAFE_CRLF_FALSE )) { buf =strbuf_detach (&nbuf, &size); re_allocated =1 ;
@@ -3669,7 +3669,7 @@ int index_fd(unsigned char *sha1, int fd, struct stat *st,else if (!S_ISREG (st->st_mode)) ret =index_pipe (sha1, fd, type, path, flags);else if (st->st_size <= big_file_threshold || type !=OBJ_BLOB || - (path &&would_convert_to_git (path))) + (path &&would_convert_to_git (&the_index, path))) ret =index_core (sha1, fd,xsize_t (st->st_size), type, path, flags);else
Signature · 1 line
2.13.1.508.gb3defc5cc-goog
PATCH v2 22/32 ls-files: convert overlay_tree_on_cache to take an index
In reply to Brandon Williams--- builtin/commit.c | 3 ++- builtin/ls-files.c | 15 ++++++++------- cache.h | 3 ++- 3 files changed, 12 insertions(+), 9 deletions(-)
builtin/commit.c +2 -1
@@ -254,7 +254,8 @@ static int list_paths(struct string_list *list, const char *with_tree,if (with_tree) {char *max_prefix =common_prefix (pattern); -overlay_tree_on_cache (with_tree, max_prefix ? max_prefix : prefix); +overlay_tree_on_index (&the_index, with_tree, + max_prefix ? max_prefix : prefix);free (max_prefix); }
builtin/ls-files.c +8 -7
@@ -432,7 +432,8 @@ static int get_common_prefix_len(const char *common_prefix)* that were given from the command line. We are not * going to write this index out. */ -void overlay_tree_on_cache (const char *tree_name,const char *prefix) +void overlay_tree_on_index (struct index_state *istate, +const char *tree_name,const char *prefix) {struct tree *tree;struct object_id oid;
@@ -447,8 +448,8 @@ void overlay_tree_on_cache(const char *tree_name, const char *prefix)die ("bad tree-ish %s" , tree_name);/* Hoist the unmerged entries up to stage #3 to make room */ -for (i =0 ; i < active_nr; i++) { -struct cache_entry *ce = active_cache[i]; +for (i =0 ; i < istate->cache_nr; i++) { +struct cache_entry *ce = istate->cache[i];if (!ce_stage (ce))continue ; ce->ce_flags |=CE_STAGEMASK ;
@@ -461,11 +462,11 @@ void overlay_tree_on_cache(const char *tree_name, const char *prefix) PATHSPEC_PREFER_CWD, prefix, matchbuf); }else memset (&pathspec,0 ,sizeof (pathspec)); -if (read_tree (tree,1 , &pathspec, &the_index)) +if (read_tree (tree,1 , &pathspec, istate))die ("unable to read tree entries %s" , tree_name); -for (i =0 ; i < active_nr; i++) { -struct cache_entry *ce = active_cache[i]; +for (i =0 ; i < istate->cache_nr; i++) { +struct cache_entry *ce = istate->cache[i];switch (ce_stage (ce)) {case 0 : last_stage0 = ce;
@@ -680,7 +681,7 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix)*/ if (show_stage || show_unmerged)die ("ls-files --with-tree is incompatible with -s or -u" ); -overlay_tree_on_cache (with_tree, max_prefix); +overlay_tree_on_index (&the_index, with_tree, max_prefix); }show_files (&dir);if (show_resolve_undo)
cache.h +2 -1
@@ -1993,7 +1993,8 @@ extern int ws_blank_line(const char *line, int len, unsigned ws_rule);#define ws_tab_width (rule) ((rule) & WS_TAB_WIDTH_MASK)/* ls-files */ -void overlay_tree_on_cache (const char *tree_name,const char *prefix); +void overlay_tree_on_index (struct index_state *istate, +const char *tree_name,const char *prefix);char *alias_lookup (const char *alias);int split_cmdline (char *cmdline,const char ***argv);
Signature · 1 line
2.13.1.508.gb3defc5cc-goog
PATCH v2 23/32 ls-files: convert write_eolinfo to take an index
In reply to Brandon Williams--- builtin/ls-files.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-)
builtin/ls-files.c +6 -7
@@ -54,17 +54,16 @@ static const char *tag_modified = "";static const char *tag_skip_worktree ="" ;static const char *tag_resolve_undo ="" ; -static void write_eolinfo (const struct cache_entry *ce,const char *path) +static void write_eolinfo (const struct index_state *istate, +const struct cache_entry *ce,const char *path) { -if (!show_eol) -return ; -else { +if (show_eol) {struct stat st;const char *i_txt ="" ;const char *w_txt ="" ;const char *a_txt =get_convert_attr_ascii (path);if (ce &&S_ISREG (ce->ce_mode)) - i_txt =get_cached_convert_stats_ascii (&the_index, + i_txt =get_cached_convert_stats_ascii (istate, ce->name);if (!lstat (path, &st) &&S_ISREG (st.st_mode)) w_txt =get_wt_convert_stats_ascii (path);
@@ -106,7 +105,7 @@ static void show_dir_entry(const char *tag, struct dir_entry *ent)return ;fputs (tag, stdout); -write_eolinfo (NULL , ent->name); +write_eolinfo (NULL ,NULL , ent->name);write_name (ent->name); }
@@ -276,7 +275,7 @@ static void show_ce_entry(const char *tag, const struct cache_entry *ce)find_unique_abbrev (ce->oid.hash, abbrev), ce_stage(ce)); } -write_eolinfo (ce, ce->name); +write_eolinfo (&the_index, ce, ce->name);write_name (ce->name);if (debug_mode) {const struct stat_data *sd = &ce->ce_stat_data;
Signature · 1 line
2.13.1.508.gb3defc5cc-goog
PATCH v2 20/32 convert: convert renormalize_buffer to take an index
In reply to Brandon Williams--- convert.c | 6 ++++-- convert.h | 3 ++- ll-merge.c | 2 +- merge-recursive.c | 4 ++-- 4 files changed, 9 insertions(+), 6 deletions(-)
convert.c +4 -2
@@ -1,3 +1,4 @@ +#define NO_THE_INDEX_COMPATIBILITY_MACROS #include "cache.h" #include "config.h" #include "attr.h"
@@ -1166,14 +1167,15 @@ int convert_to_working_tree(const char *path, const char *src, size_t len, strucreturn convert_to_working_tree_internal (path, src, len, dst,0 ); } -int renormalize_buffer (const char *path,const char *src,size_t len,struct strbuf *dst) +int renormalize_buffer (const struct index_state *istate,const char *path, +const char *src,size_t len,struct strbuf *dst) {int ret =convert_to_working_tree_internal (path, src, len, dst,1 );if (ret) { src = dst->buf; len = dst->len; } -return ret |convert_to_git (&the_index, path, src, len, dst,SAFE_CRLF_RENORMALIZE ); +return ret |convert_to_git (istate, path, src, len, dst,SAFE_CRLF_RENORMALIZE ); }/*****************************************************************
convert.h +2 -1
@@ -46,7 +46,8 @@ extern int convert_to_git(const struct index_state *istate, struct strbuf *dst, enum safe_crlf checksafe);extern int convert_to_working_tree (const char *path,const char *src,size_t len,struct strbuf *dst); -extern int renormalize_buffer (const char *path,const char *src,size_t len, +extern int renormalize_buffer (const struct index_state *istate, +const char *path,const char *src,size_t len,struct strbuf *dst);static inline int would_convert_to_git (const struct index_state *istate,const char *path)
ll-merge.c +1 -1
@@ -340,7 +340,7 @@ static const struct ll_merge_driver *find_ll_merge_driver(const char *merge_attrstatic void normalize_file (mmfile_t *mm,const char *path) {struct strbuf strbuf =STRBUF_INIT ; -if (renormalize_buffer (path, mm->ptr, mm->size, &strbuf)) { +if (renormalize_buffer (&the_index, path, mm->ptr, mm->size, &strbuf)) {free (mm->ptr); mm->size = strbuf.len; mm->ptr =strbuf_detach (&strbuf,NULL );
merge-recursive.c +2 -2
@@ -1640,8 +1640,8 @@ static int blob_unchanged(struct merge_options *opt,* performed. Comparison can be skipped if both files are * unchanged since their sha1s have already been compared. */ -if (renormalize_buffer (path, o.buf, o.len, &o) | -renormalize_buffer (path, a.buf, a.len, &a)) +if (renormalize_buffer (&the_index, path, o.buf, o.len, &o) | +renormalize_buffer (&the_index, path, a.buf, a.len, &a)) ret = (o.len == a.len && !memcmp (o.buf, a.buf, o.len)); error_return:
Signature · 1 line
2.13.1.508.gb3defc5cc-goog
PATCH v2 15/32 submodule: convert is_submodule_initialized to work on a repository
In reply to Brandon WilliamsConvert 'is_submodule_initialized()' to take a repository object and while we're at it, lets rename the function to 'is_submodule_active()' and remove the NEEDSWORK comment.
--- builtin/grep.c | 3 ++- builtin/submodule--helper.c | 9 +++++---- submodule.c | 20 ++++++++------------ submodule.h | 2 +- 4 files changed, 16 insertions(+), 18 deletions(-)
builtin/grep.c +2 -1
@@ -4,6 +4,7 @@* Copyright (c) 2006 Junio C Hamano */ #include "cache.h" +#include "repository.h" #include "config.h" #include "blob.h" #include "tree.h"
@@ -626,7 +627,7 @@ static int grep_submodule_launch(struct grep_opt *opt,static int grep_submodule (struct grep_opt *opt,const unsigned char *sha1,const char *filename,const char *path) { -if (!is_submodule_initialized (path)) +if (!is_submodule_active (the_repository, path))return 0 ;if (!is_submodule_populated_gently (path,NULL )) {/*
builtin/submodule--helper.c +5 -4
@@ -1,4 +1,5 @@#include "builtin.h" +#include "repository.h" #include "cache.h" #include "config.h" #include "parse-options.h"
@@ -280,7 +281,7 @@ static void module_list_active(struct module_list *list)for (i =0 ; i < list->nr; i++) {const struct cache_entry *ce = list->entries[i]; -if (!is_submodule_initialized (ce->name)) +if (!is_submodule_active (the_repository, ce->name))continue ; ALLOC_GROW(active_modules.entries,
@@ -362,7 +363,7 @@ static void init_submodule(const char *path, const char *prefix, int quiet)* * Set active flag for the submodule being initialized */ -if (!is_submodule_initialized (path)) { +if (!is_submodule_active (the_repository, path)) {strbuf_reset (&sb);strbuf_addf (&sb,"submodule.%s.active" , sub->name);git_config_set_gently (sb.buf,"true" );
@@ -817,7 +818,7 @@ static int prepare_to_clone_next_submodule(const struct cache_entry *ce, }/* Check if the submodule has been initialized. */ -if (!is_submodule_initialized (ce->name)) { +if (!is_submodule_active (the_repository, ce->name)) {next_submodule_warn_missing (suc, out, displaypath); goto cleanup; }
@@ -1193,7 +1194,7 @@ static int is_active(int argc, const char **argv, const char *prefix)gitmodules_config (); -return !is_submodule_initialized (argv[1 ]); +return !is_submodule_active (the_repository, argv[1 ]); }#define SUPPORT_SUPER_PREFIX (1<<0)
submodule.c +8 -12
@@ -230,21 +230,17 @@ void gitmodules_config_sha1(const unsigned char *commit_sha1) }/* -* NEEDSWORK: With the addition of different configuration options to determine -* if a submodule is of interests, the validity of this function's name comes -* into question. Once the dust has settled and more concrete terminology is -* decided upon, come up with a more proper name for this function. One -* potential candidate could be 'is_submodule_active()'. -* * Determine if a submodule has been initialized at a given 'path' */ -int is_submodule_initialized (const char *path) +int is_submodule_active (struct repository *repo,const char *path) {int ret =0 ;char *key =NULL ;char *value =NULL ;const struct string_list *sl; -const struct submodule *module =submodule_from_path (null_sha1, path); +const struct submodule *module; + + module =submodule_from_cache (repo, null_sha1, path);/* early return if there isn't a path->module mapping */ if (!module)
@@ -252,14 +248,14 @@ int is_submodule_initialized(const char *path)/* submodule.<name>.active is set */ key =xstrfmt ("submodule.%s.active" , module->name); -if (!git_config_get_bool (key, &ret)) { +if (!repo_config_get_bool (repo, key, &ret)) {free (key);return ret; }free (key);/* submodule.active is set */ - sl =git_config_get_value_multi ("submodule.active" ); + sl =repo_config_get_value_multi (repo,"submodule.active" );if (sl) {struct pathspec ps;struct argv_array args =ARGV_ARRAY_INIT ;
@@ -279,7 +275,7 @@ int is_submodule_initialized(const char *path)/* fallback to checking if the URL is set */ key =xstrfmt ("submodule.%s.url" , module->name); - ret = !git_config_get_string (key, &value); + ret = !repo_config_get_string (repo, key, &value);free (value);free (key);
@@ -1484,7 +1480,7 @@ int submodule_move_head(const char *path,const struct submodule *sub;int *error_code_ptr, error_code; -if (!is_submodule_initialized (path)) +if (!is_submodule_active (the_repository, path))return 0 ;if (flags &SUBMODULE_MOVE_HEAD_FORCE )
submodule.h +1 -1
@@ -43,7 +43,7 @@ extern int submodule_config(const char *var, const char *value, void *cb);extern void gitmodules_config (void );extern void repo_read_gitmodules (struct repository *repo);extern void gitmodules_config_sha1 (const unsigned char *commit_sha1); -extern int is_submodule_initialized (const char *path); +extern int is_submodule_active (struct repository *repo,const char *path);/* * Determine if a submodule has been populated at a given 'path' by checking if * the <path>/.git resolves to a valid git repository.
Signature · 1 line
2.13.1.508.gb3defc5cc-goog
PATCH v2 25/32 ls-files: convert show_other_files to take an index
In reply to Brandon Williams--- builtin/ls-files.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
builtin/ls-files.c +4 -3
@@ -109,13 +109,14 @@ static void show_dir_entry(const char *tag, struct dir_entry *ent)write_name (ent->name); } -static void show_other_files (struct dir_struct *dir) +static void show_other_files (const struct index_state *istate, +const struct dir_struct *dir) {int i;for (i =0 ; i < dir->nr; i++) {struct dir_entry *ent = dir->entries[i]; -if (!cache_name_is_other (ent->name, ent->len)) +if (!index_name_is_other (istate, ent->name, ent->len))continue ;show_dir_entry (tag_other, ent); }
@@ -337,7 +338,7 @@ static void show_files(struct dir_struct *dir) dir->flags |=DIR_COLLECT_KILLED_ONLY ;fill_directory (dir, &the_index, &pathspec);if (show_others) -show_other_files (dir); +show_other_files (&the_index, dir);if (show_killed)show_killed_files (&the_index, dir); }
Signature · 1 line
2.13.1.508.gb3defc5cc-goog
PATCH v2 21/32 tree: convert read_tree to take an index parameter
In reply to Brandon Williams--- builtin/ls-files.c | 2 +- tree.c | 28 ++++++++++++++++++---------- tree.h | 3 ++- 3 files changed, 21 insertions(+), 12 deletions(-)
builtin/ls-files.c +1 -1
@@ -461,7 +461,7 @@ void overlay_tree_on_cache(const char *tree_name, const char *prefix) PATHSPEC_PREFER_CWD, prefix, matchbuf); }else memset (&pathspec,0 ,sizeof (pathspec)); -if (read_tree (tree,1 , &pathspec)) +if (read_tree (tree,1 , &pathspec, &the_index))die ("unable to read tree entries %s" , tree_name);for (i =0 ; i < active_nr; i++) {
tree.c +18 -10
@@ -1,3 +1,4 @@ +#define NO_THE_INDEX_COMPATIBILITY_MACROS #include "cache.h" #include "cache-tree.h" #include "tree.h"
@@ -8,7 +9,11 @@const char *tree_type ="tree" ; -static int read_one_entry_opt (const unsigned char *sha1,const char *base,int baselen,const char *pathname,unsigned mode,int stage,int opt) +static int read_one_entry_opt (struct index_state *istate, +const unsigned char *sha1, +const char *base,int baselen, +const char *pathname, +unsigned mode,int stage,int opt) {int len;unsigned int size;
@@ -27,14 +32,15 @@ static int read_one_entry_opt(const unsigned char *sha1, const char *base, int bmemcpy (ce->name, base, baselen);memcpy (ce->name + baselen, pathname, len+1 );hashcpy (ce->oid.hash, sha1); -return add_cache_entry (ce, opt); +return add_index_entry (istate, ce, opt); }static int read_one_entry (const unsigned char *sha1,struct strbuf *base,const char *pathname,unsigned mode,int stage,void *context) { -return read_one_entry_opt (sha1, base->buf, base->len, pathname, +struct index_state *istate = context; +return read_one_entry_opt (istate, sha1, base->buf, base->len, pathname, mode, stage,ADD_CACHE_OK_TO_ADD |ADD_CACHE_SKIP_DFCHECK ); }
@@ -47,7 +53,8 @@ static int read_one_entry_quick(const unsigned char *sha1, struct strbuf *base, const char *pathname, unsigned mode, int stage, void *context) { - return read_one_entry_opt(sha1, base->buf, base->len, pathname, + struct index_state *istate = context; +return read_one_entry_opt (istate, sha1, base->buf, base->len, pathname, mode, stage,ADD_CACHE_JUST_APPEND ); }
@@ -144,7 +151,8 @@ static int cmp_cache_name_compare(const void *a_, const void *b_) ce2->name, ce2->ce_namelen, ce_stage(ce2)); } -int read_tree (struct tree *tree,int stage,struct pathspec *match) +int read_tree (struct tree *tree,int stage,struct pathspec *match, +struct index_state *istate) {read_tree_fn_t fn =NULL ;int i, err;
@@ -164,23 +172,23 @@ int read_tree(struct tree *tree, int stage, struct pathspec *match)* do it the original slow way, otherwise, append and then * sort at the end. */ -for (i =0 ; !fn && i < active_nr; i++) { -const struct cache_entry *ce = active_cache[i]; +for (i =0 ; !fn && i < istate->cache_nr; i++) { +const struct cache_entry *ce = istate->cache[i];if (ce_stage (ce) == stage) fn = read_one_entry; }if (!fn) fn = read_one_entry_quick; - err =read_tree_recursive (tree,"" ,0 , stage, match, fn,NULL ); + err =read_tree_recursive (tree,"" ,0 , stage, match, fn, istate);if (fn == read_one_entry || err)return err;/* * Sort the cache entry -- we need to nuke the cache tree, though. */ -cache_tree_free (&active_cache_tree); -QSORT (active_cache, active_nr, cmp_cache_name_compare); +cache_tree_free (&istate->cache_tree); +QSORT (istate->cache, istate->cache_nr, cmp_cache_name_compare);return 0 ; }
tree.h +2 -1
@@ -34,6 +34,7 @@ extern int read_tree_recursive(struct tree *tree, int stage, const struct pathspec *pathspec, read_tree_fn_t fn, void *context); -extern int read_tree (struct tree *tree,int stage,struct pathspec *pathspec); +extern int read_tree (struct tree *tree,int stage,struct pathspec *pathspec, +struct index_state *istate);#endif /* TREE_H */
Signature · 1 line
2.13.1.508.gb3defc5cc-goog
PATCH v2 30/32 ls-files: factor out debug info into a function
In reply to Brandon Williams--- builtin/ls-files.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-)
builtin/ls-files.c +14 -9
@@ -94,6 +94,19 @@ static void write_name(const char *name)strbuf_release (&full_name); } +static void print_debug (const struct cache_entry *ce) +{ +if (debug_mode) { +const struct stat_data *sd = &ce->ce_stat_data; + +printf (" ctime: %d:%d\n" , sd->sd_ctime.sec, sd->sd_ctime.nsec); +printf (" mtime: %d:%d\n" , sd->sd_mtime.sec, sd->sd_mtime.nsec); +printf (" dev: %d\tino: %d\n" , sd->sd_dev, sd->sd_ino); +printf (" uid: %d\tgid: %d\n" , sd->sd_uid, sd->sd_gid); +printf (" size: %d\tflags: %x\n" , sd->sd_size, ce->ce_flags); + } +} +static void show_dir_entry (const char *tag,struct dir_entry *ent) {int len = max_prefix_len;
@@ -279,15 +292,7 @@ static void show_ce_entry(const char *tag, const struct cache_entry *ce) }write_eolinfo (&the_index, ce, ce->name);write_name (ce->name); -if (debug_mode) { -const struct stat_data *sd = &ce->ce_stat_data; - -printf (" ctime: %d:%d\n" , sd->sd_ctime.sec, sd->sd_ctime.nsec); -printf (" mtime: %d:%d\n" , sd->sd_mtime.sec, sd->sd_mtime.nsec); -printf (" dev: %d\tino: %d\n" , sd->sd_dev, sd->sd_ino); -printf (" uid: %d\tgid: %d\n" , sd->sd_uid, sd->sd_gid); -printf (" size: %d\tflags: %x\n" , sd->sd_size, ce->ce_flags); - } +print_debug (ce); }strbuf_release (&name);
Signature · 1 line
2.13.1.508.gb3defc5cc-goog
PATCH v2 27/32 ls-files: convert ce_excluded to take an index
In reply to Brandon Williams--- builtin/ls-files.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
builtin/ls-files.c +5 -4
@@ -322,10 +322,11 @@ static void show_ru_info(const struct index_state *istate) } } -static int ce_excluded (struct dir_struct *dir,const struct cache_entry *ce) +static int ce_excluded (struct dir_struct *dir,struct index_state *istate, +const struct cache_entry *ce) {int dtype =ce_to_dtype (ce); -return is_excluded (dir, &the_index, ce->name, &dtype); +return is_excluded (dir, istate, ce->name, &dtype); }static void show_files (struct dir_struct *dir)
@@ -346,7 +347,7 @@ static void show_files(struct dir_struct *dir)for (i =0 ; i < active_nr; i++) {const struct cache_entry *ce = active_cache[i];if ((dir->flags &DIR_SHOW_IGNORED ) && - !ce_excluded (dir, ce)) + !ce_excluded (dir, &the_index, ce))continue ;if (show_unmerged && !ce_stage (ce))continue ;
@@ -362,7 +363,7 @@ static void show_files(struct dir_struct *dir)struct stat st;int err;if ((dir->flags &DIR_SHOW_IGNORED ) && - !ce_excluded (dir, ce)) + !ce_excluded (dir, &the_index, ce))continue ;if (ce->ce_flags &CE_UPDATE )continue ;
Signature · 1 line
2.13.1.508.gb3defc5cc-goog
PATCH v2 32/32 ls-files: use repository object
In reply to Brandon WilliamsConvert ls-files to use a repository struct and recurse submodules inprocess.
--- builtin/ls-files.c | 198 ++++++++++++++------------------- git.c | 2 +- repository.c | 4 + repository.h | 1 + t/t3007-ls-files-recurse-submodules.sh | 39 +++++++ 5 files changed, 129 insertions(+), 115 deletions(-)
builtin/ls-files.c +84 -114
@@ -5,7 +5,9 @@* * Copyright (C) Linus Torvalds, 2005 */ +#define NO_THE_INDEX_COMPATIBILITY_MACROS #include "cache.h" +#include "repository.h" #include "config.h" #include "quote.h" #include "dir.h"
@@ -32,10 +34,8 @@ static int line_terminator = '\n';static int debug_mode;static int show_eol;static int recurse_submodules; -static struct argv_array submodule_options =ARGV_ARRAY_INIT ;static const char *prefix; -static const char *super_prefix;static int max_prefix_len;static int prefix_len;static struct pathspec pathspec;
@@ -73,25 +73,12 @@ static void write_eolinfo(const struct index_state *istate,static void write_name (const char *name) { -/* -* Prepend the super_prefix to name to construct the full_name to be -* written. -*/ -struct strbuf full_name =STRBUF_INIT ; -if (super_prefix) { -strbuf_addstr (&full_name, super_prefix); -strbuf_addstr (&full_name, name); - name = full_name.buf; - } -/* * With "--full-name", prefix_len=0; this caller needs to pass * an empty string in that case (a NULL is good for ""). */ write_name_quoted_relative (name, prefix_len ? prefix :NULL , stdout, line_terminator); - -strbuf_release (&full_name); }static const char *get_tag (const struct cache_entry *ce,const char *tag)
@@ -210,82 +197,41 @@ static void show_killed_files(const struct index_state *istate, } } -/* -* Compile an argv_array with all of the options supported by --recurse_submodules -*/ -static void compile_submodule_options (const char **argv, -const struct dir_struct *dir, -int show_tag) -{ -if (line_terminator =='\0' ) -argv_array_push (&submodule_options,"-z" ); -if (show_tag) -argv_array_push (&submodule_options,"-t" ); -if (show_valid_bit) -argv_array_push (&submodule_options,"-v" ); -if (show_cached) -argv_array_push (&submodule_options,"--cached" ); -if (show_eol) -argv_array_push (&submodule_options,"--eol" ); -if (debug_mode) -argv_array_push (&submodule_options,"--debug" ); - -/* Add Pathspecs */ -argv_array_push (&submodule_options,"--" ); -for (; *argv; argv++) -argv_array_push (&submodule_options, *argv); -} +static void show_files (struct repository *repo,struct dir_struct *dir); -/** -* Recursively call ls-files on a submodule -*/ -static void show_gitlink (const struct cache_entry *ce) +static void show_submodule (const struct repository *superproject, +struct dir_struct *dir,const char *path) { -struct child_process cp =CHILD_PROCESS_INIT ; -int status; -char *dir; - -prepare_submodule_repo_env (&cp.env_array); -argv_array_push (&cp.env_array,GIT_DIR_ENVIRONMENT ); - -if (prefix_len) -argv_array_pushf (&cp.env_array,"%s=%s" , -GIT_TOPLEVEL_PREFIX_ENVIRONMENT , - prefix); -argv_array_pushf (&cp.args,"--super-prefix=%s%s/" , - super_prefix ? super_prefix :"" , - ce->name); -argv_array_push (&cp.args,"ls-files" ); -argv_array_push (&cp.args,"--recurse-submodules" ); - -/* add supported options */ -argv_array_pushv (&cp.args, submodule_options.argv); - - cp.git_cmd =1 ; - dir =mkpathdup ("%s/%s" ,get_git_work_tree (), ce->name); - cp.dir = dir; - status =run_command (&cp); -free (dir); -if (status) -exit (status); +struct repository submodule; +char *gitdir =mkpathdup ("%s/%s" , superproject->worktree, path); +repo_init (&submodule, gitdir); + +repo_read_index (&submodule); +repo_read_gitmodules (&submodule); + +if (superproject->submodule_prefix) + submodule.submodule_prefix =xstrfmt ("%s%s/" , superproject->submodule_prefix, path); +else + submodule.submodule_prefix =xstrfmt ("%s/" , path); +show_files (&submodule, dir); + +repo_clear (&submodule); +free (gitdir); } -static void show_ce_entry (const char *tag,const struct cache_entry *ce) +static void show_ce (struct repository *repo,struct dir_struct *dir, +const struct cache_entry *ce,const char *fullname, +const char *tag) { -struct strbuf name =STRBUF_INIT ; -int len = max_prefix_len; -if (super_prefix) -strbuf_addstr (&name, super_prefix); -strbuf_addstr (&name, ce->name); - -if (len >ce_namelen (ce)) +if (max_prefix_len >strlen (fullname))die ("git ls-files: internal error - cache entry not superset of prefix" );if (recurse_submodules &&S_ISGITLINK (ce->ce_mode) && -submodule_path_match (&pathspec, name.buf, ps_matched)) { -show_gitlink (ce); - }else if (match_pathspec (&pathspec, name.buf, name.len, - len, ps_matched, +submodule_path_match (&pathspec, fullname, ps_matched) && +is_submodule_active (repo, ce->name)) { +show_submodule (repo, dir, ce->name); + }else if (match_pathspec (&pathspec, fullname,strlen (fullname), + max_prefix_len, ps_matched,S_ISDIR (ce->ce_mode) ||S_ISGITLINK (ce->ce_mode))) { tag =get_tag (ce, tag);
@@ -299,12 +245,11 @@ static void show_ce_entry(const char *tag, const struct cache_entry *ce)find_unique_abbrev (ce->oid.hash, abbrev), ce_stage(ce)); } -write_eolinfo (&the_index, ce, ce->name); -write_name (ce->name); + +write_eolinfo (repo->index, ce, fullname); +write_name (fullname);print_debug (ce); } - -strbuf_release (&name); }static void show_ru_info (const struct index_state *istate)
@@ -337,59 +282,79 @@ static void show_ru_info(const struct index_state *istate) }static int ce_excluded (struct dir_struct *dir,struct index_state *istate, -const struct cache_entry *ce) +const char *fullname,const struct cache_entry *ce) {int dtype =ce_to_dtype (ce); -return is_excluded (dir, istate, ce->name, &dtype); +return is_excluded (dir, istate, fullname, &dtype); +} + +static void construct_fullname (struct strbuf *out,const struct repository *repo, +const struct cache_entry *ce) +{ +strbuf_reset (out); +if (repo->submodule_prefix) +strbuf_addstr (out, repo->submodule_prefix); +strbuf_addstr (out, ce->name); } -static void show_files (struct index_state *istate,struct dir_struct *dir) +static void show_files (struct repository *repo,struct dir_struct *dir) {int i; +struct strbuf fullname =STRBUF_INIT ;/* For cached/deleted files we don't need to even do the readdir */ if (show_others || show_killed) {if (!show_others) dir->flags |=DIR_COLLECT_KILLED_ONLY ; -fill_directory (dir, istate, &pathspec); +fill_directory (dir, repo->index, &pathspec);if (show_others) -show_other_files (istate, dir); +show_other_files (repo->index, dir);if (show_killed) -show_killed_files (istate, dir); +show_killed_files (repo->index, dir); }if (show_cached || show_stage) { -for (i =0 ; i < istate->cache_nr; i++) { -const struct cache_entry *ce = istate->cache[i]; +for (i =0 ; i < repo->index->cache_nr; i++) { +const struct cache_entry *ce = repo->index->cache[i]; + +construct_fullname (&fullname, repo, ce); +if ((dir->flags &DIR_SHOW_IGNORED ) && - !ce_excluded (dir, istate, ce)) + !ce_excluded (dir, repo->index, fullname.buf, ce))continue ;if (show_unmerged && !ce_stage (ce))continue ;if (ce->ce_flags &CE_UPDATE )continue ; -show_ce_entry (ce_stage (ce) ? tag_unmerged : - (ce_skip_worktree (ce) ? tag_skip_worktree : tag_cached), ce); +show_ce (repo, dir, ce, fullname.buf, +ce_stage (ce) ? tag_unmerged : + (ce_skip_worktree (ce) ? tag_skip_worktree : + tag_cached)); } }if (show_deleted || show_modified) { -for (i =0 ; i < istate->cache_nr; i++) { -const struct cache_entry *ce = istate->cache[i]; +for (i =0 ; i < repo->index->cache_nr; i++) { +const struct cache_entry *ce = repo->index->cache[i];struct stat st;int err; + +construct_fullname (&fullname, repo, ce); +if ((dir->flags &DIR_SHOW_IGNORED ) && - !ce_excluded (dir, istate, ce)) + !ce_excluded (dir, repo->index, fullname.buf, ce))continue ;if (ce->ce_flags &CE_UPDATE )continue ;if (ce_skip_worktree (ce))continue ; - err =lstat (ce->name, &st); + err =lstat (fullname.buf, &st);if (show_deleted && err) -show_ce_entry (tag_removed, ce); -if (show_modified &&ie_modified (istate, ce, &st,0 )) -show_ce_entry (tag_modified, ce); +show_ce (repo, dir, ce, fullname.buf, tag_removed); +if (show_modified &&ie_modified (repo->index, ce, &st,0 )) +show_ce (repo, dir, ce, fullname.buf, tag_modified); } } + +strbuf_release (&fullname); }/*
@@ -614,10 +579,9 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix) prefix = cmd_prefix;if (prefix) prefix_len =strlen (prefix); - super_prefix =get_super_prefix ();git_config (git_default_config,NULL ); -if (read_cache () <0 ) +if (repo_read_index (the_repository))die ("index file corrupt" ); argc = parse_options(argc, argv, prefix, builtin_ls_files_options,
@@ -650,8 +614,9 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix)if (require_work_tree && !is_inside_work_tree ())setup_work_tree (); -if (recurse_submodules) -compile_submodule_options (argv, &dir, show_tag); +if (recurse_submodules) { +repo_read_gitmodules (the_repository); + } if (recurse_submodules && (show_stage || show_deleted || show_others || show_unmerged ||
@@ -669,7 +634,10 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix)/* * Find common prefix for all pathspec's * This is used as a performance optimization which unfortunately cannot -* be done when recursing into submodules +* be done when recursing into submodules because when a pathspec is +* given which spans repository boundaries you can't simply remove the +* submodule entry because the pathspec may match something inside the +* submodule. */ if (recurse_submodules) max_prefix =NULL ;
@@ -677,7 +645,7 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix) max_prefix =common_prefix (&pathspec); max_prefix_len =get_common_prefix_len (max_prefix); -prune_index (&the_index, max_prefix, max_prefix_len); +prune_index (the_repository->index, max_prefix, max_prefix_len);/* Treat unmatching pathspec elements as errors */ if (pathspec.nr && error_unmatch)
@@ -698,11 +666,13 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix)*/ if (show_stage || show_unmerged)die ("ls-files --with-tree is incompatible with -s or -u" ); -overlay_tree_on_index (&the_index, with_tree, max_prefix); +overlay_tree_on_index (the_repository->index, with_tree, max_prefix); } -show_files (&the_index, &dir); + +show_files (the_repository, &dir); +if (show_resolve_undo) -show_ru_info (&the_index); +show_ru_info (the_repository->index);if (ps_matched) {int bad;
git.c +1 -1
@@ -442,7 +442,7 @@ static struct cmd_struct commands[] = { { "init-db", cmd_init_db }, { "interpret-trailers", cmd_interpret_trailers, RUN_SETUP_GENTLY }, { "log", cmd_log, RUN_SETUP }, - { "ls-files", cmd_ls_files, RUN_SETUP | SUPPORT_SUPER_PREFIX }, + { "ls-files", cmd_ls_files, RUN_SETUP }, { "ls-remote", cmd_ls_remote, RUN_SETUP_GENTLY }, { "ls-tree", cmd_ls_tree, RUN_SETUP }, { "mailinfo", cmd_mailinfo, RUN_SETUP_GENTLY },
repository.c +4 -0
@@ -152,6 +152,8 @@ int repo_init(struct repository *repo, const char *gitdir)if (verify_repo_format (&format, repo->commondir)) goto error; +repo_set_worktree (repo, gitdir); +return 0 ; error:
@@ -180,6 +182,8 @@ void repo_clear(struct repository *repo)repo_clear_env (repo);free (repo->worktree); repo->worktree =NULL ; +free (repo->submodule_prefix); + repo->submodule_prefix =NULL ;if (repo->config) {git_configset_clear (repo->config);
repository.h +1 -0
@@ -14,6 +14,7 @@ struct repository {char *graft_file;char *namespace;char *worktree; +char *submodule_prefix;/* Subsystems */ /*
t/t3007-ls-files-recurse-submodules.sh +39 -0
@@ -135,6 +135,45 @@ test_expect_success '--recurse-submodules and pathspecs setup' ' test_cmp expect actual ' +test_expect_success 'inactive submodule' ' + test_when_finished "git config --bool submodule.submodule.active true" && + test_when_finished "git -C submodule config --bool submodule.subsub.active true" && + git config --bool submodule.submodule.active "false" && + + cat >expect <<-\EOF && + .gitmodules + a + b/b + h.txt + sib/file + sub/file + submodule + EOF + + git ls-files --recurse-submodules >actual && + test_cmp expect actual && + + git config --bool submodule.submodule.active "true" && + git -C submodule config --bool submodule.subsub.active "false" && + + cat >expect <<-\EOF && + .gitmodules + a + b/b + h.txt + sib/file + sub/file + submodule/.gitmodules + submodule/c + submodule/f.TXT + submodule/g.txt + submodule/subsub + EOF + + git ls-files --recurse-submodules >actual && + test_cmp expect actual +' + test_expect_success '--recurse-submodules and pathspecs' ' cat >expect <<-\EOF && h.txt
Signature · 1 line
2.13.1.508.gb3defc5cc-goog
PATCH v2 29/32 ls-files: convert show_files to take an index
In reply to Brandon Williams--- builtin/ls-files.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-)
builtin/ls-files.c +12 -12
@@ -329,7 +329,7 @@ static int ce_excluded(struct dir_struct *dir, struct index_state *istate,return is_excluded (dir, istate, ce->name, &dtype); } -static void show_files (struct dir_struct *dir) +static void show_files (struct index_state *istate,struct dir_struct *dir) {int i;
@@ -337,17 +337,17 @@ static void show_files(struct dir_struct *dir)if (show_others || show_killed) {if (!show_others) dir->flags |=DIR_COLLECT_KILLED_ONLY ; -fill_directory (dir, &the_index, &pathspec); +fill_directory (dir, istate, &pathspec);if (show_others) -show_other_files (&the_index, dir); +show_other_files (istate, dir);if (show_killed) -show_killed_files (&the_index, dir); +show_killed_files (istate, dir); }if (show_cached || show_stage) { -for (i =0 ; i < active_nr; i++) { -const struct cache_entry *ce = active_cache[i]; +for (i =0 ; i < istate->cache_nr; i++) { +const struct cache_entry *ce = istate->cache[i];if ((dir->flags &DIR_SHOW_IGNORED ) && - !ce_excluded (dir, &the_index, ce)) + !ce_excluded (dir, istate, ce))continue ;if (show_unmerged && !ce_stage (ce))continue ;
@@ -358,12 +358,12 @@ static void show_files(struct dir_struct *dir) } }if (show_deleted || show_modified) { -for (i =0 ; i < active_nr; i++) { -const struct cache_entry *ce = active_cache[i]; +for (i =0 ; i < istate->cache_nr; i++) { +const struct cache_entry *ce = istate->cache[i];struct stat st;int err;if ((dir->flags &DIR_SHOW_IGNORED ) && - !ce_excluded (dir, &the_index, ce)) + !ce_excluded (dir, istate, ce))continue ;if (ce->ce_flags &CE_UPDATE )continue ;
@@ -372,7 +372,7 @@ static void show_files(struct dir_struct *dir) err =lstat (ce->name, &st);if (show_deleted && err)show_ce_entry (tag_removed, ce); -if (show_modified &&ce_modified (ce, &st,0 )) +if (show_modified &&ie_modified (istate, ce, &st,0 ))show_ce_entry (tag_modified, ce); } }
@@ -686,7 +686,7 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix)die ("ls-files --with-tree is incompatible with -s or -u" );overlay_tree_on_index (&the_index, with_tree, max_prefix); } -show_files (&dir); +show_files (&the_index, &dir);if (show_resolve_undo)show_ru_info (&the_index);
Signature · 1 line
2.13.1.508.gb3defc5cc-goog
PATCH v2 24/32 ls-files: convert show_killed_files to take an index
In reply to Brandon Williams--- builtin/ls-files.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-)
builtin/ls-files.c +11 -10
@@ -121,7 +121,8 @@ static void show_other_files(struct dir_struct *dir) } } -static void show_killed_files (struct dir_struct *dir) +static void show_killed_files (const struct index_state *istate, +const struct dir_struct *dir) {int i;for (i =0 ; i < dir->nr; i++) {
@@ -135,29 +136,29 @@ static void show_killed_files(struct dir_struct *dir)/* If ent->name is prefix of an entry in the * cache, it will be killed. */ - pos =cache_name_pos (ent->name, ent->len); + pos =index_name_pos (istate, ent->name, ent->len);if (0 <= pos)die ("BUG: killed-file %.*s not found" , ent->len, ent->name); pos = -pos -1 ; -while (pos < active_nr && -ce_stage (active_cache[pos])) +while (pos < istate->cache_nr && +ce_stage (istate->cache[pos])) pos++;/* skip unmerged */ -if (active_nr <= pos) +if (istate->cache_nr <= pos)break ;/* pos points at a name immediately after * ent->name in the cache. Does it expect * ent->name to be a directory? */ - len =ce_namelen (active_cache[pos]); + len =ce_namelen (istate->cache[pos]);if ((ent->len < len) && - !strncmp (active_cache[pos]->name, + !strncmp (istate->cache[pos]->name, ent->name, ent->len) && - active_cache[pos]->name[ent->len] =='/' ) + istate->cache[pos]->name[ent->len] =='/' ) killed =1 ;break ; } -if (0 <=cache_name_pos (ent->name, sp - ent->name)) { +if (0 <=index_name_pos (istate, ent->name, sp - ent->name)) {/* If any of the leading directories in * ent->name is registered in the cache, * ent->name will be killed.
@@ -338,7 +339,7 @@ static void show_files(struct dir_struct *dir)if (show_others)show_other_files (dir);if (show_killed) -show_killed_files (dir); +show_killed_files (&the_index, dir); }if (show_cached || show_stage) {for (i =0 ; i < active_nr; i++) {
Signature · 1 line
2.13.1.508.gb3defc5cc-goog
PATCH v2 26/32 ls-files: convert show_ru_info to take an index
In reply to Brandon Williams--- builtin/ls-files.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
builtin/ls-files.c +4 -4
@@ -293,14 +293,14 @@ static void show_ce_entry(const char *tag, const struct cache_entry *ce)strbuf_release (&name); } -static void show_ru_info (void ) +static void show_ru_info (const struct index_state *istate) {struct string_list_item *item; -if (!the_index.resolve_undo) +if (!istate->resolve_undo)return ; -for_each_string_list_item (item, the_index.resolve_undo) { +for_each_string_list_item (item, istate->resolve_undo) {const char *path = item->string;struct resolve_undo_info *ui = item->util;int i, len;
@@ -686,7 +686,7 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix) }show_files (&dir);if (show_resolve_undo) -show_ru_info (); +show_ru_info (&the_index);if (ps_matched) {int bad;
Signature · 1 line
2.13.1.508.gb3defc5cc-goog
PATCH v2 28/32 ls-files: convert prune_cache to take an index
In reply to Brandon Williams--- builtin/ls-files.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-)
builtin/ls-files.c +8 -7
@@ -381,30 +381,31 @@ static void show_files(struct dir_struct *dir)/* * Prune the index to only contain stuff starting with "prefix" */ -static void prune_cache (const char *prefix,size_t prefixlen) +static void prune_index (struct index_state *istate, +const char *prefix,size_t prefixlen) {int pos;unsigned int first, last;if (!prefix)return ; - pos =cache_name_pos (prefix, prefixlen); + pos =index_name_pos (istate, prefix, prefixlen);if (pos <0 ) pos = -pos-1 ; first = pos; - last = active_nr; + last = istate->cache_nr;while (last > first) {int next = (last + first) >>1 ; -const struct cache_entry *ce = active_cache[next]; +const struct cache_entry *ce = istate->cache[next];if (!strncmp (ce->name, prefix, prefixlen)) { first = next+1 ;continue ; } last = next; } -memmove (active_cache, active_cache + pos, +memmove (istate->cache, istate->cache + pos, (last - pos) *sizeof (struct cache_entry *)); - active_nr = last - pos; + istate->cache_nr = last - pos; }static int get_common_prefix_len (const char *common_prefix)
@@ -662,7 +663,7 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix) max_prefix =common_prefix (&pathspec); max_prefix_len =get_common_prefix_len (max_prefix); -prune_cache (max_prefix, max_prefix_len); +prune_index (&the_index, max_prefix, max_prefix_len);/* Treat unmatching pathspec elements as errors */ if (pathspec.nr && error_unmatch)
Signature · 1 line
2.13.1.508.gb3defc5cc-goog
PATCH v2 17/32 convert: convert crlf_to_git to take an index
In reply to Brandon Williams--- convert.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)
convert.c +8 -6
@@ -219,13 +219,13 @@ static void check_safe_crlf(const char *path, enum crlf_action crlf_action, } } -static int has_cr_in_index (const char *path) +static int has_cr_in_index (const struct index_state *istate,const char *path) {unsigned long sz;void *data;int has_cr; - data =read_blob_data_from_cache (path, &sz); + data =read_blob_data_from_index (istate, path, &sz);if (!data)return 0 ; has_cr =memchr (data,'\r' , sz) !=NULL ;
@@ -255,7 +255,8 @@ static int will_convert_lf_to_crlf(size_t len, struct text_stat *stats, } -static int crlf_to_git (const char *path,const char *src,size_t len, +static int crlf_to_git (const struct index_state *istate, +const char *path,const char *src,size_t len,struct strbuf *buf,enum crlf_action crlf_action,enum safe_crlf checksafe) {
@@ -287,7 +288,8 @@ static int crlf_to_git(const char *path, const char *src, size_t len,* unless we want to renormalize in a merge or * cherry-pick. */ -if ((checksafe !=SAFE_CRLF_RENORMALIZE ) &&has_cr_in_index (path)) +if ((checksafe !=SAFE_CRLF_RENORMALIZE ) && +has_cr_in_index (istate, path)) convert_crlf_into_lf =0 ; } if ((checksafe == SAFE_CRLF_WARN ||
@@ -1099,7 +1101,7 @@ int convert_to_git(const char *path, const char *src, size_t len, src = dst->buf; len = dst->len; } - ret |=crlf_to_git (path, src, len, dst, ca.crlf_action, checksafe); + ret |=crlf_to_git (&the_index, path, src, len, dst, ca.crlf_action, checksafe);if (ret && dst) { src = dst->buf; len = dst->len;
@@ -1119,7 +1121,7 @@ void convert_to_git_filter_fd(const char *path, int fd, struct strbuf *dst,if (!apply_filter (path,NULL ,0 , fd, dst, ca.drv,CAP_CLEAN ))die ("%s: clean filter '%s' failed" , path, ca.drv->name); -crlf_to_git (path, dst->buf, dst->len, dst, ca.crlf_action, checksafe); +crlf_to_git (&the_index, path, dst->buf, dst->len, dst, ca.crlf_action, checksafe);ident_to_git (path, dst->buf, dst->len, dst, ca.ident); }
Signature · 1 line
2.13.1.508.gb3defc5cc-goog
PATCH v2 31/32 ls-files: factor out tag calculation
In reply to Brandon Williams--- builtin/ls-files.c | 41 +++++++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 16 deletions(-)
builtin/ls-files.c +25 -16
@@ -94,6 +94,30 @@ static void write_name(const char *name)strbuf_release (&full_name); } +static const char *get_tag (const struct cache_entry *ce,const char *tag) +{ +static char alttag[4 ]; + +if (tag && *tag && show_valid_bit && (ce->ce_flags &CE_VALID )) { +memcpy (alttag, tag,3 ); + +if (isalpha (tag[0 ])) { + alttag[0 ] =tolower (tag[0 ]); + }else if (tag[0 ] =='?' ) { + alttag[0 ] ='!' ; + }else { + alttag[0 ] ='v' ; + alttag[1 ] = tag[0 ]; + alttag[2 ] =' ' ; + alttag[3 ] =0 ; + } + + tag = alttag; + } + +return tag; +} +static void print_debug (const struct cache_entry *ce) {if (debug_mode) {
@@ -264,22 +288,7 @@ static void show_ce_entry(const char *tag, const struct cache_entry *ce) len, ps_matched, S_ISDIR(ce->ce_mode) || S_ISGITLINK(ce->ce_mode))) { -if (tag && *tag && show_valid_bit && - (ce->ce_flags &CE_VALID )) { -static char alttag[4 ]; -memcpy (alttag, tag,3 ); -if (isalpha (tag[0 ])) - alttag[0 ] =tolower (tag[0 ]); -else if (tag[0 ] =='?' ) - alttag[0 ] ='!' ; -else { - alttag[0 ] ='v' ; - alttag[1 ] = tag[0 ]; - alttag[2 ] =' ' ; - alttag[3 ] =0 ; - } - tag = alttag; - } + tag =get_tag (ce, tag);if (!show_stage) {fputs (tag, stdout);
Signature · 1 line
2.13.1.508.gb3defc5cc-goog
PATCH v2 18/32 convert: convert convert_to_git_filter_fd to take an index
In reply to Brandon Williams--- convert.c | 5 +++-- convert.h | 3 ++- sha1_file.c | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-)
convert.c +3 -2
@@ -1109,7 +1109,8 @@ int convert_to_git(const char *path, const char *src, size_t len,return ret |ident_to_git (path, src, len, dst, ca.ident); } -void convert_to_git_filter_fd (const char *path,int fd,struct strbuf *dst, +void convert_to_git_filter_fd (const struct index_state *istate, +const char *path,int fd,struct strbuf *dst,enum safe_crlf checksafe) {struct conv_attrs ca;
@@ -1121,7 +1122,7 @@ void convert_to_git_filter_fd(const char *path, int fd, struct strbuf *dst,if (!apply_filter (path,NULL ,0 , fd, dst, ca.drv,CAP_CLEAN ))die ("%s: clean filter '%s' failed" , path, ca.drv->name); -crlf_to_git (&the_index, path, dst->buf, dst->len, dst, ca.crlf_action, checksafe); +crlf_to_git (istate, path, dst->buf, dst->len, dst, ca.crlf_action, checksafe);ident_to_git (path, dst->buf, dst->len, dst, ca.ident); }
convert.h +2 -1
@@ -52,7 +52,8 @@ static inline int would_convert_to_git(const char *path)return convert_to_git (path,NULL ,0 ,NULL ,0 ); }/* Precondition: would_convert_to_git_filter_fd(path) == true */ -extern void convert_to_git_filter_fd (const char *path,int fd, +extern void convert_to_git_filter_fd (const struct index_state *istate, +const char *path,int fd,struct strbuf *dst,enum safe_crlf checksafe);extern int would_convert_to_git_filter_fd (const char *path);
sha1_file.c +1 -1
@@ -3581,7 +3581,7 @@ static int index_stream_convert_blob(unsigned char *sha1, int fd,assert (path);assert (would_convert_to_git_filter_fd (path)); -convert_to_git_filter_fd (path, fd, &sbuf, +convert_to_git_filter_fd (&the_index, path, fd, &sbuf, write_object ? safe_crlf :SAFE_CRLF_FALSE );if (write_object)
Signature · 1 line
2.13.1.508.gb3defc5cc-goog
PATCH v2 13/32 submodule-config: store the_submodule_cache in the_repository
In reply to Brandon WilliamsRefactor how 'the_submodule_cache' is handled so that it can be stored inside of a repository object. Also migrate 'the_submodule_cache' to be stored in 'the_repository'.
--- repository.c | 6 +++++ repository.h | 2 ++ submodule-config.c | 70 ++++++++++++++++++++++++++++++++++++++++-------------- submodule-config.h | 10 ++++++++ 4 files changed, 70 insertions(+), 18 deletions(-)
repository.c +6 -0
@@ -1,6 +1,7 @@#include "cache.h" #include "repository.h" #include "config.h" +#include "submodule-config.h" /* The main repository */ static struct repository the_repo;
@@ -192,6 +193,11 @@ void repo_clear(struct repository *repo) repo->index =NULL ; } +if (repo->submodule_cache) { +submodule_cache_free (repo->submodule_cache); + repo->submodule_cache =NULL ; + } +memset (repo,0 ,sizeof (*repo)); }
repository.h +2 -0
@@ -3,6 +3,7 @@struct config_set ;struct index_state ; +struct submodule_cache ;struct repository {/* Environment */
@@ -22,6 +23,7 @@ struct repository {*/ struct config_set *config;struct index_state *index; +struct submodule_cache *submodule_cache;/* Configurations */ unsigned ignore_env:1;
submodule-config.c +52 -18
141 lines not on this page · raw message
submodule-config.h +10 -0
@@ -22,14 +22,24 @@ struct submodule {int recommend_shallow; }; +struct submodule_cache ; +struct repository ; + +extern void submodule_cache_free (struct submodule_cache *cache); +extern int parse_fetch_recurse_submodules_arg (const char *opt,const char *arg);extern int parse_update_recurse_submodules_arg (const char *opt,const char *arg);extern int parse_push_recurse_submodules_arg (const char *opt,const char *arg);extern int parse_submodule_config_option (const char *var,const char *value); +extern int submodule_config_option (struct repository *repo, +const char *var,const char *value);extern const struct submodule *submodule_from_name (const unsigned char *commit_or_tree,const char *name);extern const struct submodule *submodule_from_path (const unsigned char *commit_or_tree,const char *path); +extern const struct submodule *submodule_from_cache (struct repository *repo, +const unsigned char *treeish_name, +const char *key);extern int gitmodule_sha1_from_commit (const unsigned char *commit_sha1,unsigned char *gitmodules_sha1,struct strbuf *rev);
Signature · 1 line
2.13.1.508.gb3defc5cc-goog
PATCH v2 12/32 repository: add index_state to struct repo
In reply to Brandon Williams--- repository.c | 16 ++++++++++++++++ repository.h | 4 ++++ 2 files changed, 20 insertions(+)
repository.c +16 -0
@@ -186,5 +186,21 @@ void repo_clear(struct repository *repo) repo->config =NULL ; } +if (repo->index) { +discard_index (repo->index); +free (repo->index); + repo->index =NULL ; + } +memset (repo,0 ,sizeof (*repo)); } + +int repo_read_index (struct repository *repo) +{ +if (!repo->index) + repo->index =xcalloc (1 ,sizeof (struct index_state )); +else +discard_index (repo->index); + +return read_index_from (repo->index, repo->index_file); +}
repository.h +4 -0
@@ -2,6 +2,7 @@#define REPOSITORY_H struct config_set ; +struct index_state ;struct repository {/* Environment */
@@ -20,6 +21,7 @@ struct repository {* ~/.gitconfig, XDG config file and the global /etc/gitconfig) */ struct config_set *config; +struct index_state *index;/* Configurations */ unsigned ignore_env:1;
@@ -35,4 +37,6 @@ extern char *repo_worktree_path(struct repository *repo, const char *path);extern int repo_init (struct repository *repo,const char *path);extern void repo_clear (struct repository *repo); +extern int repo_read_index (struct repository *repo); +#endif /* REPOSITORY_H */
Signature · 1 line
2.13.1.508.gb3defc5cc-goog
PATCH v2 8/32 environment: place key repository state in the_repository
In reply to Brandon WilliamsMigrate 'git_dir', 'git_common_dir', 'git_object_dir', 'git_index_file', 'git_graft_file', and 'namespace' to be stored in 'the_repository'.
--- cache.h | 1 - environment.c | 65 ++++++++++++++--------------------------------------------- path.c | 11 +++++----- setup.c | 17 ++++++++++++++-- 4 files changed, 36 insertions(+), 58 deletions(-)
cache.h +0 -1
@@ -769,7 +769,6 @@ extern int core_apply_sparse_checkout;extern int precomposed_unicode;extern int protect_hfs;extern int protect_ntfs; -extern int git_db_env, git_index_env, git_graft_env, git_common_dir_env;/* * Include broken refs in all ref iterations, which will
environment.c +15 -50
141 lines not on this page · raw message
path.c +6 -5
@@ -2,6 +2,7 @@* Utilities for paths and pathnames */ #include "cache.h" +#include "repository.h" #include "strbuf.h" #include "string-list.h" #include "dir.h"
@@ -355,7 +356,7 @@ void report_linked_checkout_garbage(void)const struct common_dir *p;int len; -if (!git_common_dir_env) +if (!the_repository->different_commondir)return ;strbuf_addf (&sb,"%s/" ,get_git_dir ()); len = sb.len;
@@ -374,17 +375,17 @@ void report_linked_checkout_garbage(void)static void adjust_git_path (struct strbuf *buf,int git_dir_len) {const char *base = buf->buf + git_dir_len; -if (git_graft_env &&is_dir_file (base,"info" ,"grafts" )) +if (is_dir_file (base,"info" ,"grafts" ))strbuf_splice (buf,0 , buf->len,get_graft_file (),strlen (get_graft_file ())); -else if (git_index_env && !strcmp (base,"index" )) +else if (!strcmp (base,"index" ))strbuf_splice (buf,0 , buf->len,get_index_file (),strlen (get_index_file ())); -else if (git_db_env &&dir_prefix (base,"objects" )) +else if (dir_prefix (base,"objects" ))replace_dir (buf, git_dir_len +7 ,get_object_directory ());else if (git_hooks_path &&dir_prefix (base,"hooks" ))replace_dir (buf, git_dir_len +5 , git_hooks_path); -else if (git_common_dir_env) +else if (the_repository->different_commondir)update_common_dir (buf, git_dir_len,NULL ); }
setup.c +15 -2
@@ -1,4 +1,5 @@#include "cache.h" +#include "repository.h" #include "config.h" #include "dir.h" #include "string-list.h"
@@ -376,6 +377,11 @@ void setup_work_tree(void)if (getenv (GIT_WORK_TREE_ENVIRONMENT ))setenv (GIT_WORK_TREE_ENVIRONMENT ,"." ,1 ); +/* +* NEEDSWORK: this call can essentially be set_git_dir(get_git_dir()) +* which can cause some problems when trying to free the old value of +* gitdir. +*/ set_git_dir (remove_leading_path (git_dir, work_tree)); initialized =1 ; }
@@ -1074,8 +1080,15 @@ const char *setup_git_directory_gently(int *nongit_ok)* the user has set GIT_DIR. It may be beneficial to disallow bogus * GIT_DIR values at some point in the future. */ -if (startup_info->have_repository ||getenv (GIT_DIR_ENVIRONMENT )) -setup_git_env (); +if (startup_info->have_repository ||getenv (GIT_DIR_ENVIRONMENT )) { +if (!the_repository->gitdir) { +const char *gitdir =getenv (GIT_DIR_ENVIRONMENT ); +if (!gitdir) + gitdir =DEFAULT_GIT_DIR_ENVIRONMENT ; +repo_set_gitdir (the_repository, gitdir); +setup_git_env (); + } + }strbuf_release (&dir);strbuf_release (&gitdir);
Signature · 1 line
2.13.1.508.gb3defc5cc-goog
PATCH v2 11/32 config: read config from a repository object
In reply to Brandon WilliamsTeach the config machinery to read config information from a repository object. This involves storing a 'struct config_set' inside the repository object and adding a number of functions (repo_config*) to be able to query a repository's config.
The current config API enables lazy-loading of the config. This means that when 'git_config_get_int()' is called, if the_config_set hasn't been populated yet, then it will be populated and properly initialized by reading the necessary config files (system wide .gitconfig, user's home .gitconfig, and the repository's config). To maintain this paradigm, the new API to read from a repository object's config will also perform this lazy-initialization.
Since both APIs (git_config_get* and repo_config_get*) have the same semantics we can migrate the default config to be stored within 'the_repository' and just have the 'git_config_get*' family of functions redirect to the 'repo_config_get*' functions.
--- config.c | 209 +++++++++++++++++++++++++++++++++++++++-------------------- config.h | 24 +++++++ repository.c | 7 ++ repository.h | 10 +++ 4 files changed, 179 insertions(+), 71 deletions(-)
config.c +138 -71
@@ -7,6 +7,7 @@*/ #include "cache.h" #include "config.h" +#include "repository.h" #include "lockfile.h" #include "exec_cmd.h" #include "strbuf.h"
@@ -72,13 +73,6 @@ static int core_compression_seen;static int pack_compression_seen;static int zlib_compression_seen; -/* -* Default config_set that contains key-value pairs from the usual set of config -* config files (i.e repo specific .git/config, user wide ~/.gitconfig, XDG -* config file and the global /etc/gitconfig) -*/ -static struct config_set the_config_set; -static int config_file_fgetc (struct config_source *conf) {return getc_unlocked (conf->u.file);
@@ -1606,28 +1600,6 @@ int git_config_with_options(config_fn_t fn, void *data,return do_git_config_sequence (opts, fn, data); } -static void git_config_raw (config_fn_t fn,void *data) -{ -struct config_options opts = {0 }; - - opts.respect_includes =1 ; -if (have_git_dir ()) - opts.git_dir =get_git_common_dir (); -if (git_config_with_options (fn, data,NULL , &opts) <0 ) -/* -* git_config_with_options() normally returns only -* zero, as most errors are fatal, and -* non-fatal potential errors are guarded by "if" -* statements that are entered only when no error is -* possible. -* -* If we ever encounter a non-fatal error, it means -* something went really wrong and we should stop -* immediately. -*/ -die (_ ("unknown error occurred while reading the configuration files" )); -} -static void configset_iter (struct config_set *cs,config_fn_t fn,void *data) {int i, value_index;
@@ -1676,14 +1648,6 @@ void read_early_config(config_fn_t cb, void *data)strbuf_release (&buf); } -static void git_config_check_init (void ); - -void git_config (config_fn_t fn,void *data) -{ -git_config_check_init (); -configset_iter (&the_config_set, fn, data); -} -static struct config_set_element *configset_find_element (struct config_set *cs,const char *key) {struct config_set_element k;
@@ -1893,87 +1857,190 @@ int git_configset_get_pathname(struct config_set *cs, const char *key, const chareturn 1 ; } -static void git_config_check_init (void ) +/* Functions use to read configuration from a repository */ +static void repo_read_config (struct repository *repo) { -if (the_config_set.hash_initialized) +struct config_options opts = {1 , repo->commondir }; + +if (!repo->config) + repo->config =xcalloc (1 ,sizeof (struct config_set )); +else +git_configset_clear (repo->config); + +git_configset_init (repo->config); + +if (git_config_with_options (config_set_callback, repo->config,NULL , &opts) <0 ) +/* +* git_config_with_options() normally returns only +* zero, as most errors are fatal, and +* non-fatal potential errors are guarded by "if" +* statements that are entered only when no error is +* possible. +* +* If we ever encounter a non-fatal error, it means +* something went really wrong and we should stop +* immediately. +*/ +die (_ ("unknown error occurred while reading the configuration files" )); +} + +static void git_config_check_init (struct repository *repo) +{ +if (repo->config && repo->config->hash_initialized)return ; -git_configset_init (&the_config_set); -git_config_raw (config_set_callback, &the_config_set); +repo_read_config (repo); } -void git_config_clear (void ) +static void repo_config_clear (struct repository *repo) { -if (!the_config_set.hash_initialized) +if (!repo->config || !repo->config->hash_initialized)return ; -git_configset_clear (&the_config_set); +git_configset_clear (repo->config); } -int git_config_get_value (const char *key,const char **value) +void repo_config (struct repository *repo,config_fn_t fn,void *data) { -git_config_check_init (); -return git_configset_get_value (&the_config_set, key, value); +git_config_check_init (repo); +configset_iter (repo->config, fn, data); } -const struct string_list *git_config_get_value_multi (const char *key) +int repo_config_get_value (struct repository *repo, +const char *key,const char **value) { -git_config_check_init (); -return git_configset_get_value_multi (&the_config_set, key); +git_config_check_init (repo); +return git_configset_get_value (repo->config, key, value); } -int git_config_get_string_const (const char *key,const char **dest) +const struct string_list *repo_config_get_value_multi (struct repository *repo, +const char *key) +{ +git_config_check_init (repo); +return git_configset_get_value_multi (repo->config, key); +} + +int repo_config_get_string_const (struct repository *repo, +const char *key,const char **dest) {int ret; -git_config_check_init (); - ret =git_configset_get_string_const (&the_config_set, key, dest); +git_config_check_init (repo); + ret =git_configset_get_string_const (repo->config, key, dest);if (ret <0 )git_die_config (key,NULL );return ret; } +int repo_config_get_string (struct repository *repo, +const char *key,char **dest) +{ +git_config_check_init (repo); +return repo_config_get_string_const (repo, key, (const char **)dest); +} + +int repo_config_get_int (struct repository *repo, +const char *key,int *dest) +{ +git_config_check_init (repo); +return git_configset_get_int (repo->config, key, dest); +} + +int repo_config_get_ulong (struct repository *repo, +const char *key,unsigned long *dest) +{ +git_config_check_init (repo); +return git_configset_get_ulong (repo->config, key, dest); +} + +int repo_config_get_bool (struct repository *repo, +const char *key,int *dest) +{ +git_config_check_init (repo); +return git_configset_get_bool (repo->config, key, dest); +} + +int repo_config_get_bool_or_int (struct repository *repo, +const char *key,int *is_bool,int *dest) +{ +git_config_check_init (repo); +return git_configset_get_bool_or_int (repo->config, key, is_bool, dest); +} + +int repo_config_get_maybe_bool (struct repository *repo, +const char *key,int *dest) +{ +git_config_check_init (repo); +return git_configset_get_maybe_bool (repo->config, key, dest); +} + +int repo_config_get_pathname (struct repository *repo, +const char *key,const char **dest) +{ +int ret; +git_config_check_init (repo); + ret =git_configset_get_pathname (repo->config, key, dest); +if (ret <0 ) +git_die_config (key,NULL ); +return ret; +} + +/* Functions used historically to read configuration from 'the_repository' */ +void git_config (config_fn_t fn,void *data) +{ +repo_config (the_repository, fn, data); +} + +void git_config_clear (void ) +{ +repo_config_clear (the_repository); +} + +int git_config_get_value (const char *key,const char **value) +{ +return repo_config_get_value (the_repository, key, value); +} + +const struct string_list *git_config_get_value_multi (const char *key) +{ +return repo_config_get_value_multi (the_repository, key); +} + +int git_config_get_string_const (const char *key,const char **dest) +{ +return repo_config_get_string_const (the_repository, key, dest); +} +int git_config_get_string (const char *key,char **dest) { -git_config_check_init (); -return git_config_get_string_const (key, (const char **)dest); +return repo_config_get_string (the_repository, key, dest); }int git_config_get_int (const char *key,int *dest) { -git_config_check_init (); -return git_configset_get_int (&the_config_set, key, dest); +return repo_config_get_int (the_repository, key, dest); }int git_config_get_ulong (const char *key,unsigned long *dest) { -git_config_check_init (); -return git_configset_get_ulong (&the_config_set, key, dest); +return repo_config_get_ulong (the_repository, key, dest); }int git_config_get_bool (const char *key,int *dest) { -git_config_check_init (); -return git_configset_get_bool (&the_config_set, key, dest); +return repo_config_get_bool (the_repository, key, dest); }int git_config_get_bool_or_int (const char *key,int *is_bool,int *dest) { -git_config_check_init (); -return git_configset_get_bool_or_int (&the_config_set, key, is_bool, dest); +return repo_config_get_bool_or_int (the_repository, key, is_bool, dest); }int git_config_get_maybe_bool (const char *key,int *dest) { -git_config_check_init (); -return git_configset_get_maybe_bool (&the_config_set, key, dest); +return repo_config_get_maybe_bool (the_repository, key, dest); }int git_config_get_pathname (const char *key,const char **dest) { -int ret; -git_config_check_init (); - ret =git_configset_get_pathname (&the_config_set, key, dest); -if (ret <0 ) -git_die_config (key,NULL ); -return ret; +return repo_config_get_pathname (the_repository, key, dest); }int git_config_get_expiry (const char *key,const char **output)
config.h +24 -0
@@ -162,6 +162,30 @@ extern int git_configset_get_bool_or_int(struct config_set *cs, const char *key,extern int git_configset_get_maybe_bool (struct config_set *cs,const char *key,int *dest);extern int git_configset_get_pathname (struct config_set *cs,const char *key,const char **dest); +/* Functions for reading a repository's config */ +struct repository ; +extern void repo_config (struct repository *repo,config_fn_t fn,void *data); +extern int repo_config_get_value (struct repository *repo, +const char *key,const char **value); +extern const struct string_list *repo_config_get_value_multi (struct repository *repo, +const char *key); +extern int repo_config_get_string_const (struct repository *repo, +const char *key,const char **dest); +extern int repo_config_get_string (struct repository *repo, +const char *key,char **dest); +extern int repo_config_get_int (struct repository *repo, +const char *key,int *dest); +extern int repo_config_get_ulong (struct repository *repo, +const char *key,unsigned long *dest); +extern int repo_config_get_bool (struct repository *repo, +const char *key,int *dest); +extern int repo_config_get_bool_or_int (struct repository *repo, +const char *key,int *is_bool,int *dest); +extern int repo_config_get_maybe_bool (struct repository *repo, +const char *key,int *dest); +extern int repo_config_get_pathname (struct repository *repo, +const char *key,const char **dest); +extern int git_config_get_value (const char *key,const char **value);extern const struct string_list *git_config_get_value_multi (const char *key);extern void git_config_clear (void );
repository.c +7 -0
@@ -1,5 +1,6 @@#include "cache.h" #include "repository.h" +#include "config.h" /* The main repository */ static struct repository the_repo;
@@ -179,5 +180,11 @@ void repo_clear(struct repository *repo)free (repo->worktree); repo->worktree =NULL ; +if (repo->config) { +git_configset_clear (repo->config); +free (repo->config); + repo->config =NULL ; + } +memset (repo,0 ,sizeof (*repo)); }
repository.h +10 -0
@@ -1,6 +1,8 @@ #ifndef REPOSITORY_H #define REPOSITORY_H +struct config_set; + struct repository { /* Environment */ char *gitdir;
@@ -11,6 +13,14 @@ struct repository {char *namespace;char *worktree; +/* Subsystems */ +/* +* Repository's config which contains key-value pairs from the usual +* set of config files (i.e. repo specific .git/config, user wide +* ~/.gitconfig, XDG config file and the global /etc/gitconfig) +*/ +struct config_set *config; +/* Configurations */ unsigned ignore_env:1;/* Indicates if a repository has a different 'commondir' from 'gitdir' */
Signature · 1 line
2.13.1.508.gb3defc5cc-goog
Re: [PATCH v2 32/32] ls-files: use repository object
In reply to Brandon WilliamsQuoted 288 lines · Brandon Williams
Convert ls-files to use a repository struct and recurse submodules inprocess.
Signed-off-by Brandon Williams <[email protected]>--- builtin/ls-files.c | 198 ++++++++++++++------------------- git.c | 2 +- repository.c | 4 + repository.h | 1 + t/t3007-ls-files-recurse-submodules.sh | 39 +++++++ 5 files changed, 129 insertions(+), 115 deletions(-)builtin/ls-files.c +70
-105@@ -5,7 +5,9 @@* * Copyright (C) Linus Torvalds, 2005 */ +#define NO_THE_INDEX_COMPATIBILITY_MACROS #include "cache.h" +#include "repository.h" #include "config.h" #include "quote.h" #include "dir.h" @@ -32,10 +34,8 @@ static int line_terminator = '\n';static int debug_mode;static int show_eol;static int recurse_submodules; -static struct argv_array submodule_options =ARGV_ARRAY_INIT ;static const char *prefix; -static const char *super_prefix;static int max_prefix_len;static int prefix_len;static struct pathspec pathspec;@@ -73,25 +73,12 @@ static void write_eolinfo(const struct index_state *istate,static void write_name (const char *name) { -/* -* Prepend the super_prefix to name to construct the full_name to be -* written. -*/ -struct strbuf full_name =STRBUF_INIT ; -if (super_prefix) { -strbuf_addstr (&full_name, super_prefix); -strbuf_addstr (&full_name, name); - name = full_name.buf; - } -/* * With "--full-name", prefix_len=0; this caller needs to pass * an empty string in that case (a NULL is good for ""). */ write_name_quoted_relative (name, prefix_len ? prefix :NULL , stdout, line_terminator); - -strbuf_release (&full_name); }static const char *get_tag (const struct cache_entry *ce,const char *tag)@@ -210,82 +197,41 @@ static void show_killed_files(const struct index_state *istate, } } -/* -* Compile an argv_array with all of the options supported by --recurse_submodules -*/ -static void compile_submodule_options (const char **argv, -const struct dir_struct *dir, -int show_tag) -{ -if (line_terminator =='\0' ) -argv_array_push (&submodule_options,"-z" ); -if (show_tag) -argv_array_push (&submodule_options,"-t" ); -if (show_valid_bit) -argv_array_push (&submodule_options,"-v" ); -if (show_cached) -argv_array_push (&submodule_options,"--cached" ); -if (show_eol) -argv_array_push (&submodule_options,"--eol" ); -if (debug_mode) -argv_array_push (&submodule_options,"--debug" ); - -/* Add Pathspecs */ -argv_array_push (&submodule_options,"--" ); -for (; *argv; argv++) -argv_array_push (&submodule_options, *argv); -} +static void show_files (struct repository *repo,struct dir_struct *dir); -/** -* Recursively call ls-files on a submodule -*/ -static void show_gitlink (const struct cache_entry *ce) +static void show_submodule (const struct repository *superproject, +struct dir_struct *dir,const char *path) { -struct child_process cp =CHILD_PROCESS_INIT ; -int status; -char *dir; - -prepare_submodule_repo_env (&cp.env_array); -argv_array_push (&cp.env_array,GIT_DIR_ENVIRONMENT ); - -if (prefix_len) -argv_array_pushf (&cp.env_array,"%s=%s" , -GIT_TOPLEVEL_PREFIX_ENVIRONMENT , - prefix); -argv_array_pushf (&cp.args,"--super-prefix=%s%s/" , - super_prefix ? super_prefix :"" , - ce->name); -argv_array_push (&cp.args,"ls-files" ); -argv_array_push (&cp.args,"--recurse-submodules" ); - -/* add supported options */ -argv_array_pushv (&cp.args, submodule_options.argv); - - cp.git_cmd =1 ; - dir =mkpathdup ("%s/%s" ,get_git_work_tree (), ce->name); - cp.dir = dir; - status =run_command (&cp); -free (dir); -if (status) -exit (status); +struct repository submodule; +char *gitdir =mkpathdup ("%s/%s" , superproject->worktree, path); +repo_init (&submodule, gitdir); + +repo_read_index (&submodule); +repo_read_gitmodules (&submodule); + +if (superproject->submodule_prefix) + submodule.submodule_prefix =xstrfmt ("%s%s/" , superproject->submodule_prefix, path); +else + submodule.submodule_prefix =xstrfmt ("%s/" , path); +show_files (&submodule, dir); + +repo_clear (&submodule); +free (gitdir); } -static void show_ce_entry (const char *tag,const struct cache_entry *ce) +static void show_ce (struct repository *repo,struct dir_struct *dir, +const struct cache_entry *ce,const char *fullname, +const char *tag) { -struct strbuf name =STRBUF_INIT ; -int len = max_prefix_len; -if (super_prefix) -strbuf_addstr (&name, super_prefix); -strbuf_addstr (&name, ce->name); - -if (len >ce_namelen (ce)) +if (max_prefix_len >strlen (fullname))die ("git ls-files: internal error - cache entry not superset of prefix" );if (recurse_submodules &&S_ISGITLINK (ce->ce_mode) && -submodule_path_match (&pathspec, name.buf, ps_matched)) { -show_gitlink (ce); - }else if (match_pathspec (&pathspec, name.buf, name.len, - len, ps_matched, +submodule_path_match (&pathspec, fullname, ps_matched) && +is_submodule_active (repo, ce->name)) { +show_submodule (repo, dir, ce->name); + }else if (match_pathspec (&pathspec, fullname,strlen (fullname), + max_prefix_len, ps_matched,S_ISDIR (ce->ce_mode) ||S_ISGITLINK (ce->ce_mode))) { tag =get_tag (ce, tag);@@ -299,12 +245,11 @@ static void show_ce_entry(const char *tag, const struct cache_entry *ce)find_unique_abbrev (ce->oid.hash, abbrev), ce_stage(ce)); } -write_eolinfo (&the_index, ce, ce->name); -write_name (ce->name); + +write_eolinfo (repo->index, ce, fullname); +write_name (fullname);print_debug (ce); } - -strbuf_release (&name); }static void show_ru_info (const struct index_state *istate)@@ -337,59 +282,79 @@ static void show_ru_info(const struct index_state *istate) }static int ce_excluded (struct dir_struct *dir,struct index_state *istate, -const struct cache_entry *ce) +const char *fullname,const struct cache_entry *ce) {int dtype =ce_to_dtype (ce); -return is_excluded (dir, istate, ce->name, &dtype); +return is_excluded (dir, istate, fullname, &dtype); +} + +static void construct_fullname (struct strbuf *out,const struct repository *repo, +const struct cache_entry *ce) +{ +strbuf_reset (out); +if (repo->submodule_prefix) +strbuf_addstr (out, repo->submodule_prefix); +strbuf_addstr (out, ce->name); } -static void show_files (struct index_state *istate,struct dir_struct *dir) +static void show_files (struct repository *repo,struct dir_struct *dir) {int i; +struct strbuf fullname =STRBUF_INIT ;/* For cached/deleted files we don't need to even do the readdir */ if (show_others || show_killed) {if (!show_others) dir->flags |=DIR_COLLECT_KILLED_ONLY ; -fill_directory (dir, istate, &pathspec); +fill_directory (dir, repo->index, &pathspec);if (show_others) -show_other_files (istate, dir); +show_other_files (repo->index, dir);if (show_killed) -show_killed_files (istate, dir); +show_killed_files (repo->index, dir); }if (show_cached || show_stage) { -for (i =0 ; i < istate->cache_nr; i++) { -const struct cache_entry *ce = istate->cache[i]; +for (i =0 ; i < repo->index->cache_nr; i++) { +const struct cache_entry *ce = repo->index->cache[i]; + +construct_fullname (&fullname, repo, ce); +if ((dir->flags &DIR_SHOW_IGNORED ) && - !ce_excluded (dir, istate, ce)) + !ce_excluded (dir, repo->index, fullname.buf, ce))continue ;if (show_unmerged && !ce_stage (ce))continue ;if (ce->ce_flags &CE_UPDATE )continue ; -show_ce_entry (ce_stage (ce) ? tag_unmerged : - (ce_skip_worktree (ce) ? tag_skip_worktree : tag_cached), ce); +show_ce (repo, dir, ce, fullname.buf, +ce_stage (ce) ? tag_unmerged : + (ce_skip_worktree (ce) ? tag_skip_worktree : + tag_cached)); } }if (show_deleted || show_modified) { -for (i =0 ; i < istate->cache_nr; i++) { -const struct cache_entry *ce = istate->cache[i]; +for (i =0 ; i < repo->index->cache_nr; i++) { +const struct cache_entry *ce = repo->index->cache[i];struct stat st;int err; + +construct_fullname (&fullname, repo, ce); +if ((dir->flags &DIR_SHOW_IGNORED ) && - !ce_excluded (dir, istate, ce)) + !ce_excluded (dir, repo->index, fullname.buf, ce))continue ;if (ce->ce_flags &CE_UPDATE )continue ;if (ce_skip_worktree (ce))continue ; - err =lstat (ce->name, &st); + err =lstat (fullname.buf, &st);if (show_deleted && err) -show_ce_entry (tag_removed, ce); -if (show_modified &&ie_modified (istate, ce, &st,0 )) -show_ce_entry (tag_modified, ce); +show_ce (repo, dir, ce, fullname.buf, tag_removed); +if (show_modified &&ie_modified (repo->index, ce, &st,0 )) +show_ce (repo, dir, ce, fullname.buf, tag_modified); } } + +strbuf_release (&fullname); }/*
builtin/ls-files.c int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix) · line 584
Quoted 8 lines
builtin/ls-files.c +1
-2@@ -614,10 +579,9 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix) prefix = cmd_prefix;if (prefix) prefix_len =strlen (prefix); - super_prefix =get_super_prefix ();git_config (git_default_config,NULL ); -if (read_cache () <0 ) +if (repo_read_index (the_repository))
oops, looks like this should have been:
if (repo_read_index(the_repository) < 0)
Quoted 153 lines
builtin/ls-files.c +13
-7die ("index file corrupt" ); argc = parse_options(argc, argv, prefix, builtin_ls_files_options,@@ -650,8 +614,9 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix)if (require_work_tree && !is_inside_work_tree ())setup_work_tree (); -if (recurse_submodules) -compile_submodule_options (argv, &dir, show_tag); +if (recurse_submodules) { +repo_read_gitmodules (the_repository); + } if (recurse_submodules && (show_stage || show_deleted || show_others || show_unmerged ||@@ -669,7 +634,10 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix)/* * Find common prefix for all pathspec's * This is used as a performance optimization which unfortunately cannot -* be done when recursing into submodules +* be done when recursing into submodules because when a pathspec is +* given which spans repository boundaries you can't simply remove the +* submodule entry because the pathspec may match something inside the +* submodule. */ if (recurse_submodules) max_prefix =NULL ;@@ -677,7 +645,7 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix) max_prefix =common_prefix (&pathspec); max_prefix_len =get_common_prefix_len (max_prefix); -prune_index (&the_index, max_prefix, max_prefix_len); +prune_index (the_repository->index, max_prefix, max_prefix_len);/* Treat unmatching pathspec elements as errors */ if (pathspec.nr && error_unmatch)@@ -698,11 +666,13 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix)*/ if (show_stage || show_unmerged)die ("ls-files --with-tree is incompatible with -s or -u" ); -overlay_tree_on_index (&the_index, with_tree, max_prefix); +overlay_tree_on_index (the_repository->index, with_tree, max_prefix); } -show_files (&the_index, &dir); + +show_files (the_repository, &dir); +if (show_resolve_undo) -show_ru_info (&the_index); +show_ru_info (the_repository->index);if (ps_matched) {int bad;git.c +1
-1@@ -442,7 +442,7 @@ static struct cmd_struct commands[] = { { "init-db", cmd_init_db }, { "interpret-trailers", cmd_interpret_trailers, RUN_SETUP_GENTLY }, { "log", cmd_log, RUN_SETUP }, - { "ls-files", cmd_ls_files, RUN_SETUP | SUPPORT_SUPER_PREFIX }, + { "ls-files", cmd_ls_files, RUN_SETUP }, { "ls-remote", cmd_ls_remote, RUN_SETUP_GENTLY }, { "ls-tree", cmd_ls_tree, RUN_SETUP }, { "mailinfo", cmd_mailinfo, RUN_SETUP_GENTLY },repository.c +4
-0@@ -152,6 +152,8 @@ int repo_init(struct repository *repo, const char *gitdir)if (verify_repo_format (&format, repo->commondir)) goto error; +repo_set_worktree (repo, gitdir); +return 0 ; error:@@ -180,6 +182,8 @@ void repo_clear(struct repository *repo)repo_clear_env (repo);free (repo->worktree); repo->worktree =NULL ; +free (repo->submodule_prefix); + repo->submodule_prefix =NULL ;if (repo->config) {git_configset_clear (repo->config);repository.h +1
-0@@ -14,6 +14,7 @@ struct repository {char *graft_file;char *namespace;char *worktree; +char *submodule_prefix;/* Subsystems */ /* t/t3007-ls-files-recurse-submodules.sh +39
-0@@ -135,6 +135,45 @@ test_expect_success '--recurse-submodules and pathspecs setup' ' test_cmp expect actual ' +test_expect_success 'inactive submodule' ' + test_when_finished "git config --bool submodule.submodule.active true" && + test_when_finished "git -C submodule config --bool submodule.subsub.active true" && + git config --bool submodule.submodule.active "false" && + + cat >expect <<-\EOF && + .gitmodules + a + b/b + h.txt + sib/file + sub/file + submodule + EOF + + git ls-files --recurse-submodules >actual && + test_cmp expect actual && + + git config --bool submodule.submodule.active "true" && + git -C submodule config --bool submodule.subsub.active "false" && + + cat >expect <<-\EOF && + .gitmodules + a + b/b + h.txt + sib/file + sub/file + submodule/.gitmodules + submodule/c + submodule/f.TXT + submodule/g.txt + submodule/subsub + EOF + + git ls-files --recurse-submodules >actual && + test_cmp expect actual +' + test_expect_success '--recurse-submodules and pathspecs' ' cat >expect <<-\EOF && h.txtSignature · 1 line
2.13.1.508.gb3defc5cc-goog
Signature · 1 line
Brandon Williams
cover Add a freez() wrapper
In reply to Brandon WilliamsQuoted 8 lines · Brandon Williams
Introduce the repository object 'struct repository' which can be used to hold all state pertaining to a git repository.
[...]repository.c new file +5
-0+static void repo_clear_env (struct repository *repo) +{ +free (repo->gitdir); + repo->gitdir =NULL ; +free (repo->commondir);
repository.c line 164
Quoted 10 lines
repository.c new file +10
-0+ repo->commondir =NULL ; +free (repo->objectdir); + repo->objectdir =NULL ; +free (repo->index_file); + repo->index_file =NULL ; +free (repo->graft_file); + repo->graft_file =NULL ; +free (repo->namespace); + repo->namespace =NULL ; +}
When seeing this I wondered if it couldn't be less noisy as:
Review
Quoted 6 lines
(quoted diff) +6
-0+ freez(repo->gitdir); + freez(repo->commondir); + freez(repo->objectdir); + freez(repo->index_file); + freez(repo->graft_file); + freez(repo->namespace);
It's not a problem with your patch, but something I thought would be nice to have in general, so here's a patch series to implement that.
Ævar Arnfjörð Bjarmason (2):
git-compat-util: add a freez() wrapper around free(x); x = NULL *.[ch] refactoring: make use of the freez() wrapper
alias.c | 6 ++---- apply.c | 3 +-- attr.c | 6 ++---- blame.c | 3 +-- branch.c | 3 +-- builtin/am.c | 18 +++++------------- builtin/clean.c | 6 ++---- builtin/config.c | 6 ++---- builtin/index-pack.c | 6 ++---- builtin/pack-objects.c | 12 ++++-------- builtin/unpack-objects.c | 3 +-- builtin/worktree.c | 6 ++---- commit-slab.h | 3 +-- commit.c | 3 +-- config.c | 3 +-- credential.c | 9 +++------ diff-lib.c | 3 +-- diff.c | 6 ++---- diffcore-rename.c | 6 ++---- dir.c | 9 +++------ fast-import.c | 6 ++---- git-compat-util.h | 1 + gpg-interface.c | 15 +++++---------- grep.c | 12 ++++-------- help.c | 3 +-- http-push.c | 24 ++++++++---------------- http.c | 15 +++++---------- imap-send.c | 3 +-- line-log.c | 6 ++---- ll-merge.c | 3 +-- mailinfo.c | 3 +-- object.c | 3 +-- pathspec.c | 3 +-- prio-queue.c | 3 +-- read-cache.c | 6 ++---- ref-filter.c | 3 +-- refs/files-backend.c | 3 +-- refs/ref-cache.c | 3 +-- remote-testsvn.c | 3 +-- rerere.c | 3 +-- sequencer.c | 3 +-- sha1-array.c | 3 +-- sha1_file.c | 3 +-- split-index.c | 3 +-- transport-helper.c | 27 +++++++++------------------ transport.c | 3 +-- tree-diff.c | 6 ++---- tree-walk.c | 3 +-- tree.c | 3 +-- 49 files changed, 98 insertions(+), 197 deletions(-)
Signature · 1 line
2.13.0.506.g27d5fe0cd
PATCH 1/2 git-compat-util: add a freez() wrapper around free(x); x = NULL
Add a freez() wrapper for the common pattern of freeing a pointer and assigning NULL to it right afterwards.
The implementation is the same as the (currently unused) XDL_PTRFREE macro in xdiff/xmacros.h added in commit 3443546f6e ("Use a *real* built-in diff generator", 2006-03-24).
--- git-compat-util.h | 1 + 1 file changed, 1 insertion(+)
git-compat-util.h +1 -0
@@ -787,6 +787,7 @@ extern char *xstrdup(const char *str);extern void *xmalloc (size_t size);extern void *xmallocz (size_t size);extern void *xmallocz_gently (size_t size); +#define freez (p) do { if (p) { free(p); (p) = NULL; } } while (0)extern void *xmemdupz (const void *data,size_t len);extern char *xstrndup (const char *str,size_t len);extern void *xrealloc (void *ptr,size_t size);
Signature · 1 line
2.13.0.506.g27d5fe0cd