Exemplo n.º 1
0
 public override void SetUp()
 {
     base.SetUp();
     testDb = new TestRepository(db);
     df = new DiffFormatter(DisabledOutputStream.INSTANCE);
     df.SetRepository(db);
     df.SetAbbreviationLength(8);
 }
Exemplo n.º 2
0
        public ActionResult FileDiff(string path, string fromSha1, string toSha1)
        {
            var nGit = TM_UserData_Git.Current.NGit;

            Func <Repository, string, string, string, string> getDiff =
                (gitRepo, repoPath, fromCommitId, toCommitId) =>
            {
                var fromCommit = gitRepo.Resolve(fromCommitId);
                var toCommit   = gitRepo.Resolve(toCommitId);

                var outputStream = "Sharpen.dll".assembly().type("ByteArrayOutputStream").ctor(new object[0]).cast <OutputStream>();
                //return "diffing from {0} to  {1}".format(fromCommit, toCommit);
                var diffFormater = new DiffFormatter(outputStream);
                var pathFilter   = PathFilter.Create(repoPath);
                diffFormater.SetRepository(gitRepo);
                diffFormater.SetPathFilter(pathFilter);
                //diffFormater.Format(refLog.GetNewId(), refLog.GetOldId());
                diffFormater.Format(fromCommit, toCommit);
                return("result: " + outputStream.str());
            };

            Func <Repository, string, string, string> getFistValue =
                (gitRepo, commitSha1, repoPath) =>
            {
                var revCommit    = nGit.commit(commitSha1);
                var outputStream = "Sharpen.dll".assembly().type("ByteArrayOutputStream").ctor(new object[0]).cast <OutputStream>();
                var diffFormater = new DiffFormatter(outputStream);
                var pathFilter   = PathFilter.Create(repoPath);
                diffFormater.SetRepository(gitRepo);
                diffFormater.SetPathFilter(pathFilter);

                var revWalk             = new RevWalk(gitRepo);
                var canonicalTreeParser = new CanonicalTreeParser(null, revWalk.GetObjectReader(), revCommit.Tree);
                diffFormater.Format(new EmptyTreeIterator(), canonicalTreeParser);
                return(outputStream.str().fix_CRLF());
            };

            var rawDiff = fromSha1 == NGit_Consts.EMPTY_SHA1
                            ? getFistValue(nGit.repository(), fromSha1, path)
                            :  getDiff(nGit.repository(), path, fromSha1, toSha1);


            var viewFile = new View_GitFileDiff()
            {
                FilePath = path,
                FromSha1 = fromSha1,
                ToSha1   = toSha1,
                Diff     = rawDiff
            };

            return(View(viewFile));
        }
Exemplo n.º 3
0
        public ActionResult FileDiff(string path, string fromSha1,string toSha1)
        {
            var nGit = TM_UserData_Git.Current.NGit;

            Func<Repository, string, string, string, string> getDiff =
                (gitRepo, repoPath, fromCommitId, toCommitId) =>
                    {

                        var fromCommit = gitRepo.Resolve(fromCommitId);
                        var toCommit = gitRepo.Resolve(toCommitId);

                        var outputStream = "Sharpen.dll".assembly().type("ByteArrayOutputStream").ctor(new object[0]).cast<OutputStream>();
                        //return "diffing from {0} to  {1}".format(fromCommit, toCommit);
                        var diffFormater = new DiffFormatter(outputStream);
                        var pathFilter = PathFilter.Create(repoPath);
                        diffFormater.SetRepository(gitRepo);
                        diffFormater.SetPathFilter(pathFilter);
                        //diffFormater.Format(refLog.GetNewId(), refLog.GetOldId());
                        diffFormater.Format(fromCommit, toCommit);
                        return "result: " + outputStream.str();
                    };

            Func<Repository, string, string, string> getFistValue =
                (gitRepo, commitSha1, repoPath) =>
                    {
                        var revCommit = nGit.commit(commitSha1);
                        var outputStream = "Sharpen.dll".assembly().type("ByteArrayOutputStream").ctor(new object[0]).cast<OutputStream>();
                        var diffFormater = new DiffFormatter(outputStream);
                        var pathFilter = PathFilter.Create(repoPath);
                        diffFormater.SetRepository(gitRepo);
                        diffFormater.SetPathFilter(pathFilter);

                        var revWalk = new RevWalk(gitRepo);
                        var canonicalTreeParser = new CanonicalTreeParser(null, revWalk.GetObjectReader(), revCommit.Tree);
                        diffFormater.Format(new EmptyTreeIterator(), canonicalTreeParser);
                        return outputStream.str().fix_CRLF();
                    };

            var rawDiff = fromSha1 == NGit_Consts.EMPTY_SHA1
                            ? getFistValue(nGit.repository(), fromSha1, path)
                            :  getDiff(nGit.repository(), path, fromSha1, toSha1);

            var viewFile = new View_GitFileDiff()
                {
                    FilePath = path,
                    FromSha1 = fromSha1,
                    ToSha1 = toSha1,
                    Diff = rawDiff
                };
            return View(viewFile);
        }
