forked from git-for-windows/git
-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
virtualization: add new builtin command to print hydration level
GVFS users can easily (and accidentally) over-hydrate their enlistments. This causes some commands to be very slow. Create a command to print the current hydration level. This should help our support team investigate the state of their enlistment. Signed-off-by: Jeff Hostetler <jeffhostetler@github.com>
- Loading branch information
1 parent
1748df7
commit 6d9e562
Showing
8 changed files
with
142 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
git-virtualization(1) | ||
===================== | ||
|
||
NAME | ||
---- | ||
|
||
git-virtualization - EXPERIMENTAL: Measure virtualization level of worktree | ||
|
||
|
||
SYNOPSIS | ||
-------- | ||
[verse] | ||
(EXPERIMENTAL!) `git virtualization` <options> | ||
|
||
|
||
DESCRIPTION | ||
----------- | ||
|
||
Measure the virtualization level of the worktree. | ||
|
||
|
||
GIT | ||
--- | ||
Part of the linkgit:git[1] suite |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
#include "builtin.h" | ||
#include "config.h" | ||
#include "json-writer.h" | ||
#include "parse-options.h" | ||
#include "read-cache-ll.h" | ||
#include "repository.h" | ||
#include "trace2.h" | ||
|
||
static const char * const virt_usage[] = { | ||
N_("(EXPERIMENTAL!) git virtualization"), | ||
NULL, | ||
}; | ||
|
||
static struct option virt_options[] = { | ||
OPT_END(), | ||
}; | ||
|
||
static int virt_load_config_cb(const char *var, | ||
const char *value, | ||
const struct config_context *ctx, | ||
void *pvoid) | ||
{ | ||
return git_default_config(var, value, ctx, pvoid); | ||
} | ||
|
||
static void virt_load_config(void) | ||
{ | ||
git_config(virt_load_config_cb, NULL); | ||
} | ||
|
||
static uint64_t count_skipped(struct repository *repo) | ||
{ | ||
uint64_t k; | ||
uint64_t count = 0; | ||
|
||
for (k = 0; k < repo->index->cache_nr; k++) { | ||
const struct cache_entry *ce_k = repo->index->cache[k]; | ||
|
||
if (ce_skip_worktree(ce_k)) | ||
count++; | ||
} | ||
|
||
return count; | ||
} | ||
|
||
static void print_hydration(struct repository *repo) | ||
{ | ||
uint64_t c_skipped; | ||
uint64_t c_total; | ||
uint64_t c_hydrated; | ||
double hydration; | ||
|
||
c_skipped = count_skipped(the_repository); | ||
c_total = (uint64_t)the_repository->index->cache_nr; | ||
c_hydrated = c_total - c_skipped; | ||
|
||
if (c_total > 0) | ||
hydration = (double)(c_hydrated * 100) / (double)c_total; | ||
else | ||
hydration = 0.0; | ||
|
||
printf("Skipped: %" PRIu64 "\n", c_skipped); | ||
printf("Hydrated: %" PRIu64 "\n", c_hydrated); | ||
printf("Total: %" PRIu64 "\n", c_total); | ||
|
||
printf("Hydration: %.2f%%\n", hydration); | ||
|
||
if (trace2_is_enabled()) { | ||
struct json_writer jw = JSON_WRITER_INIT; | ||
|
||
jw_object_begin(&jw, 0); | ||
{ | ||
jw_object_intmax(&jw, "skipped", c_skipped); | ||
jw_object_intmax(&jw, "hydrated", c_hydrated); | ||
jw_object_intmax(&jw, "total", c_total); | ||
|
||
jw_object_double(&jw, "hydration", 2, hydration); | ||
} | ||
jw_end(&jw); | ||
|
||
trace2_data_json("virt", repo, "stats", &jw); | ||
|
||
jw_release(&jw); | ||
} | ||
} | ||
|
||
int cmd_virtualization(int argc, const char **argv, const char *prefix) | ||
{ | ||
prepare_repo_settings(the_repository); | ||
the_repository->settings.command_requires_full_index = 1; | ||
|
||
virt_load_config(); | ||
|
||
argc = parse_options(argc, argv, prefix, virt_options, virt_usage, 0); | ||
|
||
if (repo_read_index(the_repository) < 0) | ||
die("index file corrupt"); | ||
|
||
print_hydration(the_repository); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters