Пример #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();
        }
Пример #2
0
        public virtual void RepositoryWithRootLevelSubmoduleRelativeRef()
        {
            ObjectId id     = ObjectId.FromString("abcd1234abcd1234abcd1234abcd1234abcd1234");
            string   path   = "sub";
            FilePath dotGit = new FilePath(db.WorkTree, path + FilePath.separatorChar + Constants
                                           .DOT_GIT);

            if (!dotGit.GetParentFile().Exists())
            {
                dotGit.GetParentFile().Mkdirs();
            }
            FilePath modulesGitDir = new FilePath(db.Directory, "modules" + FilePath.separatorChar
                                                  + path);

            new FileWriter(dotGit).Append("gitdir: " + "../" + Constants.DOT_GIT + "/modules/"
                                          + path).Close();
            FileRepositoryBuilder builder = new FileRepositoryBuilder();

            builder.SetWorkTree(new FilePath(db.WorkTree, path));
            builder.Build().Create();
            DirCache       cache  = db.LockDirCache();
            DirCacheEditor editor = cache.Editor();

            editor.Add(new _PathEdit_203(id, path));
            editor.Commit();
            SubmoduleWalk gen = SubmoduleWalk.ForIndex(db);

            NUnit.Framework.Assert.IsTrue(gen.Next());
            NUnit.Framework.Assert.AreEqual(path, gen.GetPath());
            NUnit.Framework.Assert.AreEqual(id, gen.GetObjectId());
            NUnit.Framework.Assert.AreEqual(new FilePath(db.WorkTree, path), gen.GetDirectory
                                                ());
            NUnit.Framework.Assert.IsNull(gen.GetConfigUpdate());
            NUnit.Framework.Assert.IsNull(gen.GetConfigUrl());
            NUnit.Framework.Assert.IsNull(gen.GetModulesPath());
            NUnit.Framework.Assert.IsNull(gen.GetModulesUpdate());
            NUnit.Framework.Assert.IsNull(gen.GetModulesUrl());
            Repository subRepo = gen.GetRepository();

            AddRepoToClose(subRepo);
            NUnit.Framework.Assert.IsNotNull(subRepo);
            NUnit.Framework.Assert.AreEqual(modulesGitDir, subRepo.Directory);
            NUnit.Framework.Assert.AreEqual(new FilePath(db.WorkTree, path), subRepo.WorkTree
                                            );
            NUnit.Framework.Assert.IsFalse(gen.Next());
        }
Пример #3
0
        private static FileRepository GetRepository()
        {
            FileRepositoryBuilder fileRepositoryBuilder = new FileRepositoryBuilder();

            _currentDirectory = Directory.GetCurrentDirectory();
            //_currentDirectory = _debugRepoPath;
            FileRepository repository = null;

            try
            {
                fileRepositoryBuilder.FindGitDir(_currentDirectory);
                repository = fileRepositoryBuilder.Build();
            }
            catch (System.ArgumentNullException)
            {
                Console.WriteLine("ERROR: Repo not found");
                Environment.Exit(0);
            }

            return(repository);
        }
Пример #4
0
        private void RunCleanup(Status status)
        {
            try
            {
                status.SetStatusText("Compacting repository.");
                FileRepositoryBuilder builder = new FileRepositoryBuilder();
                FileRepository        fr      = builder.ReadEnvironment().SetGitDir(Path.Combine(GitRepositoryFolder, ".git")).Build();
                GC  gc    = new GC(fr);
                var stats = gc.GetStatistics();
                LogGitStats(stats);

                ValueProgressMonitor w = new ValueProgressMonitor(status);
                gc.SetProgressMonitor(w);
                gc.Gc();
                stats = gc.GetStatistics();
                LogGitStats(stats);
            }
            catch (Exception e)
            {
                Logging.Error(e, "Error running GC on version repository");
            }
        }
Пример #5
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);
        }
Пример #6
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);
        }
		public virtual void TestWorkdirIsParent_CreateRepositoryFromGitDirOnlyWithBareConfigFalse
			()
		{
			FilePath gitDir = GetFile("workdir", "repoWithBareConfigTrue", "child");
			SetBare(gitDir, false);
			FileRepository repo = new FileRepositoryBuilder().SetGitDir(gitDir).Build();
			AssertWorkdirPath(repo, "workdir", "repoWithBareConfigTrue");
		}
		public virtual void ScanWithGitDirRef()
		{
			FileRepository repo1 = CreateWorkRepository();
			FilePath dir = CreateTempDirectory("dir");
			FilePath dotGit = new FilePath(dir, Constants.DOT_GIT);
			new FileWriter(dotGit).Append("gitdir: " + repo1.Directory.GetAbsolutePath()).Close
				();
			FileRepositoryBuilder builder = new FileRepositoryBuilder();
			builder.SetWorkTree(dir);
			builder.FindGitDir(dir);
			NUnit.Framework.Assert.AreEqual(repo1.Directory, builder.GetGitDir());
			builder.SetMustExist(true);
			FileRepository repo2 = builder.Build();
			NUnit.Framework.Assert.AreEqual(repo1.Directory, repo2.Directory);
			NUnit.Framework.Assert.AreEqual(dir, repo2.WorkTree);
		}
