Example #1
0
        private Dep FindLca(Dep dep1, Dep dep2)
        {
            if (dep1.Name != dep2.Name)
            {
                throw new BadArgumentException();
            }
            var result = new Dep(dep1.Name, dep1.Treeish ?? dep2.Treeish);

            var configParser        = new ConfigurationYamlParser(new FileInfo(Path.Combine(workspace, dep1.Name)));
            var configs             = configParser.GetConfigurations();
            var commonAncestorsList = new List <string>();

            foreach (var parent in configs)
            {
                var cm = new ConfigurationManager(new[] { new Dep(null, null, parent) }, configParser);
                if (cm.ProcessedParent(dep1) && cm.ProcessedParent(dep2))
                {
                    commonAncestorsList.Add(parent);
                }
            }

            var lowestAncestor = commonAncestorsList.Where(
                c =>
                !new ConfigurationManager(commonAncestorsList.Select(cc => new Dep(null, null, cc)), configParser).ProcessedChildrenConfigurations(new Dep(null, null, c)).Any()).ToList();

            if (!commonAncestorsList.Any() || !lowestAncestor.Any())
            {
                throw new CementException("failed get common ancestor for configurations '" + dep1 + "' and '" + dep2 + "'");
            }
            result.Configuration = lowestAncestor.First();
            return(result);
        }