Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions p4-fusion/commands/change_list.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ void ChangeList::PrepareDownload(const BranchSet& branchSet)
// copy will have the target files listing the from-file with
// different changelists than the point-in-time source branch's
// changelist.
const FileLogResult& filelog = p4->FileLog(cl.number);
cl.changedFileGroups = branchSet.ParseAffectedFiles(filelog.GetFileData());
std::unique_ptr<FileLogResult> filelog = p4->FileLog(cl.number);
cl.changedFileGroups = branchSet.ParseAffectedFiles(filelog->GetFileData());
}
else
{
// If we don't care about branches, then p4->Describe is much faster.
const DescribeResult& describe = p4->Describe(cl.number);
cl.changedFileGroups = branchSet.ParseAffectedFiles(describe.GetFileData());
std::unique_ptr<DescribeResult> describe = p4->Describe(cl.number);
cl.changedFileGroups = branchSet.ParseAffectedFiles(describe->GetFileData());
}

std::unique_lock<std::mutex> lock(*cl.stateMutex);
Expand Down Expand Up @@ -118,11 +118,11 @@ void ChangeList::Flush(std::shared_ptr<std::vector<std::string>> printBatchFiles
// Only perform the batch processing when there are files to process.
if (!printBatchFileData->empty())
{
const PrintResult& printData = p4->PrintFiles(*printBatchFiles);
std::unique_ptr<PrintResult> printData = p4->PrintFiles(*printBatchFiles);

for (int i = 0; i < printBatchFiles->size(); i++)
{
printBatchFileData->at(i)->MoveContentsOnceFrom(printData.GetPrintData().at(i).contents);
printBatchFileData->at(i)->MoveContentsOnceFrom(printData->GetPrintData().at(i).contents);
}
}

Expand Down
8 changes: 8 additions & 0 deletions p4-fusion/commands/result.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,15 @@ class Result : public ClientUser
Error m_Error;

public:
Result() = default;

void HandleError(Error* e) override;

const Error& GetError() const { return m_Error; }

Result(const Result&) = delete;
Result& operator=(const Result&) = delete;

Result(Result&&) = delete;
Result& operator=(Result&&) = delete;
};
13 changes: 13 additions & 0 deletions p4-fusion/git_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,20 @@
GitAPI::GitAPI(bool fsyncEnable)
{
git_libgit2_init();

GIT2(git_libgit2_opts(GIT_OPT_ENABLE_FSYNC_GITDIR, (int)fsyncEnable));

// Since we trust the hard-drive and operating system, we can skip the verification.
GIT2(git_libgit2_opts(GIT_OPT_ENABLE_STRICT_HASH_VERIFICATION, (int)0));

// Global RAM cache: 1gb...
GIT2(git_libgit2_opts(GIT_OPT_SET_CACHE_MAX_SIZE, (ssize_t)(1024 * 1024 * 1024)));

// 20Mb for the file name tree cache...
GIT2(git_libgit2_opts(GIT_OPT_SET_CACHE_OBJECT_LIMIT, GIT_OBJECT_TREE, (size_t)(20 * 1024 * 1024)));

// 20Mb for commit info cache...
GIT2(git_libgit2_opts(GIT_OPT_SET_CACHE_OBJECT_LIMIT, GIT_OBJECT_COMMIT, (size_t)(20 * 1024 * 1024)));
}

GitAPI::~GitAPI()
Expand Down
16 changes: 8 additions & 8 deletions p4-fusion/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ int Main(int argc, char** argv)
P4API::P4PORT = Arguments::GetSingleton()->GetPort();
P4API::P4USER = Arguments::GetSingleton()->GetUsername();

const Error& serviceConnectionResult = P4API().TestConnection(5).GetError();
const Error serviceConnectionResult = P4API().TestConnection(5)->GetError();
bool serverAvailable = serviceConnectionResult.IsError() == 0;
if (serverAvailable)
{
Expand All @@ -102,7 +102,7 @@ int Main(int argc, char** argv)
return 1;
}
P4API::P4CLIENT = Arguments::GetSingleton()->GetClient();
P4API::ClientSpec = P4API().Client().GetClientSpec();
P4API::ClientSpec = P4API().Client()->GetClientSpec();

