コード例 #1
0
 public override void SetUp()
 {
     base.SetUp();
     scmData  = MockRepository.GenerateStub <IScmData>();
     logStub  = MockRepository.GenerateStub <ILog>();
     diffStub = MockRepository.GenerateStub <IDiff>();
 }
コード例 #2
0
 public override void SetUp()
 {
     base.SetUp();
     scmData = MockRepository.GenerateStub<IScmData>();
     logStub = MockRepository.GenerateStub<ILog>();
     diffStub = MockRepository.GenerateStub<IDiff>();
 }
コード例 #3
0
 public void SetUp()
 {
     scmDataStub = MockRepository.GenerateStub<IScmData>();
     calls = new List<string>();
     scmDataStub.Stub(x => x.Log(null))
         .IgnoreArguments()
         .Do((Func<string,ILog>)(r =>
         {
             calls.Add("log" + r);
             return null;
         }));
     scmDataStub.Stub(x => x.Diff(null,null))
         .IgnoreArguments()
         .Do((Func<string,string,IDiff>)((r,f) =>
         {
             calls.Add("diff" + r + f);
             return null;
         }));
     scmDataStub.Stub(x => x.Blame(null, null))
         .IgnoreArguments()
         .Do((Func<string,string,IBlame>)((r, f) =>
         {
             calls.Add("blame" + r + f);
             return null;
         }));
     cache = new ScmDataCache(scmDataStub);
 }
コード例 #4
0
 public void SetUp()
 {
     scmDataStub = MockRepository.GenerateStub <IScmData>();
     calls       = new List <string>();
     scmDataStub.Stub(x => x.Log(null))
     .IgnoreArguments()
     .Do((Func <string, ILog>)(r =>
     {
         calls.Add("log" + r);
         return(null);
     }));
     scmDataStub.Stub(x => x.Diff(null, null))
     .IgnoreArguments()
     .Do((Func <string, string, IDiff>)((r, f) =>
     {
         calls.Add("diff" + r + f);
         return(null);
     }));
     scmDataStub.Stub(x => x.Blame(null, null))
     .IgnoreArguments()
     .Do((Func <string, string, IBlame>)((r, f) =>
     {
         calls.Add("blame" + r + f);
         return(null);
     }));
     cache = new ScmDataCache(scmDataStub);
 }
コード例 #5
0
 public override void SetUp()
 {
     base.SetUp();
     scmDataStub      = MockRepository.GenerateStub <IScmData>();
     mapper           = new MappingController(scmDataStub);
     commitMapperStub = MockRepository.GenerateStub <CommitMapper>(null as IScmData);
     bugFixMapperStub = MockRepository.GenerateStub <BugFixMapper>(null, null);
     fileMapperStub   = MockRepository.GenerateStub <ProjectFileMapper>(null as IScmData);
 }
コード例 #6
0
        public ScmDataCache(IScmData innerScmData)
        {
            this.innerScmData = innerScmData;

            logs  = new FixedSizeDictionary <string, ILog>(1, x => innerScmData.Log(x));
            diffs = new FixedSizeDictionary <string, SmartDictionary <string, IDiff> >(1, x =>
                                                                                       new SmartDictionary <string, IDiff>(y => innerScmData.Diff(x, y))
                                                                                       );
            blames = new FixedSizeDictionary <string, IBlame>(100);
        }
コード例 #7
0
ファイル: ScmDataCache.cs プロジェクト: kirnosenko/msr-tools
        public ScmDataCache(IScmData innerScmData)
        {
            this.innerScmData = innerScmData;

            logs = new FixedSizeDictionary<string,ILog>(1, x => innerScmData.Log(x));
            diffs = new FixedSizeDictionary<string,SmartDictionary<string,IDiff>>(1, x =>
                new SmartDictionary<string,IDiff>(y => innerScmData.Diff(x, y))
            );
            blames = new FixedSizeDictionary<string,IBlame>(100);
        }
コード例 #8
0
        private void CheckLinesContent(IRepository repository, IScmData scmData, string testRevision)
        {
            var existentFiles = repository.SelectionDSL()
                                .Files()
                                .Reselect(pathFilter)
                                .ExistInRevision(testRevision);

            foreach (var existentFile in existentFiles)
            {
                CheckLinesContent(repository, scmData, testRevision, existentFile, false);
            }
        }
