Skip to content

Commit 6ccb3bb

Browse files
dscholdennington
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: microsoft#85 microsoft#89 microsoft#91 microsoft#98 microsoft#243 microsoft#263 Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
2 parents 93938c5 + d6a2fc2 commit 6ccb3bb

18 files changed

Lines changed: 482 additions & 42 deletions

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

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -921,6 +921,7 @@ LIB_OBJS += gettext.o
921921
LIB_OBJS += gpg-interface.o
922922
LIB_OBJS += graph.o
923923
LIB_OBJS += grep.o
924+
LIB_OBJS += gvfs.o
924925
LIB_OBJS += hash-lookup.o
925926
LIB_OBJS += hashmap.o
926927
LIB_OBJS += help.o

apply.c

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

3349+
/*
3350+
* Do not checkout the entry if the skipworktree bit is set
3351+
*
3352+
* Both callers of this method (check_preimage and load_current)
3353+
* check for the existance of the file before calling this
3354+
* method so we know that the file doesn't exist at this point
3355+
* and we don't need to perform that check again here.
3356+
* We just need to check the skip-worktree and return.
3357+
*
3358+
* This is to prevent git from creating a file in the
3359+
* working directory that has the skip-worktree bit on,
3360+
* then updating the index from the patch and not keeping
3361+
* the working directory version up to date with what it
3362+
* changed the index version to be.
3363+
*/
3364+
if (ce_skip_worktree(ce))
3365+
return 0;
3366+
33493367
costate.refresh_cache = 1;
33503368
costate.istate = istate;
33513369
if (checkout_entry(ce, &costate, NULL, NULL) ||

builtin/gc.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
#include "builtin.h"
1414
#include "repository.h"
15+
#include "gvfs.h"
1516
#include "config.h"
1617
#include "tempfile.h"
1718
#include "lockfile.h"
@@ -597,6 +598,9 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
597598
if (quiet)
598599
strvec_push(&repack, "-q");
599600

601+
if ((!auto_gc || (auto_gc && gc_auto_threshold > 0)) && gvfs_config_is_set(GVFS_BLOCK_COMMANDS))
602+
die(_("'git gc' is not supported on a GVFS repo"));
603+
600604
if (auto_gc) {
601605
/*
602606
* 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_COMPATIBILITY_MACROS
77
#include "cache.h"
8+
#include "gvfs.h"
89
#include "bulk-checkin.h"
910
#include "config.h"
1011
#include "lockfile.h"
@@ -1137,7 +1138,13 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
11371138
argc = parse_options_end(&ctx);
11381139

11391140
getline_fn = nul_term_line ? strbuf_getline_nul : strbuf_getline_lf;
1141+
if (mark_skip_worktree_only && gvfs_config_is_set(GVFS_BLOCK_COMMANDS))
1142+
die(_("modifying the skip worktree bit is not supported on a GVFS repo"));
1143+
11401144
if (preferred_index_format) {
1145+
if (preferred_index_format != 4 && gvfs_config_is_set(GVFS_BLOCK_COMMANDS))
1146+
die(_("changing the index version is not supported on a GVFS repo"));
1147+
11411148
if (preferred_index_format < INDEX_FORMAT_LB ||
11421149
INDEX_FORMAT_UB < preferred_index_format)
11431150
die("index-version %d not in range: %d..%d",
@@ -1175,6 +1182,9 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
11751182
/* by now we must have added all of the new objects */
11761183
unplug_bulk_checkin();
11771184
if (split_index > 0) {
1185+
if (gvfs_config_is_set(GVFS_BLOCK_COMMANDS))
1186+
die(_("split index is not supported on a GVFS repo"));
1187+
11781188
if (git_config_get_split_index() == 0)
11791189
warning(_("core.splitIndex is set to false; "
11801190
"remove or change it, if you really want to "

cache-tree.c

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

424424
strbuf_grow(&buffer, entlen + 100);
425-
strbuf_addf(&buffer, "%o %.*s%c", mode, entlen, path + baselen, '\0');
425+
426+
switch (mode) {
427+
case 0100644:
428+
strbuf_add(&buffer, "100644 ", 7);
429+
break;
430+
case 0100664:
431+
strbuf_add(&buffer, "100664 ", 7);
432+
break;
433+
case 0100755:
434+
strbuf_add(&buffer, "100755 ", 7);
435+
break;
436+
case 0120000:
437+
strbuf_add(&buffer, "120000 ", 7);
438+
break;
439+
case 0160000:
440+
strbuf_add(&buffer, "160000 ", 7);
441+
break;
442+
default:
443+
strbuf_addf(&buffer, "%o ", mode);
444+
break;
445+
}
446+
strbuf_add(&buffer, path + baselen, entlen);
447+
strbuf_addch(&buffer, '\0');
426448
strbuf_add(&buffer, oid->hash, the_hash_algo->rawsz);
427449

428450
#if DEBUG_CACHE_TREE

git.c

Lines changed: 87 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
#include "builtin.h"
2+
#include "gvfs.h"
23
#include "config.h"
34
#include "exec-cmd.h"
45
#include "help.h"
56
#include "run-command.h"
67
#include "alias.h"
78
#include "shallow.h"
9+
#include "dir.h"
810

911
#define RUN_SETUP (1<<0)
1012
#define RUN_SETUP_GENTLY (1<<1)
@@ -17,6 +19,7 @@
1719
#define SUPPORT_SUPER_PREFIX (1<<4)
1820
#define DELAY_PAGER_CONFIG (1<<5)
1921
#define NO_PARSEOPT (1<<6) /* parse-options is not used */
22+
#define BLOCK_ON_GVFS_REPO (1<<7) /* command not allowed in GVFS repos */
2023

2124
struct cmd_struct {
2225
const char *cmd;
@@ -416,6 +419,64 @@ static int handle_alias(int *argcp, const char ***argv)
416419
return ret;
417420
}
418421

422+
/* Runs pre/post-command hook */
423+
static struct strvec sargv = STRVEC_INIT;
424+
static int run_post_hook = 0;
425+
static int exit_code = -1;
426+
427+
static int run_pre_command_hook(const char **argv)
428+
{
429+
char *lock;
430+
int ret = 0;
431+
432+
/*
433+
* Ensure the global pre/post command hook is only called for
434+
* the outer command and not when git is called recursively
435+
* or spawns multiple commands (like with the alias command)
436+
*/
437+
lock = getenv("COMMAND_HOOK_LOCK");
438+
if (lock && !strcmp(lock, "true"))
439+
return 0;
440+
setenv("COMMAND_HOOK_LOCK", "true", 1);
441+
442+
/* call the hook proc */
443+
strvec_pushv(&sargv, argv);
444+
strvec_pushf(&sargv, "--git-pid=%"PRIuMAX, (uintmax_t)getpid());
445+
ret = run_hook_strvec(NULL, "pre-command", &sargv);
446+
447+
if (!ret)
448+
run_post_hook = 1;
449+
return ret;
450+
}
451+
452+
static int run_post_command_hook(void)
453+
{
454+
char *lock;
455+
int ret = 0;
456+
457+
/*
458+
* Only run post_command if pre_command succeeded in this process
459+
*/
460+
if (!run_post_hook)
461+
return 0;
462+
lock = getenv("COMMAND_HOOK_LOCK");
463+
if (!lock || strcmp(lock, "true"))
464+
return 0;
465+
466+
strvec_pushf(&sargv, "--exit_code=%u", exit_code);
467+
ret = run_hook_strvec(NULL, "post-command", &sargv);
468+
469+
run_post_hook = 0;
470+
strvec_clear(&sargv);
471+
setenv("COMMAND_HOOK_LOCK", "false", 1);
472+
return ret;
473+
}
474+
475+
static void post_command_hook_atexit(void)
476+
{
477+
run_post_command_hook();
478+
}
479+
419480
static int run_builtin(struct cmd_struct *p, int argc, const char **argv)
420481
{
421482
int status, help;
@@ -455,18 +516,26 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv)
455516
if (!help && p->option & NEED_WORK_TREE)
456517
setup_work_tree();
457518

519+
if (!help && p->option & BLOCK_ON_GVFS_REPO && gvfs_config_is_set(GVFS_BLOCK_COMMANDS))
520+
die("'git %s' is not supported on a GVFS repo", p->cmd);
521+
522+
if (run_pre_command_hook(argv))
523+
die("pre-command hook aborted command");
524+
458525
trace_argv_printf(argv, "trace: built-in: git");
459526
trace2_cmd_name(p->cmd);
460527
trace2_cmd_list_config();
461528
trace2_cmd_list_env_vars();
462529

463530
validate_cache_entries(the_repository->index);
464-
status = p->fn(argc, argv, prefix);
531+
exit_code = status = p->fn(argc, argv, prefix);
465532
validate_cache_entries(the_repository->index);
466533

467534
if (status)
468535
return status;
469536

537+
run_post_command_hook();
538+
470539
/* Somebody closed stdout? */
471540
if (fstat(fileno(stdout), &st))
472541
return 0;
@@ -534,7 +603,7 @@ static struct cmd_struct commands[] = {
534603
{ "for-each-ref", cmd_for_each_ref, RUN_SETUP },
535604
{ "for-each-repo", cmd_for_each_repo, RUN_SETUP_GENTLY },
536605
{ "format-patch", cmd_format_patch, RUN_SETUP },
537-
{ "fsck", cmd_fsck, RUN_SETUP },
606+
{ "fsck", cmd_fsck, RUN_SETUP | BLOCK_ON_GVFS_REPO},
538607
{ "fsck-objects", cmd_fsck, RUN_SETUP },
539608
{ "fsmonitor--daemon", cmd_fsmonitor__daemon, RUN_SETUP },
540609
{ "gc", cmd_gc, RUN_SETUP },
@@ -574,7 +643,7 @@ static struct cmd_struct commands[] = {
574643
{ "pack-refs", cmd_pack_refs, RUN_SETUP },
575644
{ "patch-id", cmd_patch_id, RUN_SETUP_GENTLY | NO_PARSEOPT },
576645
{ "pickaxe", cmd_blame, RUN_SETUP },
577-
{ "prune", cmd_prune, RUN_SETUP },
646+
{ "prune", cmd_prune, RUN_SETUP | BLOCK_ON_GVFS_REPO},
578647
{ "prune-packed", cmd_prune_packed, RUN_SETUP },
579648
{ "pull", cmd_pull, RUN_SETUP | NEED_WORK_TREE },
580649
{ "push", cmd_push, RUN_SETUP },
@@ -586,7 +655,7 @@ static struct cmd_struct commands[] = {
586655
{ "remote", cmd_remote, RUN_SETUP },
587656
{ "remote-ext", cmd_remote_ext, NO_PARSEOPT },
588657
{ "remote-fd", cmd_remote_fd, NO_PARSEOPT },
589-
{ "repack", cmd_repack, RUN_SETUP },
658+
{ "repack", cmd_repack, RUN_SETUP | BLOCK_ON_GVFS_REPO },
590659
{ "replace", cmd_replace, RUN_SETUP },
591660
{ "rerere", cmd_rerere, RUN_SETUP },
592661
{ "reset", cmd_reset, RUN_SETUP },
@@ -606,7 +675,7 @@ static struct cmd_struct commands[] = {
606675
{ "stash", cmd_stash, RUN_SETUP | NEED_WORK_TREE },
607676
{ "status", cmd_status, RUN_SETUP | NEED_WORK_TREE },
608677
{ "stripspace", cmd_stripspace },
609-
{ "submodule--helper", cmd_submodule__helper, RUN_SETUP | SUPPORT_SUPER_PREFIX | NO_PARSEOPT },
678+
{ "submodule--helper", cmd_submodule__helper, RUN_SETUP | SUPPORT_SUPER_PREFIX | NO_PARSEOPT | BLOCK_ON_GVFS_REPO },
610679
{ "switch", cmd_switch, RUN_SETUP | NEED_WORK_TREE },
611680
{ "symbolic-ref", cmd_symbolic_ref, RUN_SETUP },
612681
{ "tag", cmd_tag, RUN_SETUP | DELAY_PAGER_CONFIG },
@@ -624,7 +693,7 @@ static struct cmd_struct commands[] = {
624693
{ "verify-tag", cmd_verify_tag, RUN_SETUP },
625694
{ "version", cmd_version },
626695
{ "whatchanged", cmd_whatchanged, RUN_SETUP },
627-
{ "worktree", cmd_worktree, RUN_SETUP | NO_PARSEOPT },
696+
{ "worktree", cmd_worktree, RUN_SETUP | NO_PARSEOPT | BLOCK_ON_GVFS_REPO },
628697
{ "write-tree", cmd_write_tree, RUN_SETUP },
629698
};
630699

@@ -745,13 +814,16 @@ static void execv_dashed_external(const char **argv)
745814
*/
746815
trace_argv_printf(cmd.args.v, "trace: exec:");
747816

817+
if (run_pre_command_hook(cmd.args.v))
818+
die("pre-command hook aborted command");
819+
748820
/*
749821
* If we fail because the command is not found, it is
750822
* OK to return. Otherwise, we just pass along the status code,
751823
* or our usual generic code if we were not even able to exec
752824
* the program.
753825
*/
754-
status = run_command(&cmd);
826+
exit_code = status = run_command(&cmd);
755827

756828
/*
757829
* If the child process ran and we are now going to exit, emit a
@@ -762,6 +834,8 @@ static void execv_dashed_external(const char **argv)
762834
exit(status);
763835
else if (errno != ENOENT)
764836
exit(128);
837+
838+
run_post_command_hook();
765839
}
766840

767841
static int run_argv(int *argcp, const char ***argv)
@@ -869,6 +943,7 @@ int cmd_main(int argc, const char **argv)
869943
}
870944

871945
trace_command_performance(argv);
946+
atexit(post_command_hook_atexit);
872947

873948
/*
874949
* "git-xxxx" is the same as "git xxxx", but we obviously:
@@ -896,10 +971,14 @@ int cmd_main(int argc, const char **argv)
896971
} else {
897972
/* The user didn't specify a command; give them help */
898973
commit_pager_choice();
974+
if (run_pre_command_hook(argv))
975+
die("pre-command hook aborted command");
899976
printf(_("usage: %s\n\n"), git_usage_string);
900977
list_common_cmds_help();
901978
printf("\n%s\n", _(git_more_info_string));
902-
exit(1);
979+
exit_code = 1;
980+
run_post_command_hook();
981+
exit(exit_code);
903982
}
904983
cmd = argv[0];
905984

0 commit comments

Comments
 (0)