2023-10-25 19:55:08 +03:00
|
|
|
#pragma once
|
|
|
|
|
2023-12-11 23:28:53 +02:00
|
|
|
#include "filtering-input-accessor.hh"
|
2023-10-25 19:55:08 +03:00
|
|
|
#include "input-accessor.hh"
|
2023-12-21 10:49:52 +02:00
|
|
|
#include "fs-sink.hh"
|
2023-10-25 19:55:08 +03:00
|
|
|
|
|
|
|
namespace nix {
|
|
|
|
|
2023-11-09 17:48:41 +02:00
|
|
|
namespace fetchers { struct PublicKey; }
|
|
|
|
|
2023-12-21 10:49:52 +02:00
|
|
|
struct GitFileSystemObjectSink : FileSystemObjectSink
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Flush builder and return a final Git hash.
|
|
|
|
*/
|
|
|
|
virtual Hash sync() = 0;
|
|
|
|
};
|
|
|
|
|
2023-10-25 19:55:08 +03:00
|
|
|
struct GitRepo
|
|
|
|
{
|
|
|
|
virtual ~GitRepo()
|
|
|
|
{ }
|
|
|
|
|
2024-02-06 23:23:58 +02:00
|
|
|
static ref<GitRepo> openRepo(const std::filesystem::path & path, bool create = false, bool bare = false);
|
2023-10-25 19:55:08 +03: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 10:30:58 +02:00
|
|
|
virtual void setRemote(const std::string & name, const std::string & url) = 0;
|
|
|
|
|
2023-10-31 16:59:25 +02:00
|
|
|
/**
|
|
|
|
* Info about a submodule.
|
|
|
|
*/
|
|
|
|
struct Submodule
|
|
|
|
{
|
|
|
|
CanonPath path;
|
|
|
|
std::string url;
|
|
|
|
std::string branch;
|
|
|
|
};
|
|
|
|
|
2023-10-25 19:55:08 +03: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 16:59:25 +02:00
|
|
|
|
|
|
|
/* The submodules listed in .gitmodules of this workdir. */
|
|
|
|
std::vector<Submodule> submodules;
|
2023-10-25 19:55:08 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
virtual WorkdirInfo getWorkdirInfo() = 0;
|
|
|
|
|
|
|
|
/* Get the ref that HEAD points to. */
|
|
|
|
virtual std::optional<std::string> getWorkdirRef() = 0;
|
|
|
|
|
2023-10-31 16:59:25 +02:00
|
|
|
/**
|
|
|
|
* Return the submodules of this repo at the indicated revision,
|
|
|
|
* along with the revision of each submodule.
|
|
|
|
*/
|
2023-11-27 23:34:41 +02:00
|
|
|
virtual std::vector<std::tuple<Submodule, Hash>> getSubmodules(const Hash & rev, bool exportIgnore) = 0;
|
2023-10-27 19:39:00 +03:00
|
|
|
|
2024-03-15 10:30:58 +02:00
|
|
|
virtual std::string resolveSubmoduleUrl(const std::string & url) = 0;
|
2023-10-27 19:39:00 +03:00
|
|
|
|
2023-10-25 19:55:08 +03:00
|
|
|
virtual bool hasObject(const Hash & oid) = 0;
|
|
|
|
|
2023-11-27 23:34:41 +02:00
|
|
|
virtual ref<InputAccessor> getAccessor(const Hash & rev, bool exportIgnore) = 0;
|
2023-10-25 19:55:08 +03:00
|
|
|
|
2023-12-11 23:28:53 +02:00
|
|
|
virtual ref<InputAccessor> getAccessor(const WorkdirInfo & wd, bool exportIgnore, MakeNotAllowedError makeNotAllowedError) = 0;
|
2023-10-25 19:55:08 +03:00
|
|
|
|
2023-12-21 10:49:52 +02:00
|
|
|
virtual ref<GitFileSystemObjectSink> getFileSystemObjectSink() = 0;
|
|
|
|
|
2023-10-25 19:55:08 +03:00
|
|
|
virtual void fetch(
|
|
|
|
const std::string & url,
|
2023-11-15 15:43:30 +02:00
|
|
|
const std::string & refspec,
|
|
|
|
bool shallow) = 0;
|
2023-11-09 17:48:41 +02: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 13:57:36 +02: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 19:55:08 +03:00
|
|
|
};
|
|
|
|
|
2024-02-15 22:58:08 +02:00
|
|
|
ref<GitRepo> getTarballCache();
|
|
|
|
|
2023-10-25 19:55:08 +03:00
|
|
|
}
|