コード例 #9
0
 public CodeBlockMapperBasedOnBlame(IScmData scmData)
     : base(scmData)
 {
 }
コード例 #10
0
 public CodeBlockMapper(IScmData scmData)
     : base(scmData)
 {
 }
コード例 #11
0
 public CommitMapperForExistentRevision(IScmData scmData)
     : base(scmData)
 {
 }
コード例 #12
0
 public CommitMapperForExistentRevision(IScmData scmData)
     : base(scmData)
 {
 }
コード例 #13
0
ファイル: MappingTool.cs プロジェクト: kirnosenko/msr-tools
        private bool CheckLinesContent(IRepository repository, IScmData scmData, string testRevision, ProjectFile file, bool resultOnly)
        {
            IBlame fileBlame = null;
            try
            {
                fileBlame = scmData.Blame(testRevision, file.Path);
            }
            catch
            {
            }
            if (fileBlame == null)
            {
                if (! resultOnly)
                {
                    Console.WriteLine("File {0} does not exist.", file.Path);
                }
                return false;
            }

            double currentLOC = repository.SelectionDSL()
                    .Commits().TillRevision(testRevision)
                    .Files().IdIs(file.ID)
                    .Modifications().InCommits().InFiles()
                    .CodeBlocks().InModifications()
                    .CalculateLOC();

            bool correct = currentLOC == fileBlame.Count;

            if (! correct)
            {
                if (! resultOnly)
                {
                    Console.WriteLine("Incorrect number of lines in file {0}. {1} should be {2}",
                        file.Path, currentLOC, fileBlame.Count
                    );
                }
                else
                {
                    return false;
                }
            }

            SmartDictionary<string, int> linesByRevision = new SmartDictionary<string, int>(x => 0);
            foreach (var line in fileBlame)
            {
                linesByRevision[line.Value]++;
            }

            var codeBySourceRevision =
            (
                from f in repository.Queryable<ProjectFile>()
                join m in repository.Queryable<Modification>() on f.ID equals m.FileID
                join cb in repository.Queryable<CodeBlock>() on m.ID equals cb.ModificationID
                join c in repository.Queryable<Commit>() on m.CommitID equals c.ID
                let addedCodeBlock = repository.Queryable<CodeBlock>()
                    .Single(x => x.ID == (cb.Size < 0 ? cb.TargetCodeBlockID : cb.ID))
                let codeAddedInitiallyInRevision = repository.Queryable<Commit>()
                    .Single(x => x.ID == addedCodeBlock.AddedInitiallyInCommitID)
                    .Revision
                let testRevisionNumber = repository.Queryable<Commit>()
                    .Single(x => x.Revision == testRevision)
                    .OrderedNumber
                where
                    f.ID == file.ID
                    &&
                    c.OrderedNumber <= testRevisionNumber
                group cb.Size by codeAddedInitiallyInRevision into g
                select new
                {
                    FromRevision = g.Key,
                    CodeSize = g.Sum()
                }
            ).Where(x => x.CodeSize != 0).ToList();

            var errorCode =
                (
                    from codeFromRevision in codeBySourceRevision
                    where
                        codeFromRevision.CodeSize != linesByRevision[codeFromRevision.FromRevision]
                    select new
                    {
                        SourceRevision = codeFromRevision.FromRevision,
                        CodeSize = codeFromRevision.CodeSize,
                        RealCodeSize = linesByRevision[codeFromRevision.FromRevision]
                    }
                ).ToList();

            correct =
                correct
                &&
                codeBySourceRevision.Count() == linesByRevision.Count
                &&
                errorCode.Count == 0;

            if (! resultOnly)
            {
                if (codeBySourceRevision.Count() != linesByRevision.Count)
                {
                    Console.WriteLine("Number of revisions file {0} contains code from is incorrect. {1} should be {2}",
                        file.Path, codeBySourceRevision.Count(), linesByRevision.Count
                    );
                }
                foreach (var error in errorCode)
                {
                    Console.WriteLine("Incorrect number of lines in file {0} from revision {1}. {2} should be {3}",
                        file.Path,
                        error.SourceRevision,
                        error.CodeSize,
                        error.RealCodeSize
                    );
                }
                if ((! correct) && (errorCode.Count > 0))
                {
                    string latestCodeRevision = repository.LastRevision(errorCode.Select(x => x.SourceRevision));

                    var commitsFileTouchedIn = repository.SelectionDSL()
                        .Files().IdIs(file.ID)
                        .Commits().FromRevision(latestCodeRevision).TouchFiles()
                        .OrderBy(c => c.OrderedNumber);

                    foreach (var commit in commitsFileTouchedIn)
                    {
                        if (!CheckLinesContent(repository, scmData, commit.Revision, file, true))
                        {
                            Console.WriteLine("{0} - incorrectly mapped commit.", commit.Revision);
                            if ((automaticallyFixDiffErrors) && (errorCode.Sum(x => x.CodeSize - x.RealCodeSize) == 0))
                            {
                                var incorrectDeleteCodeBlocks =
                                    from cb in repository.SelectionDSL()
                                        .Commits().RevisionIs(commit.Revision)
                                        .Files().PathIs(file.Path)
                                        .Modifications().InCommits().InFiles()
                                        .CodeBlocks().InModifications().Deleted()
                                    join tcb in repository.Queryable<CodeBlock>() on cb.TargetCodeBlockID equals tcb.ID
                                    join m in repository.Queryable<Modification>() on tcb.ModificationID equals m.ID
                                    join c in repository.Queryable<Commit>() on m.CommitID equals c.ID
                                    where
                                        errorCode.Select(x => x.SourceRevision).Contains(c.Revision)
                                    select new
                                    {
                                        Code = cb,
                                        TargetRevision = c.Revision
                                    };

                                foreach (var error in errorCode)
                                {
                                    var incorrectDeleteCodeBlock = incorrectDeleteCodeBlocks.SingleOrDefault(x => x.TargetRevision == error.SourceRevision);
                                    var codeBlock = incorrectDeleteCodeBlock == null ? null : incorrectDeleteCodeBlock.Code;
                                    double difference = error.CodeSize - error.RealCodeSize;
                                    if (codeBlock == null)
                                    {
                                        codeBlock = new CodeBlock()
                                        {
                                            Size = 0,
                                            Modification = repository.SelectionDSL()
                                                .Commits().RevisionIs(commit.Revision)
                                                .Files().PathIs(file.Path)
                                                .Modifications().InCommits().InFiles().Single(),
                                        };
                                        repository.Add(codeBlock);
                                    }
                                    Console.WriteLine("Fix code block size for file {0} in revision {1}:", file.Path, commit.Revision);
                                    Console.Write("Was {0}", codeBlock.Size);
                                    codeBlock.Size -= difference;
                                    if (codeBlock.Size == 0)
                                    {
                                        repository.Delete(codeBlock);
                                    }
                                    else if ((codeBlock.Size > 0) && (codeBlock.AddedInitiallyInCommitID == null))
                                    {
                                        codeBlock.AddedInitiallyInCommit = commit;
                                    }
                                    else if ((codeBlock.Size < 0) && (codeBlock.TargetCodeBlockID == null))
                                    {
                                        codeBlock.TargetCodeBlock = repository.SelectionDSL()
                                            .Commits().RevisionIs(error.SourceRevision)
                                            .Files().PathIs(file.Path)
                                            .Modifications().InFiles()
                                            .CodeBlocks().InModifications().AddedInitiallyInCommits().Single();
                                    }
                                    Console.WriteLine(", now {0}", codeBlock.Size);
                                }
                            }
                            break;
                        }
                    }
                }
            }

            return correct;
        }
