Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat: show git file mode change if exist #69

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

Merged
love-linger merged 5 commits into sourcegit-scm:develop from gadfly3173:feat/diff-file-mode
Apr 13, 2024
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
17 changes: 17 additions & 0 deletions src/Commands/Diff.cs
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using SourceGit.Models;

namespace SourceGit.Commands
{
Expand Down Expand Up @@ -46,6 +47,22 @@ public Models.DiffResult Result()

protected override void OnReadline(string line)
{
if (line.StartsWith("old mode ", StringComparison.Ordinal))
{
_result.FileModeDiff ??= new FileModeDiff();

_result.FileModeDiff.Old = line.Substring(9);
return;
}

if (line.StartsWith("new mode ", StringComparison.Ordinal))
{
_result.FileModeDiff ??= new FileModeDiff();

_result.FileModeDiff.New = line.Substring(9);
return;
}

if (_result.IsBinary)
return;

Expand Down
7 changes: 7 additions & 0 deletions src/Models/DiffResult.cs
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -576,11 +576,18 @@ public class NoOrEOLChange
{
}

public class FileModeDiff
{
public string Old { get; set; } = string.Empty;
public string New { get; set; } = string.Empty;
}

public class DiffResult
{
public bool IsBinary { get; set; } = false;
public bool IsLFS { get; set; } = false;
public TextDiff TextDiff { get; set; } = null;
public LFSDiff LFSDiff { get; set; } = null;
public FileModeDiff FileModeDiff { get; set; } = null;
}
}
1 change: 1 addition & 0 deletions src/Resources/Locales/en_US.axaml
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@
<x:String x:Key="Text.Diff.Binary.New" xml:space="preserve">NEW</x:String>
<x:String x:Key="Text.Diff.Binary.Old" xml:space="preserve">OLD</x:String>
<x:String x:Key="Text.Diff.Copy" xml:space="preserve">Copy</x:String>
<x:String x:Key="Text.Diff.FileModeChanged" xml:space="preserve">File Mode Changed :</x:String>
<x:String x:Key="Text.Diff.LFS" xml:space="preserve">LFS OBJECT CHANGE</x:String>
<x:String x:Key="Text.Diff.Next" xml:space="preserve">Next Difference</x:String>
<x:String x:Key="Text.Diff.NoChange" xml:space="preserve">NO CHANGES OR ONLY EOL CHANGES</x:String>
Expand Down
1 change: 1 addition & 0 deletions src/Resources/Locales/zh_CN.axaml
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@
<x:String x:Key="Text.Diff.Binary.New" xml:space="preserve">当前大小</x:String>
<x:String x:Key="Text.Diff.Binary.Old" xml:space="preserve">原始大小</x:String>
<x:String x:Key="Text.Diff.Copy" xml:space="preserve">复制</x:String>
<x:String x:Key="Text.Diff.FileModeChanged" xml:space="preserve">文件权限已变化 :</x:String>
<x:String x:Key="Text.Diff.LFS" xml:space="preserve">LFS对象变更</x:String>
<x:String x:Key="Text.Diff.Next" xml:space="preserve">下一个差异</x:String>
<x:String x:Key="Text.Diff.NoChange" xml:space="preserve">没有变更或仅有换行符差异</x:String>
Expand Down
15 changes: 15 additions & 0 deletions src/ViewModels/DiffContext.cs
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Threading.Tasks;

using Avalonia;
using Avalonia.Media;
using Avalonia.Media.Imaging;
using Avalonia.Threading;

Expand Down Expand Up @@ -66,6 +67,14 @@ public Vector SyncScrollOffset
set => SetProperty(ref _syncScrollOffset, value);
}

public Models.FileModeDiff FileModeDiff
{
get => _fileModeDiff;
set => SetProperty(ref _fileModeDiff, value);
}

public TextTrimming PathTrimming { get; } = new TextLeadingPrefixTrimming("...", 20);

