Nix 2.36.0
Nix, the purely functional package manager; unstable internal interfaces
Loading...
Searching...
No Matches
git-utils.hh
1#pragma once
2
3#include "nix/fetchers/filtering-source-accessor.hh"
5
6namespace nix {
7
13const std::filesystem::path & gitProgram();
14
15namespace fetchers {
16struct PublicKey;
17struct Settings;
18} // namespace fetchers
19
21{
22 bool exportIgnore = false;
23 bool smudgeLfs = false;
24};
25
26struct GitRepo
27{
28 virtual ~GitRepo() = default;
29
30 struct Options
31 {
32 bool create = false;
33 bool bare = false;
34 bool packfilesOnly = false;
40 bool dontFindDeltas = false;
41 };
42
43 static ref<GitRepo> openRepo(const std::filesystem::path & path, Options options);
44
45 virtual uint64_t getLastModified(const Hash & rev) = 0;
46
47 virtual bool isShallow() = 0;
48
49 /* Return the commit hash to which a ref points. */
50 virtual Hash resolveRef(std::string ref) = 0;
51
52 virtual void setRemote(const std::string & name, const std::string & url) = 0;
53
57 struct Submodule
58 {
59 CanonPath path;
60 std::string url;
61 std::string branch;
62 };
63
65 {
66 bool isDirty = false;
67
68 /* The checked out commit, or nullopt if there are no commits
69 in the repo yet. */
70 std::optional<Hash> headRev;
71
72 /* All files in the working directory that are unchanged,
73 modified or added, but excluding deleted files. */
74 std::set<CanonPath> files;
75
76 /* All modified or added files. */
77 std::set<CanonPath> dirtyFiles;
78
79 /* The deleted files. */
80 std::set<CanonPath> deletedFiles;
81
82 /* The submodules listed in .gitmodules of this workdir. */
83 std::vector<Submodule> submodules;
84 };
85
86 virtual WorkdirInfo getWorkdirInfo() = 0;
87
88 static WorkdirInfo getCachedWorkdirInfo(const std::filesystem::path & path);
89
90 /* Drop all entries from the getCachedWorkdirInfo() cache. */
91 static void invalidateWorkdirInfoCache();
92
93 /* Get the ref that HEAD points to. */
94 virtual std::optional<std::string> getWorkdirRef() = 0;
95
100 virtual std::vector<std::tuple<Submodule, Hash>> getSubmodules(const Hash & rev, bool exportIgnore) = 0;
101
102 virtual std::string resolveSubmoduleUrl(const std::string & url) = 0;
103
104 virtual bool hasObject(const Hash & oid) = 0;
105
106 virtual ref<SourceAccessor>
107 getAccessor(const Hash & rev, const GitAccessorOptions & options, std::string displayPrefix) = 0;
108
109 virtual ref<SourceAccessor> getAccessor(
110 const WorkdirInfo & wd, const GitAccessorOptions & options, MakeNotAllowedError makeNotAllowedError) = 0;
111
112 virtual void flush() = 0;
113
114 virtual std::unique_ptr<merkle::DirectorySinkWithFinalize> makeDirectorySink() = 0;
115 virtual std::unique_ptr<merkle::RegularFileSinkWithFinalize> makeRegularFileSink() = 0;
116
117 virtual void fetch(const std::string & url, const std::string & refspec, bool shallow) = 0;
118
123 virtual void verifyCommit(const Hash & rev, const std::vector<fetchers::PublicKey> & publicKeys) = 0;
124
129 virtual Hash treeHashToNarHash(const fetchers::Settings & settings, const Hash & treeHash) = 0;
130
136 virtual Hash dereferenceSingletonDirectory(const Hash & oid) = 0;
137};
138
140{
141 virtual ~GitRepoPool() = default;
142
143 static ref<GitRepoPool> create(const std::filesystem::path & path, GitRepo::Options options);
144
145 virtual uint64_t getRevCount(const Hash & rev) = 0;
146};
147
148// A helper to ensure that we don't leak objects returned by libgit2.
149template<typename T>
150struct Setter
151{
152 T & t;
153 typename T::pointer p = nullptr;
154
155 Setter(T & t)
156 : t(t)
157 {
158 }
159
160 ~Setter()
161 {
162 if (p)
163 t = T(p);
164 }
165
166 operator typename T::pointer *()
167 {
168 return &p;
169 }
170};
171
180bool isLegalRefName(const std::string & refName);
181
182} // namespace nix
Definition canon-path.hh:50
Definition ref.hh:58
Definition git-utils.hh:21
Definition git-utils.hh:140
Definition git-utils.hh:31
bool dontFindDeltas
Definition git-utils.hh:40
Definition git-utils.hh:58
Definition git-utils.hh:65
Definition git-utils.hh:27
virtual std::vector< std::tuple< Submodule, Hash > > getSubmodules(const Hash &rev, bool exportIgnore)=0
virtual Hash treeHashToNarHash(const fetchers::Settings &settings, const Hash &treeHash)=0
virtual Hash dereferenceSingletonDirectory(const Hash &oid)=0
virtual void verifyCommit(const Hash &rev, const std::vector< fetchers::PublicKey > &publicKeys)=0
Definition hash.hh:58
Definition fetchers.hh:303
Definition fetch-settings.hh:27
Definition merkle-tar-adapter.hh:48