Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the git log and git status output processors. Split status field into two. #1058

Merged
merged 5 commits into from
Jun 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion common/SolutionInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
namespace System
{
internal static class AssemblyVersionInformation {
private const string GitHubForUnityVersion = "1.3.2";
private const string GitHubForUnityVersion = "1.4.0";
internal const string VersionForAssembly = GitHubForUnityVersion;

// If this is an alpha, beta or other pre-release, mark it as such as shown below
Expand Down
3 changes: 2 additions & 1 deletion src/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -312,4 +312,5 @@ sysinfo.txt
# Builds
*.apk
*.unitypackage
UnityExtension/**/manifest.json
UnityExtension/**/manifest.json
tests/IntegrationTests/IOTestsRepo/
4 changes: 2 additions & 2 deletions src/GitHub.Api/Git/GitObjectFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ public GitObjectFactory(IEnvironment environment)
this.environment = environment;
}

public GitStatusEntry CreateGitStatusEntry(string path, GitFileStatus status, string originalPath = null, bool staged = false)
public GitStatusEntry CreateGitStatusEntry(string path, GitFileStatus indexStatus, GitFileStatus workTreeStatus = GitFileStatus.None, string originalPath = null)
{
var absolutePath = new NPath(path).MakeAbsolute();
var relativePath = absolutePath.RelativeTo(environment.RepositoryPath);
var projectPath = absolutePath.RelativeTo(environment.UnityProjectPath);

return new GitStatusEntry(relativePath, absolutePath, projectPath, status, originalPath?.ToNPath(), staged);
return new GitStatusEntry(relativePath, absolutePath, projectPath, indexStatus, workTreeStatus, originalPath?.ToNPath());
}
}
}
78 changes: 65 additions & 13 deletions src/GitHub.Api/Git/GitStatusEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,22 @@ public struct GitStatusEntry
public string fullPath;
public string projectPath;
public string originalPath;
public GitFileStatus status;
public bool staged;
public GitFileStatus indexStatus;
public GitFileStatus workTreeStatus;

public GitStatusEntry(string path, string fullPath, string projectPath, GitFileStatus status,
string originalPath = null, bool staged = false)
public GitStatusEntry(string path, string fullPath, string projectPath,
GitFileStatus indexStatus, GitFileStatus workTreeStatus,
string originalPath = null)
{
Guard.ArgumentNotNullOrWhiteSpace(path, "path");
Guard.ArgumentNotNullOrWhiteSpace(fullPath, "fullPath");

this.path = path;
this.status = status;
this.indexStatus = indexStatus;
this.workTreeStatus = workTreeStatus;
this.fullPath = fullPath;
this.projectPath = projectPath;
this.originalPath = originalPath;
this.staged = staged;
}

public override int GetHashCode()
Expand All @@ -35,8 +36,8 @@ public override int GetHashCode()
hash = hash * 23 + (fullPath?.GetHashCode() ?? 0);
hash = hash * 23 + (projectPath?.GetHashCode() ?? 0);
hash = hash * 23 + (originalPath?.GetHashCode() ?? 0);
hash = hash * 23 + status.GetHashCode();
hash = hash * 23 + staged.GetHashCode();
hash = hash * 23 + indexStatus.GetHashCode();
hash = hash * 23 + workTreeStatus.GetHashCode();
return hash;
}

Expand All @@ -54,8 +55,8 @@ public bool Equals(GitStatusEntry other)
String.Equals(fullPath, other.fullPath) &&
String.Equals(projectPath, other.projectPath) &&
String.Equals(originalPath, other.originalPath) &&
status == other.status &&
staged == other.staged
indexStatus == other.indexStatus &&
workTreeStatus == other.workTreeStatus
;
}

Expand All @@ -78,6 +79,49 @@ public bool Equals(GitStatusEntry other)
return !(lhs == rhs);
}

public static GitFileStatus ParseStatusMarker(char changeFlag)
{
GitFileStatus status = GitFileStatus.None;
switch (changeFlag)
{
case 'M':
status = GitFileStatus.Modified;
break;
case 'A':
status = GitFileStatus.Added;
break;
case 'D':
status = GitFileStatus.Deleted;
break;
case 'R':
status = GitFileStatus.Renamed;
break;
case 'C':
status = GitFileStatus.Copied;
break;
case 'U':
status = GitFileStatus.Unmerged;
break;
case 'T':
status = GitFileStatus.TypeChange;
break;
case 'X':
status = GitFileStatus.Unknown;
break;
case 'B':
status = GitFileStatus.Broken;
break;
case '?':
status = GitFileStatus.Untracked;
break;
case '!':
status = GitFileStatus.Ignored;
break;
default: break;
}
return status;
}

public string Path => path;

public string FullPath => fullPath;
Expand All @@ -86,13 +130,21 @@ public bool Equals(GitStatusEntry other)

public string OriginalPath => originalPath;

public GitFileStatus Status => status;
public GitFileStatus Status => workTreeStatus != GitFileStatus.None ? workTreeStatus : indexStatus;
public GitFileStatus IndexStatus => indexStatus;
public GitFileStatus WorkTreeStatus => workTreeStatus;

public bool Staged => indexStatus != GitFileStatus.None && !Unmerged && !Untracked && !Ignored;

public bool Unmerged => (indexStatus == workTreeStatus && (indexStatus == GitFileStatus.Added || indexStatus == GitFileStatus.Deleted)) ||
indexStatus == GitFileStatus.Unmerged || workTreeStatus == GitFileStatus.Unmerged;

public bool Staged => staged;
public bool Untracked => workTreeStatus == GitFileStatus.Untracked;
public bool Ignored => workTreeStatus == GitFileStatus.Ignored;

