feature: add an indicator that shows those commits the current branch ahead/behind its upstream

This commit is contained in:
leo 2024-07-19 09:29:16 +08:00
parent 9de2853003
commit f0649c95b5
No known key found for this signature in database
12 changed files with 180 additions and 194 deletions

View file

@ -33,7 +33,6 @@ namespace SourceGit.Commands
argsBuilder.Append("--all-match -i");
search = argsBuilder.ToString();
}
WorkingDirectory = repo;
Context = repo;
@ -63,7 +62,9 @@ namespace SourceGit.Commands
ParseParent(line);
break;
case 2:
ParseDecorators(line);
_current.ParseDecorators(line);
if (_current.IsMerged && !_isHeadFounded)
_isHeadFounded = true;
break;
case 3:
_current.Author = Models.User.FindOrAdd(line);
@ -114,74 +115,6 @@ namespace SourceGit.Commands
_current.Parents.Add(data.Substring(idx + 1));
}
private void ParseDecorators(string data)
{
if (data.Length < 3)
return;
var subs = data.Split(',', StringSplitOptions.RemoveEmptyEntries);
foreach (var sub in subs)
{
var d = sub.Trim();
if (d.EndsWith("/HEAD", StringComparison.Ordinal))
continue;
if (d.StartsWith("tag: refs/tags/", StringComparison.Ordinal))
{
_current.Decorators.Add(new Models.Decorator()
{
Type = Models.DecoratorType.Tag,
Name = d.Substring(15),
});
}
else if (d.StartsWith("HEAD -> refs/heads/", StringComparison.Ordinal))
{
_current.IsMerged = true;
_current.Decorators.Add(new Models.Decorator()
{
Type = Models.DecoratorType.CurrentBranchHead,
Name = d.Substring(19),
});
}
else if (d.Equals("HEAD"))
{
_current.IsMerged = true;
_current.Decorators.Add(new Models.Decorator()
{
Type = Models.DecoratorType.CurrentCommitHead,
Name = d,
});
}
else if (d.StartsWith("refs/heads/", StringComparison.Ordinal))
{
_current.Decorators.Add(new Models.Decorator()
{
Type = Models.DecoratorType.LocalBranchHead,
Name = d.Substring(11),
});
}
else if (d.StartsWith("refs/remotes/", StringComparison.Ordinal))
{
_current.Decorators.Add(new Models.Decorator()
{
Type = Models.DecoratorType.RemoteBranchHead,
Name = d.Substring(13),
});
}
}
_current.Decorators.Sort((l, r) =>
{
if (l.Type != r.Type)
return (int)l.Type - (int)r.Type;
else
return string.Compare(l.Name, r.Name, StringComparison.Ordinal);
});
if (_current.IsMerged && !_isHeadFounded)
_isHeadFounded = true;
}
private void MarkFirstMerged()
{
Args = $"log --since=\"{_commits[^1].CommitterTimeStr}\" --format=\"%H\"";