From cefce84f5eb95884344c3f97fc710d4ac0626359 Mon Sep 17 00:00:00 2001 From: Alexander Neonxp Kiryukhin Date: Fri, 16 May 2025 23:32:08 +0300 Subject: =?UTF-8?q?=D0=9E=D0=B1=D0=BD=D0=BE=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D1=8F=20=D0=BA=D0=BE=D0=BD=D1=84=D0=B8=D0=B3=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- zsh/theme/gitstatus/src/repo.h | 126 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 126 insertions(+) create mode 100644 zsh/theme/gitstatus/src/repo.h (limited to 'zsh/theme/gitstatus/src/repo.h') diff --git a/zsh/theme/gitstatus/src/repo.h b/zsh/theme/gitstatus/src/repo.h new file mode 100644 index 0000000..f243f86 --- /dev/null +++ b/zsh/theme/gitstatus/src/repo.h @@ -0,0 +1,126 @@ +// Copyright 2019 Roman Perepelitsa. +// +// This file is part of GitStatus. +// +// GitStatus is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// GitStatus is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with GitStatus. If not, see . + +#ifndef ROMKATV_GITSTATUS_REPO_H_ +#define ROMKATV_GITSTATUS_REPO_H_ + +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "check.h" +#include "index.h" +#include "options.h" +#include "string_cmp.h" +#include "tag_db.h" +#include "time.h" + +namespace gitstatus { + +struct IndexStats { + size_t index_size = 0; + size_t num_staged = 0; + size_t num_unstaged = 0; + size_t num_conflicted = 0; + size_t num_untracked = 0; + size_t num_staged_new = 0; + size_t num_staged_deleted = 0; + size_t num_unstaged_deleted = 0; + size_t num_skip_worktree = 0; + size_t num_assume_unchanged = 0; +}; + +class Repo { + public: + explicit Repo(git_repository* repo, Limits lim); + Repo(Repo&& other) = delete; + ~Repo(); + + git_repository* repo() const { return repo_; } + + // Head can be null, in which case has_staged will be false. + IndexStats GetIndexStats(const git_oid* head, git_config* cfg); + + // Returns the last tag in lexicographical order whose target is equal to the given, or an + // empty string. Target can be null, in which case the tag is empty. + std::future GetTagName(const git_oid* target); + + private: + struct Shard { + bool Contains(Str<> str, StringView path) const; + std::string start_s; + std::string end_s; + size_t start_i; + size_t end_i; + }; + + void UpdateShards(); + + int OnDelta(const char* type, const git_diff_delta& d, std::atomic& c1, size_t m1, + const std::atomic& c2, size_t m2); + + void StartStagedScan(const git_oid* head); + void StartDirtyScan(const std::vector& paths); + + void DecInflight(); + void RunAsync(std::function f); + void Wait(); + + Limits lim_; + git_repository* const repo_; + git_index* git_index_ = nullptr; + std::vector shards_; + git_oid head_ = {}; + TagDb tag_db_; + + std::unique_ptr index_; + + std::mutex mutex_; + std::condition_variable cv_; + std::atomic inflight_{0}; + std::atomic error_{false}; + std::atomic staged_{0}; + std::atomic unstaged_{0}; + std::atomic conflicted_{0}; + std::atomic untracked_{0}; + std::atomic staged_new_{0}; + std::atomic staged_deleted_{0}; + std::atomic unstaged_deleted_{0}; + std::atomic skip_worktree_{0}; + std::atomic assume_unchanged_{0}; + std::atomic untracked_cache_{Tribool::kUnknown}; +}; + +} // namespace gitstatus + +#endif // ROMKATV_GITSTATUS_REPO_H_ -- cgit v1.2.3