2024-02-05 23:08:37 -08:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
namespace SourceGit.Commands
|
|
|
|
|
{
|
|
|
|
|
public partial class CompareRevisions : Command
|
|
|
|
|
{
|
2024-03-16 02:09:27 -07:00
|
|
|
|
[GeneratedRegex(@"^(\s?[\w\?]{1,4})\s+(.+)$")]
|
|
|
|
|
private static partial Regex REG_FORMAT();
|
2024-02-05 23:08:37 -08:00
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public CompareRevisions(string repo, string start, string end)
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
WorkingDirectory = repo;
|
|
|
|
|
Context = repo;
|
|
|
|
|
Args = $"diff --name-status {start} {end}";
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public List<Models.Change> Result()
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
Exec();
|
|
|
|
|
_changes.Sort((l, r) => l.Path.CompareTo(r.Path));
|
|
|
|
|
return _changes;
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
protected override void OnReadline(string line)
|
|
|
|
|
{
|
2024-03-16 02:09:27 -07:00
|
|
|
|
var match = REG_FORMAT().Match(line);
|
2024-03-31 01:54:29 -07:00
|
|
|
|
if (!match.Success)
|
|
|
|
|
return;
|
2024-02-05 23:08:37 -08:00
|
|
|
|
|
|
|
|
|
var change = new Models.Change() { Path = match.Groups[2].Value };
|
|
|
|
|
var status = match.Groups[1].Value;
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
switch (status[0])
|
|
|
|
|
{
|
2024-03-31 01:54:29 -07:00
|
|
|
|
case 'M':
|
|
|
|
|
change.Set(Models.ChangeState.Modified);
|
|
|
|
|
_changes.Add(change);
|
|
|
|
|
break;
|
|
|
|
|
case 'A':
|
|
|
|
|
change.Set(Models.ChangeState.Added);
|
|
|
|
|
_changes.Add(change);
|
|
|
|
|
break;
|
|
|
|
|
case 'D':
|
|
|
|
|
change.Set(Models.ChangeState.Deleted);
|
|
|
|
|
_changes.Add(change);
|
|
|
|
|
break;
|
|
|
|
|
case 'R':
|
|
|
|
|
change.Set(Models.ChangeState.Renamed);
|
|
|
|
|
_changes.Add(change);
|
|
|
|
|
break;
|
|
|
|
|
case 'C':
|
|
|
|
|
change.Set(Models.ChangeState.Copied);
|
|
|
|
|
_changes.Add(change);
|
|
|
|
|
break;
|
2024-02-05 23:08:37 -08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
private readonly List<Models.Change> _changes = new List<Models.Change>();
|
2024-02-05 23:08:37 -08:00
|
|
|
|
}
|
2024-03-31 01:54:29 -07:00
|
|
|
|
}
|