Пример #9
0
 public virtual void Test000_openrepo_alternate_index_file_and_objdirs()
 {
     FilePath repo1Parent = new FilePath(trash.GetParentFile(), "r1");
     FilePath indexFile = new FilePath(trash, "idx");
     FilePath objDir = new FilePath(trash, "../obj");
     FilePath altObjDir = ((ObjectDirectory)db.ObjectDatabase).GetDirectory();
     Repository repo1initial = new FileRepository(new FilePath(repo1Parent, Constants.
         DOT_GIT));
     repo1initial.Create();
     repo1initial.Close();
     FilePath theDir = new FilePath(repo1Parent, Constants.DOT_GIT);
     FileRepository r = new FileRepositoryBuilder().SetGitDir(theDir).SetObjectDirectory
         (objDir).AddAlternateObjectDirectory(altObjDir).SetIndexFile(indexFile).Build();
     //
     //
     //
     //
     AssertEqualsPath(theDir, r.Directory);
     AssertEqualsPath(theDir.GetParentFile(), r.WorkTree);
     AssertEqualsPath(indexFile, r.GetIndexFile());
     AssertEqualsPath(objDir, ((ObjectDirectory)r.ObjectDatabase).GetDirectory());
     NUnit.Framework.Assert.IsNotNull(r.Open(ObjectId.FromString("6db9c2ebf75590eef973081736730a9ea169a0c4"
         )));
     // Must close or the default repo pack files created by this test gets
     // locked via the alternate object directories on Windows.
     r.Close();
 }
Пример #10
0
 public virtual void Test000_openrepo_default_workDirSet()
 {
     FilePath repo1Parent = new FilePath(trash.GetParentFile(), "r1");
     Repository repo1initial = new FileRepository(new FilePath(repo1Parent, Constants.
         DOT_GIT));
     repo1initial.Create();
     repo1initial.Close();
     FilePath theDir = new FilePath(repo1Parent, Constants.DOT_GIT);
     FileRepository r = new FileRepositoryBuilder().SetWorkTree(repo1Parent).Build();
     AssertEqualsPath(theDir, r.Directory);
     AssertEqualsPath(repo1Parent, r.WorkTree);
     AssertEqualsPath(new FilePath(theDir, "index"), r.GetIndexFile());
     AssertEqualsPath(new FilePath(theDir, "objects"), ((ObjectDirectory)r.ObjectDatabase
         ).GetDirectory());
 }
Пример #11
0
 public virtual void Test000_openrepo_default_relative_workdirconfig()
 {
     FilePath repo1Parent = new FilePath(trash.GetParentFile(), "r1");
     FilePath workdir = new FilePath(trash.GetParentFile(), "rw");
     FileUtils.Mkdir(workdir);
     FileRepository repo1initial = new FileRepository(new FilePath(repo1Parent, Constants
         .DOT_GIT));
     repo1initial.Create();
     FileBasedConfig cfg = ((FileBasedConfig)repo1initial.GetConfig());
     cfg.SetString("core", null, "worktree", "../../rw");
     cfg.Save();
     repo1initial.Close();
     FilePath theDir = new FilePath(repo1Parent, Constants.DOT_GIT);
     FileRepository r = new FileRepositoryBuilder().SetGitDir(theDir).Build();
     AssertEqualsPath(theDir, r.Directory);
     AssertEqualsPath(workdir, r.WorkTree);
     AssertEqualsPath(new FilePath(theDir, "index"), r.GetIndexFile());
     AssertEqualsPath(new FilePath(theDir, "objects"), ((ObjectDirectory)r.ObjectDatabase
         ).GetDirectory());
 }
