Skip to content

Commit 17f5d70

Browse files
sstepashkaDmitrii Kuragin
authored andcommitted
Disable copying on ClientUser subclasses.
1 parent 24daa7c commit 17f5d70

File tree

5 files changed

+79
-69
lines changed

5 files changed

+79
-69
lines changed

p4-fusion/commands/change_list.cc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,14 @@ void ChangeList::PrepareDownload(const BranchSet& branchSet)
4242
// copy will have the target files listing the from-file with
4343
// different changelists than the point-in-time source branch's
4444
// changelist.
45-
const FileLogResult& filelog = p4->FileLog(cl.number);
46-
cl.changedFileGroups = branchSet.ParseAffectedFiles(filelog.GetFileData());
45+
std::unique_ptr<FileLogResult> filelog = p4->FileLog(cl.number);
46+
cl.changedFileGroups = branchSet.ParseAffectedFiles(filelog->GetFileData());
4747
}
4848
else
4949
{
5050
// If we don't care about branches, then p4->Describe is much faster.
51-
const DescribeResult& describe = p4->Describe(cl.number);
52-
cl.changedFileGroups = branchSet.ParseAffectedFiles(describe.GetFileData());
51+
std::unique_ptr<DescribeResult> describe = p4->Describe(cl.number);
52+
cl.changedFileGroups = branchSet.ParseAffectedFiles(describe->GetFileData());
5353
}
5454

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

123123
for (int i = 0; i < printBatchFiles->size(); i++)
124124
{
125-
printBatchFileData->at(i)->MoveContentsOnceFrom(printData.GetPrintData().at(i).contents);
125+
printBatchFileData->at(i)->MoveContentsOnceFrom(printData->GetPrintData().at(i).contents);
126126
}
127127
}
128128

p4-fusion/commands/result.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,15 @@ class Result : public ClientUser
1313
Error m_Error;
1414

1515
public:
16+
Result() = default;
17+
1618
void HandleError(Error* e) override;
1719

1820
const Error& GetError() const { return m_Error; }
21+
22+
Result(const Result&) = delete;
23+
Result& operator=(const Result&) = delete;
24+
25+
Result(Result&&) = delete;
26+
Result& operator=(Result&&) = delete;
1927
};

p4-fusion/main.cc

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ int Main(int argc, char** argv)
9090
P4API::P4PORT = Arguments::GetSingleton()->GetPort();
9191
P4API::P4USER = Arguments::GetSingleton()->GetUsername();
9292

93-
const Error serviceConnectionResult = P4API().TestConnection(5).GetError();
93+
const Error serviceConnectionResult = P4API().TestConnection(5)->GetError();
9494
bool serverAvailable = serviceConnectionResult.IsError() == 0;
9595
if (serverAvailable)
9696
{
@@ -102,7 +102,7 @@ int Main(int argc, char** argv)
102102
return 1;
103103
}
104104
P4API::P4CLIENT = Arguments::GetSingleton()->GetClient();
105-
P4API::ClientSpec = P4API().Client().GetClientSpec();
105+
P4API::ClientSpec = P4API().Client()->GetClientSpec();
106106

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

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

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

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

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

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

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

350350
// Commit procedure start

p4-fusion/p4_api.cc

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "p4_api.h"
88

99
#include <csignal>
10+
#include <memory>
1011

1112
#include "commands/stream_result.h"
1213
#include "utils/std_helpers.h"
@@ -166,32 +167,32 @@ void P4API::UpdateClientSpec()
166167
Run<Result>("client", {});
167168
}
168169

169-
ClientResult P4API::Client()
170+
std::unique_ptr<ClientResult> P4API::Client()
170171
{
171172
return Run<ClientResult>("client", { "-o" });
172173
}
173174

174-
StreamResult P4API::Stream(const std::string& path)
175+
std::unique_ptr<StreamResult> P4API::Stream(const std::string& path)
175176
{
176177
return Run<StreamResult>("stream", { "-o", path });
177178
}
178179

179-
TestResult P4API::TestConnection(const int retries)
180+
std::unique_ptr<TestResult> P4API::TestConnection(const int retries)
180181
{
181182
return RunEx<TestResult>("changes", { "-m", "1", "//..." }, retries);
182183
}
183184

