|
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 <array> |
12 | | -#include <memory> |
13 | | -#include <stdexcept> |
14 | | - |
15 | | -#include "commands/file_map.h" |
16 | | -#include "commands/file_data.h" |
17 | | -#include "utils/std_helpers.h" |
18 | | - |
19 | | -struct BranchedFileGroup |
20 | | -{ |
21 | | - // If a BranchedFiles collection hasSource == true, |
22 | | - // then all files in this collection MUST be a merge |
23 | | - // from the given source branch to the target branch. |
24 | | - // These branch names will be the Git branch names. |
25 | | - std::string sourceBranch; |
26 | | - std::string targetBranch; |
27 | | - bool hasSource; |
28 | | - std::vector<FileData> files; |
29 | | - |
30 | | - // Get all the relative file names from each of the file data. |
31 | | - std::vector<std::string> GetRelativeFileNames(); |
32 | | -}; |
33 | | - |
34 | | -struct ChangedFileGroups |
35 | | -{ |
36 | | -private: |
37 | | - ChangedFileGroups(); |
38 | | - |
39 | | -public: |
40 | | - std::vector<BranchedFileGroup> branchedFileGroups; |
41 | | - int totalFileCount; |
42 | | - |
43 | | - // When all the file groups have finished being used, |
44 | | - // only then can we safely clear out the data. |
45 | | - void Clear(); |
46 | | - |
47 | | - ChangedFileGroups(std::vector<BranchedFileGroup>& groups, int totalFileCount); |
48 | | - |
49 | | - static std::unique_ptr<ChangedFileGroups> Empty() { return std::unique_ptr<ChangedFileGroups>(new ChangedFileGroups); }; |
50 | | -}; |
51 | | - |
52 | | -struct Branch |
53 | | -{ |
54 | | -public: |
55 | | - const std::string depotBranchPath; |
56 | | - const std::string gitAlias; |
57 | | - |
58 | | - Branch(const std::string& branch, const std::string& alias); |
59 | | - |
60 | | - // splitBranchPath If the relativeDepotPath matches, returns {branch alias, branch file path}. |
61 | | - // Otherwise, returns {"", ""} |
62 | | - std::array<std::string, 2> SplitBranchPath(const std::string& relativeDepotPath) const; |
63 | | -}; |
64 | | - |
65 | | -// A singular view on the branches and a base view (acts as a filter to trim down affected files). |
66 | | -// Maps a changed file state to a list of resulting branches and affected files. |
67 | | -struct BranchSet |
68 | | -{ |
69 | | -private: |
70 | | - // Technically, these should all be const. |
71 | | - const bool m_includeBinaries; |
72 | | - std::string m_basePath; |
73 | | - const std::vector<Branch> m_branches; |
74 | | - FileMap m_view; |
75 | | - |
76 | | - // stripBasePath remove the base path from the depot path, or "" if not in the base path. |
77 | | - std::string stripBasePath(const std::string& depotPath) const; |
78 | | - |
79 | | - // splitBranchPath extract the branch name and path under the branch (no leading '/' on the path) |
80 | | - // relativeDepotPath - already stripped from running stripBasePath. |
81 | | - std::array<std::string, 2> splitBranchPath(const std::string& relativeDepotPath) const; |
82 | | - |
83 | | -public: |
84 | | - BranchSet(std::vector<std::string>& clientViewMapping, const std::string& baseDepotPath, const std::vector<std::string>& branches, const bool includeBinaries); |
85 | | - |
86 | | - // HasMergeableBranch is there a branch model that requires integration history? |
87 | | - bool HasMergeableBranch() const { return !m_branches.empty(); }; |
88 | | - |
89 | | - int Count() const { return m_branches.size(); }; |
90 | | - |
91 | | - // ParseAffectedFiles create collections of merges and commits. |
92 | | - // Breaks up the files into those that are within the view, with each item in the |
93 | | - // list is its own target Git branch. |
94 | | - // This also has the side-effect of populating the relative path value in the file data. |
95 | | - // ... the FileData object is copied, but it's underlying shared data is shared. So, this |
96 | | - // breaks the const. |
97 | | - std::unique_ptr<ChangedFileGroups> ParseAffectedFiles(const std::vector<FileData>& cl) const; |
98 | | -}; |
| 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 <array> |
| 12 | +#include <memory> |
| 13 | +#include <stdexcept> |
| 14 | + |
| 15 | +#include "commands/file_map.h" |
| 16 | +#include "commands/file_data.h" |
| 17 | +#include "commands/stream_result.h" |
| 18 | +#include "utils/std_helpers.h" |
| 19 | + |
| 20 | +struct BranchedFileGroup |
| 21 | +{ |
| 22 | + // If a BranchedFiles collection hasSource == true, |
| 23 | + // then all files in this collection MUST be a merge |
| 24 | + // from the given source branch to the target branch. |
| 25 | + // These branch names will be the Git branch names. |
| 26 | + std::string sourceBranch; |
| 27 | + std::string targetBranch; |
| 28 | + bool hasSource; |
| 29 | + std::vector<FileData> files; |
| 30 | + |
| 31 | + // Get all the relative file names from each of the file data. |
| 32 | + std::vector<std::string> GetRelativeFileNames(); |
| 33 | +}; |
| 34 | + |
| 35 | +struct ChangedFileGroups |
| 36 | +{ |
| 37 | +private: |
| 38 | + ChangedFileGroups(); |
| 39 | + |
| 40 | +public: |
| 41 | + std::vector<BranchedFileGroup> branchedFileGroups; |
| 42 | + int totalFileCount; |
| 43 | + |
| 44 | + // When all the file groups have finished being used, |
| 45 | + // only then can we safely clear out the data. |
| 46 | + void Clear(); |
| 47 | + |
| 48 | + ChangedFileGroups(std::vector<BranchedFileGroup>& groups, int totalFileCount); |
| 49 | + |
| 50 | + static std::unique_ptr<ChangedFileGroups> Empty() { return std::unique_ptr<ChangedFileGroups>(new ChangedFileGroups); }; |
| 51 | +}; |
| 52 | + |
| 53 | +struct Branch |
| 54 | +{ |
| 55 | +public: |
| 56 | + const std::string depotBranchPath; |
| 57 | + const std::string gitAlias; |
| 58 | + |
| 59 | + Branch(const std::string& branch, const std::string& alias); |
| 60 | + |
| 61 | + // splitBranchPath If the relativeDepotPath matches, returns {branch alias, branch file path}. |
| 62 | + // Otherwise, returns {"", ""} |
| 63 | + std::array<std::string, 2> SplitBranchPath(const std::string& relativeDepotPath) const; |
| 64 | +}; |
| 65 | + |
| 66 | +// A singular view on the branches and a base view (acts as a filter to trim down affected files). |
| 67 | +// Maps a changed file state to a list of resulting branches and affected files. |
| 68 | +struct BranchSet |
| 69 | +{ |
| 70 | +private: |
| 71 | + // Technically, these should all be const. |
| 72 | + const bool m_includeBinaries; |
| 73 | + std::string m_basePath; |
| 74 | + const std::vector<Branch> m_branches; |
| 75 | + const std::vector<StreamResult::MappingData> m_mappings; |
| 76 | + const std::vector<StreamResult::MappingData> m_exclusions; |
| 77 | + FileMap m_view; |
| 78 | + |
| 79 | + // stripBasePath remove the base path from the depot path, or "" if not in the base path. |
| 80 | + std::string stripBasePath(const std::string& depotPath) const; |
| 81 | + |
| 82 | + // splitBranchPath extract the branch name and path under the branch (no leading '/' on the path) |
| 83 | + // relativeDepotPath - already stripped from running stripBasePath. |
| 84 | + std::array<std::string, 2> splitBranchPath(const std::string& relativeDepotPath) const; |
| 85 | + |
| 86 | +public: |
| 87 | + BranchSet(std::vector<std::string>& clientViewMapping, const std::string& baseDepotPath, const std::vector<std::string>& branches, const std::vector<StreamResult::MappingData>& mappings, const std::vector<StreamResult::MappingData>& exclusions, const bool includeBinaries); |
| 88 | + |
| 89 | + // HasMergeableBranch is there a branch model that requires integration history? |
| 90 | + bool HasMergeableBranch() const { return !m_branches.empty(); }; |
| 91 | + |
| 92 | + int Count() const { return m_branches.size(); }; |
| 93 | + |
| 94 | + // ParseAffectedFiles create collections of merges and commits. |
| 95 | + // Breaks up the files into those that are within the view, with each item in the |
| 96 | + // list is its own target Git branch. |
| 97 | + // This also has the side-effect of populating the relative path value in the file data. |
| 98 | + // ... the FileData object is copied, but it's underlying shared data is shared. So, this |
| 99 | + // breaks the const. |
| 100 | + std::unique_ptr<ChangedFileGroups> ParseAffectedFiles(const std::vector<FileData>& cl) const; |
| 101 | +}; |
0 commit comments