Skip to content

Commit 654b886

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: #85 #89 #91 #98 #243 #263 Signed-off-by: Derrick Stolee <[email protected]>
2 parents aee3134 + 632cebb commit 654b886

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
@@ -3414,6 +3414,24 @@ static int checkout_target(struct index_state *istate,
34143414
{
34153415
struct checkout costate = CHECKOUT_INIT;
34163416

3417+
/*
3418+
* Do not checkout the entry if the skipworktree bit is set
3419+
*
3420+
* Both callers of this method (check_preimage and load_current)
3421+
* check for the existance of the file before calling this
3422+
* method so we know that the file doesn't exist at this point
3423+
* and we don't need to perform that check again here.
3424+
* We just need to check the skip-worktree and return.
3425+
*
3426+
* This is to prevent git from creating a file in the
3427+
* working directory that has the skip-worktree bit on,
3428+
* then updating the index from the patch and not keeping
3429+
* the working directory version up to date with what it
3430+
* changed the index version to be.
3431+
*/
3432+
if (ce_skip_worktree(ce))
3433+
return 0;
3434+
34173435
costate.refresh_cache = 1;
34183436
costate.istate = istate;
34193437
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

77
#include "builtin.h"
8+
#include "gvfs.h"
89
#include "bulk-checkin.h"
910
#include "config.h"
1011
#include "environment.h"
@@ -1110,7 +1111,13 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
11101111
argc = parse_options_end(&ctx);
11111112

11121113
getline_fn = nul_term_line ? strbuf_getline_nul : strbuf_getline_lf;
1114+
if (mark_skip_worktree_only && gvfs_config_is_set(GVFS_BLOCK_COMMANDS))
1115+
die(_("modifying the skip worktree bit is not supported on a GVFS repo"));
1116+
11131117
if (preferred_index_format) {
1118+
if (preferred_index_format != 4 && gvfs_config_is_set(GVFS_BLOCK_COMMANDS))
1119+
die(_("changing the index version is not supported on a GVFS repo"));
1120+
11141121
if (preferred_index_format < 0) {
11151122
printf(_("%d\n"), the_repository->index->version);
11161123
} else if (preferred_index_format < INDEX_FORMAT_LB ||
@@ -1156,6 +1163,9 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
11561163
end_odb_transaction();
11571164

11581165
if (split_index > 0) {
1166+
if (gvfs_config_is_set(GVFS_BLOCK_COMMANDS))
1167+
die(_("split index is not supported on a GVFS repo"));
1168+
11591169
if (git_config_get_split_index() == 0)
11601170
warning(_("core.splitIndex is set to false; "
11611171
"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"
@@ -1407,6 +1408,13 @@ int cmd_worktree(int ac, const char **av, const char *prefix)
14071408

14081409
git_config(git_worktree_config, NULL);
14091410

1411+
/*
1412+
* git-worktree is special-cased to work in Scalar repositories
1413+
* even when they use the GVFS Protocol.
1414+
*/
1415+
if (core_gvfs & GVFS_USE_VIRTUAL_FILESYSTEM)
1416+
die("'git %s' is not supported on a GVFS repo", "worktree");
1417+
14101418
if (!prefix)
14111419
prefix = "";
14121420

cache-tree.c

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

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

436458
#if DEBUG_CACHE_TREE

git.c

Lines changed: 91 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#define USE_THE_REPOSITORY_VARIABLE
22

33
#include "builtin.h"
4+
#include "gvfs.h"
45
#include "config.h"
56
#include "environment.h"
67
#include "exec-cmd.h"
@@ -17,6 +18,8 @@
1718
#include "shallow.h"
1819
#include "trace.h"
1920
#include "trace2.h"
21+
#include "dir.h"
22+
#include "hook.h"
2023

2124
#define RUN_SETUP (1<<0)
2225
#define RUN_SETUP_GENTLY (1<<1)
@@ -28,6 +31,7 @@
2831
#define NEED_WORK_TREE (1<<3)
2932
#define DELAY_PAGER_CONFIG (1<<4)
3033
#define NO_PARSEOPT (1<<5) /* parse-options is not used */
34+
#define BLOCK_ON_GVFS_REPO (1<<6) /* command not allowed in GVFS repos */
3135

3236
struct cmd_struct {
3337
const char *cmd;
@@ -434,6 +438,68 @@ static int handle_alias(int *argcp, const char ***argv)
434438
return ret;
435439
}
436440

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

538+
if (!help && p->option & BLOCK_ON_GVFS_REPO && gvfs_config_is_set(GVFS_BLOCK_COMMANDS))
539+
die("'git %s' is not supported on a GVFS repo", p->cmd);
540+
541+
if (run_pre_command_hook(argv))
542+
die("pre-command hook aborted command");
543+
472544
trace_argv_printf(argv, "trace: built-in: git");
473545
trace2_cmd_name(p->cmd);
474546

475547
validate_cache_entries(the_repository->index);
476-
status = p->fn(argc, argv, prefix);
548+
exit_code = status = p->fn(argc, argv, prefix);
477549
validate_cache_entries(the_repository->index);
478550

479551
if (status)
480552
return status;
481553

554+
run_post_command_hook();
555+
482556
/* Somebody closed stdout? */
483557
if (fstat(fileno(stdout), &st))
484558
return 0;
@@ -546,7 +620,7 @@ static struct cmd_struct commands[] = {
546620
{ "for-each-ref", cmd_for_each_ref, RUN_SETUP },
547621
{ "for-each-repo", cmd_for_each_repo, RUN_SETUP_GENTLY },
548622
{ "format-patch", cmd_format_patch, RUN_SETUP },
549-
{ "fsck", cmd_fsck, RUN_SETUP },
623+
{ "fsck", cmd_fsck, RUN_SETUP | BLOCK_ON_GVFS_REPO},
550624
{ "fsck-objects", cmd_fsck, RUN_SETUP },
551625
{ "fsmonitor--daemon", cmd_fsmonitor__daemon, RUN_SETUP },
552626
{ "gc", cmd_gc, RUN_SETUP },
@@ -587,7 +661,7 @@ static struct cmd_struct commands[] = {
587661
{ "pack-refs", cmd_pack_refs, RUN_SETUP },
588662
{ "patch-id", cmd_patch_id, RUN_SETUP_GENTLY | NO_PARSEOPT },
589663
{ "pickaxe", cmd_blame, RUN_SETUP },
590-
{ "prune", cmd_prune, RUN_SETUP },
664+
{ "prune", cmd_prune, RUN_SETUP | BLOCK_ON_GVFS_REPO},
591665
{ "prune-packed", cmd_prune_packed, RUN_SETUP },
592666
{ "pull", cmd_pull, RUN_SETUP | NEED_WORK_TREE },
593667
{ "push", cmd_push, RUN_SETUP },
@@ -600,7 +674,7 @@ static struct cmd_struct commands[] = {
600674
{ "remote", cmd_remote, RUN_SETUP },
601675
{ "remote-ext", cmd_remote_ext, NO_PARSEOPT },
602676
{ "remote-fd", cmd_remote_fd, NO_PARSEOPT },
603-
{ "repack", cmd_repack, RUN_SETUP },
677+
{ "repack", cmd_repack, RUN_SETUP | BLOCK_ON_GVFS_REPO },
604678
{ "replace", cmd_replace, RUN_SETUP },
605679
{ "replay", cmd_replay, RUN_SETUP },
606680
{ "rerere", cmd_rerere, RUN_SETUP },
@@ -621,7 +695,7 @@ static struct cmd_struct commands[] = {
621695
{ "stash", cmd_stash, RUN_SETUP | NEED_WORK_TREE },
622696
{ "status", cmd_status, RUN_SETUP | NEED_WORK_TREE },
623697
{ "stripspace", cmd_stripspace },
624-
{ "submodule--helper", cmd_submodule__helper, RUN_SETUP },
698+
{ "submodule--helper", cmd_submodule__helper, RUN_SETUP | BLOCK_ON_GVFS_REPO },
625699
{ "survey", cmd_survey, RUN_SETUP },
626700
{ "switch", cmd_switch, RUN_SETUP | NEED_WORK_TREE },
627701
{ "symbolic-ref", cmd_symbolic_ref, RUN_SETUP },
@@ -758,13 +832,16 @@ static void execv_dashed_external(const char **argv)
758832
*/
759833
trace_argv_printf(cmd.args.v, "trace: exec:");
760834

835+
if (run_pre_command_hook(cmd.args.v))
836+
die("pre-command hook aborted command");
837+
761838
/*
762839
* If we fail because the command is not found, it is
763840
* OK to return. Otherwise, we just pass along the status code,
764841
* or our usual generic code if we were not even able to exec
765842
* the program.
766843
*/
767-
status = run_command(&cmd);
844+
exit_code = status = run_command(&cmd);
768845

769846
/*
770847
* If the child process ran and we are now going to exit, emit a
@@ -775,6 +852,8 @@ static void execv_dashed_external(const char **argv)
775852
exit(status);
776853
else if (errno != ENOENT)
777854
exit(128);
855+
856+
run_post_command_hook();
778857
}
779858

780859
static int run_argv(int *argcp, const char ***argv)
@@ -882,6 +961,7 @@ int cmd_main(int argc, const char **argv)
882961
}
883962

884963
trace_command_performance(argv);
964+
atexit(post_command_hook_atexit);
885965

886966
/*
887967
* "git-xxxx" is the same as "git xxxx", but we obviously:
@@ -907,10 +987,14 @@ int cmd_main(int argc, const char **argv)
907987
if (!argc) {
908988
/* The user didn't specify a command; give them help */
909989
commit_pager_choice();
990+
if (run_pre_command_hook(argv))
991+
die("pre-command hook aborted command");
910992
printf(_("usage: %s\n\n"), git_usage_string);
911993
list_common_cmds_help();
912994
printf("\n%s\n", _(git_more_info_string));
913-
exit(1);
995+
exit_code = 1;
996+
run_post_command_hook();
997+
exit(exit_code);
914998
}
915999

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

0 commit comments

Comments
 (0)