Ejemplo n.º 1
0
        private string FullyParsePatch(string fileName, string rawUrl, string patch)
        {
            DiffParser parser  = new DiffParser();
            string     rawFile = GetFullRawFile(rawUrl);
            var        terms   = parser.FindTerms(fileName, rawFile, patch);

            return(string.Join(' ', terms));
        }
Ejemplo n.º 2
0
        public void CanParseDiff()
        {
            List <DiffLine> result = DiffParser.ParseDiff(c_ExampleDiff);

            foreach (var l in result)
            {
                Log(l.ToString());
            }
        }
Ejemplo n.º 3
0
        public static IEnumerable<FileDiff> Parse(string input, string lineEnding = "\n")
        {
            if (string.IsNullOrWhiteSpace(input)) return Enumerable.Empty<FileDiff>();

            var lines = input.Split(new[] { lineEnding }, StringSplitOptions.None);

            if (lines.Length == 0) return Enumerable.Empty<FileDiff>();

            var parser = new DiffParser();

            return parser.Run(lines);
        }
Ejemplo n.º 4
0
        public void CanVisitDiff()
        {
            List <DiffLine> result = DiffParser.ParseDiff(c_ExampleDiff);

            var visitor = new LineVisitorContext();

            foreach (var l in result)
            {
                l.Accept(visitor);
                Trace.WriteLine(string.Format("{0} {1} {2}", visitor.CurrentNewFile, visitor.CurrentNewFileLineNumber, visitor.CurrentLineText ?? visitor.CurrentFunctionName ?? visitor.CurrentContext));
            }
        }
Ejemplo n.º 5
0
        private IEnumerable <DiffComment> Review(string diff)
        {
            var parsedDiff = DiffParser.ParseDiff(diff);

            foreach (var reviewerCreator in m_Reviewers)
            {
                var reviewer = reviewerCreator();
                foreach (var comment in reviewer.Review(parsedDiff))
                {
                    yield return(comment);
                }
            }
        }
Ejemplo n.º 6
0
        public void ShouldParseDiffPage()
        {
            //arrange
            const string pageUri       = @"https://patch-diff.githubusercontent.com/raw/MaxVortman/F_Sharp_Homework/pull/15.diff";
            const string firstFileName = "F_Sharp_Homework.sln";
            const string lastFileName  = "Phonebook(Task5)/UIFactory.fs";
            const int    count         = 9;
            var          diffParser    = new DiffParser(pageUri);
            //act
            var files = diffParser.DiffFiles;

            //assert
            Assert.AreEqual(count, files.Count());
            var first = files.First();
            var last  = files.Last();

            Assert.AreEqual(firstFileName, first.Name);
            Assert.AreEqual(lastFileName, last.Name);
        }
