Skip to content

Commit

Permalink
Add virtual file system settings and hook proc
Browse files Browse the repository at this point in the history
On index load, clear/set the skip worktree bits based on the virtual
file system data. Use virtual file system data to update skip-worktree
bit in unpack-trees. Use virtual file system data to exclude files and
folders not explicitly requested.

Signed-off-by: Ben Peart <benpeart@microsoft.com>
  • Loading branch information
benpeart authored and dscho committed Dec 15, 2018
1 parent 7d4dce9 commit 322557a
Show file tree
Hide file tree
Showing 13 changed files with 789 additions and 9 deletions.
8 changes: 8 additions & 0 deletions Documentation/config/core.txt
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@ core.fsmonitor::
avoiding unnecessary processing of files that have not changed.
See the "fsmonitor-watchman" section of linkgit:githooks[5].

core.virtualFilesystem::
If set, the value of this variable is used as a command which
will identify all files and directories that are present in
the working directory. Git will only track and update files
listed in the virtual file system. Using the virtual file system
will supersede the sparse-checkout settings which will be ignored.
See the "virtual file system" section of linkgit:githooks[6].

core.trustctime::
If false, the ctime differences between the index and the
working tree are ignored; useful when the inode change time
Expand Down
20 changes: 20 additions & 0 deletions Documentation/githooks.txt
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,26 @@ This hook is invoked by `git-p4 submit`. It takes no parameters and nothing
from standard input. Exiting with non-zero status from this script prevent
`git-p4 submit` from launching. Run `git-p4 submit --help` for details.

virtualFilesystem
~~~~~~~~~~~~~~~~~~

"Virtual File System" allows populating the working directory sparsely.
The projection data is typically automatically generated by an external
process. Git will limit what files it checks for changes as well as which
directories are checked for untracked files based on the path names given.
Git will also only update those files listed in the projection.

The hook is invoked when the configuration option core.virtualFilesystem
is set. It takes one argument, a version (currently 1).

The hook should output to stdout the list of all files in the working
directory that git should track. The paths are relative to the root
of the working directory and are separated by a single NUL. Full paths
('dir1/a.txt') as well as directories are supported (ie 'dir1/').

The exit status determines whether git will use the data from the
hook. On error, git will abort the command with an error message.

GIT
---
Part of the linkgit:git[1] suite
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -1016,6 +1016,7 @@ LIB_OBJS += utf8.o
LIB_OBJS += varint.o
LIB_OBJS += version.o
LIB_OBJS += versioncmp.o
LIB_OBJS += virtualfilesystem.o
LIB_OBJS += walker.o
LIB_OBJS += wildmatch.o
LIB_OBJS += worktree.o
Expand Down
1 change: 1 addition & 0 deletions cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -886,6 +886,7 @@ extern char *git_replace_ref_base;
extern int fsync_object_files;
extern int core_preload_index;
extern int core_apply_sparse_checkout;
extern const char *core_virtualfilesystem;
extern int core_gvfs;
extern int precomposed_unicode;
extern int protect_hfs;
Expand Down
23 changes: 22 additions & 1 deletion config.c
Original file line number Diff line number Diff line change
Expand Up @@ -1331,7 +1331,11 @@ static int git_default_core_config(const char *var, const char *value, void *cb)
}

if (!strcmp(var, "core.sparsecheckout")) {
core_apply_sparse_checkout = git_config_bool(var, value);
/* virtual file system relies on the sparse checkout logic so force it on */
if (core_virtualfilesystem)
core_apply_sparse_checkout = 1;
else
core_apply_sparse_checkout = git_config_bool(var, value);
return 0;
}

Expand Down Expand Up @@ -2312,6 +2316,23 @@ int git_config_get_fsmonitor(void)
return 0;
}

int git_config_get_virtualfilesystem(void)
{
if (git_config_get_pathname("core.virtualfilesystem", &core_virtualfilesystem))
core_virtualfilesystem = getenv("GIT_VIRTUALFILESYSTEM_TEST");

if (core_virtualfilesystem && !*core_virtualfilesystem)
core_virtualfilesystem = NULL;

/* virtual file system relies on the sparse checkout logic so force it on */
if (core_virtualfilesystem) {
core_apply_sparse_checkout = 1;
return 1;
}

return 0;
}

