Skip to content

Commit e222b1f

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: git#85 git#89 git#91 git#98 git#243 git#263 Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
2 parents 05689ee + 8289b81 commit e222b1f

18 files changed

+478
-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
@@ -3369,6 +3369,24 @@ static int checkout_target(struct index_state *istate,
33693369
{
33703370
struct checkout costate = CHECKOUT_INIT;
33713371

3372+
/*
3373+
* Do not checkout the entry if the skipworktree bit is set
3374+
*
3375+
* Both callers of this method (check_preimage and load_current)
3376+
* check for the existance of the file before calling this
3377+
* method so we know that the file doesn't exist at this point
3378+
* and we don't need to perform that check again here.
3379+
* We just need to check the skip-worktree and return.
3380+
*
3381+
* This is to prevent git from creating a file in the
3382+
* working directory that has the skip-worktree bit on,
3383+
* then updating the index from the patch and not keeping
3384+
* the working directory version up to date with what it
3385+
* changed the index version to be.
3386+
*/
3387+
if (ce_skip_worktree(ce))
3388+
return 0;
3389+
33723390
costate.refresh_cache = 1;
33733391
costate.istate = istate;
33743392
if (checkout_entry(ce, &costate, NULL, NULL) ||

builtin/gc.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "date.h"
1616
#include "environment.h"
1717
#include "hex.h"
18+
#include "gvfs.h"
1819
#include "config.h"
1920
#include "tempfile.h"
2021
#include "lockfile.h"
@@ -736,6 +737,9 @@ struct repository *repo UNUSED)
736737
if (quiet)
737738
strvec_push(&repack, "-q");
738739

740+
if ((!opts.auto_flag || (opts.auto_flag && cfg.gc_auto_threshold > 0)) && gvfs_config_is_set(GVFS_BLOCK_COMMANDS))
741+
die(_("'git gc' is not supported on a GVFS repo"));
742+
739743
if (opts.auto_flag) {
740744
if (cfg.detach_auto && opts.detach < 0)
741745
opts.detach = 1;

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_REPOSITORY_VARIABLE
77
#include "builtin.h"
8+
#include "gvfs.h"
89
#include "bulk-checkin.h"
910
#include "config.h"
1011
#include "environment.h"
@@ -1112,7 +1113,13 @@ int cmd_update_index(int argc,
11121113
argc = parse_options_end(&ctx);
11131114

11141115
getline_fn = nul_term_line ? strbuf_getline_nul : strbuf_getline_lf;
1116+
if (mark_skip_worktree_only && gvfs_config_is_set(GVFS_BLOCK_COMMANDS))
1117+
die(_("modifying the skip worktree bit is not supported on a GVFS repo"));
1118+
11151119
if (preferred_index_format) {
1120+
if (preferred_index_format != 4 && gvfs_config_is_set(GVFS_BLOCK_COMMANDS))
1121+
die(_("changing the index version is not supported on a GVFS repo"));
1122+
11161123
if (preferred_index_format < 0) {
11171124
printf(_("%d\n"), the_repository->index->version);
11181125
} else if (preferred_index_format < INDEX_FORMAT_LB ||
@@ -1158,6 +1165,9 @@ int cmd_update_index(int argc,
11581165
end_odb_transaction();
11591166

11601167
if (split_index > 0) {
1168+
if (gvfs_config_is_set(GVFS_BLOCK_COMMANDS))
1169+
die(_("split index is not supported on a GVFS repo"));
1170+
11611171
if (repo_config_get_split_index(the_repository) == 0)
11621172
warning(_("core.splitIndex is set to false; "
11631173
"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
@@ -2,6 +2,7 @@
22
#include "builtin.h"
33
#include "abspath.h"
44
#include "advice.h"
5+
#include "gvfs.h"
56
#include "checkout.h"
67
#include "config.h"
78
#include "copy.h"
@@ -1412,6 +1413,13 @@ int cmd_worktree(int ac,
14121413

14131414
git_config(git_worktree_config, NULL);
14141415

1416+
/*
1417+
* git-worktree is special-cased to work in Scalar repositories
1418+
* even when they use the GVFS Protocol.
1419+
*/
1420+
if (core_gvfs & GVFS_USE_VIRTUAL_FILESYSTEM)
1421+
die("'git %s' is not supported on a GVFS repo", "worktree");
1422+
14151423
if (!prefix)
14161424
prefix = "";
14171425

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;
@@ -441,6 +445,68 @@ static int handle_alias(int *argcp, const char ***argv)
441445
return ret;
442446
}
443447

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

545+
if (!help && p->option & BLOCK_ON_GVFS_REPO && gvfs_config_is_set(GVFS_BLOCK_COMMANDS))
546+
die("'git %s' is not supported on a GVFS repo", p->cmd);
547+
548+
if (run_pre_command_hook(the_repository, argv))
549+
die("pre-command hook aborted command");
550+
479551
trace_argv_printf(argv, "trace: built-in: git");
480552
trace2_cmd_name(p->cmd);
481553

482554
validate_cache_entries(repo->index);
483-
status = p->fn(argc, argv, prefix, (p->option & RUN_SETUP)? repo : NULL);
555+
exit_code = status = p->fn(argc, argv, prefix, (p->option & RUN_SETUP)? repo : NULL);
484556
validate_cache_entries(repo->index);
485557

486558
if (status)
487559
return status;
488560

561+
run_post_command_hook(the_repository);
562+
489563
/* Somebody closed stdout? */
490564
if (fstat(fileno(stdout), &st))
491565
return 0;
@@ -554,7 +628,7 @@ static struct cmd_struct commands[] = {
554628
{ "for-each-ref", cmd_for_each_ref, RUN_SETUP },
555629
{ "for-each-repo", cmd_for_each_repo, RUN_SETUP_GENTLY },
556630
{ "format-patch", cmd_format_patch, RUN_SETUP },
557-
{ "fsck", cmd_fsck, RUN_SETUP },
631+
{ "fsck", cmd_fsck, RUN_SETUP | BLOCK_ON_GVFS_REPO},
558632
{ "fsck-objects", cmd_fsck, RUN_SETUP },
559633
{ "fsmonitor--daemon", cmd_fsmonitor__daemon, RUN_SETUP },
560634
{ "gc", cmd_gc, RUN_SETUP },
@@ -595,7 +669,7 @@ static struct cmd_struct commands[] = {
595669
{ "pack-refs", cmd_pack_refs, RUN_SETUP },
596670
{ "patch-id", cmd_patch_id, RUN_SETUP_GENTLY | NO_PARSEOPT },
597671
{ "pickaxe", cmd_blame, RUN_SETUP },
598-
{ "prune", cmd_prune, RUN_SETUP },
672+
{ "prune", cmd_prune, RUN_SETUP | BLOCK_ON_GVFS_REPO},
599673
{ "prune-packed", cmd_prune_packed, RUN_SETUP },
600674
{ "pull", cmd_pull, RUN_SETUP | NEED_WORK_TREE },
601675
{ "push", cmd_push, RUN_SETUP },
@@ -608,7 +682,7 @@ static struct cmd_struct commands[] = {
608682
{ "remote", cmd_remote, RUN_SETUP },
609683
{ "remote-ext", cmd_remote_ext, NO_PARSEOPT },
610684
{ "remote-fd", cmd_remote_fd, NO_PARSEOPT },
611-
{ "repack", cmd_repack, RUN_SETUP },
685+
{ "repack", cmd_repack, RUN_SETUP | BLOCK_ON_GVFS_REPO },
612686
{ "replace", cmd_replace, RUN_SETUP },
613687
{ "replay", cmd_replay, RUN_SETUP },
614688
{ "rerere", cmd_rerere, RUN_SETUP },
@@ -629,7 +703,7 @@ static struct cmd_struct commands[] = {
629703
{ "stash", cmd_stash, RUN_SETUP | NEED_WORK_TREE },
630704
{ "status", cmd_status, RUN_SETUP | NEED_WORK_TREE },
631705
{ "stripspace", cmd_stripspace },
632-
{ "submodule--helper", cmd_submodule__helper, RUN_SETUP },
706+
{ "submodule--helper", cmd_submodule__helper, RUN_SETUP | BLOCK_ON_GVFS_REPO },
633707
{ "survey", cmd_survey, RUN_SETUP },
634708
{ "switch", cmd_switch, RUN_SETUP | NEED_WORK_TREE },
635709
{ "symbolic-ref", cmd_symbolic_ref, RUN_SETUP },
@@ -782,13 +856,16 @@ static void execv_dashed_external(const char **argv)
782856
*/
783857
trace_argv_printf(cmd.args.v, "trace: exec:");
784858

859+
if (run_pre_command_hook(the_repository, cmd.args.v))
860+
die("pre-command hook aborted command");
861+
785862
/*
786863
* If we fail because the command is not found, it is
787864
* OK to return. Otherwise, we just pass along the status code,
788865
* or our usual generic code if we were not even able to exec
789866
* the program.
790867
*/
791-
status = run_command(&cmd);
868+
exit_code = status = run_command(&cmd);
792869

793870
/*
794871
* If the child process ran and we are now going to exit, emit a
@@ -799,6 +876,8 @@ static void execv_dashed_external(const char **argv)
799876
exit(status);
800877
else if (errno != ENOENT)
801878
exit(128);
879+
880+
run_post_command_hook(the_repository);
802881
}
803882

804883
static int run_argv(int *argcp, const char ***argv)
@@ -906,6 +985,7 @@ int cmd_main(int argc, const char **argv)
906985
}
907986

908987
trace_command_performance(argv);
988+
atexit(post_command_hook_atexit);
909989

910990
/*
911991
* "git-xxxx" is the same as "git xxxx", but we obviously:
@@ -931,10 +1011,14 @@ int cmd_main(int argc, const char **argv)
9311011
if (!argc) {
9321012
/* The user didn't specify a command; give them help */
9331013
commit_pager_choice();
1014+
if (run_pre_command_hook(the_repository, argv))
1015+
die("pre-command hook aborted command");
9341016
printf(_("usage: %s\n\n"), git_usage_string);
9351017
list_common_cmds_help();
9361018
printf("\n%s\n", _(git_more_info_string));
937-
exit(1);
1019+
exit_code = 1;
1020+
run_post_command_hook(the_repository);
1021+
exit(exit_code);
9381022
}
9391023

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

0 commit comments

Comments
 (0)