184-
ChangesResult P4API::ShortChanges(const std::string& path)
185+
std::unique_ptr<ChangesResult> P4API::ShortChanges(const std::string& path)
185186
{
186-
ChangesResult changes = Run<ChangesResult>("changes", {
187+
std::unique_ptr<ChangesResult> changes = Run<ChangesResult>("changes", {
187188
"-s", "submitted", // Only include submitted CLs
188189
path // Depot path to get CLs from
189190
});
190-
changes.reverse();
191+
changes->reverse();
191192
return changes;
192193
}
193194

194-
ChangesResult P4API::Changes(const std::string& path)
195+
std::unique_ptr<ChangesResult> P4API::Changes(const std::string& path)
195196
{
196197
MTR_SCOPE("P4", __func__);
197198
return Run<ChangesResult>("changes", {
@@ -201,7 +202,7 @@ ChangesResult P4API::Changes(const std::string& path)
201202
});
202203
}
203204

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

232233
args.push_back(path + pathAddition);
233234

234-
ChangesResult result = Run<ChangesResult>("changes", args);
235-
result.reverse();
235+
std::unique_ptr<ChangesResult> result = Run<ChangesResult>("changes", args);
236+
result->reverse();
236237
return result;
237238
}
238239

239-
ChangesResult P4API::ChangesFromTo(const std::string& path, const std::string& from, const std::string& to)
240+
std::unique_ptr<ChangesResult> P4API::ChangesFromTo(const std::string& path, const std::string& from, const std::string& to)
240241
{
241242
std::string pathArg = path + "@" + from + "," + to;
242243
return Run<ChangesResult>("changes", {
@@ -245,7 +246,7 @@ ChangesResult P4API::ChangesFromTo(const std::string& path, const std::string& f
245246
});
246247
}
247248

248-
ChangesResult P4API::LatestChange(const std::string& path)
249+
std::unique_ptr<ChangesResult> P4API::LatestChange(const std::string& path)
249250
{
250251
MTR_SCOPE("P4", __func__);
251252
return Run<ChangesResult>("changes", {
@@ -255,25 +256,25 @@ ChangesResult P4API::LatestChange(const std::string& path)
255256
});
256257
}
257258

258-
ChangesResult P4API::OldestChange(const std::string& path)
259+
std::unique_ptr<ChangesResult> P4API::OldestChange(const std::string& path)
259260
{
260-
ChangesResult changes = Run<ChangesResult>("changes", {
261+
std::unique_ptr<ChangesResult> changes = Run<ChangesResult>("changes", {
261262
"-s", "submitted", // Only include submitted CLs,
262263
"-m", "1", // Get top-most change
263264
path // Depot path to get CLs from
264265
});
265-
changes.reverse();
266+
changes->reverse();
266267
return changes;
267268
}
268269

269-
DescribeResult P4API::Describe(const std::string& cl)
270+
std::unique_ptr<DescribeResult> P4API::Describe(const std::string& cl)
270271
{
271272
MTR_SCOPE("P4", __func__);
272273
return Run<DescribeResult>("describe", { "-s", // Omit the diffs
273274
cl });
274275
}
275276

276-
FileLogResult P4API::FileLog(const std::string& changelist)
277+
std::unique_ptr<FileLogResult> P4API::FileLog(const std::string& changelist)
277278
{
278279
return Run<FileLogResult>("filelog", {
279280
"-c", // restrict output to a single changelist
@@ -283,17 +284,17 @@ FileLogResult P4API::FileLog(const std::string& changelist)
283284
});
284285
}
285286

286-
SizesResult P4API::Size(const std::string& file)
287+
std::unique_ptr<SizesResult> P4API::Size(const std::string& file)
287288
{
288289
return Run<SizesResult>("sizes", { "-a", "-s", file });
289290
}
290291

291-
Result P4API::Sync()
292+
std::unique_ptr<Result> P4API::Sync()
292293
{
293294
return Run<Result>("sync", {});
294295
}
295296

296-
SyncResult P4API::GetFilesToSyncAtCL(const std::string& path, const std::string& cl)
297+
std::unique_ptr<SyncResult> P4API::GetFilesToSyncAtCL(const std::string& path, const std::string& cl)
297298
{
298299
std::string clCommand = "@" + cl;
299300
return Run<SyncResult>("sync", {
@@ -302,40 +303,40 @@ SyncResult P4API::GetFilesToSyncAtCL(const std::string& path, const std::string&
302303
});
303304
}
304305

305-
PrintResult P4API::PrintFile(const std::string& filePathRevision)
306+
std::unique_ptr<PrintResult> P4API::PrintFile(const std::string& filePathRevision)
306307
{
307308
return Run<PrintResult>("print", {
308309
filePathRevision,
309310
});
310311
}
311312

312-
PrintResult P4API::PrintFiles(const std::vector<std::string>& fileRevisions)
313+
std::unique_ptr<PrintResult> P4API::PrintFiles(const std::vector<std::string>& fileRevisions)
313314
{
314315
MTR_SCOPE("P4", __func__);
315316

316317
if (fileRevisions.empty())
317318
{
318-
return PrintResult();
319+
return std::unique_ptr<PrintResult>(new PrintResult());
319320
}
320321

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

324-
Result P4API::Sync(const std::string& path)
325+
std::unique_ptr<Result> P4API::Sync(const std::string& path)
325326
{
326327
return Run<Result>("sync", {
327328
path // Sync a particular depot path
328329
});
329330
}
330331

331-
UsersResult P4API::Users()
332+
std::unique_ptr<UsersResult> P4API::Users()
332333
{
333334
return Run<UsersResult>("users", {
334335
"-a" // Include service accounts
335336
});
336337
}
337338

338-
InfoResult P4API::Info()
339+
std::unique_ptr<InfoResult> P4API::Info()
339340
{
340341
return Run<InfoResult>("info", {});
341342
}

0 commit comments

Comments
 (0)