From 9dea278f7e22b1caf25424ad1034992847cf29af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20Gr=C3=BCtzmacher?= Date: Mon, 18 Dec 2017 14:57:29 +0100 Subject: [PATCH] fixed StackOverflowException in complex branch history --- src/GitTfs.VsCommon/TfsHelper.Common.cs | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/GitTfs.VsCommon/TfsHelper.Common.cs b/src/GitTfs.VsCommon/TfsHelper.Common.cs index 031cb61b..eb7d4084 100644 --- a/src/GitTfs.VsCommon/TfsHelper.Common.cs +++ b/src/GitTfs.VsCommon/TfsHelper.Common.cs @@ -248,6 +248,7 @@ namespace GitTfs.VsCommon public IList GetRootChangesetForBranch(string tfsPathBranchToCreate, int lastChangesetIdToCheck = -1, string tfsPathParentBranch = null) { + Trace.WriteLine("Looking for root changeset tree on " + tfsPathBranchToCreate); var rootBranches = new List(); GetRootChangesetForBranch(rootBranches, tfsPathBranchToCreate, lastChangesetIdToCheck, tfsPathParentBranch); return rootBranches; @@ -284,8 +285,8 @@ namespace GitTfs.VsCommon if (tfsParentBranch == null) { - throw new GitTfsException("error : the branch you try to initialize '" + tfsPathBranchToCreate + "' is a root branch (e.g. has no parents).", - new List { "Clone this branch from Tfs instead of trying to initialize it!\n Command: git tfs clone " + Url + " " + tfsPathBranchToCreate }); + Trace.WriteLine("There is no parent branch for " + tfsPathBranchToCreate + ". Ignoring."); + return; } tfsPathParentBranch = tfsParentBranch; @@ -362,9 +363,9 @@ namespace GitTfs.VsCommon rootChangesetMergeInfo.TargetChangeset : rootChangesetMergeInfo.SourceChangeset; var rootBranch = new RootBranch(rootChangesetInParentBranch, rootChangesetInChildBranch, tfsPathBranchToCreate); - AddNewRootBranch(rootBranches, rootBranch); + var added = AddNewRootBranch(rootBranches, rootBranch); - if (renameFromBranch != null) + if (added && renameFromBranch != null) { Trace.WriteLine("Found original branch '" + renameFromBranch + "' (renamed in branch '" + tfsPathBranchToCreate + "')"); GetRootChangesetForBranch(rootBranches, renameFromBranch); @@ -531,11 +532,19 @@ namespace GitTfs.VsCommon }); } - private static void AddNewRootBranch(IList rootBranches, RootBranch rootBranch) + private static bool AddNewRootBranch(IList rootBranches, RootBranch rootBranch) { + if (rootBranches.Any(x => x.TfsBranchPath == rootBranch.TfsBranchPath)) + { + // already in + return false; + } + if (rootBranches.Any()) rootBranch.IsRenamedBranch = true; rootBranches.Insert(0, rootBranch); + + return true; } private int AskForRootChangesetId()