2023-10-25 18:55:08 +02:00
|
|
|
#pragma once
|
|
|
|
|
2024-05-06 17:29:03 +02:00
|
|
|
#include "filtering-source-accessor.hh"
|
2023-12-21 03:49:52 -05:00
|
|
|
#include "fs-sink.hh"
|
2023-10-25 18:55:08 +02:00
|
|
|
|
|
|
|
namespace nix {
|
|
|
|
|
2023-11-09 16:48:41 +01:00
|
|
|
namespace fetchers { struct PublicKey; }
|
|
|
|
|
2023-12-21 03:49:52 -05:00
|
|
|
struct GitFileSystemObjectSink : FileSystemObjectSink
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Flush builder and return a final Git hash.
|
|
|
|
*/
|
|
|
|
virtual Hash sync() = 0;
|
|
|
|
};
|
|
|
|
|
2023-10-25 18:55:08 +02:00
|
|
|
struct GitRepo
|
|
|
|
{
|
|
|
|
virtual ~GitRepo()
|
|
|
|
{ }
|
|
|
|
|
2024-02-06 16:23:58 -05:00
|
|
|
static ref<GitRepo> openRepo(const std::filesystem::path & path, bool create = false, bool bare = false);
|
2023-10-25 18:55:08 +02:00
|
|
|
|
|
|
|
virtual uint64_t getRevCount(const Hash & rev) = 0;
|
|
|
|
|
|
|
|
virtual uint64_t getLastModified(const Hash & rev) = 0;
|
|
|
|
|
|
|
|
virtual bool isShallow() = 0;
|
|
|
|
|
|
|
|
/* Return the commit hash to which a ref points. */
|
|
|
|
virtual Hash resolveRef(std::string ref) = 0;
|
|
|
|
|
2024-03-15 09:30:58 +01:00
|
|
|
virtual void setRemote(const std::string & name, const std::string & url) = 0;
|
|
|
|
|
2023-10-31 15:59:25 +01:00
|
|
|
/**
|
|
|
|
* Info about a submodule.
|
|
|
|
*/
|
|
|
|
struct Submodule
|
|
|
|
{
|
|
|
|
CanonPath path;
|
|
|
|
std::string url;
|
|
|
|
std::string branch;
|
|
|
|
};
|
|
|
|
|
2023-10-25 18:55:08 +02:00
|
|
|
struct WorkdirInfo
|
|
|
|
{
|
|
|
|
bool isDirty = false;
|
|
|
|
|
|
|
|
/* The checked out commit, or nullopt if there are no commits
|
|
|
|
in the repo yet. */
|
|
|
|
std::optional<Hash> headRev;
|
|
|
|
|
|
|
|
/* All files in the working directory that are unchanged,
|
|
|
|
modified or added, but excluding deleted files. */
|
|
|
|
std::set<CanonPath> files;
|
2023-10-31 15:59:25 +01:00
|
|
|
|
|
|
|
/* The submodules listed in .gitmodules of this workdir. */
|
|
|
|
std::vector<Submodule> submodules;
|
2023-10-25 18:55:08 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
virtual WorkdirInfo getWorkdirInfo() = 0;
|
|
|
|
|
|
|
|
/* Get the ref that HEAD points to. */
|
|
|
|
virtual std::optional<std::string> getWorkdirRef() = 0;
|
|
|
|
|
2023-10-31 15:59:25 +01:00
|
|
|
/**
|
|
|
|
* Return the submodules of this repo at the indicated revision,
|
|
|
|
* along with the revision of each submodule.
|
|
|
|
*/
|
2023-11-27 22:34:41 +01:00
|
|
|
virtual std::vector<std::tuple<Submodule, Hash>> getSubmodules(const Hash & rev, bool exportIgnore) = 0;
|
2023-10-27 18:39:00 +02:00
|
|
|
|
2024-03-15 09:30:58 +01:00
|
|
|
virtual std::string resolveSubmoduleUrl(const std::string & url) = 0;
|
2023-10-27 18:39:00 +02:00
|
|
|
|
2023-10-25 18:55:08 +02:00
|
|
|
virtual bool hasObject(const Hash & oid) = 0;
|
|
|
|
|
2024-05-03 12:14:01 +02:00
|
|
|
virtual ref<SourceAccessor> getAccessor(const Hash & rev, bool exportIgnore) = 0;
|
2023-10-25 18:55:08 +02:00
|
|
|
|
2024-05-03 12:14:01 +02:00
|
|
|
virtual ref<SourceAccessor> getAccessor(const WorkdirInfo & wd, bool exportIgnore, MakeNotAllowedError makeNotAllowedError) = 0;
|
2023-10-25 18:55:08 +02:00
|
|
|
|
2023-12-21 03:49:52 -05:00
|
|
|
virtual ref<GitFileSystemObjectSink> getFileSystemObjectSink() = 0;
|
|
|
|
|
2023-10-25 18:55:08 +02:00
|
|
|
virtual void fetch(
|
|
|
|
const std::string & url,
|
2023-11-15 14:43:30 +01:00
|
|
|
const std::string & refspec,
|
|
|
|
bool shallow) = 0;
|
2023-11-09 16:48:41 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Verify that commit `rev` is signed by one of the keys in
|
|
|
|
* `publicKeys`. Throw an error if it isn't.
|
|
|
|
*/
|
|
|
|
virtual void verifyCommit(
|
|
|
|
const Hash & rev,
|
|
|
|
const std::vector<fetchers::PublicKey> & publicKeys) = 0;
|
2024-02-20 12:57:36 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Given a Git tree hash, compute the hash of its NAR
|
|
|
|
* serialisation. This is memoised on-disk.
|
|
|
|
*/
|
|
|
|
virtual Hash treeHashToNarHash(const Hash & treeHash) = 0;
|
2023-10-25 18:55:08 +02:00
|
|
|
};
|
|
|
|
|
2024-02-15 21:58:08 +01:00
|
|
|
ref<GitRepo> getTarballCache();
|
|
|
|
|
2023-10-25 18:55:08 +02:00
|
|
|
}
|