Skip to content

Commit 2d2ba50

Browse files
committed
Merge advanced VFS-specific features
Most of these were done in private before microsoft/git. However, the following pull requests modified the core feature: #85 #89 #91 #98 #243 #263 Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
2 parents 79692ca + 180746b commit 2d2ba50

18 files changed

+476
-18
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+
```

apply.c

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

3391+
/*
3392+
* Do not checkout the entry if the skipworktree bit is set
3393+
*
3394+
* Both callers of this method (check_preimage and load_current)
3395+
* check for the existance of the file before calling this
3396+
* method so we know that the file doesn't exist at this point
3397+
* and we don't need to perform that check again here.
3398+
* We just need to check the skip-worktree and return.
3399+
*
3400+
* This is to prevent git from creating a file in the
3401+
* working directory that has the skip-worktree bit on,
3402+
* then updating the index from the patch and not keeping
3403+
* the working directory version up to date with what it
3404+
* changed the index version to be.
3405+
*/
3406+
if (ce_skip_worktree(ce))
3407+
return 0;
3408+
33913409
costate.refresh_cache = 1;
33923410
costate.istate = istate;
33933411
if (checkout_entry(ce, &costate, NULL, NULL) ||

builtin/gc.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "environment.h"
1717
#include "hex.h"
1818
#include "repository.h"
19+
#include "gvfs.h"
1920
#include "config.h"
2021
#include "tempfile.h"
2122
#include "lockfile.h"
@@ -676,6 +677,9 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
676677
if (quiet)
677678
strvec_push(&repack, "-q");
678679

680+
if ((!opts.auto_flag || (opts.auto_flag && gc_auto_threshold > 0)) && gvfs_config_is_set(GVFS_BLOCK_COMMANDS))
681+
die(_("'git gc' is not supported on a GVFS repo"));
682+
679683
if (opts.auto_flag) {
680684
/*
681685
* 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_VARIABLE
77
#include "builtin.h"
8+
#include "gvfs.h"
89
#include "bulk-checkin.h"
910
#include "config.h"
1011
#include "environment.h"
@@ -1109,7 +1110,13 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
11091110
argc = parse_options_end(&ctx);
11101111

11111112
getline_fn = nul_term_line ? strbuf_getline_nul : strbuf_getline_lf;
1113+
if (mark_skip_worktree_only && gvfs_config_is_set(GVFS_BLOCK_COMMANDS))
1114+
die(_("modifying the skip worktree bit is not supported on a GVFS repo"));
1115+
11121116
if (preferred_index_format) {
1117+
if (preferred_index_format != 4 && gvfs_config_is_set(GVFS_BLOCK_COMMANDS))
1118+
die(_("changing the index version is not supported on a GVFS repo"));
1119+
11131120
if (preferred_index_format < 0) {
11141121
printf(_("%d\n"), the_index.version);
11151122
} else if (preferred_index_format < INDEX_FORMAT_LB ||
@@ -1155,6 +1162,9 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
11551162
end_odb_transaction();
11561163

11571164
if (split_index > 0) {
1165+
if (gvfs_config_is_set(GVFS_BLOCK_COMMANDS))
1166+
die(_("split index is not supported on a GVFS repo"));
1167+
11581168
if (git_config_get_split_index() == 0)
11591169
warning(_("core.splitIndex is set to false; "
11601170
"remove or change it, if you really want to "

builtin/worktree.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "builtin.h"
22
#include "abspath.h"
33
#include "advice.h"
4+
#include "gvfs.h"
45
#include "checkout.h"
56
#include "config.h"
67
#include "copy.h"
@@ -1402,6 +1403,13 @@ int cmd_worktree(int ac, const char **av, const char *prefix)
14021403

14031404
git_config(git_worktree_config, NULL);
14041405

1406+
/*
1407+
* git-worktree is special-cased to work in Scalar repositories
1408+
* even when they use the GVFS Protocol.
1409+
*/
1410+
if (core_gvfs & GVFS_USE_VIRTUAL_FILESYSTEM)
1411+
die("'git %s' is not supported on a GVFS repo", "worktree");
1412+
14051413
if (!prefix)
14061414
prefix = "";
14071415

cache-tree.c

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

430430
strbuf_grow(&buffer, entlen + 100);
431-
strbuf_addf(&buffer, "%o %.*s%c", mode, entlen, path + baselen, '\0');
431+
432+
switch (mode) {
433+
case 0100644:
434+
strbuf_add(&buffer, "100644 ", 7);
435+
break;
436+
case 0100664:
437+
strbuf_add(&buffer, "100664 ", 7);
438+
break;
439+
case 0100755:
440+
strbuf_add(&buffer, "100755 ", 7);
441+
break;
442+
case 0120000:
443+
strbuf_add(&buffer, "120000 ", 7);
444+
break;
445+
case 0160000:
446+
strbuf_add(&buffer, "160000 ", 7);
447+
break;
448+
default:
449+
strbuf_addf(&buffer, "%o ", mode);
450+
break;
451+
}
452+
strbuf_add(&buffer, path + baselen, entlen);
453+
strbuf_addch(&buffer, '\0');
432454
strbuf_add(&buffer, oid->hash, the_hash_algo->rawsz);
433455

434456
#if DEBUG_CACHE_TREE

git.c

Lines changed: 91 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "builtin.h"
2+
#include "gvfs.h"
23
#include "config.h"
34
#include "environment.h"
45
#include "exec-cmd.h"
@@ -15,6 +16,8 @@
1516
#include "shallow.h"
1617
#include "trace.h"
1718
#include "trace2.h"
19+
#include "dir.h"
20+
#include "hook.h"
1821

1922
#define RUN_SETUP (1<<0)
2023
#define RUN_SETUP_GENTLY (1<<1)
@@ -26,6 +29,7 @@
2629
#define NEED_WORK_TREE (1<<3)
2730
#define DELAY_PAGER_CONFIG (1<<4)
2831
#define NO_PARSEOPT (1<<5) /* parse-options is not used */
32+
#define BLOCK_ON_GVFS_REPO (1<<6) /* command not allowed in GVFS repos */
2933

3034
struct cmd_struct {
3135
const char *cmd;
@@ -427,6 +431,68 @@ static int handle_alias(int *argcp, const char ***argv)
427431
return ret;
428432
}
429433

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

531+
if (!help && p->option & BLOCK_ON_GVFS_REPO && gvfs_config_is_set(GVFS_BLOCK_COMMANDS))
532+
die("'git %s' is not supported on a GVFS repo", p->cmd);
533+
534+
if (run_pre_command_hook(argv))
535+
die("pre-command hook aborted command");
536+
465537
trace_argv_printf(argv, "trace: built-in: git");
466538
trace2_cmd_name(p->cmd);
467539

468540
validate_cache_entries(the_repository->index);
469-
status = p->fn(argc, argv, prefix);
541+
exit_code = status = p->fn(argc, argv, prefix);
470542
validate_cache_entries(the_repository->index);
471543

472544
if (status)
473545
return status;
474546

547+
run_post_command_hook();
548+
475549
/* Somebody closed stdout? */
476550
if (fstat(fileno(stdout), &st))
477551
return 0;
@@ -539,7 +613,7 @@ static struct cmd_struct commands[] = {
539613
{ "for-each-ref", cmd_for_each_ref, RUN_SETUP },
540614
{ "for-each-repo", cmd_for_each_repo, RUN_SETUP_GENTLY },
541615
{ "format-patch", cmd_format_patch, RUN_SETUP },
542-
{ "fsck", cmd_fsck, RUN_SETUP },
616+
{ "fsck", cmd_fsck, RUN_SETUP | BLOCK_ON_GVFS_REPO},
543617
{ "fsck-objects", cmd_fsck, RUN_SETUP },
544618
{ "fsmonitor--daemon", cmd_fsmonitor__daemon, RUN_SETUP },
545619
{ "gc", cmd_gc, RUN_SETUP },
@@ -580,7 +654,7 @@ static struct cmd_struct commands[] = {
580654
{ "pack-refs", cmd_pack_refs, RUN_SETUP },
581655
{ "patch-id", cmd_patch_id, RUN_SETUP_GENTLY | NO_PARSEOPT },
582656
{ "pickaxe", cmd_blame, RUN_SETUP },
583-
{ "prune", cmd_prune, RUN_SETUP },
657+
{ "prune", cmd_prune, RUN_SETUP | BLOCK_ON_GVFS_REPO},
584658
{ "prune-packed", cmd_prune_packed, RUN_SETUP },
585659
{ "pull", cmd_pull, RUN_SETUP | NEED_WORK_TREE },
586660
{ "push", cmd_push, RUN_SETUP },
@@ -592,7 +666,7 @@ static struct cmd_struct commands[] = {
592666
{ "remote", cmd_remote, RUN_SETUP },
593667
{ "remote-ext", cmd_remote_ext, NO_PARSEOPT },
594668
{ "remote-fd", cmd_remote_fd, NO_PARSEOPT },
595-
{ "repack", cmd_repack, RUN_SETUP },
669+
{ "repack", cmd_repack, RUN_SETUP | BLOCK_ON_GVFS_REPO },
596670
{ "replace", cmd_replace, RUN_SETUP },
597671
{ "replay", cmd_replay, RUN_SETUP },
598672
{ "rerere", cmd_rerere, RUN_SETUP },
@@ -613,7 +687,7 @@ static struct cmd_struct commands[] = {
613687
{ "stash", cmd_stash, RUN_SETUP | NEED_WORK_TREE },
614688
{ "status", cmd_status, RUN_SETUP | NEED_WORK_TREE },
615689
{ "stripspace", cmd_stripspace },
616-
{ "submodule--helper", cmd_submodule__helper, RUN_SETUP },
690+
{ "submodule--helper", cmd_submodule__helper, RUN_SETUP | BLOCK_ON_GVFS_REPO },
617691
{ "switch", cmd_switch, RUN_SETUP | NEED_WORK_TREE },
618692
{ "symbolic-ref", cmd_symbolic_ref, RUN_SETUP },
619693
{ "tag", cmd_tag, RUN_SETUP | DELAY_PAGER_CONFIG },
@@ -749,13 +823,16 @@ static void execv_dashed_external(const char **argv)
749823
*/
750824
trace_argv_printf(cmd.args.v, "trace: exec:");
751825

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

760837
/*
761838
* If the child process ran and we are now going to exit, emit a
@@ -766,6 +843,8 @@ static void execv_dashed_external(const char **argv)
766843
exit(status);
767844
else if (errno != ENOENT)
768845
exit(128);
846+
847+
run_post_command_hook();
769848
}
770849

771850
static int run_argv(int *argcp, const char ***argv)
@@ -873,6 +952,7 @@ int cmd_main(int argc, const char **argv)
873952
}
874953

875954
trace_command_performance(argv);
955+
atexit(post_command_hook_atexit);
876956

877957
/*
878958
* "git-xxxx" is the same as "git xxxx", but we obviously:
@@ -898,10 +978,14 @@ int cmd_main(int argc, const char **argv)
898978
if (!argc) {
899979
/* The user didn't specify a command; give them help */
900980
commit_pager_choice();
981+
if (run_pre_command_hook(argv))
982+
die("pre-command hook aborted command");
901983
printf(_("usage: %s\n\n"), git_usage_string);
902984
list_common_cmds_help();
903985
printf("\n%s\n", _(git_more_info_string));
904-
exit(1);
986+
exit_code = 1;
987+
run_post_command_hook();
988+
exit(exit_code);
905989
}
906990

907991
if (!strcmp("--version", argv[0]) || !strcmp("-v", argv[0]))

0 commit comments

Comments
 (0)