@@ -50,19 +50,15 @@ Branch::Branch(const std::string& branch, const std::string& alias)
5050 }
5151}
5252
53- std::array<std::string, 2 > Branch::SplitBranchPath (const std::string& relativeDepotPath) const
53+ bool Branch::IsInBranch (const std::string& relativeDepotPath) const
5454{
55- if (
55+ return
5656 // The relative depot branch, to match this branch path, must start with the
5757 // branch path + "/". The "StartsWith" is put at the end of the 'and' checks,
5858 // because it takes the longest.
5959 relativeDepotPath.size () > depotBranchPath.size ()
6060 && relativeDepotPath[depotBranchPath.size ()] == ' /'
61- && STDHelpers::StartsWith (relativeDepotPath, depotBranchPath))
62- {
63- return { gitAlias, relativeDepotPath.substr (depotBranchPath.size () + 1 ) };
64- }
65- return { " " , " " };
61+ && STDHelpers::StartsWith (relativeDepotPath, depotBranchPath);
6662}
6763
6864Branch createBranchFromPath (const std::string& depotBranchPath)
@@ -140,23 +136,22 @@ BranchSet::BranchSet(GitAPI& gitAPI,
140136 }
141137}
142138
143- std::array<std::string, 2 > BranchSet::splitBranchPath (const std::string& relativeDepotPath) const
139+ const Branch* BranchSet::getBranchFor (const std::string& relativeDepotPath) const
144140{
145141 // Check if the relative depot path starts with any of the branches.
146142 // This checks the branches in their stored order, which can mean that having a branch
147143 // order like "//a/b/c" and "//a/b" will only work if the sub-branches are listed first.
148144 // To do this properly, the stored branches should be scanned based on their length - longest
149145 // first, but that's extra processing and code for a use case that is rare and has a manual
150146 // work around (list branches in a specific order).
151- for (auto & branch : m_branches)
147+ for (const Branch & branch : m_branches)
152148 {
153- auto split = branch.SplitBranchPath (relativeDepotPath);
154- if (!split[0 ].empty () && !split[1 ].empty ())
149+ if (branch.IsInBranch (relativeDepotPath))
155150 {
156- return split ;
151+ return &branch ;
157152 }
158153 }
159- return { " " , " " } ;
154+ return nullptr ;
160155}
161156
162157bool BranchSet::matchesExcludes (const std::string& depotPath) const
@@ -187,19 +182,19 @@ struct branchIntegrationMap
187182 std::unordered_map<std::string, int > branchIndicies;
188183 int fileCount = 0 ;
189184
190- void addMerge (const std::string& sourceBranch, const std::string& targetBranch, const FileData& rev);
191- void addTarget (const std::string& targetBranch, const FileData& rev);
185+ void addMerge (const std::string& sourceBranch, const std::string& targetBranch, const std::string& depotBranchPath, const FileData& rev);
186+ void addTarget (const std::string& targetBranch, const std::string& depotBranchPath, const FileData& rev);
192187
193188 // note: not const, because it cleans out the branchGroups.
194189 std::unique_ptr<ChangedFileGroups> createChangedFileGroups () { return std::unique_ptr<ChangedFileGroups>(new ChangedFileGroups (branchGroups, fileCount)); };
195190};
196191
197- void branchIntegrationMap::addTarget (const std::string& targetBranch, const FileData& fileData)
192+ void branchIntegrationMap::addTarget (const std::string& targetBranch, const std::string& depotBranchPath, const FileData& fileData)
198193{
199- addMerge (EMPTY_STRING, targetBranch, fileData);
194+ addMerge (EMPTY_STRING, targetBranch, depotBranchPath, fileData);
200195}
201196
202- void branchIntegrationMap::addMerge (const std::string& sourceBranch, const std::string& targetBranch, const FileData& fileData)
197+ void branchIntegrationMap::addMerge (const std::string& sourceBranch, const std::string& targetBranch, const std::string& depotBranchPath, const FileData& fileData)
203198{
204199 // Need to store this in the integration map, using "src/tgt" as the
205200 // key. Because stream names can't have a '/' in them, this creates a unique key.
@@ -214,6 +209,7 @@ void branchIntegrationMap::addMerge(const std::string& sourceBranch, const std::
214209 BranchedFileGroup& bfg = branchGroups[index];
215210 bfg.sourceBranch = sourceBranch;
216211 bfg.targetBranch = targetBranch;
212+ bfg.depotBranchPath = depotBranchPath;
217213 bfg.hasSource = !sourceBranch.empty ();
218214 bfg.files .push_back (fileData);
219215 }
@@ -327,50 +323,46 @@ std::unique_ptr<ChangedFileGroups> BranchSet::ParseAffectedFiles(const std::vect
327323 if (HasMergeableBranch ())
328324 {
329325 // [0] == branch name, [1] == relative path in the branch.
330- std::array<std::string, 2 > branchPath = splitBranchPath (relativeDepotPath);
331- if (
332- branchPath[0 ].empty ()
333- || branchPath[1 ].empty ())
326+ const Branch* branch = getBranchFor (relativeDepotPath);
327+ if (branch == nullptr )
334328 {
335329 // not a valid branch file. skip it.
336330 continue ;
337331 }
338332
339333 // It's a valid destination to a branch.
340334 // Make sure the relative path is set.
341- fileData.SetRelativeDepotPath (branchPath[1 ]);
335+ const std::string branchFilePath = relativeDepotPath.substr (branch->depotBranchPath .size () + 1 );
336+ fileData.SetRelativeDepotPath (branchFilePath);
342337
343338 bool needsHandling = true ;
344339 if (fileData.IsIntegrated ())
345340 {
346341 // Only add the integration if the source is from a branch we care about.
347342 // [0] == branch name, [1] == relative path in the branch.
348- std::array<std::string, 2 > fromBranchPath = splitBranchPath (stripBasePath (fileData.GetFromDepotFile ()));
349- if (
350- !fromBranchPath[0 ].empty ()
351- && !fromBranchPath[1 ].empty ()
352-
343+ const Branch* fromBranch = getBranchFor (stripBasePath (fileData.GetFromDepotFile ()));
344+ if (fromBranch != nullptr
353345 // Can't have source and target be pointing to the same branch; that's not
354346 // a branch operation in the Git sense.
355- && fromBranchPath[ 0 ] != branchPath[ 0 ] )
347+ && fromBranch-> gitAlias != branch-> gitAlias )
356348 {
357349 // This is a valid integrate from a known source to a known target branch.
358- branchMap.addMerge (fromBranchPath[ 0 ], branchPath[ 0 ] , fileData);
350+ branchMap.addMerge (fromBranch-> gitAlias , branch-> gitAlias , branch-> depotBranchPath , fileData);
359351 needsHandling = false ;
360352 }
361353 }
362354 if (needsHandling)
363355 {
364356 // Either not a valid integrate, or a normal operation.
365- branchMap.addTarget (branchPath[ 0 ] , fileData);
357+ branchMap.addTarget (branch-> gitAlias , branch-> depotBranchPath , fileData);
366358 }
367359 }
368360 else
369361 {
370362 // It's a non-branching setup.
371363 // Make sure the relative path is set.
372364 fileData.SetRelativeDepotPath (relativeDepotPath);
373- branchMap.addTarget (EMPTY_STRING, fileData);
365+ branchMap.addTarget (EMPTY_STRING, EMPTY_STRING, fileData);
374366 }
375367 }
376368 return branchMap.createChangedFileGroups ();
0 commit comments