Nix
2.36.0
Nix, the purely functional package manager; unstable internal interfaces
Toggle main menu visibility
Loading...
Searching...
No Matches
git-utils.hh
1
#pragma once
2
3
#include "nix/fetchers/filtering-source-accessor.hh"
4
#include "
nix/fetchers/merkle-tar-adapter.hh
"
5
6
namespace
nix {
7
13
const
std::filesystem::path & gitProgram();
14
15
namespace
fetchers {
16
struct
PublicKey
;
17
struct
Settings
;
18
}
// namespace fetchers
19
20
struct
GitAccessorOptions
21
{
22
bool
exportIgnore =
false
;
23
bool
smudgeLfs =
false
;
24
};
25
26
struct
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
64
struct
WorkdirInfo
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
139
struct
GitRepoPool
:
merkle::FileSinkBuilder
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.
149
template
<
typename
T>
150
struct
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
180
bool
isLegalRefName(
const
std::string & refName);
181
182
}
// namespace nix
nix::CanonPath
Definition
canon-path.hh:50
nix::ref
Definition
ref.hh:58
merkle-tar-adapter.hh
nix::GitAccessorOptions
Definition
git-utils.hh:21
nix::GitRepoPool
Definition
git-utils.hh:140
nix::GitRepo::Options
Definition
git-utils.hh:31
nix::GitRepo::Options::dontFindDeltas
bool dontFindDeltas
Definition
git-utils.hh:40
nix::GitRepo::Submodule
Definition
git-utils.hh:58
nix::GitRepo::WorkdirInfo
Definition
git-utils.hh:65
nix::GitRepo
Definition
git-utils.hh:27
nix::GitRepo::getSubmodules
virtual std::vector< std::tuple< Submodule, Hash > > getSubmodules(const Hash &rev, bool exportIgnore)=0
nix::GitRepo::treeHashToNarHash
virtual Hash treeHashToNarHash(const fetchers::Settings &settings, const Hash &treeHash)=0
nix::GitRepo::dereferenceSingletonDirectory
virtual Hash dereferenceSingletonDirectory(const Hash &oid)=0
nix::GitRepo::verifyCommit
virtual void verifyCommit(const Hash &rev, const std::vector< fetchers::PublicKey > &publicKeys)=0
nix::Hash
Definition
hash.hh:58
nix::fetchers::PublicKey
Definition
fetchers.hh:303
nix::fetchers::Settings
Definition
fetch-settings.hh:27
nix::merkle::FileSinkBuilder
Definition
merkle-tar-adapter.hh:48
libfetchers
include
nix
fetchers
git-utils.hh
Generated by
1.18.0