예제 #1
0
        static void Main(string[] args)
        {
            var data = new SqlServerDataStore("git", "localhost", "1433", "sa", "QWEqwe123")
            {
                //Logger = Console.WriteLine,
                //SingletonSession = true,
            };
            var gitClient = new CommandLineGitClient("D:/src/git/.git")
            {
                //Branch = "development",
                //ExtendedLog = true,
            };
            var vcsData = new VcsDataCached(gitClient, 1000, 1000);
            var mapper  = ConstructDataMapper(data, vcsData, new VcsDataMapper.MappingSettings()
            {
                RevisionLimit = 6000,
                CheckMode     = VcsDataMapper.CheckMode.TOUCHED,
            });

            using (ConsoleTimeLogger.Start("time"))
            {
                mapper.MapRevisions();
                //mapper.Truncate(1000);
                //mapper.Check(2309, DataMapper.CheckMode.ALL);
                //mapper.CheckAndTruncate("/test-delta.c");

                //GetLog(vcsData);
                //BlameDiff(vcsData);
                //FileHistory(data, vcsData, "/Documentation/merge-pull-opts.txt");
                //Select(data);
            }

            Console.ReadKey();
        }
예제 #2
0
        public void Check(string stopRevision, string path, bool automaticallyFixDiffErrors)
        {
            pathFilter = e => path == null ? e : e.PathIs(path);
            this.automaticallyFixDiffErrors = automaticallyFixDiffErrors;

            using (ConsoleTimeLogger.Start("checking time"))
                using (var s = data.OpenSession())
                {
                    string testRevision = stopRevision;
                    if (s.Queryable <Commit>().SingleOrDefault(c => c.Revision == testRevision) == null)
                    {
                        Console.WriteLine("Could not find revision {0}.", testRevision);
                        return;
                    }

                    CheckEmptyCodeBlocks(s, testRevision);
                    CheckCodeSizeForDeletedFiles(s, testRevision);
                    CheckTargetsForCodeBlocks(s, testRevision);
                    CheckDeletedCodeBlocksVsAdded(s, testRevision);
                    CheckLinesContent(s, scmDataWithoutCache, testRevision);
                    if (automaticallyFixDiffErrors)
                    {
                        s.SubmitChanges();
                    }
                }
        }
예제 #3
0
        private void Map(MappingController mapping)
        {
            using (ConsoleTimeLogger.Start("mapping time"))
            {
                mapping.OnRevisionMapping += (r, n) => Console.WriteLine(
                    "mapping of revision {0}{1}",
                    r,
                    r != n ? string.Format(" ({0})", n) : ""
                    );

                mapping.Map(data);
            }
        }
예제 #4
0
        public void MapReleases(IDictionary <string, string> releases)
        {
            using (ConsoleTimeLogger.Start("releases mapping time"))
                using (var s = data.OpenSession())
                {
                    foreach (var release in releases)
                    {
                        s.MappingDSL()
                        .Commit(release.Key).IsRelease(release.Value);
                    }

                    s.SubmitChanges();
                }
        }
예제 #5
0
 public void MapReleaseEntity(string revision, string tag)
 {
     using (ConsoleTimeLogger.Start("entity mapping time"))
         using (var s = data.OpenSession())
         {
             s.Add(new Release()
             {
                 Commit = s.Queryable <Commit>().Single(c =>
                                                        c.Revision == revision
                                                        ),
                 Tag = tag
             });
             s.SubmitChanges();
         }
 }
예제 #6
0
        static void Select(IDataStore data)
        {
            using (var s = data.OpenSession())
            {
                int count = 0;
                using (ConsoleTimeLogger.Start("time"))
                {
                    //count = s.SelectionDSL().Commits()
                    //.OnBranchBack("00000000000000000101000000000100001")
                    //.Count();

                    count = s.SelectionDSL().Commits()
                            .OnBranchForward("000000000000000001010000000001")
                            .Count();
                }
                Console.WriteLine(count);
            }
        }