Ejemplo n.º 7
0
        public void DiffParser_True_StreamParseDiff()
        {
            var lines  = @"diff --git a/.gitmodules b/.gitmodules
new file mode 100644
index 0000000..6abde17
--- /dev/null
+++ b/.gitmodules
@@ -0,0 +1,3 @@
+[submodule ""gogs/docs-api""]
+	path = gogs/docs-api
+	url = https://github.com/gogs/docs-api.git
diff --git a/gogs/docs-api b/gogs/docs-api
new file mode 160000
index 0000000..6b08f76
--- /dev/null
+++ b/gogs/docs-api
@@ -0,0 +1 @@
+Subproject commit 6b08f76a5313fa3d26859515b30aa17a5faa2807";
            var dp     = new DiffParser(0, 0, 0);
            var result = dp.StreamParseDiff(lines, '\n');

            lines  = @"diff --git a/pom.xml b/pom.xml
index ee791be..9997571 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1,7 +1,7 @@
 <project xmlns=""http://maven.apache.org/POM/4.0.0"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance""
   xsi:schemaLocation=""http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"">
   <modelVersion>4.0.0</modelVersion>
-  <groupId>com.ambientideas</groupId>
+  <groupId>com.github</groupId>
   <artifactId>egitdemo</artifactId>
   <packaging>jar</packaging>
   <version>1.0-SNAPSHOT</version>";
            result = dp.StreamParseDiff(lines, '\n');

            lines = @"diff --git a/img/sourcegraph.png b/img/sourcegraph.png
new file mode 100644
index 0000000..2ce9188
Binary files /dev/null and b/img/sourcegraph.png differ";

            result = dp.StreamParseDiff(lines, '\n');

            lines = @"diff --git a/fix.txt b/fix.txt
deleted file mode 100644
index e69de29..0000000";

            result = dp.StreamParseDiff(lines, '\n');

            lines = @"diff --git a/runme.sh b/run.sh
similarity index 100%
rename from runme.sh
rename to run.sh";

            result = dp.StreamParseDiff(lines, '\n');

            lines = @"diff --git a/dir/file.txt b/dir/file.txt
index b6fc4c620b67d95f953a5c1c1230aaab5db5a1b0..ab80bda5dd90d8b42be25ac2c7a071b722171f09 100644
--- a/dir/file.txt
+++ b/dir/file.txt
@@ -1 +1,3 @@
-hello
\ No newline at end of file
+hello
+
+fdsfdsfds
\ No newline at end of file";

            result = dp.StreamParseDiff(lines, '\n');

            lines = @"diff --git a/src/app/tabs/teacher/teacher.module.ts b/src/app/tabs/friends/friends.module.ts
similarity index 69%
rename from src/app/tabs/teacher/teacher.module.ts
rename to src/app/tabs/friends/friends.module.ts
index ce53c7e..56a156b 100644
--- a/src/app/tabs/teacher/teacher.module.ts
+++ b/src/app/tabs/friends/friends.module.ts
@@ -2,9 +2,9 @@ import { IonicModule } from '@ionic/angular'
 import { RouterModule } from '@angular/router'
 import { NgModule } from '@angular/core'
 import { CommonModule } from '@angular/common'
-import { FormsModule } from '@angular/forms'
-import { TeacherPage } from './teacher.page'
 import { ComponentsModule } from '@components/components.module'
+import { FormsModule } from '@angular/forms'
+import { FriendsPage } from './friends.page'";

            result = dp.StreamParseDiff(lines, '\n');

            lines  = @"diff --git a/.travis.yml b/.travis.yml
index 335db7ea..51d7543e 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,9 +1,6 @@
 sudo: false
 language: go
 go:
-  - 1.4.x
-  - 1.5.x
-  - 1.6.x
   - 1.7.x
   - 1.8.x
   - 1.9.x
@@ -12,6 +9,7 @@ go:
   - 1.12.x
   - 1.13.x
 
+install: go get -v ./...
 script: 
   - go get golang.org/x/tools/cmd/cover
   - go get github.com/smartystreets/goconvey";
            dp     = new DiffParser(0, 2, 0);
            result = dp.StreamParseDiff(lines, '\n');

            lines  = @"diff --git a/.gitmodules b/.gitmodules
new file mode 100644
index 0000000..6abde17
--- /dev/null
+++ b/.gitmodules
@@ -0,0 +1,3 @@
+[submodule ""gogs/docs-api""]
+	path = gogs/docs-api
+	url = https://github.com/gogs/docs-api.git"    ;
            dp     = new DiffParser(0, 0, 30);
            result = dp.StreamParseDiff(lines, '\n');

            lines  = @"diff --git a/.gitmodules b/.gitmodules
new file mode 100644
index 0000000..6abde17
--- /dev/null
+++ b/.gitmodules
@@ -0,0 +1,3 @@
+[submodule ""gogs/docs-api""]
+	path = gogs/docs-api
+	url = https://github.com/gogs/docs-api.git
diff --git a/gogs/docs-api b/gogs/docs-api
new file mode 160000
index 0000000..6b08f76
--- /dev/null
+++ b/gogs/docs-api
@@ -0,0 +1 @@
+Subproject commit 6b08f76a5313fa3d26859515b30aa17a5faa2807";
            dp     = new DiffParser(1, 2, 30);
            result = dp.StreamParseDiff(lines, '\n');
        }
