Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions gitstatus.plugin.sh
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,7 @@ function gitstatus_stop() {
# Non-negative integer.
# VCS_STATUS_NUM_ASSUME_UNCHANGED The number of files in the index with assume-unchanged bit set.
# Non-negative integer.
# VCS_STATUS_INDEX_DISABLED Either the -p option was set or the index could not be read.
#
# The point of reporting -1 via VCS_STATUS_HAS_* is to allow the command to skip scanning files in
# large repos. See -m flag of gitstatus_start.
Expand Down Expand Up @@ -418,6 +419,7 @@ function gitstatus_query() {
VCS_STATUS_NUM_ASSUME_UNCHANGED="${resp[26]:-0}"
VCS_STATUS_COMMIT_ENCODING="${resp[27]-}"
VCS_STATUS_COMMIT_SUMMARY="${resp[28]-}"
VCS_STATUS_INDEX_DISABLED="${resp[29]-}"
VCS_STATUS_HAS_STAGED=$((VCS_STATUS_NUM_STAGED > 0))
if (( _GITSTATUS_DIRTY_MAX_INDEX_SIZE >= 0 &&
VCS_STATUS_INDEX_SIZE > _GITSTATUS_DIRTY_MAX_INDEX_SIZE_ )); then
Expand Down
4 changes: 3 additions & 1 deletion gitstatus.plugin.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
# VCS_STATUS_STASHES=0
# VCS_STATUS_TAG=''
# VCS_STATUS_WORKDIR=/home/romka/powerlevel10k
# VCS_STATUS_INDEX_DISABLED=0

[[ -o 'interactive' ]] || 'return'

Expand Down Expand Up @@ -347,7 +348,8 @@ function _gitstatus_process_response"${1:-}"() {
VCS_STATUS_NUM_SKIP_WORKTREE \
VCS_STATUS_NUM_ASSUME_UNCHANGED \
VCS_STATUS_COMMIT_ENCODING \
VCS_STATUS_COMMIT_SUMMARY in "${(@)resp[3,29]}"; do
VCS_STATUS_COMMIT_SUMMARY \
VCS_STATUS_INDEX_DISABLED in "${(@)resp[3,30]}"; do
done
typeset -gi VCS_STATUS_{INDEX_SIZE,NUM_STAGED,NUM_UNSTAGED,NUM_CONFLICTED,NUM_UNTRACKED,COMMITS_AHEAD,COMMITS_BEHIND,STASHES,NUM_UNSTAGED_DELETED,NUM_STAGED_NEW,NUM_STAGED_DELETED,PUSH_COMMITS_AHEAD,PUSH_COMMITS_BEHIND,NUM_SKIP_WORKTREE,NUM_ASSUME_UNCHANGED}
typeset -gi VCS_STATUS_HAS_STAGED=$((VCS_STATUS_NUM_STAGED > 0))
Expand Down
5 changes: 4 additions & 1 deletion src/gitstatus.cc
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ void ProcessRequest(const Options& opts, RepoCache& cache, Request req) {
// Repository state, A.K.A. action. For example, "merge".
resp.Print(RepoState(repo->repo()));

IndexStats stats;
IndexStats stats {.disabled = true};
// Look for staged, unstaged and untracked. This is where most of the time is spent.
if (req.diff) stats = repo->GetIndexStats(head_target, cfg);

Expand Down Expand Up @@ -176,6 +176,9 @@ void ProcessRequest(const Options& opts, RepoCache& cache, Request req) {
resp.Print(msg.encoding);
resp.Print(msg.summary);

// 1 if index computation disabled by req or we could not read the index, 0 otherwise
resp.Print(stats.disabled);

resp.Dump("with git status");
}

Expand Down
2 changes: 2 additions & 0 deletions src/options.cc
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ void PrintUsage() {
<< " 27. Number of files in the index with assume-unchanged bit set.\n"
<< " 28. Encoding of the HEAD's commit message. Empty value means UTF-8.\n"
<< " 29. The first paragraph of the HEAD's commit message as one line.\n"
<< " 30. 1 if index was not read, 0 otherwise.\n"
<< "\n"
<< "Note: Renamed files are reported as deleted plus new.\n"
<< "\n"
Expand Down Expand Up @@ -228,6 +229,7 @@ void PrintUsage() {
<< " '0'\n"
<< " ''\n"
<< " 'add a build server for darwin-arm64'\n"
<< " '0'\n"
<< "\n"
<< "EXIT STATUS\n"
<< "\n"
Expand Down
8 changes: 6 additions & 2 deletions src/repo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,10 @@ IndexStats Repo::GetIndexStats(const git_oid* head, git_config* cfg) {
index_.reset();
}
} else {
VERIFY(!git_repository_index(&git_index_, repo_)) << GitError();
if (git_repository_index(&git_index_, repo_)) {
// Can't read index, proceed as if index computations are disabled
return {.disabled = true};
}
// Query an attribute (doesn't matter which) to initialize repo's attribute
// cache. It's a workaround for synchronization bugs (data races) in libgit2
// that result from lazy cache initialization without synchronization.
Expand Down Expand Up @@ -239,7 +242,8 @@ IndexStats Repo::GetIndexStats(const git_oid* head, git_config* cfg) {
.num_staged_deleted = std::min(Load(staged_deleted_), num_staged),
.num_unstaged_deleted = std::min(Load(unstaged_deleted_), num_unstaged),
.num_skip_worktree = Load(skip_worktree_),
.num_assume_unchanged = Load(assume_unchanged_)};
.num_assume_unchanged = Load(assume_unchanged_),
.disabled = false};
}

int Repo::OnDelta(const char* type, const git_diff_delta& d, std::atomic<size_t>& c1, size_t m1,
Expand Down
1 change: 1 addition & 0 deletions src/repo.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ struct IndexStats {
size_t num_unstaged_deleted = 0;
size_t num_skip_worktree = 0;
size_t num_assume_unchanged = 0;
bool disabled = false;
};

class Repo {
Expand Down