예제 #7
0
        public void Truncate(string lastRevisionToKeep)
        {
            using (ConsoleTimeLogger.Start("truncating time"))
                using (var s = data.OpenSession())
                {
                    var selectionDSL = s.SelectionDSL();

                    var addedCommits       = selectionDSL.Commits().AfterRevision(lastRevisionToKeep);
                    var addedBugFixes      = addedCommits.BugFixes().InCommits();
                    var addedModifications = addedCommits.Modifications().InCommits();
                    var addedFiles         = addedCommits.Files().AddedInCommits();
                    var deletedFiles       = addedCommits.Files().DeletedInCommits();
                    var addedCodeBlocks    = addedModifications.CodeBlocks().InModifications();

                    foreach (var codeBlock in addedCodeBlocks)
                    {
                        s.Delete(codeBlock);
                    }
                    foreach (var modification in addedModifications)
                    {
                        s.Delete(modification);
                    }
                    foreach (var file in addedFiles)
                    {
                        s.Delete(file);
                    }
                    foreach (var file in deletedFiles)
                    {
                        file.DeletedInCommit = null;
                    }
                    foreach (var bugFix in addedBugFixes)
                    {
                        s.Delete(bugFix);
                    }
                    foreach (var commit in addedCommits)
                    {
                        s.Delete(commit);
                    }

                    s.SubmitChanges();
                }
        }
예제 #8
0
 public void GenerateStat(string targetDir, string outputDir, string templateDir)
 {
     using (ConsoleTimeLogger.Start("generating statistics time"))
     {
         StatBuilder builder = GetConfiguredType <StatBuilder>();
         if (targetDir != null)
         {
             builder.TargetDir = targetDir;
         }
         if (outputDir != null)
         {
             builder.OutputDir = outputDir;
         }
         if (templateDir != null)
         {
             builder.TargetDir = templateDir;
         }
         builder.GenerateStat(data);
     }
 }
예제 #9
0
        public void ShowBlame(string targetDir, string targetPath)
        {
            using (ConsoleTimeLogger.Start("getting blame time"))
                using (var s = data.OpenSession())
                {
                    Func <ProjectFileSelectionExpression, ProjectFileSelectionExpression> fileSelector = e =>
                    {
                        return(targetDir != null?
                               e.InDirectory(targetDir)
                                   :
                                   e.PathIs(targetPath));
                    };

                    var authors = s.SelectionDSL()
                                  .Files().Reselect(fileSelector)
                                  .Commits().TouchFiles()
                                  .Select(x => x.Author).Distinct().OrderBy(x => x)
                                  .ToList();

                    int maxAuthorLen = authors.Select(x => x.Length).Max();
                    if (maxAuthorLen < 6)
                    {
                        maxAuthorLen = 6;
                    }
                    string format = "{0,X}{1,13}{2,13}{3,13}{4,15}".Replace("X", maxAuthorLen.ToString());
                    string line   = "-".Repeat(maxAuthorLen + 13 + 13 + 13 + 15);
                    Console.WriteLine(format, "Author", "Added LOC", "Removed LOC", "Current LOC", "Max & Min Age");
                    Console.WriteLine(line);
                    foreach (var author in authors)
                    {
                        var addedCode = s.SelectionDSL()
                                        .Commits().AuthorIs(author)
                                        .Files().Reselect(fileSelector)
                                        .Modifications().InFiles()
                                        .CodeBlocks().InModifications().AddedInitiallyInCommits()
                                        .Fixed();
                        var removedCode = s.SelectionDSL()
                                          .Commits().AuthorIs(author)
                                          .Files().Reselect(fileSelector)
                                          .Modifications().InCommits().InFiles()
                                          .CodeBlocks().InModifications().Deleted()
                                          .Fixed();

                        DateTime now               = DateTime.Now;
                        double   addedLoc          = addedCode.CalculateLOC();
                        var      remainingCode     = addedCode.CalculateRemainingCodeSize(s.LastRevision());
                        var      remainingCodeSize = remainingCode.Sum(x => x.Value);

                        var remainingCodeAge =
                            (
                                from cb in remainingCode
                                let CommitID = s.Queryable <CodeBlock>()
                                               .Single(x => x.ID == cb.Key)
                                               .AddedInitiallyInCommitID
                                               from c in s.Queryable <Commit>()
                                               where c.ID == CommitID
                                               select(now - c.Date).Days
                            ).ToList();

                        string age = remainingCodeAge.Count() > 0 ?
                                     remainingCodeAge.Max().ToString() + "-" + remainingCodeAge.Min().ToString()
                                                :
                                     "";

                        Console.WriteLine(format,
                                          author,
                                          addedLoc,
                                          -removedCode.CalculateLOC(),
                                          remainingCode.Sum(x => x.Value),
                                          age
                                          );
                    }
                    Console.WriteLine(line);
                }
        }