Skip to content

Commit 6776832

Browse files
Merge pull request #96 from salesforce/build-fixes
Fix the existing repo update code path
2 parents 6040bd7 + 6221202 commit 6776832

File tree

8 files changed

+108
-106
lines changed

8 files changed

+108
-106
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,8 @@ Because of the extra effort the script performs, expect it to take orders of mag
138138
## Build
139139
140140
0. Pre-requisites
141-
* Install openssl (both 1.1.1 and 3 work)
141+
* Install zlib - `brew install zlib`
142+
* Install openssl (try 1.1.1, 3.x.x doesn't work with p4 API libs) - `brew install openssl@1.1`
142143
* Install CMake 3.16+.
143144
* Install g++ 11.2.0 (older versions compatible with C++11 are also supported).
144145
* Clone this repository or [get a release distribution](https://github.com/salesforce/p4-fusion/releases).

generate_cache.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ cmakeArgs=(
99
-DBUILD_SHARED_LIBS=OFF
1010
-DBUILD_CLAR=OFF
1111
-DBUILD_EXAMPLES=OFF
12-
-DUSE_BUNDLED_ZLIB=ON
12+
-DUSE_BUNDLED_ZLIB=OFF
1313
-DREGEX_BACKEND=builtin
1414
-DTHREADSAFE=ON
1515
-DUSE_SSH=OFF
1616
-DUSE_HTTPS=OFF
1717
-DUSE_THREADS=ON
18-
-DOPENSSL_ROOT_DIR=/usr/local/ssl
18+
-DOPENSSL_ROOT_DIR=/opt/homebrew/Cellar/openssl@1.1/1.1.1w
1919
-DCMAKE_C_COMPILER=/usr/bin/gcc
2020
-DCMAKE_CXX_COMPILER=/usr/bin/g++
2121
)

p4-fusion/commands/changes_result.cc

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
* SPDX-License-Identifier: BSD-3-Clause
55
* For full license text, see the LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
66
*/
7-
#include <algorithm>
87
#include "changes_result.h"
98

109
void ChangesResult::OutputStat(StrDict* varList)
@@ -15,8 +14,3 @@ void ChangesResult::OutputStat(StrDict* varList)
1514
varList->GetVar("user")->Text(),
1615
varList->GetVar("time")->Atoi64());
1716
}
18-
19-
void ChangesResult::reverse()
20-
{
21-
std::reverse(m_Changes.begin(), m_Changes.end());
22-
}

p4-fusion/commands/changes_result.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
#pragma once
88

99
#include <vector>
10+
1011
#include "common.h"
12+
1113
#include "change_list.h"
1214
#include "result.h"
1315

@@ -18,7 +20,6 @@ class ChangesResult : public Result
1820

1921
public:
2022
std::vector<ChangeList>& GetChanges() { return m_Changes; }
21-
void reverse();
2223

2324
void OutputStat(StrDict* varList) override;
2425
};

