Skip to content

Commit fbc2654

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 <[email protected]>
2 parents 6259631 + 4bde6ad commit fbc2654

19 files changed

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

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

builtin/gc.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "date.h"
1919
#include "environment.h"
2020
#include "hex.h"
21+
#include "gvfs.h"
2122
#include "config.h"
2223
#include "tempfile.h"
2324
#include "lockfile.h"
@@ -749,6 +750,9 @@ struct repository *repo UNUSED)
749750
if (quiet)
750751
strvec_push(&repack, "-q");
751752

753+
if ((!opts.auto_flag || (opts.auto_flag && cfg.gc_auto_threshold > 0)) && gvfs_config_is_set(GVFS_BLOCK_COMMANDS))
754+
die(_("'git gc' is not supported on a GVFS repo"));
755+
752756
if (opts.auto_flag) {
753757
if (cfg.detach_auto && opts.detach < 0)
754758
opts.detach = 1;

builtin/update-index.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#define DISABLE_SIGN_COMPARE_WARNINGS
99

1010
#include "builtin.h"
11+
#include "gvfs.h"
1112
#include "bulk-checkin.h"
1213
#include "config.h"
1314
#include "environment.h"
@@ -1115,7 +1116,13 @@ int cmd_update_index(int argc,
11151116
argc = parse_options_end(&ctx);
11161117

11171118
getline_fn = nul_term_line ? strbuf_getline_nul : strbuf_getline_lf;
1119+
if (mark_skip_worktree_only && gvfs_config_is_set(GVFS_BLOCK_COMMANDS))
1120+
die(_("modifying the skip worktree bit is not supported on a GVFS repo"));
1121+
11181122
if (preferred_index_format) {
1123+
if (preferred_index_format != 4 && gvfs_config_is_set(GVFS_BLOCK_COMMANDS))
1124+
die(_("changing the index version is not supported on a GVFS repo"));
1125+
11191126
if (preferred_index_format < 0) {
11201127
printf(_("%d\n"), the_repository->index->version);
11211128
} else if (preferred_index_format < INDEX_FORMAT_LB ||
@@ -1161,6 +1168,9 @@ int cmd_update_index(int argc,
11611168
end_odb_transaction();
11621169

11631170
if (split_index > 0) {
1171+
if (gvfs_config_is_set(GVFS_BLOCK_COMMANDS))
1172+
die(_("split index is not supported on a GVFS repo"));
1173+
11641174
if (repo_config_get_split_index(the_repository) == 0)
11651175
warning(_("core.splitIndex is set to false; "
11661176
"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
@@ -4,6 +4,7 @@
44
#include "builtin.h"
55
#include "abspath.h"
66
#include "advice.h"
7+
#include "gvfs.h"
78
#include "checkout.h"
89
#include "config.h"
910
#include "copy.h"
@@ -1429,6 +1430,13 @@ int cmd_worktree(int ac,
14291430

14301431
git_config(git_worktree_config, NULL);
14311432

1433+
/*
1434+
* git-worktree is special-cased to work in Scalar repositories
1435+
* even when they use the GVFS Protocol.
1436+
*/
1437+
if (core_gvfs & GVFS_USE_VIRTUAL_FILESYSTEM)
1438+
die("'git %s' is not supported on a GVFS repo", "worktree");
1439+
14321440
if (!prefix)
14331441
prefix = "";
14341442

cache-tree.c

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

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

438460
#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;
@@ -437,6 +441,68 @@ static int handle_alias(struct strvec *args)
437441
return ret;
438442
}
439443

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

542+
if (!help && p->option & BLOCK_ON_GVFS_REPO && gvfs_config_is_set(GVFS_BLOCK_COMMANDS))
543+
die("'git %s' is not supported on a GVFS repo", p->cmd);
544+
545+
if (run_pre_command_hook(the_repository, argv))
546+
die("pre-command hook aborted command");
547+
476548
trace_argv_printf(argv, "trace: built-in: git");
477549
trace2_cmd_name(p->cmd);
478550

479551
validate_cache_entries(repo->index);
480-
status = p->fn(argc, argv, prefix, no_repo ? NULL : repo);
552+
exit_code = status = p->fn(argc, argv, prefix, no_repo ? NULL : repo);
481553
validate_cache_entries(repo->index);
482554

483555
if (status)
484556
return status;
485557

558+
run_post_command_hook(the_repository);
559+
486560
/* Somebody closed stdout? */
487561
if (fstat(fileno(stdout), &st))
488562
return 0;
@@ -551,7 +625,7 @@ static struct cmd_struct commands[] = {
551625
{ "for-each-ref", cmd_for_each_ref, RUN_SETUP },
552626
{ "for-each-repo", cmd_for_each_repo, RUN_SETUP_GENTLY },
553627
{ "format-patch", cmd_format_patch, RUN_SETUP },
554-
{ "fsck", cmd_fsck, RUN_SETUP },
628+
{ "fsck", cmd_fsck, RUN_SETUP | BLOCK_ON_GVFS_REPO},
555629
{ "fsck-objects", cmd_fsck, RUN_SETUP },
556630
{ "fsmonitor--daemon", cmd_fsmonitor__daemon, RUN_SETUP },
557631
{ "gc", cmd_gc, RUN_SETUP },
@@ -592,7 +666,7 @@ static struct cmd_struct commands[] = {
592666
{ "pack-refs", cmd_pack_refs, RUN_SETUP },
593667
{ "patch-id", cmd_patch_id, RUN_SETUP_GENTLY | NO_PARSEOPT },
594668
{ "pickaxe", cmd_blame, RUN_SETUP },
595-
{ "prune", cmd_prune, RUN_SETUP },
669+
{ "prune", cmd_prune, RUN_SETUP | BLOCK_ON_GVFS_REPO},
596670
{ "prune-packed", cmd_prune_packed, RUN_SETUP },
597671
{ "pull", cmd_pull, RUN_SETUP | NEED_WORK_TREE },
598672
{ "push", cmd_push, RUN_SETUP },
@@ -605,7 +679,7 @@ static struct cmd_struct commands[] = {
605679
{ "remote", cmd_remote, RUN_SETUP },
606680
{ "remote-ext", cmd_remote_ext, NO_PARSEOPT },
607681
{ "remote-fd", cmd_remote_fd, NO_PARSEOPT },
608-
{ "repack", cmd_repack, RUN_SETUP },
682+
{ "repack", cmd_repack, RUN_SETUP | BLOCK_ON_GVFS_REPO },
609683
{ "replace", cmd_replace, RUN_SETUP },
610684
{ "replay", cmd_replay, RUN_SETUP },
611685
{ "rerere", cmd_rerere, RUN_SETUP },
@@ -626,7 +700,7 @@ static struct cmd_struct commands[] = {
626700
{ "stash", cmd_stash, RUN_SETUP | NEED_WORK_TREE },
627701
{ "status", cmd_status, RUN_SETUP | NEED_WORK_TREE },
628702
{ "stripspace", cmd_stripspace },
629-
{ "submodule--helper", cmd_submodule__helper, RUN_SETUP },
703+
{ "submodule--helper", cmd_submodule__helper, RUN_SETUP | BLOCK_ON_GVFS_REPO },
630704
{ "survey", cmd_survey, RUN_SETUP },
631705
{ "switch", cmd_switch, RUN_SETUP | NEED_WORK_TREE },
632706
{ "symbolic-ref", cmd_symbolic_ref, RUN_SETUP },
@@ -770,13 +844,16 @@ static void execv_dashed_external(const char **argv)
770844
*/
771845
trace_argv_printf(cmd.args.v, "trace: exec:");
772846

847+
if (run_pre_command_hook(the_repository, cmd.args.v))
848+
die("pre-command hook aborted command");
849+
773850
/*
774851
* If we fail because the command is not found, it is
775852
* OK to return. Otherwise, we just pass along the status code,
776853
* or our usual generic code if we were not even able to exec
777854
* the program.
778855
*/
779-
status = run_command(&cmd);
856+
exit_code = status = run_command(&cmd);
780857

781858
/*
782859
* If the child process ran and we are now going to exit, emit a
@@ -787,6 +864,8 @@ static void execv_dashed_external(const char **argv)
787864
exit(status);
788865
else if (errno != ENOENT)
789866
exit(128);
867+
868+
run_post_command_hook(the_repository);
790869
}
791870

792871
static int run_argv(struct strvec *args)
@@ -894,6 +973,7 @@ int cmd_main(int argc, const char **argv)
894973
}
895974

896975
trace_command_performance(argv);
976+
atexit(post_command_hook_atexit);
897977

898978
/*
899979
* "git-xxxx" is the same as "git xxxx", but we obviously:
@@ -921,10 +1001,14 @@ int cmd_main(int argc, const char **argv)
9211001
if (!argc) {
9221002
/* The user didn't specify a command; give them help */
9231003
commit_pager_choice();
1004+
if (run_pre_command_hook(the_repository, argv))
1005+
die("pre-command hook aborted command");
9241006
printf(_("usage: %s\n\n"), git_usage_string);
9251007
list_common_cmds_help();
9261008
printf("\n%s\n", _(git_more_info_string));
927-
exit(1);
1009+
exit_code = 1;
1010+
run_post_command_hook(the_repository);
1011+
exit(exit_code);
9281012
}
9291013

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

0 commit comments

Comments
 (0)