Skip to content

Commit 4f56030

Browse files
dschomjcheetham
authored andcommitted
Merge advanced VFS-specific features
Most of these were done in private before microsoft/git. However, the following pull requests modified the core feature: git-for-windows#85 git-for-windows#89 git-for-windows#91 git-for-windows#98 git-for-windows#243 git-for-windows#263 Signed-off-by: Derrick Stolee <[email protected]>
2 parents 63c6daa + 6c8b00b commit 4f56030

18 files changed

+488
-42
lines changed

BRANCHES.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
Branches used in this repo
2+
==========================
3+
4+
The document explains the branching structure that we are using in the VFSForGit repository as well as the forking strategy that we have adopted for contributing.
5+
6+
Repo Branches
7+
-------------
8+
9+
1. `vfs-#`
10+
11+
These branches are used to track the specific version that match Git for Windows with the VFSForGit specific patches on top. When a new version of Git for Windows is released, the VFSForGit patches will be rebased on that windows version and a new gvfs-# branch created to create pull requests against.
12+
13+
#### Examples
14+
15+
```
16+
vfs-2.27.0
17+
vfs-2.30.0
18+
```
19+
20+
The versions of git for VFSForGit are based on the Git for Windows versions. v2.20.0.vfs.1 will correspond with the v2.20.0.windows.1 with the VFSForGit specific patches applied to the windows version.
21+
22+
2. `vfs-#-exp`
23+
24+
These branches are for releasing experimental features to early adopters. They
25+
should contain everything within the corresponding `vfs-#` branch; if the base
26+
branch updates, then merge into the `vfs-#-exp` branch as well.
27+
28+
Tags
29+
----
30+
31+
We are using annotated tags to build the version number for git. The build will look back through the commit history to find the first tag matching `v[0-9]*vfs*` and build the git version number using that tag.
32+
33+
Full releases are of the form `v2.XX.Y.vfs.Z.W` where `v2.XX.Y` comes from the
34+
upstream version and `Z.W` are custom updates within our fork. Specifically,
35+
the `.Z` value represents the "compatibility level" with VFS for Git. Only
36+
increase this version when making a breaking change with a released version
37+
of VFS for Git. The `.W` version is used for minor updates between major
38+
versions.
39+
40+
Experimental releases are of the form `v2.XX.Y.vfs.Z.W.exp`. The `.exp`
41+
suffix indicates that experimental features are available. The rest of the
42+
version string comes from the full release tag. These versions will only
43+
be made available as pre-releases on the releases page, never a full release.
44+
45+
Forking
46+
-------
47+
48+
A personal fork of this repository and a branch in that repository should be used for development.
49+
50+
These branches should be based on the latest vfs-# branch. If there are work in progress pull requests that you have based on a previous version branch when a new version branch is created, you will need to move your patches to the new branch to get them in that latest version.
51+
52+
#### Example
53+
54+
```
55+
git clone <personal fork repo URL>
56+
git remote add ms https://github.com/Microsoft/git.git
57+
git checkout -b my-changes ms/vfs-2.20.0 --no-track
58+
git push -fu origin HEAD
59+
```

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -958,6 +958,7 @@ LIB_OBJS += gettext.o
958958
LIB_OBJS += gpg-interface.o
959959
LIB_OBJS += graph.o
960960
LIB_OBJS += grep.o
961+
LIB_OBJS += gvfs.o
961962
LIB_OBJS += hash-lookup.o
962963
LIB_OBJS += hashmap.o
963964
LIB_OBJS += help.o