Exemplo n.º 4
0
 public static List<DiffEntry> diff_Commits(this API_NGit nGit, RevCommit from_RevCommit, RevCommit to_RevCommit)
 {
     if (nGit.repository().notNull())
         try
         {
             var outputStream = NGit_Factory.New_OutputStream();
             var diffFormater = new DiffFormatter(outputStream);
             diffFormater.SetRepository(nGit.repository());
             return diffFormater.Scan(from_RevCommit, to_RevCommit).toList();
         }
         catch (Exception ex)
         {
             ex.log("[API_NGit][diff]");
         }
     return new List<DiffEntry>();
 }
 public static List <DiffEntry> diff_Commits(this API_NGit nGit, RevCommit from_RevCommit, RevCommit to_RevCommit)
 {
     if (nGit.repository().notNull())
     {
         try
         {
             var outputStream = NGit_Factory.New_OutputStream();
             var diffFormater = new DiffFormatter(outputStream);
             diffFormater.SetRepository(nGit.repository());
             return(diffFormater.Scan(from_RevCommit, to_RevCommit).toList());
         }
         catch (Exception ex)
         {
             ex.log("[API_NGit][diff]");
         }
     }
     return(new List <DiffEntry>());
 }
Exemplo n.º 6
0
        /// <exception cref="System.IO.IOException"></exception>
        private RebaseResult Stop(RevCommit commitToPick)
        {
            PersonIdent author       = commitToPick.GetAuthorIdent();
            string      authorScript = ToAuthorScript(author);

            CreateFile(rebaseDir, AUTHOR_SCRIPT, authorScript);
            CreateFile(rebaseDir, MESSAGE, commitToPick.GetFullMessage());
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            DiffFormatter         df  = new DiffFormatter(bos);

            df.SetRepository(repo);
            df.Format(commitToPick.GetParent(0), commitToPick);
            CreateFile(rebaseDir, PATCH, Sharpen.Runtime.GetStringForBytes(bos.ToByteArray(),
                                                                           Constants.CHARACTER_ENCODING));
            CreateFile(rebaseDir, STOPPED_SHA, repo.NewObjectReader().Abbreviate(commitToPick
                                                                                 ).Name);
            return(new RebaseResult(commitToPick));
        }
Exemplo n.º 7
0
        } // End Function ReadFile 


        public static string GetDiff(Repository repo, DiffEntry entry)
        {
            string strDiff = null;

            using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
            {
                DiffFormatter diffFormatter = new DiffFormatter(ms);
                diffFormatter.SetRepository(repo);
                diffFormatter.Format(diffFormatter.ToFileHeader(entry));

                ms.Position = 0;
                using (System.IO.StreamReader sr = new System.IO.StreamReader(ms))
                {
                    strDiff = sr.ReadToEnd();
                }
            }

            return strDiff;
        } // End Function GetDiff
