Skip to content

Commit 19d49cd

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 c69afbb + eb6bdc1 commit 19d49cd

19 files changed

+472
-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
@@ -3373,6 +3373,24 @@ static int checkout_target(struct index_state *istate,
33733373
{
33743374
struct checkout costate = CHECKOUT_INIT;
33753375

3376+
/*
3377+
* Do not checkout the entry if the skipworktree bit is set
3378+
*
3379+
* Both callers of this method (check_preimage and load_current)
3380+
* check for the existance of the file before calling this
3381+
* method so we know that the file doesn't exist at this point
3382+
* and we don't need to perform that check again here.
3383+
* We just need to check the skip-worktree and return.
3384+
*
3385+
* This is to prevent git from creating a file in the
3386+
* working directory that has the skip-worktree bit on,
3387+
* then updating the index from the patch and not keeping
3388+
* the working directory version up to date with what it
3389+
* changed the index version to be.
3390+
*/
3391+
if (ce_skip_worktree(ce))
3392+
return 0;
3393+
33763394
costate.refresh_cache = 1;
33773395
costate.istate = istate;
33783396
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"
@@ -759,6 +760,9 @@ struct repository *repo UNUSED)
759760
if (quiet)
760761
strvec_push(&repack, "-q");
761762

763+
if ((!opts.auto_flag || (opts.auto_flag && cfg.gc_auto_threshold > 0)) && gvfs_config_is_set(GVFS_BLOCK_COMMANDS))
764+
die(_("'git gc' is not supported on a GVFS repo"));
765+
762766
if (opts.auto_flag) {
763767
if (cfg.detach_auto && opts.detach < 0)
764768
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"
@@ -1450,6 +1451,13 @@ int cmd_worktree(int ac,
14501451

14511452
git_config(git_worktree_config, NULL);
14521453

1454+
/*
1455+
* git-worktree is special-cased to work in Scalar repositories
1456+
* even when they use the GVFS Protocol.
1457+
*/
1458+
if (core_gvfs & GVFS_USE_VIRTUAL_FILESYSTEM)
1459+
die("'git %s' is not supported on a GVFS repo", "worktree");
1460+
14531461
if (!prefix)
14541462
prefix = "";
14551463

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 },
@@ -594,7 +668,7 @@ static struct cmd_struct commands[] = {
594668
{ "pack-refs", cmd_pack_refs, RUN_SETUP },
595669
{ "patch-id", cmd_patch_id, RUN_SETUP_GENTLY | NO_PARSEOPT },
596670
{ "pickaxe", cmd_blame, RUN_SETUP },
597-
{ "prune", cmd_prune, RUN_SETUP },
671+
{ "prune", cmd_prune, RUN_SETUP | BLOCK_ON_GVFS_REPO},
598672
{ "prune-packed", cmd_prune_packed, RUN_SETUP },
599673
{ "pull", cmd_pull, RUN_SETUP | NEED_WORK_TREE },
600674
{ "push", cmd_push, RUN_SETUP },
@@ -607,7 +681,7 @@ static struct cmd_struct commands[] = {
607681
{ "remote", cmd_remote, RUN_SETUP },
608682
{ "remote-ext", cmd_remote_ext, NO_PARSEOPT },
609683
{ "remote-fd", cmd_remote_fd, NO_PARSEOPT },
610-
{ "repack", cmd_repack, RUN_SETUP },
684+
{ "repack", cmd_repack, RUN_SETUP | BLOCK_ON_GVFS_REPO },
611685
{ "replace", cmd_replace, RUN_SETUP },
612686
{ "replay", cmd_replay, RUN_SETUP },
613687
{ "rerere", cmd_rerere, RUN_SETUP },
@@ -628,7 +702,7 @@ static struct cmd_struct commands[] = {
628702
{ "stash", cmd_stash, RUN_SETUP | NEED_WORK_TREE },
629703
{ "status", cmd_status, RUN_SETUP | NEED_WORK_TREE },
630704
{ "stripspace", cmd_stripspace },
631-
{ "submodule--helper", cmd_submodule__helper, RUN_SETUP },
705+
{ "submodule--helper", cmd_submodule__helper, RUN_SETUP | BLOCK_ON_GVFS_REPO },
632706
{ "survey", cmd_survey, RUN_SETUP },
633707
{ "switch", cmd_switch, RUN_SETUP | NEED_WORK_TREE },
634708
{ "symbolic-ref", cmd_symbolic_ref, RUN_SETUP },
@@ -772,13 +846,16 @@ static void execv_dashed_external(const char **argv)
772846
*/
773847
trace_argv_printf(cmd.args.v, "trace: exec:");
774848

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

783860
/*
784861
* If the child process ran and we are now going to exit, emit a
@@ -789,6 +866,8 @@ static void execv_dashed_external(const char **argv)
789866
exit(status);
790867
else if (errno != ENOENT)
791868
exit(128);
869+
870+
run_post_command_hook(the_repository);
792871
}
793872

794873
static int run_argv(struct strvec *args)
@@ -896,6 +975,7 @@ int cmd_main(int argc, const char **argv)
896975
}
897976

898977
trace_command_performance(argv);
978+
atexit(post_command_hook_atexit);
899979

900980
/*
901981
* "git-xxxx" is the same as "git xxxx", but we obviously:
@@ -923,10 +1003,14 @@ int cmd_main(int argc, const char **argv)
9231003
if (!argc) {
9241004
/* The user didn't specify a command; give them help */
9251005
commit_pager_choice();
1006+
if (run_pre_command_hook(the_repository, argv))
1007+
die("pre-command hook aborted command");
9261008
printf(_("usage: %s\n\n"), git_usage_string);
9271009
list_common_cmds_help();
9281010
printf("\n%s\n", _(git_more_info_string));
929-
exit(1);
1011+
exit_code = 1;
1012+
run_post_command_hook(the_repository);
1013+
exit(exit_code);
9301014
}
9311015

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

0 commit comments

Comments
 (0)