int git_config_get_index_threads(int *dest)
{
int is_bool, val;
Expand Down
1 change: 1 addition & 0 deletions config.h
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ 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);
extern int git_config_get_fsmonitor(void);
extern int git_config_get_virtualfilesystem(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);
Expand Down
34 changes: 32 additions & 2 deletions dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "ewah/ewok.h"
#include "fsmonitor.h"
#include "submodule-config.h"
#include "virtualfilesystem.h"

/*
* Tells read_directory_recursive how a file or directory should be treated.
Expand Down Expand Up @@ -1159,6 +1160,18 @@ int is_excluded_from_list(const char *pathname,
struct exclude_list *el, struct index_state *istate)
{
struct exclude *exclude;

/*
* The virtual file system data is used to prevent git from traversing
* any part of the tree that is not in the virtual file system. Return
* 1 to exclude the entry if it is not found in the virtual file system,
* else fall through to the regular excludes logic as it may further exclude.
*/
if (*dtype == DT_UNKNOWN)
*dtype = get_dtype(NULL, istate, pathname, pathlen);
if (is_excluded_from_virtualfilesystem(pathname, pathlen, *dtype) > 0)
return 1;

exclude = last_exclude_matching_from_list(pathname, pathlen, basename,
dtype, el, istate);
if (exclude)
Expand Down Expand Up @@ -1374,8 +1387,20 @@ struct exclude *last_exclude_matching(struct dir_struct *dir,
int is_excluded(struct dir_struct *dir, struct index_state *istate,
const char *pathname, int *dtype_p)
{
struct exclude *exclude =
last_exclude_matching(dir, istate, pathname, dtype_p);
struct exclude *exclude;

/*
* The virtual file system data is used to prevent git from traversing
* any part of the tree that is not in the virtual file system. Return
* 1 to exclude the entry if it is not found in the virtual file system,
* else fall through to the regular excludes logic as it may further exclude.
*/
if (*dtype_p == DT_UNKNOWN)
*dtype_p = get_dtype(NULL, istate, pathname, strlen(pathname));
if (is_excluded_from_virtualfilesystem(pathname, strlen(pathname), *dtype_p) > 0)
return 1;

exclude = last_exclude_matching(dir, istate, pathname, dtype_p);
if (exclude)
return exclude->flags & EXC_FLAG_NEGATIVE ? 0 : 1;
return 0;
Expand Down Expand Up @@ -1728,6 +1753,9 @@ static enum path_treatment treat_one_path(struct dir_struct *dir,
if (dtype != DT_DIR && has_path_in_index)
return path_none;

if (is_excluded_from_virtualfilesystem(path->buf, path->len, dtype) > 0)
return path_excluded;

/*
* When we are looking at a directory P in the working tree,
* there are three cases:
Expand Down Expand Up @@ -2068,6 +2096,8 @@ static enum path_treatment read_directory_recursive(struct dir_struct *dir,
/* add the path to the appropriate result list */
switch (state) {
case path_excluded:
if (is_excluded_from_virtualfilesystem(path.buf, path.len, DT_DIR) > 0)
break;
if (dir->flags & DIR_SHOW_IGNORED)
dir_add_name(dir, istate, path.buf, path.len);
else if ((dir->flags & DIR_SHOW_IGNORED_TOO) ||
Expand Down
1 change: 1 addition & 0 deletions environment.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ char *notes_ref_name;
int grafts_replace_parents = 1;
int core_apply_sparse_checkout;
int core_gvfs;
const char *core_virtualfilesystem;
int merge_log_config = -1;
int precomposed_unicode = -1; /* see probe_utf8_pathname_composition() */
unsigned long pack_size_limit_cfg;
Expand Down
2 changes: 2 additions & 0 deletions read-cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "fsmonitor.h"
#include "thread-utils.h"
#include "progress.h"
#include "virtualfilesystem.h"
#include "gvfs.h"

/* Mask for the name length in ce_flags in the on-disk index */
Expand Down Expand Up @@ -1897,6 +1898,7 @@ static void post_read_index_from(struct index_state *istate)
tweak_untracked_cache(istate);
tweak_split_index(istate);
tweak_fsmonitor(istate);
apply_virtualfilesystem(istate);
}

static size_t estimate_cache_size_from_compressed(unsigned int entries)
Expand Down
Loading

0 comments on commit 322557a

Please sign in to comment.