Пример #12
0
		public virtual void RepositoryWithRootLevelSubmoduleRelativeRef()
		{
			ObjectId id = ObjectId.FromString("abcd1234abcd1234abcd1234abcd1234abcd1234");
			string path = "sub";
			FilePath dotGit = new FilePath(db.WorkTree, path + FilePath.separatorChar + Constants
				.DOT_GIT);
			if (!dotGit.GetParentFile().Exists())
			{
				dotGit.GetParentFile().Mkdirs();
			}
			FilePath modulesGitDir = new FilePath(db.Directory, "modules" + FilePath.separatorChar
				 + path);
			new FileWriter(dotGit).Append("gitdir: " + "../" + Constants.DOT_GIT + "/modules/"
				 + path).Close();
			FileRepositoryBuilder builder = new FileRepositoryBuilder();
			builder.SetWorkTree(new FilePath(db.WorkTree, path));
			builder.Build().Create();
			DirCache cache = db.LockDirCache();
			DirCacheEditor editor = cache.Editor();
			editor.Add(new _PathEdit_203(id, path));
			editor.Commit();
			SubmoduleWalk gen = SubmoduleWalk.ForIndex(db);
			NUnit.Framework.Assert.IsTrue(gen.Next());
			NUnit.Framework.Assert.AreEqual(path, gen.GetPath());
			NUnit.Framework.Assert.AreEqual(id, gen.GetObjectId());
			NUnit.Framework.Assert.AreEqual(new FilePath(db.WorkTree, path), gen.GetDirectory
				());
			NUnit.Framework.Assert.IsNull(gen.GetConfigUpdate());
			NUnit.Framework.Assert.IsNull(gen.GetConfigUrl());
			NUnit.Framework.Assert.IsNull(gen.GetModulesPath());
			NUnit.Framework.Assert.IsNull(gen.GetModulesUpdate());
			NUnit.Framework.Assert.IsNull(gen.GetModulesUrl());
			Repository subRepo = gen.GetRepository();
			AddRepoToClose(subRepo);
			NUnit.Framework.Assert.IsNotNull(subRepo);
			NUnit.Framework.Assert.AreEqual(modulesGitDir, subRepo.Directory);
			NUnit.Framework.Assert.AreEqual(new FilePath(db.WorkTree, path), subRepo.WorkTree
				);
			NUnit.Framework.Assert.IsFalse(gen.Next());
		}
		public virtual void TestWorkdirIsDotGit_CreateRepositoryFromWorkDirOnly()
		{
			FilePath workdir = GetFile("workdir", "repo");
			FileRepository repo = new FileRepositoryBuilder().SetWorkTree(workdir).Build();
			AssertGitdirPath(repo, "workdir", "repo", Constants.DOT_GIT);
		}
		public virtual void TestNotBare_CreateRepositoryFromWorkDirOnly()
		{
			FilePath workdir = GetFile("workdir", "repo");
			FileRepository repo = new FileRepositoryBuilder().SetWorkTree(workdir).Build();
			NUnit.Framework.Assert.IsFalse(repo.IsBare);
			AssertWorkdirPath(repo, "workdir", "repo");
			AssertGitdirPath(repo, "workdir", "repo", Constants.DOT_GIT);
		}
Пример #15
0
		public virtual void RelativeGitDirRef()
		{
			FileRepository repo1 = CreateWorkRepository();
			FilePath dir = new FilePath(repo1.WorkTree, "dir");
			NUnit.Framework.Assert.IsTrue(dir.Mkdir());
			FilePath dotGit = new FilePath(dir, Constants.DOT_GIT);
			new FileWriter(dotGit).Append("gitdir: ../" + Constants.DOT_GIT).Close();
			FileRepositoryBuilder builder = new FileRepositoryBuilder();
			builder.SetWorkTree(dir);
			builder.SetMustExist(true);
			FileRepository repo2 = builder.Build();
			NUnit.Framework.Assert.AreEqual(repo1.Directory, repo2.Directory);
			NUnit.Framework.Assert.AreEqual(dir, repo2.WorkTree);
		}
		public virtual void TestBare_CreateRepositoryFromGitDirOnlyWithBareConfigTrue()
		{
			FilePath gitDir = GetFile("workdir", "repoWithConfig");
			SetBare(gitDir, true);
			FileRepository repo = new FileRepositoryBuilder().SetGitDir(gitDir).Build();
			NUnit.Framework.Assert.IsTrue(repo.IsBare);
		}
		public virtual void TestNotBare_CreateRepositoryFromGitDirOnlyWithWorktreeConfig(
			)
		{
			FilePath gitDir = GetFile("workdir", "repoWithConfig");
			FilePath workTree = GetFile("workdir", "treeRoot");
			SetWorkTree(gitDir, workTree);
			FileRepository repo = new FileRepositoryBuilder().SetGitDir(gitDir).Build();
			NUnit.Framework.Assert.IsFalse(repo.IsBare);
			AssertWorkdirPath(repo, "workdir", "treeRoot");
			AssertGitdirPath(repo, "workdir", "repoWithConfig");
		}
Пример #18
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();
        }
Пример #19
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();
        }
Пример #20
0
        private Repository OpenRepository()
        {
            FileRepositoryBuilder builder = new FileRepositoryBuilder();

            return(builder.ReadEnvironment().SetGitDir(Path.Combine(GitRepositoryFolder, ".git")).Build());
        }
		public virtual void TestNotBare_CreateRepositoryFromGitDirOnlyWithBareConfigFalse
			()
		{
			FilePath gitDir = GetFile("workdir", "repoWithBareConfigFalse", "child");
			SetBare(gitDir, false);
			FileRepository repo = new FileRepositoryBuilder().SetGitDir(gitDir).Build();
			NUnit.Framework.Assert.IsFalse(repo.IsBare);
			AssertWorkdirPath(repo, "workdir", "repoWithBareConfigFalse");
			AssertGitdirPath(repo, "workdir", "repoWithBareConfigFalse", "child");
		}