feature<DiffViewer>: supports to diff with external merge tools

This commit is contained in:
leo 2021-05-31 10:25:48 +08:00
parent 8993f50944
commit 259473626b
6 changed files with 50 additions and 9 deletions

View file

@ -13,23 +13,25 @@ namespace SourceGit.Models {
public string Name { get; set; } public string Name { get; set; }
public string Exec { get; set; } public string Exec { get; set; }
public string Cmd { get; set; } public string Cmd { get; set; }
public string DiffCmd { get; set; }
public Func<string> Finder { get; set; } public Func<string> Finder { get; set; }
public static List<MergeTool> Supported = new List<MergeTool>() { public static List<MergeTool> Supported = new List<MergeTool>() {
new MergeTool(0, "--", "", "", () => ""), new MergeTool(0, "--", "", "", "", () => ""),
new MergeTool(1, "Visual Studio Code", "Code.exe", "-n --wait \"$MERGED\"", FindVSCode), new MergeTool(1, "Visual Studio Code", "Code.exe", "-n --wait \"$MERGED\"", "-n --wait --diff \"$LOCAL\" \"$REMOTE\"", FindVSCode),
new MergeTool(2, "Visual Studio 2017/2019", "vsDiffMerge.exe", "\"$REMOTE\" \"$LOCAL\" \"$BASE\" \"$MERGED\" //m", FindVSMerge), new MergeTool(2, "Visual Studio 2017/2019", "vsDiffMerge.exe", "\"$REMOTE\" \"$LOCAL\" \"$BASE\" \"$MERGED\" /m", "\"$LOCAL\" \"$REMOTE\"", FindVSMerge),
new MergeTool(3, "Tortoise Merge", "TortoiseMerge.exe", "-base:\"$BASE\" -theirs:\"$REMOTE\" -mine:\"$LOCAL\" -merged:\"$MERGED\"", FindTortoiseMerge), new MergeTool(3, "Tortoise Merge", "TortoiseMerge.exe", "-base:\"$BASE\" -theirs:\"$REMOTE\" -mine:\"$LOCAL\" -merged:\"$MERGED\"", "-base:\"$LOCAL\" -theirs:\"$REMOTE\"", FindTortoiseMerge),
new MergeTool(4, "KDiff3", "kdiff3.exe", "\"$REMOTE\" -b \"$BASE\" \"$LOCAL\" -o \"$MERGED\"", FindKDiff3), new MergeTool(4, "KDiff3", "kdiff3.exe", "\"$REMOTE\" -b \"$BASE\" \"$LOCAL\" -o \"$MERGED\"", "\"$LOCAL\" \"$REMOTE\"", FindKDiff3),
new MergeTool(5, "Beyond Compare 4", "BComp.exe", "\"$REMOTE\" \"$LOCAL\" \"$BASE\" \"$MERGED\"", FindBCompare), new MergeTool(5, "Beyond Compare 4", "BComp.exe", "\"$REMOTE\" \"$LOCAL\" \"$BASE\" \"$MERGED\"", "\"$LOCAL\" \"$REMOTE\"", FindBCompare),
new MergeTool(6, "WinMerge", "WinMergeU.exe", "-u -e \"$REMOTE\" \"$LOCAL\" \"$MERGED\"", FindWinMerge), new MergeTool(6, "WinMerge", "WinMergeU.exe", "-u -e \"$REMOTE\" \"$LOCAL\" \"$MERGED\"", "-u -e \"$LOCAL\" \"$REMOTE\"", FindWinMerge),
}; };
public MergeTool(int type, string name, string exec, string cmd, Func<string> finder) { public MergeTool(int type, string name, string exec, string cmd, string diffCmd, Func<string> finder) {
Type = type; Type = type;
Name = name; Name = name;
Exec = exec; Exec = exec;
Cmd = cmd; Cmd = cmd;
DiffCmd = diffCmd;
Finder = finder; Finder = finder;
} }

View file

@ -42,6 +42,7 @@
<Geometry x:Key="Icon.Folder.Open">M832 960l192-512H192L0 960zM128 384L0 960V128h288l128 128h416v128z</Geometry> <Geometry x:Key="Icon.Folder.Open">M832 960l192-512H192L0 960zM128 384L0 960V128h288l128 128h416v128z</Geometry>
<Geometry x:Key="Icon.File">M959 320H960v640A64 64 0 01896 1024H192A64 64 0 01128 960V64A64 64 0 01192 0H640v321h320L959 320zM320 544c0 17 14 32 32 32h384A32 32 0 00768 544c0-17-14-32-32-32H352A32 32 0 00320 544zm0 128c0 17 14 32 32 32h384a32 32 0 0032-32c0-17-14-32-32-32H352a32 32 0 00-32 32zm0 128c0 17 14 32 32 32h384a32 32 0 0032-32c0-17-14-32-32-32H352a32 32 0 00-32 32z</Geometry> <Geometry x:Key="Icon.File">M959 320H960v640A64 64 0 01896 1024H192A64 64 0 01128 960V64A64 64 0 01192 0H640v321h320L959 320zM320 544c0 17 14 32 32 32h384A32 32 0 00768 544c0-17-14-32-32-32H352A32 32 0 00320 544zm0 128c0 17 14 32 32 32h384a32 32 0 0032-32c0-17-14-32-32-32H352a32 32 0 00-32 32zm0 128c0 17 14 32 32 32h384a32 32 0 0032-32c0-17-14-32-32-32H352a32 32 0 00-32 32z</Geometry>
<Geometry x:Key="Icon.Diff">M854 307 611 73c-6-6-14-9-22-9H296c-4 0-8 4-8 8v56c0 4 4 8 8 8h277l219 211V824c0 4 4 8 8 8h56c4 0 8-4 8-8V330c0-9-4-17-10-23zM553 201c-6-6-14-9-23-9H192c-18 0-32 14-32 32v704c0 18 14 32 32 32h512c18 0 32-14 32-32V397c0-9-3-17-9-23L553 201zM568 753c0 4-3 7-8 7h-225c-4 0-8-3-8-7v-42c0-4 3-7 8-7h225c4 0 8 3 8 7v42zm0-220c0 4-3 7-8 7H476v85c0 4-3 7-7 7h-42c-4 0-7-3-7-7V540h-85c-4 0-8-3-8-7v-42c0-4 3-7 8-7H420v-85c0-4 3-7 7-7h42c4 0 7 3 7 7V484h85c4 0 8 3 8 7v42z</Geometry> <Geometry x:Key="Icon.Diff">M854 307 611 73c-6-6-14-9-22-9H296c-4 0-8 4-8 8v56c0 4 4 8 8 8h277l219 211V824c0 4 4 8 8 8h56c4 0 8-4 8-8V330c0-9-4-17-10-23zM553 201c-6-6-14-9-23-9H192c-18 0-32 14-32 32v704c0 18 14 32 32 32h512c18 0 32-14 32-32V397c0-9-3-17-9-23L553 201zM568 753c0 4-3 7-8 7h-225c-4 0-8-3-8-7v-42c0-4 3-7 8-7h225c4 0 8 3 8 7v42zm0-220c0 4-3 7-8 7H476v85c0 4-3 7-7 7h-42c-4 0-7-3-7-7V540h-85c-4 0-8-3-8-7v-42c0-4 3-7 8-7H420v-85c0-4 3-7 7-7h42c4 0 7 3 7 7V484h85c4 0 8 3 8 7v42z</Geometry>
<Geometry x:Key="Icon.DiffWith">M683 409v204L1024 308 683 0v191c-413 0-427 526-427 526c117-229 203-307 427-307zm85 492H102V327h153s38-63 114-122H51c-28 0-51 27-51 61v697c0 34 23 61 51 61h768c28 0 51-27 51-61V614l-102 100v187z</Geometry>
<Geometry x:Key="Icon.Filter">M599 425 599 657 425 832 425 425 192 192 832 192Z</Geometry> <Geometry x:Key="Icon.Filter">M599 425 599 657 425 832 425 425 192 192 832 192Z</Geometry>
<Geometry x:Key="Icon.Binary">M71 1024V0h661L953 219V1024H71zm808-731-220-219H145V951h735V293zM439 512h-220V219h220V512zm-74-219H292v146h74v-146zm0 512h74v73h-220v-73H292v-146H218V585h147v219zm294-366h74V512H512v-73h74v-146H512V219h147v219zm74 439H512V585h220v293zm-74-219h-74v146h74v-146z</Geometry> <Geometry x:Key="Icon.Binary">M71 1024V0h661L953 219V1024H71zm808-731-220-219H145V951h735V293zM439 512h-220V219h220V512zm-74-219H292v146h74v-146zm0 512h74v73h-220v-73H292v-146H218V585h147v219zm294-366h74V512H512v-73h74v-146H512V219h147v219zm74 439H512V585h220v293zm-74-219h-74v146h74v-146z</Geometry>

View file

@ -228,6 +228,7 @@
<sys:String x:Key="Text.Diff.Next">Next Difference</sys:String> <sys:String x:Key="Text.Diff.Next">Next Difference</sys:String>
<sys:String x:Key="Text.Diff.Prev">Previous Difference</sys:String> <sys:String x:Key="Text.Diff.Prev">Previous Difference</sys:String>
<sys:String x:Key="Text.Diff.Mode">Toggle One-Side/Two-Sides</sys:String> <sys:String x:Key="Text.Diff.Mode">Toggle One-Side/Two-Sides</sys:String>
<sys:String x:Key="Text.Diff.UseMerger">Open With Merge Tool</sys:String>
<sys:String x:Key="Text.Diff.Welcome">SELECT FILE TO VIEW CHANGES</sys:String> <sys:String x:Key="Text.Diff.Welcome">SELECT FILE TO VIEW CHANGES</sys:String>
<sys:String x:Key="Text.Diff.NoChange">NO CHANGES OR ONLY EOL CHANGES</sys:String> <sys:String x:Key="Text.Diff.NoChange">NO CHANGES OR ONLY EOL CHANGES</sys:String>
<sys:String x:Key="Text.Diff.Binary">BINARY DIFF</sys:String> <sys:String x:Key="Text.Diff.Binary">BINARY DIFF</sys:String>

View file

@ -228,6 +228,7 @@
<sys:String x:Key="Text.Diff.Next">下一个差异</sys:String> <sys:String x:Key="Text.Diff.Next">下一个差异</sys:String>
<sys:String x:Key="Text.Diff.Prev">上一个差异</sys:String> <sys:String x:Key="Text.Diff.Prev">上一个差异</sys:String>
<sys:String x:Key="Text.Diff.Mode">切换显示模式</sys:String> <sys:String x:Key="Text.Diff.Mode">切换显示模式</sys:String>
<sys:String x:Key="Text.Diff.UseMerger">使用外部合并工具查看</sys:String>
<sys:String x:Key="Text.Diff.Welcome">请选择需要对比的文件</sys:String> <sys:String x:Key="Text.Diff.Welcome">请选择需要对比的文件</sys:String>
<sys:String x:Key="Text.Diff.NoChange">没有变更或仅有换行符差异</sys:String> <sys:String x:Key="Text.Diff.NoChange">没有变更或仅有换行符差异</sys:String>
<sys:String x:Key="Text.Diff.Binary">二进制文件</sys:String> <sys:String x:Key="Text.Diff.Binary">二进制文件</sys:String>

View file

@ -58,12 +58,19 @@
<ToggleButton <ToggleButton
Width="14" Height="14" Width="14" Height="14"
Margin="4,0,0,0" Margin="4,0"
Style="{StaticResource Style.ToggleButton.SplitDirection}" Style="{StaticResource Style.ToggleButton.SplitDirection}"
Foreground="{StaticResource Brush.FG1}" Foreground="{StaticResource Brush.FG1}"
ToolTip="{StaticResource Text.Diff.Mode}" ToolTip="{StaticResource Text.Diff.Mode}"
IsChecked="{Binding Source={x:Static models:Preference.Instance}, Path=Window.UseCombinedDiff, Mode=TwoWay}" IsChecked="{Binding Source={x:Static models:Preference.Instance}, Path=Window.UseCombinedDiff, Mode=TwoWay}"
Checked="OnDiffViewModeChanged" Unchecked="OnDiffViewModeChanged"/> Checked="OnDiffViewModeChanged" Unchecked="OnDiffViewModeChanged"/>
<controls:IconButton
Width="14" Height="14"
Margin="4,0,0,0"
Icon="{StaticResource Icon.DiffWith}"
ToolTip="{StaticResource Text.Diff.UseMerger}"
Click="OpenWithMerger"/>
</StackPanel> </StackPanel>
</Grid> </Grid>
</Border> </Border>

View file

@ -668,6 +668,35 @@ namespace SourceGit.Views.Widgets {
} }
} }
} }
private async void OpenWithMerger(object sender, RoutedEventArgs e) {
var mergeType = Models.Preference.Instance.MergeTool.Type;
var mergeExe = Models.Preference.Instance.MergeTool.Path;
var merger = Models.MergeTool.Supported.Find(x => x.Type == mergeType);
if (merger == null || merger.Type == 0 || !System.IO.File.Exists(mergeExe)) {
Models.Exception.Raise("Invalid merge tool in preference setting!");
return;
}
var args = $"{opt.ExtraArgs} ";
if (opt.RevisionRange.Length > 0) args += $"{opt.RevisionRange[0]} ";
if (opt.RevisionRange.Length > 1) args += $"{opt.RevisionRange[1]} ";
args += "-- ";
if (!string.IsNullOrEmpty(opt.OrgPath)) args += $"\"{opt.OrgPath}\" ";
args += $"\"{opt.Path}\"";
var cmd = new Commands.Command();
cmd.Cwd = repo;
cmd.DontRaiseError = true;
cmd.Args = $"-c difftool.sourcegit.cmd=\"\\\"{mergeExe}\\\" {merger.DiffCmd}\" ";
cmd.Args += $"difftool --tool=sourcegit --no-prompt {args}";
await Task.Run(() => cmd.Exec());
e.Handled = true;
}
#endregion #endregion
} }
} }