Exemplo n.º 8
0
        private static void BuildStopWordIndex(Iterable <RevCommit> log, Repository repository, Git git)
        {
            Console.WriteLine("Index build start -" + System.DateTime.Now);
            DateTime startTime = DateTime.Now;

            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)
                    {
                        string filename = diff.GetNewPath();
                        if (Utils.AllowedFileExtentions(filename))
                        {
                            string data = GitHelper.GetCommitDiff(repository, git, rev, filename);
                            StopWords.StopWordIndexBuilder.BuildWordIndex(filename, data);
                        }
                    }
                }

                if (DateTime.Now.Subtract(startTime).TotalMinutes > 60)
                {
                    break;
                }
            }

            Console.WriteLine("Index build end -" + System.DateTime.Now);

            StopWords.StopWordIndexBuilder.BuildStopWordsIndex();
            StopWords.StopWordIndexBuilder.WriteToFile();

            Console.WriteLine("Stop word keyword index build completed..");
        }
Exemplo n.º 9
0
 public static string diff(this API_NGit nGit, string from_CommitId, string to_CommitId)
 {
     if (nGit.repository().notNull())
         try
         {
             var fromCommit = nGit.resolve(from_CommitId);
             var toCommit = nGit.resolve(to_CommitId);
             var outputStream = NGit_Factory.New_OutputStream();
             var diffFormater = new DiffFormatter(outputStream);
             diffFormater.SetRepository(nGit.repository());
             diffFormater.Format(fromCommit, toCommit);
             return outputStream.str();
         }
         catch (Exception ex)
         {
             ex.log("[API_NGit][diff]");
         }
     return null;
 }
 public static string            diff(this API_NGit nGit, string from_CommitId, string to_CommitId)
 {
     if (nGit.repository().notNull())
     {
         try
         {
             var fromCommit   = nGit.resolve(from_CommitId);
             var toCommit     = nGit.resolve(to_CommitId);
             var outputStream = NGit_Factory.New_OutputStream();
             var diffFormater = new DiffFormatter(outputStream);
             diffFormater.SetRepository(nGit.repository());
             diffFormater.Format(fromCommit, toCommit);
             return(outputStream.str());
         }
         catch (Exception ex)
         {
             ex.log("[API_NGit][diff]");
         }
     }
     return(null);
 }
Exemplo n.º 11
0
		public virtual void TestDiff()
		{
			Write(new FilePath(db.Directory.GetParent(), "test.txt"), "test");
			FilePath folder = new FilePath(db.Directory.GetParent(), "folder");
			folder.Mkdir();
			Write(new FilePath(folder, "folder.txt"), "folder");
			Git git = new Git(db);
			git.Add().AddFilepattern(".").Call();
			git.Commit().SetMessage("Initial commit").Call();
			Write(new FilePath(folder, "folder.txt"), "folder change");
			ByteArrayOutputStream os = new ByteArrayOutputStream();
			DiffFormatter df = new DiffFormatter(new BufferedOutputStream(os));
			df.SetRepository(db);
			df.SetPathFilter(PathFilter.Create("folder"));
			DirCacheIterator oldTree = new DirCacheIterator(db.ReadDirCache());
			FileTreeIterator newTree = new FileTreeIterator(db);
			df.Format(oldTree, newTree);
			df.Flush();
			string actual = os.ToString();
			string expected = "diff --git a/folder/folder.txt b/folder/folder.txt\n" + "index 0119635..95c4c65 100644\n"
				 + "--- a/folder/folder.txt\n" + "+++ b/folder/folder.txt\n" + "@@ -1 +1 @@\n" +
				 "-folder\n" + "\\ No newline at end of file\n" + "+folder change\n" + "\\ No newline at end of file\n";
			NUnit.Framework.Assert.AreEqual(expected.ToString(), actual);
		}