if (P4API::ClientSpec.mapping.empty())
{
Expand Down Expand Up @@ -169,7 +169,7 @@ int Main(int argc, char** argv)
auto tempStr = depotPath.substr(0, depotPath.size() - 4);
auto val = p4.Stream(tempStr);
// First we get the shallow imports.
for (auto const& v : val.GetStreamSpec().mapping)
for (auto const& v : val->GetStreamSpec().mapping)
{
// We don't need stream isolate or share, so we don't check them
if (v.rule == StreamResult::EStreamImport)
Expand All @@ -196,7 +196,7 @@ int Main(int argc, char** argv)
// A path isn't nessecarily a fully qualified stream in itself but p4 stream works with arbitrary paths
auto streamName = mappings[idx].stream2.substr(0, mappings[idx].stream2.size() - 4);
auto subStream = p4.Stream(streamName);
for (auto& v : subStream.GetStreamSpec().mapping)
for (auto& v : subStream->GetStreamSpec().mapping)
{
// According to the perforce rules, exclude should not be propagated outside the parent stream
// The only rules we need to care about are import and exclude.
Expand Down Expand Up @@ -279,14 +279,14 @@ int Main(int argc, char** argv)

PRINT("Requesting changelists to convert from the Perforce server");

std::vector<ChangeList> changes = std::move(p4.Changes(depotPath, resumeFromCL, maxChanges).GetChanges());
std::vector<ChangeList> changes = std::move(p4.Changes(depotPath, resumeFromCL, maxChanges)->GetChanges());

if (streamMappings)
{
PRINT("Path: " << depotPath << " has " << changes.size() << " changes!");
for (auto const& mapped : mappings)
{
std::vector<ChangeList> temp = std::move(p4.Changes(mapped.stream2, resumeFromCL, maxChanges).GetChanges());
std::vector<ChangeList> temp = std::move(p4.Changes(mapped.stream2, resumeFromCL, maxChanges)->GetChanges());
PRINT("Path: " << mapped.stream2 << " has " << temp.size() << " changes!");
changes.insert(changes.end(), std::make_move_iterator(temp.begin()), std::make_move_iterator(temp.end()));
}
Expand Down Expand Up @@ -340,11 +340,11 @@ int Main(int argc, char** argv)

SUCCESS("Queued first " << startupDownloadsCount << " CLs up until CL " << changes.at(lastDownloadedCL).number << " for downloading");

int timezoneMinutes = p4.Info().GetServerTimezoneMinutes();
int timezoneMinutes = p4.Info()->GetServerTimezoneMinutes();
SUCCESS("Perforce server timezone is " << timezoneMinutes << " minutes");

// Map usernames to emails
const std::unordered_map<UsersResult::UserID, UsersResult::UserData> users = std::move(p4.Users().GetUserEmails());
const std::unordered_map<UsersResult::UserID, UsersResult::UserData> users = std::move(p4.Users()->GetUserEmails());
SUCCESS("Received userbase details from the Perforce server");

// Commit procedure start
Expand Down
53 changes: 27 additions & 26 deletions p4-fusion/p4_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "p4_api.h"

#include <csignal>
#include <memory>

#include "commands/stream_result.h"
#include "utils/std_helpers.h"
Expand Down Expand Up @@ -166,32 +167,32 @@ void P4API::UpdateClientSpec()
Run<Result>("client", {});
}

ClientResult P4API::Client()
std::unique_ptr<ClientResult> P4API::Client()
{
return Run<ClientResult>("client", { "-o" });
}

StreamResult P4API::Stream(const std::string& path)
std::unique_ptr<StreamResult> P4API::Stream(const std::string& path)
{
return Run<StreamResult>("stream", { "-o", path });
}

TestResult P4API::TestConnection(const int retries)
std::unique_ptr<TestResult> P4API::TestConnection(const int retries)
{
return RunEx<TestResult>("changes", { "-m", "1", "//..." }, retries);
}

ChangesResult P4API::ShortChanges(const std::string& path)
std::unique_ptr<ChangesResult> P4API::ShortChanges(const std::string& path)
{
ChangesResult changes = Run<ChangesResult>("changes", {
std::unique_ptr<ChangesResult> changes = Run<ChangesResult>("changes", {
"-s", "submitted", // Only include submitted CLs
path // Depot path to get CLs from
});
changes.reverse();
changes->reverse();
return changes;
}

ChangesResult P4API::Changes(const std::string& path)
std::unique_ptr<ChangesResult> P4API::Changes(const std::string& path)
{
MTR_SCOPE("P4", __func__);
return Run<ChangesResult>("changes", {
Expand All @@ -201,7 +202,7 @@ ChangesResult P4API::Changes(const std::string& path)
});
}

ChangesResult P4API::Changes(const std::string& path, const std::string& from, int32_t maxCount)
std::unique_ptr<ChangesResult> P4API::Changes(const std::string& path, const std::string& from, int32_t maxCount)
{
std::vector<std::string> args = {
"-l", // Get full descriptions instead of sending cut-short ones
Expand Down Expand Up @@ -231,12 +232,12 @@ ChangesResult P4API::Changes(const std::string& path, const std::string& from, i

args.push_back(path + pathAddition);

ChangesResult result = Run<ChangesResult>("changes", args);
result.reverse();
std::unique_ptr<ChangesResult> result = Run<ChangesResult>("changes", args);
result->reverse();
return result;
}

ChangesResult P4API::ChangesFromTo(const std::string& path, const std::string& from, const std::string& to)
std::unique_ptr<ChangesResult> P4API::ChangesFromTo(const std::string& path, const std::string& from, const std::string& to)
{
std::string pathArg = path + "@" + from + "," + to;
return Run<ChangesResult>("changes", {
Expand All @@ -245,7 +246,7 @@ ChangesResult P4API::ChangesFromTo(const std::string& path, const std::string& f
});
}

ChangesResult P4API::LatestChange(const std::string& path)
std::unique_ptr<ChangesResult> P4API::LatestChange(const std::string& path)
{
MTR_SCOPE("P4", __func__);
return Run<ChangesResult>("changes", {
Expand All @@ -255,25 +256,25 @@ ChangesResult P4API::LatestChange(const std::string& path)
});
}

ChangesResult P4API::OldestChange(const std::string& path)
std::unique_ptr<ChangesResult> P4API::OldestChange(const std::string& path)
{
ChangesResult changes = Run<ChangesResult>("changes", {
std::unique_ptr<ChangesResult> changes = Run<ChangesResult>("changes", {
"-s", "submitted", // Only include submitted CLs,
"-m", "1", // Get top-most change
path // Depot path to get CLs from
});
changes.reverse();
changes->reverse();
return changes;
}

DescribeResult P4API::Describe(const std::string& cl)
std::unique_ptr<DescribeResult> P4API::Describe(const std::string& cl)
{
MTR_SCOPE("P4", __func__);
return Run<DescribeResult>("describe", { "-s", // Omit the diffs
cl });
}

FileLogResult P4API::FileLog(const std::string& changelist)
std::unique_ptr<FileLogResult> P4API::FileLog(const std::string& changelist)
{
return Run<FileLogResult>("filelog", {
"-c", // restrict output to a single changelist
Expand All @@ -283,17 +284,17 @@ FileLogResult P4API::FileLog(const std::string& changelist)
});
}

SizesResult P4API::Size(const std::string& file)
std::unique_ptr<SizesResult> P4API::Size(const std::string& file)
{
return Run<SizesResult>("sizes", { "-a", "-s", file });
}

Result P4API::Sync()
std::unique_ptr<Result> P4API::Sync()
{
return Run<Result>("sync", {});
}

SyncResult P4API::GetFilesToSyncAtCL(const std::string& path, const std::string& cl)
std::unique_ptr<SyncResult> P4API::GetFilesToSyncAtCL(const std::string& path, const std::string& cl)
{
std::string clCommand = "@" + cl;
return Run<SyncResult>("sync", {
Expand All @@ -302,40 +303,40 @@ SyncResult P4API::GetFilesToSyncAtCL(const std::string& path, const std::string&
});
}

PrintResult P4API::PrintFile(const std::string& filePathRevision)
std::unique_ptr<PrintResult> P4API::PrintFile(const std::string& filePathRevision)
{
return Run<PrintResult>("print", {
filePathRevision,
});
}

PrintResult P4API::PrintFiles(const std::vector<std::string>& fileRevisions)
std::unique_ptr<PrintResult> P4API::PrintFiles(const std::vector<std::string>& fileRevisions)
{
MTR_SCOPE("P4", __func__);

if (fileRevisions.empty())
{
return PrintResult();
return std::unique_ptr<PrintResult>(new PrintResult());
}

return Run<PrintResult>("print", fileRevisions);
}

Result P4API::Sync(const std::string& path)
std::unique_ptr<Result> P4API::Sync(const std::string& path)
{
return Run<Result>("sync", {
path // Sync a particular depot path
});
}

UsersResult P4API::Users()
std::unique_ptr<UsersResult> P4API::Users()
{
return Run<UsersResult>("users", {
"-a" // Include service accounts
});
}

InfoResult P4API::Info()
std::unique_ptr<InfoResult> P4API::Info()
{
return Run<InfoResult>("info", {});
}
Loading
Loading