p4-fusion/git_api.cc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ std::string GitAPI::Commit(
263263
const std::string& user,
264264
const std::string& email,
265265
const int& timezone,
266-
const std::string& desc,
266+
std::string desc,
267267
const int64_t& timestamp,
268268
const std::string& mergeFromStream)
269269
{
@@ -278,6 +278,11 @@ std::string GitAPI::Commit(
278278
git_signature* author = nullptr;
279279
GIT2(git_signature_new(&author, user.c_str(), email.c_str(), timestamp, timezone));
280280

281+
STDHelpers::StripSurrounding(desc, '\n');
282+
STDHelpers::StripSurrounding(desc, '\r');
283+
STDHelpers::StripSurrounding(desc, ' ');
284+
STDHelpers::StripSurrounding(desc, '\t');
285+
281286
// -3 to remove the trailing "..."
282287
std::string commitMsg = cl + " - " + desc + "\n[p4-fusion: depot-paths = \"" + depotPath.substr(0, depotPath.size() - 3) + "\": change = " + cl + "]";
283288

p4-fusion/git_api.h

Lines changed: 54 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,54 @@
1-
/*
2-
* Copyright (c) 2022 Salesforce, Inc.
3-
* All rights reserved.
4-
* SPDX-License-Identifier: BSD-3-Clause
5-
* For full license text, see the LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
6-
*/
7-
#pragma once
8-
9-
#include <string>
10-
#include <vector>
11-
#include <utility>
12-
13-
#include "common.h"
14-
#include "git2/oid.h"
15-
16-
struct git_repository;
17-
18-
class GitAPI
19-
{
20-
git_repository* m_Repo = nullptr;
21-
git_index* m_Index = nullptr;
22-
git_oid m_FirstCommitOid;
23-
24-
std::string m_CurrentBranch = "";
25-
26-
public:
27-
GitAPI(bool fsyncEnable);
28-
~GitAPI();
29-
30-
bool InitializeRepository(const std::string& srcPath);
31-
void OpenRepository(const std::string& repoPath);
32-
33-
bool IsHEADExists();
34-
bool IsRepositoryClonedFrom(const std::string& depotPath);
35-
std::string DetectLatestCL();
36-
37-
git_oid CreateBlob(const std::vector<char>& data);
38-
39-
void CreateIndex();
40-
void SetActiveBranch(const std::string& branchName);
41-
void AddFileToIndex(const std::string& relativePath, const std::vector<char>& contents, const bool plusx);
42-
void RemoveFileFromIndex(const std::string& relativePath);
43-
44-
std::string Commit(
45-
const std::string& depotPath,
46-
const std::string& cl,
47-
const std::string& user,
48-
const std::string& email,
49-
const int& timezone,
50-
const std::string& desc,
51-
const int64_t& timestamp,
52-
const std::string& mergeFromStream);
53-
void CloseIndex();
54-
};
1+
/*
2+
* Copyright (c) 2022 Salesforce, Inc.
3+
* All rights reserved.
4+
* SPDX-License-Identifier: BSD-3-Clause
5+
* For full license text, see the LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
6+
*/
7+
#pragma once
8+
9+
#include <string>
10+
#include <vector>
11+
#include <utility>
12+
13+
#include "common.h"
14+
#include "git2/oid.h"
15+
16+
struct git_repository;
17+
18+
class GitAPI
19+
{
20+
git_repository* m_Repo = nullptr;
21+
git_index* m_Index = nullptr;
22+
git_oid m_FirstCommitOid;
23+
24+
std::string m_CurrentBranch = "";
25+
26+
public:
27+
GitAPI(bool fsyncEnable);
28+
~GitAPI();
29+
30+
bool InitializeRepository(const std::string& srcPath);
31+
void OpenRepository(const std::string& repoPath);
32+
33+
bool IsHEADExists();
34+
bool IsRepositoryClonedFrom(const std::string& depotPath);
35+
std::string DetectLatestCL();
36+
37+
git_oid CreateBlob(const std::vector<char>& data);
38+
39+
void CreateIndex();
40+
void SetActiveBranch(const std::string& branchName);
41+
void AddFileToIndex(const std::string& relativePath, const std::vector<char>& contents, const bool plusx);
42+
void RemoveFileFromIndex(const std::string& relativePath);
43+
44+
std::string Commit(
45+
const std::string& depotPath,
46+
const std::string& cl,
47+
const std::string& user,
48+
const std::string& email,
49+
const int& timezone,
50+
std::string desc,
51+
const int64_t& timestamp,
52+
const std::string& mergeFromStream);
53+
void CloseIndex();
54+
};

p4-fusion/main.cc

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -313,29 +313,30 @@ int Main(int argc, char** argv)
313313
ThreadPool::GetSingleton()->Initialize(networkThreads);
314314
SUCCESS("Created " << ThreadPool::GetSingleton()->GetThreadCount() << " threads in thread pool");
315315

316-
int startupDownloadsCount = 0;
317-
316+
318317
// Go in the chronological order
319318
size_t lastDownloadedCL = 0;
320319
for (size_t currentCL = 0; currentCL < changes.size() && currentCL < lookAhead; currentCL++)
321320
{
322321
ChangeList& cl = changes.at(currentCL);
323-
322+
324323
// Start gathering changed files with `p4 describe` or `p4 filelog`
325324
cl.PrepareDownload(branchSet);
326-
325+
327326
lastDownloadedCL = currentCL;
328327
}
329-
328+
330329
// This is intentionally put in a separate loop.
331330
// We want to submit `p4 describe` commands before sending any of the `p4 print` commands.
332331
// Gives ~15% perf boost.
332+
int startupDownloadsCount = 0;
333333
for (size_t currentCL = 0; currentCL <= lastDownloadedCL; currentCL++)
334334
{
335335
ChangeList& cl = changes.at(currentCL);
336336

337337
// Start running `p4 print` on changed files when the describe is finished
338338
cl.StartDownload(printBatch);
339+
startupDownloadsCount++;
339340
}
340341

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

p4-fusion/p4_api.cc

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -185,28 +185,29 @@ std::unique_ptr<TestResult> P4API::TestConnection(const int retries)
185185
std::unique_ptr<ChangesResult> P4API::ShortChanges(const std::string& path)
186186
{
187187
std::unique_ptr<ChangesResult> changes = Run<ChangesResult>("changes", {
188-
"-s", "submitted", // Only include submitted CLs
189-
path // Depot path to get CLs from
190-
});
191-
changes->reverse();
188+
"-r", // Get CLs from earliest to latest
189+
"-s", "submitted", // Only include submitted CLs
190+
path // Depot path to get CLs from
191+
});
192192
return changes;
193193
}
194194

195195
std::unique_ptr<ChangesResult> P4API::Changes(const std::string& path)
196196
{
197197
MTR_SCOPE("P4", __func__);
198198
return Run<ChangesResult>("changes", {
199-
"-l", // Get full descriptions instead of sending cut-short ones
200-
"-s", "submitted", // Only include submitted CLs
201-
path // Depot path to get CLs from
202-
});
199+
"-l", // Get full descriptions instead of sending cut-short ones
200+
"-s", "submitted", // Only include submitted CLs
201+
path // Depot path to get CLs from
202+
});
203203
}
204204