Exemplo n.º 12
0
        } // End Function GetDiff


        // https://stackoverflow.com/questions/13537734/how-to-use-jgit-to-get-list-of-changed-files
        // https://github.com/centic9/jgit-cookbook/blob/master/src/main/java/org/dstadler/jgit/porcelain/ShowChangedFilesBetweenCommits.java
        public static void GetChanges(Git git, Repository repo, RevCommit oldCommit, RevCommit newCommit)
        {
            System.Console.WriteLine("Printing diff between commit: " + oldCommit.ToString() + " and " + newCommit.ToString());
            ObjectReader reader = repo.NewObjectReader();

            // prepare the two iterators to compute the diff between
            CanonicalTreeParser oldTreeIter = new CanonicalTreeParser();
            oldTreeIter.Reset(reader, oldCommit.Tree.Id);
            CanonicalTreeParser newTreeIter = new CanonicalTreeParser();
            newTreeIter.Reset(reader, newCommit.Tree.Id);

            // DiffStatFormatter df = new DiffStatFormatter(newCommit.Name, repo);
            using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
            {

                DiffFormatter diffFormatter = new DiffFormatter(ms);
                diffFormatter.SetRepository(repo);

                int entryCount = 0;
                foreach (DiffEntry entry in diffFormatter.Scan(oldCommit, newCommit))
                {
                    string pathToUse = null;

                    TreeWalk treeWalk = new TreeWalk(repo);
                    treeWalk.Recursive = true;

                    if (entry.GetChangeType() == DiffEntry.ChangeType.DELETE)
                    {
                        treeWalk.AddTree(oldCommit.Tree);
                        pathToUse = entry.GetOldPath();
                    }
                    else
                    {
                        treeWalk.AddTree(newCommit.Tree);
                        pathToUse = entry.GetNewPath();   
                    }

                    treeWalk.Filter = PathFilter.Create(pathToUse); 
                        
                    if (!treeWalk.Next())
                    {
                        throw new System.Exception("Did not find expected file '" + pathToUse + "'");
                    }

                    ObjectId objectId = treeWalk.GetObjectId(0);
                    ObjectLoader loader = repo.Open(objectId);

                    string strModifiedFile = ReadFile(loader);
                    System.Console.WriteLine(strModifiedFile);

                    //////////////
                    // https://stackoverflow.com/questions/27361538/how-to-show-changes-between-commits-with-jgit
                    diffFormatter.Format(diffFormatter.ToFileHeader(entry));

                    string diff = GetDiff(repo, entry);
                    System.Console.WriteLine(diff);

                    entryCount++;
                } // Next entry 

                System.Console.WriteLine(entryCount);

                ms.Position = 0;
                using (System.IO.StreamReader sr = new System.IO.StreamReader(ms))
                {
                    string strAllDiffs = sr.ReadToEnd();
                    System.Console.WriteLine(strAllDiffs);
                } // End Using sr 
                
            } // End Using ms 


            System.Collections.Generic.IList<DiffEntry> diffs = git.Diff()
                             .SetNewTree(newTreeIter)
                             .SetOldTree(oldTreeIter)
                             .Call();

            foreach (DiffEntry entry in diffs)
            {
                System.Console.WriteLine("Entry: " + entry);
                System.Console.WriteLine("Entry: " + entry.GetChangeType());
            } // Next entry 

            System.Console.WriteLine("Done");
        } // End Sub GetChanges 
Exemplo n.º 13
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();
        }
Exemplo n.º 14
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();
        }
Exemplo n.º 15
0
		static string GenerateDiff (byte[] data1, byte[] data2, NGit.Repository repo)
		{
			if (RawText.IsBinary (data1) || RawText.IsBinary (data2)) {
				if (data1.Length != data2.Length)
					return GettextCatalog.GetString (" Binary files differ");
				if (data1.Length == data2.Length) {
					for (int n=0; n<data1.Length; n++) {
						if (data1[n] != data2[n])
							return GettextCatalog.GetString (" Binary files differ");
					}
				}
				return string.Empty;
			}
			var text1 = new RawText (data1);
			var text2 = new RawText (data2);

			var edits = DiffAlgorithm.GetAlgorithm (DiffAlgorithm.SupportedAlgorithm.MYERS)
					.Diff (RawTextComparator.DEFAULT, text1, text2);
			MemoryStream s = new MemoryStream ();
			var formatter = new DiffFormatter (s);
			formatter.SetRepository (repo);
			formatter.Format (edits, text1, text2);
			return Encoding.UTF8.GetString (s.ToArray ());
		}