apply.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3353,6 +3353,24 @@ static int checkout_target(struct index_state *istate,
33533353
{
33543354
struct checkout costate = CHECKOUT_INIT;
33553355

3356+
/*
3357+
* Do not checkout the entry if the skipworktree bit is set
3358+
*
3359+
* Both callers of this method (check_preimage and load_current)
3360+
* check for the existance of the file before calling this
3361+
* method so we know that the file doesn't exist at this point
3362+
* and we don't need to perform that check again here.
3363+
* We just need to check the skip-worktree and return.
3364+
*
3365+
* This is to prevent git from creating a file in the
3366+
* working directory that has the skip-worktree bit on,
3367+
* then updating the index from the patch and not keeping
3368+
* the working directory version up to date with what it
3369+
* changed the index version to be.
3370+
*/
3371+
if (ce_skip_worktree(ce))
3372+
return 0;
3373+
33563374
costate.refresh_cache = 1;
33573375
costate.istate = istate;
33583376
if (checkout_entry(ce, &costate, NULL, NULL) ||

builtin/gc.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
#include "builtin.h"
1414
#include "repository.h"
15+
#include "gvfs.h"
1516
#include "config.h"
1617
#include "tempfile.h"
1718
#include "lockfile.h"
@@ -604,6 +605,9 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
604605
if (quiet)
605606
strvec_push(&repack, "-q");
606607

608+
if ((!auto_gc || (auto_gc && gc_auto_threshold > 0)) && gvfs_config_is_set(GVFS_BLOCK_COMMANDS))
609+
die(_("'git gc' is not supported on a GVFS repo"));
610+
607611
if (auto_gc) {
608612
/*
609613
* Auto-gc should be least intrusive as possible.

builtin/update-index.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
#define USE_THE_INDEX_COMPATIBILITY_MACROS
77
#include "cache.h"
8+
#include "gvfs.h"
89
#include "bulk-checkin.h"
910
#include "config.h"
1011
#include "lockfile.h"
@@ -1170,7 +1171,13 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
11701171
argc = parse_options_end(&ctx);
11711172

11721173
getline_fn = nul_term_line ? strbuf_getline_nul : strbuf_getline_lf;
1174+
if (mark_skip_worktree_only && gvfs_config_is_set(GVFS_BLOCK_COMMANDS))
1175+
die(_("modifying the skip worktree bit is not supported on a GVFS repo"));
1176+
11731177
if (preferred_index_format) {
1178+
if (preferred_index_format != 4 && gvfs_config_is_set(GVFS_BLOCK_COMMANDS))
1179+
die(_("changing the index version is not supported on a GVFS repo"));
1180+
11741181
if (preferred_index_format < INDEX_FORMAT_LB ||
11751182
INDEX_FORMAT_UB < preferred_index_format)
11761183
die("index-version %d not in range: %d..%d",
@@ -1211,6 +1218,9 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
12111218
end_odb_transaction();
12121219

12131220
if (split_index > 0) {
1221+
if (gvfs_config_is_set(GVFS_BLOCK_COMMANDS))
1222+
die(_("split index is not supported on a GVFS repo"));
1223+
12141224
if (git_config_get_split_index() == 0)
12151225
warning(_("core.splitIndex is set to false; "
12161226
"remove or change it, if you really want to "

cache-tree.c

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,29 @@ static int update_one(struct cache_tree *it,
450450
continue;
451451

452452
strbuf_grow(&buffer, entlen + 100);
453-
strbuf_addf(&buffer, "%o %.*s%c", mode, entlen, path + baselen, '\0');
453+
454+
switch (mode) {
455+
case 0100644:
456+
strbuf_add(&buffer, "100644 ", 7);
457+
break;
458+
case 0100664:
459+
strbuf_add(&buffer, "100664 ", 7);
460+
break;
461+
case 0100755:
462+
strbuf_add(&buffer, "100755 ", 7);
463+
break;
464+
case 0120000:
465+
strbuf_add(&buffer, "120000 ", 7);
466+
break;
467+
case 0160000:
468+
strbuf_add(&buffer, "160000 ", 7);
469+
break;
470+
default:
471+
strbuf_addf(&buffer, "%o ", mode);
472+
break;
473+
}
474+
strbuf_add(&buffer, path + baselen, entlen);
475+
strbuf_addch(&buffer, '\0');
454476
strbuf_add(&buffer, oid->hash, the_hash_algo->rawsz);
455477

456478
#if DEBUG_CACHE_TREE

git.c

Lines changed: 92 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
#include "builtin.h"
2+
#include "gvfs.h"
23
#include "config.h"
34
#include "exec-cmd.h"
45
#include "help.h"
56
#include "run-command.h"
67
#include "alias.h"
78
#include "shallow.h"
9+
#include "dir.h"
10+
#include "hook.h"
811

912
#define RUN_SETUP (1<<0)
1013
#define RUN_SETUP_GENTLY (1<<1)
@@ -17,6 +20,7 @@
1720
#define SUPPORT_SUPER_PREFIX (1<<4)
1821
#define DELAY_PAGER_CONFIG (1<<5)
1922
#define NO_PARSEOPT (1<<6) /* parse-options is not used */
23+
#define BLOCK_ON_GVFS_REPO (1<<7) /* command not allowed in GVFS repos */
2024

2125
struct cmd_struct {
2226
const char *cmd;
@@ -417,6 +421,68 @@ static int handle_alias(int *argcp, const char ***argv)
417421
return ret;
418422
}
419423

424+
/* Runs pre/post-command hook */
425+
static struct strvec sargv = STRVEC_INIT;
426+
static int run_post_hook = 0;
427+
static int exit_code = -1;
428+
429+
static int run_pre_command_hook(const char **argv)
430+
{
431+
char *lock;
432+
int ret = 0;
433+
struct run_hooks_opt opt = RUN_HOOKS_OPT_INIT;
434+
435+
/*
436+
* Ensure the global pre/post command hook is only called for
437+
* the outer command and not when git is called recursively
438+
* or spawns multiple commands (like with the alias command)
439+
*/
440+
lock = getenv("COMMAND_HOOK_LOCK");
441+
if (lock && !strcmp(lock, "true"))
442+
return 0;
443+
setenv("COMMAND_HOOK_LOCK", "true", 1);
444+
445+
/* call the hook proc */
446+
strvec_pushv(&sargv, argv);
447+
strvec_pushf(&sargv, "--git-pid=%"PRIuMAX, (uintmax_t)getpid());
448+
strvec_pushv(&opt.args, sargv.v);
449+
ret = run_hooks_opt("pre-command", &opt);
450+
451+
if (!ret)
452+
run_post_hook = 1;
453+
return ret;
454+
}
455+
456+
static int run_post_command_hook(void)
457+
{
458+
char *lock;
459+
int ret = 0;
460+
struct run_hooks_opt opt = RUN_HOOKS_OPT_INIT;
461+
462+
/*
463+
* Only run post_command if pre_command succeeded in this process
464+
*/
465+
if (!run_post_hook)
466+
return 0;
467+
lock = getenv("COMMAND_HOOK_LOCK");
468+
if (!lock || strcmp(lock, "true"))
469+
return 0;
470+
471+
strvec_pushv(&opt.args, sargv.v);
472+
strvec_pushf(&opt.args, "--exit_code=%u", exit_code);
473+
ret = run_hooks_opt("post-command", &opt);
474+
475+
run_post_hook = 0;
476+
strvec_clear(&sargv);
477+
setenv("COMMAND_HOOK_LOCK", "false", 1);
478+
return ret;
479+
}
480+
481+
static void post_command_hook_atexit(void)
482+
{
483+
run_post_command_hook();
484+
}
485+
420486
static int run_builtin(struct cmd_struct *p, int argc, const char **argv)
421487
{
422488
int status, help;
@@ -457,18 +523,26 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv)
457523
if (!help && p->option & NEED_WORK_TREE)
458524
setup_work_tree();
459525

526+
if (!help && p->option & BLOCK_ON_GVFS_REPO && gvfs_config_is_set(GVFS_BLOCK_COMMANDS))
527+
die("'git %s' is not supported on a GVFS repo", p->cmd);
528+
529+
if (run_pre_command_hook(argv))
530+
die("pre-command hook aborted command");
531+
460532
trace_argv_printf(argv, "trace: built-in: git");
461533
trace2_cmd_name(p->cmd);
462534
trace2_cmd_list_config();
463535
trace2_cmd_list_env_vars();
464536

465537
validate_cache_entries(the_repository->index);
466-
status = p->fn(argc, argv, prefix);
538+
exit_code = status = p->fn(argc, argv, prefix);
467539
validate_cache_entries(the_repository->index);
468540

469541
if (status)
470542
return status;
471543

544+
run_post_command_hook();
545+
472546
/* Somebody closed stdout? */
473547
if (fstat(fileno(stdout), &st))
474548
return 0;
@@ -536,7 +610,7 @@ static struct cmd_struct commands[] = {
536610
{ "for-each-ref", cmd_for_each_ref, RUN_SETUP },
537611
{ "for-each-repo", cmd_for_each_repo, RUN_SETUP_GENTLY },
538612
{ "format-patch", cmd_format_patch, RUN_SETUP },
539-
{ "fsck", cmd_fsck, RUN_SETUP },
613+
{ "fsck", cmd_fsck, RUN_SETUP | BLOCK_ON_GVFS_REPO},
540614
{ "fsck-objects", cmd_fsck, RUN_SETUP },
541615
{ "fsmonitor--daemon", cmd_fsmonitor__daemon, SUPPORT_SUPER_PREFIX | RUN_SETUP },
542616
{ "gc", cmd_gc, RUN_SETUP },
@@ -577,7 +651,7 @@ static struct cmd_struct commands[] = {
577651
{ "pack-refs", cmd_pack_refs, RUN_SETUP },
578652
{ "patch-id", cmd_patch_id, RUN_SETUP_GENTLY | NO_PARSEOPT },
579653
{ "pickaxe", cmd_blame, RUN_SETUP },
580-
{ "prune", cmd_prune, RUN_SETUP },
654+
{ "prune", cmd_prune, RUN_SETUP | BLOCK_ON_GVFS_REPO},
581655
{ "prune-packed", cmd_prune_packed, RUN_SETUP },
582656
{ "pull", cmd_pull, RUN_SETUP | NEED_WORK_TREE },
583657
{ "push", cmd_push, RUN_SETUP },
@@ -589,7 +663,7 @@ static struct cmd_struct commands[] = {
589663
{ "remote", cmd_remote, RUN_SETUP },
590664
{ "remote-ext", cmd_remote_ext, NO_PARSEOPT },
591665
{ "remote-fd", cmd_remote_fd, NO_PARSEOPT },
592-
{ "repack", cmd_repack, RUN_SETUP },
666+
{ "repack", cmd_repack, RUN_SETUP | BLOCK_ON_GVFS_REPO },
593667
{ "replace", cmd_replace, RUN_SETUP },
594668
{ "rerere", cmd_rerere, RUN_SETUP },
595669
{ "reset", cmd_reset, RUN_SETUP },
@@ -609,7 +683,7 @@ static struct cmd_struct commands[] = {
609683
{ "stash", cmd_stash, RUN_SETUP | NEED_WORK_TREE },
610684
{ "status", cmd_status, RUN_SETUP | NEED_WORK_TREE },
611685
{ "stripspace", cmd_stripspace },
612-
{ "submodule--helper", cmd_submodule__helper, RUN_SETUP | SUPPORT_SUPER_PREFIX | NO_PARSEOPT },
686+
{ "submodule--helper", cmd_submodule__helper, RUN_SETUP | SUPPORT_SUPER_PREFIX | NO_PARSEOPT | BLOCK_ON_GVFS_REPO },
613687
{ "switch", cmd_switch, RUN_SETUP | NEED_WORK_TREE },
614688
{ "symbolic-ref", cmd_symbolic_ref, RUN_SETUP },
615689
{ "tag", cmd_tag, RUN_SETUP | DELAY_PAGER_CONFIG },
@@ -627,7 +701,7 @@ static struct cmd_struct commands[] = {
627701
{ "verify-tag", cmd_verify_tag, RUN_SETUP },
628702
{ "version", cmd_version },
629703
{ "whatchanged", cmd_whatchanged, RUN_SETUP },
630-
{ "worktree", cmd_worktree, RUN_SETUP | NO_PARSEOPT },
704+
{ "worktree", cmd_worktree, RUN_SETUP | NO_PARSEOPT | BLOCK_ON_GVFS_REPO },
631705
{ "write-tree", cmd_write_tree, RUN_SETUP },
632706
};
633707

@@ -748,13 +822,16 @@ static void execv_dashed_external(const char **argv)
748822
*/
749823
trace_argv_printf(cmd.args.v, "trace: exec:");
750824

825+
if (run_pre_command_hook(cmd.args.v))
826+
die("pre-command hook aborted command");
827+
751828
/*
752829
* If we fail because the command is not found, it is
753830
* OK to return. Otherwise, we just pass along the status code,
754831
* or our usual generic code if we were not even able to exec
755832
* the program.
756833
*/
757-
status = run_command(&cmd);
834+
exit_code = status = run_command(&cmd);
758835

759836
/*
760837
* If the child process ran and we are now going to exit, emit a
@@ -765,6 +842,8 @@ static void execv_dashed_external(const char **argv)
765842
exit(status);
766843
else if (errno != ENOENT)
767844
exit(128);
845+
846+
run_post_command_hook();
768847
}
769848

770849
static int run_argv(int *argcp, const char ***argv)
@@ -872,6 +951,7 @@ int cmd_main(int argc, const char **argv)
872951
}
873952

874953
trace_command_performance(argv);
954+
atexit(post_command_hook_atexit);
875955

876956
/*
877957
* "git-xxxx" is the same as "git xxxx", but we obviously:
@@ -901,10 +981,14 @@ int cmd_main(int argc, const char **argv)
901981
} else {
902982
/* The user didn't specify a command; give them help */
903983
commit_pager_choice();
984+
if (run_pre_command_hook(argv))
985+
die("pre-command hook aborted command");
904986
printf(_("usage: %s\n\n"), git_usage_string);
905987
list_common_cmds_help();
906988
printf("\n%s\n", _(git_more_info_string));
907-
exit(1);
989+
exit_code = 1;
990+
run_post_command_hook();
991+
exit(exit_code);
908992
}
909993
cmd = argv[0];
910994

0 commit comments

Comments
 (0)