Ejemplo n.º 8
0
        private void bwDiff_DoWork(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker worker = sender as BackgroundWorker;
            Config conf = e.Argument as Config;

            while (true)
            {
                try
                {
                    if (string.IsNullOrEmpty(Cnfg.Program)) return;

                    Process getdiff = new Process();
                    getdiff.StartInfo.FileName = Cnfg.Program;
                    getdiff.StartInfo.Arguments = Cnfg.Arguments;
                    getdiff.StartInfo.WorkingDirectory = Cnfg.WorkDir;
                    getdiff.StartInfo.RedirectStandardOutput = true;
                    getdiff.StartInfo.UseShellExecute = false;
                    getdiff.StartInfo.CreateNoWindow = true;
                    getdiff.Start();
                    string result = getdiff.StandardOutput.ReadToEnd();
                    getdiff.WaitForExit();

                    Dictionary<string, string> files = new Dictionary<string, string>();

                    DiffParser parser = new DiffParser();
                    Regex regLines =
                        new Regex(
                            @"@@ \-(?<OldLine>\d+)(\,(?<OldChangeLine>\d+))? \+(?<Line>\d+)(\,(?<ChangeLine>\d+))? @@(?<FuncName>.*)",
                            RegexOptions.Compiled);

                    int countlineheader = 0;
                    List<string> delete = new List<string>();
                    List<string> add = new List<string>();
                    foreach (string line in result.Split(new[] { '\n' }))
                    {
                        if (string.IsNullOrEmpty(line)) continue;

                        countlineheader--;
                        if (line.Length > 12 && line.Substring(0, 11) == @"diff --git ")
                        {
                            countlineheader = 4;
                        }
                        else if (countlineheader == 3)
                        {
                            parser.IndexAndMode = line.Substring(6);
                        }
                        else if (countlineheader == 2)
                        {
                            parser.OldFileName = line.Substring(line.IndexOf("/") + 1).TrimEnd();
                        }
                        else if (countlineheader == 1)
                        {
                            parser.FileName = line.Substring(line.IndexOf("/") + 1).TrimEnd();
                            files.Add(parser.FileName, "");
                        }
                        else
                        {
                            Match match_lines = regLines.Match(line);
                            if (match_lines.Success)
                            {
                                try
                                {
                                    parser.FuncName = match_lines.Groups["FuncName"].Value;
                                    parser.Line = int.Parse(match_lines.Groups["Line"].Value);
                                    parser.ChangeLine = int.Parse(match_lines.Groups["ChangeLine"].Value);
                                    parser.OldLine = int.Parse(match_lines.Groups["OldLine"].Value);
                                    parser.OldChangeLine = int.Parse(match_lines.Groups["OldChangeLine"].Value);
                                    parser.LineShift = 0;
                                    files[parser.FileName] += "<span class=\"lines\">" +
                                                              System.Net.WebUtility.HtmlEncode(line) +
                                                              "</span>" + Environment.NewLine;
                                }
                                catch (Exception ex)
                                {
                                }
                            }
                            else
                            {
                                string diffstatus = line.Length > 0 ? line.Substring(0, 1) : "";
                                if (diffstatus == "-") delete.Add(line.Substring(1));
                                else if (diffstatus == "+") add.Add(line.Substring(1));
                                else
                                {
                                    if (delete.Count > 0 && add.Count > 0)
                                    {
                                        files[parser.FileName] += "<span class=\"modif\">" +
                                                                  System.Net.WebUtility.HtmlEncode(
                                            add.Aggregate((now, next) => now + Environment.NewLine + next)) +
                                                                  "</span>" + Environment.NewLine;
                                    }
                                    else if (delete.Count > 0)
                                    {
                                        files[parser.FileName] += "<span class=\"delete\">" +
                                                                  System.Net.WebUtility.HtmlEncode(
                                            delete.Aggregate((now, next) => now + Environment.NewLine + next)) +
                                                                  "</span>" + Environment.NewLine;
                                    }
                                    else if (add.Count > 0)
                                    {
                                        files[parser.FileName] += "<span class=\"add\">" +
                                                                  System.Net.WebUtility.HtmlEncode(
                                            add.Aggregate((now, next) => now + Environment.NewLine + next)) +
                                                                  "</span>" + Environment.NewLine;
                                    }
                                    files[parser.FileName] +=
                                        (line.Length > 0 ? System.Net.WebUtility.HtmlEncode(line.Substring(1)) : "") +
                                        Environment.NewLine;
                                    delete.Clear();
                                    add.Clear();
                                }
                            }
                        }
                    }

                    string html = "";

                    foreach (string key in files.Keys.OrderByDescending(
                                 delegate(string name)
                                 {
                                     FileInfo fi = new FileInfo(Cnfg.WorkDir + "\\" + name);
                                     return fi.LastWriteTime;
                                 }))
                    {
                        html += "<pre><span class=\"file\">" + key + "</span>" + Environment.NewLine + files[key] + "</pre>";
                    }

                    html = "<!DOCTYPE html>" + Environment.NewLine +
                           "<html>" + Environment.NewLine +
                           "<head>" + Environment.NewLine +
                           "<style type=\"text/css\">" + Environment.NewLine +
                           "body {background-color: #323232; color: #999999; font: " + Cnfg.Font + ";}" + Environment.NewLine +
                           ".file {color: #ffcc33}" + Environment.NewLine +
                           ".lines {color: #0099ff}" + Environment.NewLine +
                           ".add {color: #00ff33}" + Environment.NewLine +
                           ".delete {color: #ff6600}" + Environment.NewLine +
                           ".modif {color: #ff32ff}" + Environment.NewLine +
                           "</style>" + Environment.NewLine +
                           "</head>" + Environment.NewLine +
                           "<body>" + Environment.NewLine +
                           html +
                           "</body>" + Environment.NewLine +
                           "</html>";
                    worker.ReportProgress(0, html);
                }
                catch (Exception ex)
                {
                    string html = "<!DOCTYPE html>" + Environment.NewLine +
                                  "<html>" + Environment.NewLine +
                                  "<head>" + Environment.NewLine +
                                  "</head>" + Environment.NewLine +
                                  "<body>" + Environment.NewLine +
                                  "<pre>" + ex.ToString() + "</pre>" + Environment.NewLine +
                                  "</body>" + Environment.NewLine +
                                  "</html>";
                    worker.ReportProgress(0, html);
                }

                for (int sleep = (int)conf.Update * 10; sleep >= 0; sleep--)
                {
                    if (worker.CancellationPending)
                    {
                        e.Cancel = true;
                        return;
                    }
                    Thread.Sleep(100);
                }
            }
        }
 public void Setup()
 {
     _diffParser = new DiffParser();
 }