public override string ToString()
{
return $"Path:'{Path}' Status:'{Status}' FullPath:'{FullPath}' ProjectPath:'{ProjectPath}' OriginalPath:'{OriginalPath}' Staged:'{Staged}'";
return $"Path:'{Path}' Status:'{Status}' FullPath:'{FullPath}' ProjectPath:'{ProjectPath}' OriginalPath:'{OriginalPath}' Staged:'{Staged}' Unmerged:'{Unmerged}' Status:'{IndexStatus}' Status:'{WorkTreeStatus}' ";
}
}
}
2 changes: 1 addition & 1 deletion src/GitHub.Api/Git/IGitObjectFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ namespace GitHub.Unity
{
public interface IGitObjectFactory
{
GitStatusEntry CreateGitStatusEntry(string path, GitFileStatus status, string originalPath = null, bool staged = false);
GitStatusEntry CreateGitStatusEntry(string path, GitFileStatus indexStatus, GitFileStatus workTreeStatus, string originalPath = null);
}
}
2 changes: 1 addition & 1 deletion src/GitHub.Api/Git/RepositoryManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ public ITask DiscardChanges(GitStatusEntry[] gitStatusEntries)

foreach (var gitStatusEntry in gitStatusEntries)
{
if (gitStatusEntry.status == GitFileStatus.Added || gitStatusEntry.status == GitFileStatus.Untracked)
if (gitStatusEntry.WorkTreeStatus == GitFileStatus.Added || gitStatusEntry.WorkTreeStatus == GitFileStatus.Untracked)
{
itemsToDelete.Add(gitStatusEntry.path.ToNPath().MakeAbsolute());
}
Expand Down
21 changes: 20 additions & 1 deletion src/GitHub.Api/Git/Tasks/GitLogTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,39 @@ public class GitLogTask : ProcessTaskWithListOutput<GitLogEntry>
private readonly string arguments;

public GitLogTask(IGitObjectFactory gitObjectFactory,
CancellationToken token,
BaseOutputListProcessor<GitLogEntry> processor = null)
: this(0, gitObjectFactory, token, processor)
{
}

public GitLogTask(string file,
IGitObjectFactory gitObjectFactory,
CancellationToken token, BaseOutputListProcessor<GitLogEntry> processor = null)
: this(file, 0, gitObjectFactory, token, processor)
{
}

public GitLogTask(int numberOfCommits, IGitObjectFactory gitObjectFactory,
CancellationToken token,
BaseOutputListProcessor<GitLogEntry> processor = null)
: base(token, processor ?? new LogEntryOutputProcessor(gitObjectFactory))
{
Name = TaskName;
arguments = baseArguments;
if (numberOfCommits > 0)
arguments += " -n " + numberOfCommits;
}

public GitLogTask(string file,
public GitLogTask(string file, int numberOfCommits,
IGitObjectFactory gitObjectFactory,
CancellationToken token, BaseOutputListProcessor<GitLogEntry> processor = null)
: base(token, processor ?? new LogEntryOutputProcessor(gitObjectFactory))
{
Name = TaskName;
arguments = baseArguments;
if (numberOfCommits > 0)
arguments += " -n " + numberOfCommits;
arguments += " -- ";
arguments += " \"" + file + "\"";
}
Expand Down
2 changes: 1 addition & 1 deletion src/GitHub.Api/Git/Tasks/GitStatusTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public GitStatusTask(IGitObjectFactory gitObjectFactory,

public override string ProcessArguments
{
get { return "-c i18n.logoutputencoding=utf8 -c core.quotepath=false status -b -u --porcelain"; }
get { return "-c i18n.logoutputencoding=utf8 -c core.quotepath=false --no-optional-locks status -b -u --porcelain"; }
}
public override TaskAffinity Affinity { get { return TaskAffinity.Exclusive; } }
public override string Message { get; set; } = "Listing changed files...";
Expand Down
21 changes: 11 additions & 10 deletions src/GitHub.Api/OutputProcessors/BranchListOutputProcessor.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Security.AccessControl;
using System.Text.RegularExpressions;

namespace GitHub.Unity
Expand All @@ -18,23 +19,24 @@ public override void LineReceived(string line)

try
{
proc.Matches('*');
string name;
string trackingName = null;

if (proc.Matches('*'))
proc.MoveNext();
proc.SkipWhitespace();
var detached = proc.Matches("(HEAD ");
var name = "detached";
if (detached)
if (proc.Matches("(HEAD "))
{
name = "detached";
proc.MoveToAfter(')');
}
else
{
name = proc.ReadUntilWhitespace();
}
proc.SkipWhitespace();
proc.ReadUntilWhitespace();
var tracking = proc.Matches(trackingBranchRegex);
var trackingName = "";
if (tracking)

proc.ReadUntilWhitespaceTrim();
if (proc.Matches(trackingBranchRegex))
{
trackingName = proc.ReadChunk('[', ']');
var indexOf = trackingName.IndexOf(':');
Expand All @@ -45,7 +47,6 @@ public override void LineReceived(string line)
}

var branch = new GitBranch(name, trackingName);

RaiseOnEntry(branch);
}
catch(Exception ex)
Expand Down
5 changes: 2 additions & 3 deletions src/GitHub.Api/OutputProcessors/GitCountObjectsProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ public override void LineReceived(string line)
{
var proc = new LineParser(line);

proc.ReadUntil(',');
proc.SkipWhitespace();
var kilobytes = int.Parse(proc.ReadUntilWhitespace());
proc.MoveToAfter(',');
var kilobytes = int.Parse(proc.ReadUntilWhitespaceTrim());

RaiseOnEntry(kilobytes);
}
Expand Down
Loading