コード例 #14
0
ファイル: MappingTool.cs プロジェクト: kirnosenko/msr-tools
        private void CheckLinesContent(IRepository repository, IScmData scmData, string testRevision)
        {
            var existentFiles = repository.SelectionDSL()
                .Files()
                    .Reselect(pathFilter)
                    .ExistInRevision(testRevision);

            foreach (var existentFile in existentFiles)
            {
                CheckLinesContent(repository, scmData, testRevision, existentFile, false);
            }
        }
コード例 #15
0
 public CommitMapper(IScmData scmData)
     : base(scmData)
 {
 }
コード例 #16
0
 public MappingTool(string configFile)
     : base(configFile, "mappingtool")
 {
     scmData             = GetScmData();
     scmDataWithoutCache = GetScmDataWithoutCache();
 }
コード例 #17
0
 public ModificationMapper(IScmData scmData)
     : base(scmData)
 {
 }
コード例 #18
0
 public ProjectFileMapper(IScmData scmData)
     : base(scmData)
 {
 }
コード例 #19
0
        private bool CheckLinesContent(IRepository repository, IScmData scmData, string testRevision, ProjectFile file, bool resultOnly)
        {
            IBlame fileBlame = null;

            try
            {
                fileBlame = scmData.Blame(testRevision, file.Path);
            }
            catch
            {
            }
            if (fileBlame == null)
            {
                if (!resultOnly)
                {
                    Console.WriteLine("File {0} does not exist.", file.Path);
                }
                return(false);
            }

            double currentLOC = repository.SelectionDSL()
                                .Commits().TillRevision(testRevision)
                                .Files().IdIs(file.ID)
                                .Modifications().InCommits().InFiles()
                                .CodeBlocks().InModifications()
                                .CalculateLOC();

            bool correct = currentLOC == fileBlame.Count;

            if (!correct)
            {
                if (!resultOnly)
                {
                    Console.WriteLine("Incorrect number of lines in file {0}. {1} should be {2}",
                                      file.Path, currentLOC, fileBlame.Count
                                      );
                }
                else
                {
                    return(false);
                }
            }

            SmartDictionary <string, int> linesByRevision = new SmartDictionary <string, int>(x => 0);

            foreach (var line in fileBlame)
            {
                linesByRevision[line.Value]++;
            }

            var codeBySourceRevision =
                (
                    from f in repository.Queryable <ProjectFile>()
                    join m in repository.Queryable <Modification>() on f.ID equals m.FileID
                    join cb in repository.Queryable <CodeBlock>() on m.ID equals cb.ModificationID
                    join c in repository.Queryable <Commit>() on m.CommitID equals c.ID
                    let addedCodeBlock = repository.Queryable <CodeBlock>()
                                         .Single(x => x.ID == (cb.Size < 0 ? cb.TargetCodeBlockID : cb.ID))
                                         let codeAddedInitiallyInRevision = repository.Queryable <Commit>()
                                                                            .Single(x => x.ID == addedCodeBlock.AddedInitiallyInCommitID)
                                                                            .Revision
                                                                            let testRevisionNumber = repository.Queryable <Commit>()
                                                                                                     .Single(x => x.Revision == testRevision)
                                                                                                     .OrderedNumber
                                                                                                     where
                                                                                                     f.ID == file.ID
                                                                                                     &&
                                                                                                     c.OrderedNumber <= testRevisionNumber
                                                                                                     group cb.Size by codeAddedInitiallyInRevision into g
                                                                                                     select new
            {
                FromRevision = g.Key,
                CodeSize = g.Sum()
            }
                ).Where(x => x.CodeSize != 0).ToList();

            var errorCode =
                (
                    from codeFromRevision in codeBySourceRevision
                    where
                    codeFromRevision.CodeSize != linesByRevision[codeFromRevision.FromRevision]
                    select new
            {
                SourceRevision = codeFromRevision.FromRevision,
                CodeSize = codeFromRevision.CodeSize,
                RealCodeSize = linesByRevision[codeFromRevision.FromRevision]
            }
                ).ToList();

            correct =
                correct
                &&
                codeBySourceRevision.Count() == linesByRevision.Count
                &&
                errorCode.Count == 0;

            if (!resultOnly)
            {
                if (codeBySourceRevision.Count() != linesByRevision.Count)
                {
                    Console.WriteLine("Number of revisions file {0} contains code from is incorrect. {1} should be {2}",
                                      file.Path, codeBySourceRevision.Count(), linesByRevision.Count
                                      );
                }
                foreach (var error in errorCode)
                {
                    Console.WriteLine("Incorrect number of lines in file {0} from revision {1}. {2} should be {3}",
                                      file.Path,
                                      error.SourceRevision,
                                      error.CodeSize,
                                      error.RealCodeSize
                                      );
                }
                if ((!correct) && (errorCode.Count > 0))
                {
                    string latestCodeRevision = repository.LastRevision(errorCode.Select(x => x.SourceRevision));

                    var commitsFileTouchedIn = repository.SelectionDSL()
                                               .Files().IdIs(file.ID)
                                               .Commits().FromRevision(latestCodeRevision).TouchFiles()
                                               .OrderBy(c => c.OrderedNumber);

                    foreach (var commit in commitsFileTouchedIn)
                    {
                        if (!CheckLinesContent(repository, scmData, commit.Revision, file, true))
                        {
                            Console.WriteLine("{0} - incorrectly mapped commit.", commit.Revision);
                            if ((automaticallyFixDiffErrors) && (errorCode.Sum(x => x.CodeSize - x.RealCodeSize) == 0))
                            {
                                var incorrectDeleteCodeBlocks =
                                    from cb in repository.SelectionDSL()
                                    .Commits().RevisionIs(commit.Revision)
                                    .Files().PathIs(file.Path)
                                    .Modifications().InCommits().InFiles()
                                    .CodeBlocks().InModifications().Deleted()
                                    join tcb in repository.Queryable <CodeBlock>() on cb.TargetCodeBlockID equals tcb.ID
                                    join m in repository.Queryable <Modification>() on tcb.ModificationID equals m.ID
                                    join c in repository.Queryable <Commit>() on m.CommitID equals c.ID
                                    where
                                    errorCode.Select(x => x.SourceRevision).Contains(c.Revision)
                                    select new
                                {
                                    Code           = cb,
                                    TargetRevision = c.Revision
                                };

                                foreach (var error in errorCode)
                                {
                                    var    incorrectDeleteCodeBlock = incorrectDeleteCodeBlocks.SingleOrDefault(x => x.TargetRevision == error.SourceRevision);
                                    var    codeBlock  = incorrectDeleteCodeBlock == null ? null : incorrectDeleteCodeBlock.Code;
                                    double difference = error.CodeSize - error.RealCodeSize;
                                    if (codeBlock == null)
                                    {
                                        codeBlock = new CodeBlock()
                                        {
                                            Size         = 0,
                                            Modification = repository.SelectionDSL()
                                                           .Commits().RevisionIs(commit.Revision)
                                                           .Files().PathIs(file.Path)
                                                           .Modifications().InCommits().InFiles().Single(),
                                        };
                                        repository.Add(codeBlock);
                                    }
                                    Console.WriteLine("Fix code block size for file {0} in revision {1}:", file.Path, commit.Revision);
                                    Console.Write("Was {0}", codeBlock.Size);
                                    codeBlock.Size -= difference;
                                    if (codeBlock.Size == 0)
                                    {
                                        repository.Delete(codeBlock);
                                    }
                                    else if ((codeBlock.Size > 0) && (codeBlock.AddedInitiallyInCommitID == null))
                                    {
                                        codeBlock.AddedInitiallyInCommit = commit;
                                    }
                                    else if ((codeBlock.Size < 0) && (codeBlock.TargetCodeBlockID == null))
                                    {
                                        codeBlock.TargetCodeBlock = repository.SelectionDSL()
                                                                    .Commits().RevisionIs(error.SourceRevision)
                                                                    .Files().PathIs(file.Path)
                                                                    .Modifications().InFiles()
                                                                    .CodeBlocks().InModifications().AddedInitiallyInCommits().Single();
                                    }
                                    Console.WriteLine(", now {0}", codeBlock.Size);
                                }
                            }
                            break;
                        }
                    }
                }
            }

            return(correct);
        }
コード例 #20
0
 public BugFixMapper(IScmData scmData, IBugFixDetector bugFixDetector)
     : base(scmData)
 {
     this.bugFixDetector = bugFixDetector;
 }
コード例 #21
0
 public EntityMapper(IScmData scmData)
 {
     this.scmData = scmData;
 }
コード例 #22
0
ファイル: MappingTool.cs プロジェクト: kirnosenko/msr-tools
 public MappingTool(string configFile)
     : base(configFile, "mappingtool")
 {
     scmData = GetScmData();
     scmDataWithoutCache = GetScmDataWithoutCache();
 }
コード例 #23
0
 public MappingController(IScmData scmData)
 {
     this.scmData   = scmData;
     CreateDataBase = false;
 }
コード例 #24
0
 public ReleaseMapper(IScmData scmData, IReleaseDetector releaseDetector)
     : base(scmData)
 {
     this.releaseDetector = releaseDetector;
 }
コード例 #25
0
 public DebuggingTool(string configFile)
     : base(configFile, "mappingtool", "generatingtool")
 {
     scmDataWithoutCache = GetScmDataWithoutCache();
 }