Esempio n. 1
0
        public void PerformPull(string gitFolder)
        {
            if (string.IsNullOrEmpty(gitFolder)) { throw new ArgumentNullException("gitFolder"); }
            if (!Directory.Exists(gitFolder)) { throw new DirectoryNotFoundException(string.Format("git directory not found at [{0}]", gitFolder)); }

            string pathToDotGitFolder = gitFolder;
            // if this is not pointing to .git then add that to the path
            DirectoryInfo di = new DirectoryInfo(pathToDotGitFolder);
            if (string.Compare(".git", di.Name, StringComparison.OrdinalIgnoreCase) != 0) {
                pathToDotGitFolder = Path.Combine(gitFolder, @".git\");
            }

            // ensure that there is no \ at the end of the path
            pathToDotGitFolder = pathToDotGitFolder.Trim().TrimEnd('\\');

            FileRepositoryBuilder builder = new FileRepositoryBuilder();
            Repository repo = builder
                                .SetGitDir(pathToDotGitFolder)
                                .ReadEnvironment()
                                .FindGitDir()
                                .Build();

            Git git = new Git(repo);
            PullCommand pullCommand = git.Pull();
            PullResult pullResult = null;

            // TODO: need to cover this in a try/catch and log errors
            pullResult = pullCommand.Call();
        }
Esempio n. 2
0
        private bool CreateRepositoryIfNotExists()
        {
            bool createRepository = !Directory.Exists(Path.Combine(GitRepositoryFolder, ".git"));

            if (createRepository)
            {
                CreateUpdateGitIgnore();

                FileRepositoryBuilder builder = new FileRepositoryBuilder();
                Repository            r       = builder.SetGitDir(Path.Combine(GitRepositoryFolder, ".git")).Build();
                r.Create();
                //Git.Init().SetDirectory(GitRepositoryFolder).Call();
            }
            else
            {
                try
                {
                    var git = Git.Open(Path.Combine(GitRepositoryFolder, ".git"));
                    git.Status().Call();
                }
                catch (Exception e)
                {
                    Logging.Error(e, "Error opening repository. Attempting to recreate it.");
                    try
                    {
                        Directory.Delete(Path.Combine(GitRepositoryFolder, ".git"), true);
                        CreateUpdateGitIgnore();
                        Git.Init().SetDirectory(GitRepositoryFolder).Call();
                    }
                    catch (Exception e2)
                    {
                        Logging.Error(e2, "Error attempting to delete and recreate the repository.");
                        var messageBox = new MessageBoxForm("The version repository is corrupt. Please delete the .git folder in the profile directory and try again.", "Corrupt version repository!", MessageBoxButtons.OK, SystemIcons.Error);
                        messageBox.ShowDialog();
                    }
                }
            }
            return(createRepository);
        }
Esempio n. 3
0
        private static Iterable <RevCommit> GetRevCommitList()
        {
            string GitPath = "";

            //GitPath = @"D:\Personal\E Books\Higher Education\Research\SampleProjects\NopCommerce\.git";
            GitPath = @"C:\Users\neemathu\Documents\GitHub\angular.js\.git";
            //GitPath = @"C:\Users\neemathu\Documents\GitHub\Umbraco-CMS\.git";
            //GitPath = @" D:\Personal\E Books\Higher Education\Research\SampleProjects\SignalR\SignalR\.git";
            //GitPath = @"D:\Personal\E Books\Higher Education\RefactoringActivity\ganttproject\.git";

            FileRepositoryBuilder builder    = new FileRepositoryBuilder();
            Repository            repository = builder.SetGitDir(new FilePath(GitPath))
                                               .ReadEnvironment() // scan environment GIT_* variables
                                               .FindGitDir()      // scan up the file system tree
                                               .Build();

            Git git = new Git(repository);

            Iterable <RevCommit> log = git.Log().Call();

            return(log);
        }
Esempio n. 4
0
        static void Main(string[] args)
        {
            FileRepositoryBuilder builder    = new FileRepositoryBuilder();
            Repository            repository = builder.SetGitDir(new FilePath(@"D:\Personal\E Books\Higher Education\Research\SampleProjects\NopCommerce\.git"))
                                                                  //Repository repository = builder.SetGitDir(new FilePath(@"C:\Users\neemathu\Documents\GitHub\angular.js\.git"))
                                                                  // Repository repository = builder.SetGitDir(new FilePath(@"D:\Personal\E Books\Higher Education\RefactoringActivity\ganttproject\.git"))
                                               .ReadEnvironment() // scan environment GIT_* variables
                                               .FindGitDir()      // scan up the file system tree
                                               .Build();



            HashSet <String>         uniqueFile      = new HashSet <string>();
            Dictionary <String, int> logicalCoupling = new Dictionary <string, int>();

            RevWalk rw = new RevWalk(repository);


            Git git = new Git(repository);

            Iterable <RevCommit> log = git.Log().Call();

            for (Iterator <RevCommit> iterator = log.Iterator(); iterator.HasNext();)
            {
                RevCommit rev = iterator.Next();


                //RevWalk revWalk = new RevWalk(git.GetRepository());
                //RevTree revTree = revWalk.ParseTree(rev.Tree.Id);
                //TreeWalk treeWalk = new TreeWalk(git.GetRepository());
                //treeWalk.AddTree(revTree);

                //while (treeWalk.Next())
                //{
                //    //compare treeWalk.NameString yourself


                //    byte[] bytes = treeWalk.ObjectReader.Open(treeWalk.GetObjectId(0)).GetBytes();
                //    string result1 = System.Text.Encoding.UTF8.GetString(bytes);


                //}



                // Sharpen.OutputStream os = new Sharpen.OutputStream();

                //rev.CopyRawTo(os);

                //System.Console.WriteLine("Author: "+rev.GetAuthorIdent().GetName());
                //System.Console.WriteLine("ID:" + rev.Id);


                var dt = new DateTime(1970, 1, 1, 0, 0, 0, 0).AddSeconds(rev.CommitTime).ToLocalTime();
                //var ts = new TimeSpan(DateTime.UtcNow.Ticks - rev.CommitTime);
                //System.Console.WriteLine("Date:" + dt.ToString());
                //System.Console.WriteLine("Description:" + rev.GetFullMessage());

                DiffFormatter df = new DiffFormatter(DisabledOutputStream.INSTANCE);
                df.SetRepository(repository);
                df.SetDiffComparator(RawTextComparator.DEFAULT);
                df.SetDetectRenames(true);

                List <String> files = new List <string>();

                if (rev.ParentCount > 0)
                {
                    List <DiffEntry> diffs = df.Scan(rev.GetParent(0).Tree, rev.Tree).ToList();


                    foreach (DiffEntry diff in diffs)
                    {
                        // Fetch data from the commited new file
                        //ObjectLoader loader = repository.Open(diff.GetNewId().ToObjectId());
                        //OutputStream @out = new ByteArrayOutputStream();
                        ////loader.CopyTo(@out);

                        ////Fetch diffrence of commit
                        //DiffCommand diff1 = git.Diff().SetPathFilter(PathFilter.Create(diff.GetNewPath())).SetOldTree(GetTreeIterator(rev.GetParent(0).Tree.Name, repository)).SetNewTree(GetTreeIterator(rev.Tree.Name, repository)).SetOutputStream(@out);
                        //IList<DiffEntry>  entries = diff1.Call();
                        //string data = @out.ToString();

                        files.Add(diff.GetNewPath());
                        uniqueFile.Add(diff.GetNewPath());
                        //System.Console.WriteLine(String.Format("FilePath: {0} {1}", diff.GetNewMode().GetBits(), diff.GetNewPath()));
                    }
                }



                if (isContainFile(rev, files))
                {
                    //System.Console.WriteLine(rev.Id);
                    //System.Console.WriteLine(dt);
                    //System.Console.WriteLine(rev.GetAuthorIdent().GetName());
                    //System.Console.WriteLine(rev.GetFullMessage());

                    tfIdfBeforeData.Add(rev.Id.Name, new Dictionary <string, Dictionary <string, double> >());


                    foreach (String file in files)
                    {
                        String fileName = file.Substring(file.LastIndexOf("/") + 1, file.Length - file.LastIndexOf("/") - 1);

                        if (IsFileExtentionAllowed(fileName))
                        {
                            string data = GetCommitDiff(repository, git, rev, file);
                            Dictionary <string, double> tokensTF = GetTokensWithTF(data);

                            tfIdfBeforeData[rev.Id.Name].Add(file, tokensTF);


                            //System.Console.WriteLine("File path: " + file);
                            //System.Console.WriteLine(data);
                            //System.Console.WriteLine("------------------");

                            if (!logicalCoupling.ContainsKey(fileName))
                            {
                                logicalCoupling.Add(fileName, 1);
                            }
                            else
                            {
                                logicalCoupling[fileName] += 1;
                            }
                        }
                    }

                    //System.Console.WriteLine("###################################");
                }


                //foreach (var item in uniqueFile)
                //{

                //    System.Console.WriteLine(item);
                //}

                //System.Console.WriteLine("--------------------");


                //http://stackoverflow.com/questions/11869412/jgit-using-revwalk-to-get-revcommit-returns-nothing

                ////ObjectId head = repository.Resolve("master");
                //RevWalk walk = new RevWalk(repository);

                //foreach (var commit in walk)
                //{
                //    String email = commit.GetAuthorIdent().GetEmailAddress();
                //}
            }

            CalculateTfIdfScore("defaultResources.nopres.xml");

            CalculateLogicalDependency(logicalCoupling);

            System.Console.WriteLine("----------Done----------");
            System.Console.ReadLine();
        }
Esempio n. 5
0
        static void Main(string[] args)
        {
            //string input = "group, and test but not testing.  But yes to test";
            //string val="Group";
            //string pattern = @"\b" + val + @"\b";
            //string replace = " ";
            //string result = System.Text.RegularExpressions.Regex.Replace(input, pattern, replace, System.Text.RegularExpressions.RegexOptions.IgnoreCase);
            //Console.WriteLine(result);

            FileRepositoryBuilder builder    = new FileRepositoryBuilder();
            Repository            repository = builder.SetGitDir(new FilePath(@"D:\Personal\E Books\Higher Education\Research\SampleProjects\NopCommerce\.git"))
                                                                  //Repository repository = builder.SetGitDir(new FilePath(@"C:\Users\neemathu\Documents\GitHub\angular.js\.git"))
                                                                  // Repository repository = builder.SetGitDir(new FilePath(@"D:\Personal\E Books\Higher Education\RefactoringActivity\ganttproject\.git"))
                                               .ReadEnvironment() // scan environment GIT_* variables
                                               .FindGitDir()      // scan up the file system tree
                                               .Build();

            RevWalk rw = new RevWalk(repository);

            Git git = new Git(repository);

            Iterable <RevCommit> log = git.Log().Call();


            if (args.Length > 0)
            {
                switch (args[0])
                {
                case "buildstopwordindex":
                    BuildStopWordIndex(log, repository, git);
                    return;

                    break;

                default:
                    break;
                }
            }


            // Iterat over revisions
            for (Iterator <RevCommit> iterator = log.Iterator(); iterator.HasNext();)
            {
                RevCommit rev = iterator.Next();

                var dt = new DateTime(1970, 1, 1, 0, 0, 0, 0).AddSeconds(rev.CommitTime).ToLocalTime();

                DiffFormatter df = new DiffFormatter(DisabledOutputStream.INSTANCE);
                df.SetRepository(repository);
                df.SetDiffComparator(RawTextComparator.DEFAULT);
                df.SetDetectRenames(true);

                List <String> files = new List <string>();
                if (rev.ParentCount > 0)
                {
                    List <DiffEntry> diffs = df.Scan(rev.GetParent(0).Tree, rev.Tree).ToList();
                    foreach (DiffEntry diff in diffs)
                    {
                        // Fetch data from the commited new file
                        //ObjectLoader loader = repository.Open(diff.GetNewId().ToObjectId());
                        //OutputStream @out = new ByteArrayOutputStream();
                        ////loader.CopyTo(@out);

                        ////Fetch diffrence of commit
                        //DiffCommand diff1 = git.Diff().SetPathFilter(PathFilter.Create(diff.GetNewPath())).SetOldTree(GetTreeIterator(rev.GetParent(0).Tree.Name, repository)).SetNewTree(GetTreeIterator(rev.Tree.Name, repository)).SetOutputStream(@out);
                        //IList<DiffEntry>  entries = diff1.Call();
                        //string data = @out.ToString();

                        string filePath = diff.GetNewPath();

                        //if (fileCount.ContainsKey(filePath))
                        //{
                        //    fileCount[filePath] = fileCount[filePath] + 1;

                        //}
                        //else
                        //{
                        //    fileCount.Add(filePath, 1);

                        //}

                        files.Add(filePath);

                        //System.Console.WriteLine(String.Format("FilePath: {0} {1}", diff.GetNewMode().GetBits(), diff.GetNewPath()));
                    }
                    //continue;
                }

                if (GitHelper.HasFile(files))
                {
                    foreach (String file in files)
                    {
                        String FileName = file.Substring(file.LastIndexOf("/") + 1, file.Length - file.LastIndexOf("/") - 1);
                        if (Utils.AllowedFileExtentions(FileName))
                        {
                            string DiffContent = GitHelper.GetCommitDiff(repository, git, rev, file);
                            //data = Common.Utils.RemoveStopWords(data);

                            LogicalDependency.LogicalDependency.AddArtifact(rev.Id.Name, file, DiffContent);

                            //StopWords.StopWordIndexBuilder.BuildWordIndex(file, data);
                        }
                    }
                }
            }

            //var sortedElements = fileCount.OrderByDescending(kvp => kvp.Value);

            //foreach (var item in sortedElements)
            //{
            //    Console.WriteLine(item.Key + ": " + item.Value);
            //}

            LogicalDependency.LogicalDependency.CalculateSimilarityIndex();
        }