public DiffContext(string repo, Models.DiffOption option, DiffContext previous = null)
{
_repo = repo;
Expand All @@ -86,6 +95,11 @@ public DiffContext(string repo, Models.DiffOption option, DiffContext previous =
var latest = new Commands.Diff(repo, option).Result();
var rs = null as object;

if (latest.FileModeDiff != null)
{
FileModeDiff = latest.FileModeDiff;
}

if (latest.TextDiff != null)
{
latest.TextDiff.File = _option.Path;
Expand Down Expand Up @@ -180,5 +194,6 @@ private Bitmap BitmapFromRevisionFile(string repo, string revision, string file)
private bool _isTextDiff = false;
private object _content = null;
private Vector _syncScrollOffset = Vector.Zero;
private Models.FileModeDiff _fileModeDiff = null;
}
}
20 changes: 14 additions & 6 deletions src/Views/DiffView.axaml
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,28 @@
<Grid RowDefinitions="26,*">
<!-- Toolbar -->
<Border Grid.Row="0" BorderThickness="0,0,0,1" BorderBrush="{DynamicResource Brush.Border2}">
<Grid ColumnDefinitions="Auto,*,Auto">
<Grid ColumnDefinitions="Auto,*,Auto,Auto">
<StackPanel Grid.Column="0" Orientation="Horizontal" IsVisible="{Binding IsOrgFilePathVisible}" VerticalAlignment="Center">
<Path Width="12" Height="12" Data="{StaticResource Icons.File}" Margin="8,0,0,0"/>
<TextBlock Classes="monospace" Margin="4,0,0,0" Text="{Binding OrgFilePath, Converter={x:Static c:PathConverters.TruncateIfTooLong}}" FontSize="11"/>
<TextBlock Margin="8,0,0,0" Text="→"/>
</StackPanel>

<StackPanel Grid.Column="1" Orientation="Horizontal" VerticalAlignment="Center">
<Path Width="12" Height="12" Data="{StaticResource Icons.File}" Margin="8,0,0,0"/>
<TextBlock Classes="monospace" Margin="4,0,0,0" Text="{Binding FilePath, Converter={x:Static c:PathConverters.TruncateIfTooLong}}" FontSize="11"/>
<Path Classes="rotating" Width="10" Height="10" Margin="8,0" Data="{DynamicResource Icons.Loading}" IsVisible="{Binding IsLoading}"/>
<DockPanel Grid.Column="1" VerticalAlignment="Center">
<Path DockPanel.Dock="Left" Width="12" Height="12" Data="{StaticResource Icons.File}" Margin="8,0,0,0"/>
<TextBlock Classes="monospace" Margin="4,0,0,0" Text="{Binding FilePath}"
TextTrimming="{Binding PathTrimming}" TextWrapping="NoWrap" HorizontalAlignment="Stretch" ToolTip.Tip="{Binding FilePath}" FontSize="11"/>
<Path DockPanel.Dock="Right" Classes="rotating" Width="10" Height="10" Margin="8,0" Data="{StaticResource Icons.Loading}" IsVisible="{Binding IsLoading}"/>
</DockPanel>

<StackPanel Grid.Column="2" Orientation="Horizontal" VerticalAlignment="Center" IsVisible="{Binding FileModeDiff, Converter={x:Static ObjectConverters.IsNotNull}}">
<TextBlock Classes="monospace" Margin="8,0,0,0" Text="{DynamicResource Text.Diff.FileModeChanged}" FontSize="11"/>
<TextBlock Classes="monospace" Text="{Binding FileModeDiff.Old}" FontSize="11"/>
<TextBlock Margin="4,0" Text="→"/>
<TextBlock Classes="monospace" Text="{Binding FileModeDiff.New}" FontSize="11"/>
</StackPanel>

<StackPanel Grid.Column="2" Margin="32,0,0,0" Orientation="Horizontal" VerticalAlignment="Center">
<StackPanel Grid.Column="3" Margin="32,0,0,0" Orientation="Horizontal" VerticalAlignment="Center">
<ToggleButton Classes="line_path"
Width="32" Height="18"
Background="Transparent"
Expand Down

AltStyle によって変換されたページ (->オリジナル) /