205205
std::unique_ptr<ChangesResult> P4API::Changes(const std::string& path, const std::string& from, int32_t maxCount)
206206
{
207207
std::vector<std::string> args = {
208208
"-l", // Get full descriptions instead of sending cut-short ones
209209
"-s", "submitted", // Only include submitted CLs
210+
"-r" // Send CLs in chronological order
210211
};
211212

212213
// This needs to be declared outside the if scope below to
@@ -233,55 +234,54 @@ std::unique_ptr<ChangesResult> P4API::Changes(const std::string& path, const std
233234
args.push_back(path + pathAddition);
234235

235236
std::unique_ptr<ChangesResult> result = Run<ChangesResult>("changes", args);
236-
result->reverse();
237237
return result;
238238
}
239239

240240
std::unique_ptr<ChangesResult> P4API::ChangesFromTo(const std::string& path, const std::string& from, const std::string& to)
241241
{
242242
std::string pathArg = path + "@" + from + "," + to;
243243
return Run<ChangesResult>("changes", {
244-
"-s", "submitted", // Only include submitted CLs
245-
pathArg // Depot path to get CLs from
246-
});
244+
"-s", "submitted", // Only include submitted CLs
245+
pathArg // Depot path to get CLs from
246+
});
247247
}
248248

249249
std::unique_ptr<ChangesResult> P4API::LatestChange(const std::string& path)
250250
{
251251
MTR_SCOPE("P4", __func__);
252252
return Run<ChangesResult>("changes", {
253-
"-s", "submitted", // Only include submitted CLs,
254-
"-m", "1", // Get top-most change
255-
path // Depot path to get CLs from
256-
});
253+
"-s", "submitted", // Only include submitted CLs,
254+
"-m", "1", // Get top-most change
255+
path // Depot path to get CLs from
256+
});
257257
}
258258

259259
std::unique_ptr<ChangesResult> P4API::OldestChange(const std::string& path)
260260
{
261261
std::unique_ptr<ChangesResult> changes = Run<ChangesResult>("changes", {
262-
"-s", "submitted", // Only include submitted CLs,
263-
"-m", "1", // Get top-most change
264-
path // Depot path to get CLs from
265-
});
266-
changes->reverse();
262+
"-r", // List from earliest to latest
263+
"-s", "submitted", // Only include submitted CLs,
264+
"-m", "1", // Get top-most change
265+
path // Depot path to get CLs from
266+
});
267267
return changes;
268268
}
269269

270270
std::unique_ptr<DescribeResult> P4API::Describe(const std::string& cl)
271271
{
272272
MTR_SCOPE("P4", __func__);
273273
return Run<DescribeResult>("describe", { "-s", // Omit the diffs
274-
cl });
274+
cl });
275275
}
276276

277277
std::unique_ptr<FileLogResult> P4API::FileLog(const std::string& changelist)
278278
{
279279
return Run<FileLogResult>("filelog", {
280-
"-c", // restrict output to a single changelist
281-
changelist,
282-
"-m1", // don't get the full history, just the first entry.
283-
"//..." // rather than require the path to be passed in, just list all files.
284-
});
280+
"-c", // restrict output to a single changelist
281+
changelist,
282+
"-m1", // don't get the full history, just the first entry.
283+
"//..." // rather than require the path to be passed in, just list all files.
284+
});
285285
}
286286

287287
std::unique_ptr<SizesResult> P4API::Size(const std::string& file)
@@ -298,16 +298,16 @@ std::unique_ptr<SyncResult> P4API::GetFilesToSyncAtCL(const std::string& path, c
298298
{
299299
std::string clCommand = "@" + cl;
300300
return Run<SyncResult>("sync", {
301-
"-n", // Only preview the files to sync. Don't send file contents...yet
302-
clCommand,
303-
});
301+
"-n", // Only preview the files to sync. Don't send file contents...yet
302+
clCommand,
303+
});
304304
}
305305

306306
std::unique_ptr<PrintResult> P4API::PrintFile(const std::string& filePathRevision)
307307
{
308308
return Run<PrintResult>("print", {
309-
filePathRevision,
310-
});
309+
filePathRevision,
310+
});
311311
}
312312

313313
std::unique_ptr<PrintResult> P4API::PrintFiles(const std::vector<std::string>& fileRevisions)
@@ -325,15 +325,15 @@ std::unique_ptr<PrintResult> P4API::PrintFiles(const std::vector<std::string>& f
325325
std::unique_ptr<Result> P4API::Sync(const std::string& path)
326326
{
327327
return Run<Result>("sync", {
328-
path // Sync a particular depot path
329-
});
328+
path // Sync a particular depot path
329+
});
330330
}
331331

332332
std::unique_ptr<UsersResult> P4API::Users()
333333
{
334334
return Run<UsersResult>("users", {
335-
"-a" // Include service accounts
336-
});
335+
"-a" // Include service accounts
336+
});
337337
}
338338

339339
std::unique_ptr<InfoResult> P4API::Info()

0 commit comments

Comments
 (0)