Merge branch 'sourcegit-scm:develop' into develop

This commit is contained in:
Nils van Rijsinge 2024-08-23 11:12:49 +02:00 committed by GitHub
commit aec8c0ddc4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
16 changed files with 188 additions and 25 deletions

View file

@ -0,0 +1,37 @@
using System;
using System.Collections.Generic;
namespace SourceGit.Commands
{
public class QueryRefsContainsCommit : Command
{
public QueryRefsContainsCommit(string repo, string commit)
{
WorkingDirectory = repo;
RaiseError = false;
Args = $"for-each-ref --format=\"%(refname)\" --contains {commit}";
}
public List<Models.Decorator> Result()
{
var rs = new List<Models.Decorator>();
var output = ReadToEnd();
if (!output.IsSuccess)
return rs;
var lines = output.StdOut.Split('\n');
foreach (var line in lines)
{
if (line.StartsWith("refs/heads/", StringComparison.Ordinal))
rs.Add(new() { Name = line.Substring("refs/heads/".Length), Type = Models.DecoratorType.LocalBranchHead });
else if (line.StartsWith("refs/remotes/", StringComparison.Ordinal))
rs.Add(new() { Name = line.Substring("refs/remotes/".Length), Type = Models.DecoratorType.RemoteBranchHead });
else if (line.StartsWith("refs/tags/", StringComparison.Ordinal))
rs.Add(new() { Name = line.Substring("refs/tags/".Length), Type = Models.DecoratorType.Tag });
}
return rs;
}
}
}

View file

@ -14,5 +14,6 @@
{
public DecoratorType Type { get; set; } = DecoratorType.None;
public string Name { get; set; } = "";
public bool IsTag => Type == DecoratorType.Tag;
}
}

View file

@ -80,6 +80,7 @@
<StreamGeometry x:Key="Icons.Pull">M432 0h160c27 0 48 21 48 48v336h175c36 0 53 43 28 68L539 757c-15 15-40 15-55 0L180 452c-25-25-7-68 28-68H384V48c0-27 21-48 48-48zm592 752v224c0 27-21 48-48 48H48c-27 0-48-21-48-48V752c0-27 21-48 48-48h293l98 98c40 40 105 40 145 0l98-98H976c27 0 48 21 48 48zm-248 176c0-22-18-40-40-40s-40 18-40 40s18 40 40 40s40-18 40-40zm128 0c0-22-18-40-40-40s-40 18-40 40s18 40 40 40s40-18 40-40z</StreamGeometry>
<StreamGeometry x:Key="Icons.Push">M592 768h-160c-27 0-48-21-48-48V384h-175c-36 0-53-43-28-68L485 11c15-15 40-15 55 0l304 304c25 25 7 68-28 68H640v336c0 27-21 48-48 48zm432-16v224c0 27-21 48-48 48H48c-27 0-48-21-48-48V752c0-27 21-48 48-48h272v16c0 62 50 112 112 112h160c62 0 112-50 112-112v-16h272c27 0 48 21 48 48zm-248 176c0-22-18-40-40-40s-40 18-40 40s18 40 40 40s40-18 40-40zm128 0c0-22-18-40-40-40s-40 18-40 40s18 40 40 40s40-18 40-40z</StreamGeometry>
<StreamGeometry x:Key="Icons.Rebase">M277 85a149 149 0 00-43 292v230a32 32 0 0064 0V555h267A160 160 0 00725 395v-12a149 149 0 10-64-5v17a96 96 0 01-96 96H299V383A149 149 0 00277 85zM228 720a32 32 0 00-37-52 150 150 0 00-53 68 32 32 0 1060 23 85 85 0 0130-39zm136-52a32 32 0 00-37 52 86 86 0 0130 39 32 32 0 1060-23 149 149 0 00-53-68zM204 833a32 32 0 10-55 32 149 149 0 0063 58 32 32 0 0028-57 85 85 0 01-36-33zm202 32a32 32 0 00-55-32 85 85 0 01-36 33 32 32 0 0028 57 149 149 0 0063-58z</StreamGeometry>
<StreamGeometry x:Key="Icons.Relation">M672 336l64-89c-13-19-26-45-26-70 0-64 51-115 109-115s109 51 109 115-51 115-109 115c-19 0-38-6-51-13l-64 89c32 38 51 89 51 147 0 70-32 128-77 172l51 64c13-6 32-13 51-13 57 0 109 51 109 115s-51 109-109 109-109-51-109-115c0-26 13-51 26-70L646 707c-32 19-64 26-102 26-121 0-217-102-217-223v-38l-57-13c-19 32-57 57-96 57C116 515 65 464 65 400s51-115 109-115 109 51 109 115v13l57 19C372 349 448 292 538 292c51 0 102 19 134 45z</StreamGeometry>
<StreamGeometry x:Key="Icons.Remote">M706 302a289 289 0 00-173 44 27 27 0 1029 46 234 234 0 01125-36c23 0 45 3 66 9 93 28 161 114 161 215C914 704 813 805 687 805H337C211 805 110 704 110 580c0-96 61-178 147-210C282 263 379 183 495 183a245 245 0 01210 119z</StreamGeometry>
<StreamGeometry x:Key="Icons.Remote.Add">M364 512h67v108h108v67h-108v108h-67v-108h-108v-67h108v-108zm298-64A107 107 0 01768 555C768 614 720 660 660 660h-108v-54h-108v-108h-94v108h-94c4-21 22-47 44-51l-1-12a75 75 0 0171-75a128 128 0 01239-7a106 106 0 0153-14z</StreamGeometry>
<StreamGeometry x:Key="Icons.RemoveAll">M1024 64v704h-128v128h-128v128h-768v-704h128v-128h128v-128zM64 960h640v-576h-640zM320 128v64h576v512h64v-576zM192 256v64h576v512h64v-576zM432 688L576 832H480L384 736 288 832H192l144-144L192 544h96L384 640l96-96H576z</StreamGeometry>

View file

@ -116,6 +116,8 @@
<x:String x:Key="Text.CommitDetail.Info.Author" xml:space="preserve">AUTHOR</x:String>
<x:String x:Key="Text.CommitDetail.Info.Changed" xml:space="preserve">CHANGED</x:String>
<x:String x:Key="Text.CommitDetail.Info.Committer" xml:space="preserve">COMMITTER</x:String>
<x:String x:Key="Text.CommitDetail.Info.ContainsIn" xml:space="preserve">Check refs that contains this commit</x:String>
<x:String x:Key="Text.CommitDetail.Info.ContainsIn.Title" xml:space="preserve">COMMIT CONTAINS IN</x:String>
<x:String x:Key="Text.CommitDetail.Info.GotoChangesPage" xml:space="preserve">Shows only the first 100 changes. See all changes on the CHANGES tab.</x:String>
<x:String x:Key="Text.CommitDetail.Info.Message" xml:space="preserve">MESSAGE</x:String>
<x:String x:Key="Text.CommitDetail.Info.Parents" xml:space="preserve">PARENTS</x:String>

View file

@ -119,6 +119,8 @@
<x:String x:Key="Text.CommitDetail.Info.Author" xml:space="preserve">修改者</x:String>
<x:String x:Key="Text.CommitDetail.Info.Changed" xml:space="preserve">变更列表</x:String>
<x:String x:Key="Text.CommitDetail.Info.Committer" xml:space="preserve">提交者</x:String>
<x:String x:Key="Text.CommitDetail.Info.ContainsIn" xml:space="preserve">查看包含此提交的分支/标签</x:String>
<x:String x:Key="Text.CommitDetail.Info.ContainsIn.Title" xml:space="preserve">本提交已被以下分支/标签包含</x:String>
<x:String x:Key="Text.CommitDetail.Info.GotoChangesPage" xml:space="preserve">仅显示前100项变更。请前往【变更对比】页面查看全部。</x:String>
<x:String x:Key="Text.CommitDetail.Info.Message" xml:space="preserve">提交信息</x:String>
<x:String x:Key="Text.CommitDetail.Info.Parents" xml:space="preserve">父提交</x:String>

View file

@ -119,6 +119,8 @@
<x:String x:Key="Text.CommitDetail.Info.Author" xml:space="preserve">修改者</x:String>
<x:String x:Key="Text.CommitDetail.Info.Changed" xml:space="preserve">變更列表</x:String>
<x:String x:Key="Text.CommitDetail.Info.Committer" xml:space="preserve">提交者</x:String>
<x:String x:Key="Text.CommitDetail.Info.ContainsIn" xml:space="preserve">查看包含此提交的分支/標籤</x:String>
<x:String x:Key="Text.CommitDetail.Info.ContainsIn.Title" xml:space="preserve">本提交已被以下分支/標籤包含</x:String>
<x:String x:Key="Text.CommitDetail.Info.GotoChangesPage" xml:space="preserve">僅顯示前100項變更。 請前往『變更對比』頁面查看全部。</x:String>
<x:String x:Key="Text.CommitDetail.Info.Message" xml:space="preserve">提交資訊</x:String>
<x:String x:Key="Text.CommitDetail.Info.Parents" xml:space="preserve">父提交</x:String>

View file

@ -141,6 +141,11 @@ namespace SourceGit.ViewModels
_repo?.NavigateToCommit(commitSHA);
}
public List<Models.Decorator> GetRefsContainsThisCommit()
{
return new Commands.QueryRefsContainsCommit(_repo.FullPath, _commit.SHA).Result();
}
public void ClearSearchChangeFilter()
{
SearchChangeFilter = string.Empty;
@ -460,14 +465,18 @@ namespace SourceGit.ViewModels
if (_commit == null)
return;
Task.Run(() =>
{
var fullMessage = new Commands.QueryCommitFullMessage(_repo.FullPath, _commit.SHA).Result();
Dispatcher.UIThread.Invoke(() => FullMessage = fullMessage);
});
if (_cancelToken != null)
_cancelToken.Requested = true;
_cancelToken = new Commands.Command.CancelToken();
Task.Run(() =>
{
var fullMessage = new Commands.QueryCommitFullMessage(_repo.FullPath, _commit.SHA).Result();
var parent = _commit.Parents.Count == 0 ? "4b825dc642cb6eb9a060e54bf8d69288fbee4904" : _commit.Parents[0];
var cmdChanges = new Commands.CompareRevisions(_repo.FullPath, parent, _commit.SHA) { Cancel = _cancelToken };
var changes = cmdChanges.Result();
@ -486,7 +495,6 @@ namespace SourceGit.ViewModels
{
Dispatcher.UIThread.Post(() =>
{
FullMessage = fullMessage;
Changes = changes;
VisibleChanges = visible;
});

View file

@ -57,12 +57,16 @@
<StackPanel Grid.Row="0" Grid.Column="1" Orientation="Horizontal">
<SelectableTextBlock Classes="primary"
Text="{Binding SHA}"
Margin="12,0,0,0"
Margin="12,0,4,0"
VerticalAlignment="Center"/>
<Button Classes="icon_button" Cursor="Hand" Click="OnOpenWebLink" IsVisible="{Binding #ThisControl.WebLinks, Converter={x:Static c:ListConverters.IsNotNullOrEmpty}}">
<Button Classes="icon_button" Width="24" Cursor="Hand" Click="OnOpenWebLink" IsVisible="{Binding #ThisControl.WebLinks, Converter={x:Static c:ListConverters.IsNotNullOrEmpty}}">
<Path Width="12" Height="12" Data="{StaticResource Icons.Link}" Fill="{DynamicResource Brush.Link}"/>
</Button>
<Button Classes="icon_button" Width="24" Cursor="Hand" Click="OnOpenContainsIn" IsVisible="{Binding #ThisControl.SupportsContainsIn}" ToolTip.Tip="{DynamicResource Text.CommitDetail.Info.ContainsIn}">
<Path Width="12" Height="12" Data="{StaticResource Icons.Relation}"/>
</Button>
</StackPanel>
@ -98,7 +102,8 @@
LabelForeground="{DynamicResource Brush.DecoratorFG}"
FontFamily="{DynamicResource Fonts.Monospace}"
FontSize="10"
VerticalAlignment="Center"/>
VerticalAlignment="Center"
Refs="{Binding Decorators}"/>
</Border>
<!-- Messages -->

View file

@ -1,3 +1,5 @@
using System.Threading.Tasks;
using Avalonia;
using Avalonia.Collections;
using Avalonia.Controls;
@ -17,6 +19,15 @@ namespace SourceGit.Views
set => SetValue(MessageProperty, value);
}
public static readonly StyledProperty<bool> SupportsContainsInProperty =
AvaloniaProperty.Register<CommitBaseInfo, bool>(nameof(SupportsContainsIn));
public bool SupportsContainsIn
{
get => GetValue(SupportsContainsInProperty);
set => SetValue(SupportsContainsInProperty, value);
}
public static readonly StyledProperty<AvaloniaList<Models.CommitLink>> WebLinksProperty =
AvaloniaProperty.Register<CommitBaseInfo, AvaloniaList<Models.CommitLink>>(nameof(WebLinks));
@ -74,6 +85,19 @@ namespace SourceGit.Views
e.Handled = true;
}
private void OnOpenContainsIn(object sender, RoutedEventArgs e)
{
if (DataContext is ViewModels.CommitDetail detail && sender is Button button)
{
var tracking = new CommitRelationTracking(detail);
var flyout = new Flyout();
flyout.Content = tracking;
flyout.ShowAt(button);
}
e.Handled = true;
}
private void OnParentSHAPressed(object sender, PointerPressedEventArgs e)
{
if (DataContext is ViewModels.CommitDetail detail && sender is Control { DataContext: string sha })

View file

@ -21,6 +21,7 @@
<!-- Base Information -->
<v:CommitBaseInfo Content="{Binding Commit}"
Message="{Binding FullMessage}"
SupportsContainsIn="True"
WebLinks="{Binding WebLinks}"
IssueTrackerRules="{Binding IssueTrackerRules}"/>

View file

@ -17,6 +17,15 @@ namespace SourceGit.Views
public bool IsTag { get; set; } = false;
}
public static readonly StyledProperty<List<Models.Decorator>> RefsProperty =
AvaloniaProperty.Register<CommitRefsPresenter, List<Models.Decorator>>(nameof(Refs));
public List<Models.Decorator> Refs
{
get => GetValue(RefsProperty);
set => SetValue(RefsProperty, value);
}
public static readonly StyledProperty<FontFamily> FontFamilyProperty =
TextBlock.FontFamilyProperty.AddOwner<CommitRefsPresenter>();
@ -85,7 +94,8 @@ namespace SourceGit.Views
AffectsMeasure<CommitRefsPresenter>(
FontFamilyProperty,
FontSizeProperty,
LabelForegroundProperty);
LabelForegroundProperty,
RefsProperty);
AffectsRender<CommitRefsPresenter>(
IconBackgroundProperty,
@ -121,17 +131,12 @@ namespace SourceGit.Views
}
}
protected override void OnDataContextChanged(EventArgs e)
{
base.OnDataContextChanged(e);
InvalidateMeasure();
}
protected override Size MeasureOverride(Size availableSize)
{
_items.Clear();
if (DataContext is Models.Commit commit && commit.HasDecorators)
var refs = Refs;
if (refs != null && refs.Count > 0)
{
var typeface = new Typeface(FontFamily);
var typefaceBold = new Typeface(FontFamily, FontStyle.Normal, FontWeight.Bold);
@ -139,7 +144,7 @@ namespace SourceGit.Views
var labelSize = FontSize;
var requiredWidth = 0.0;
foreach (var decorator in commit.Decorators)
foreach (var decorator in refs)
{
var isHead = decorator.Type == Models.DecoratorType.CurrentBranchHead ||
decorator.Type == Models.DecoratorType.CurrentCommitHead;

View file

@ -0,0 +1,36 @@
<UserControl xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:m="using:SourceGit.Models"
xmlns:v="using:SourceGit.Views"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="SourceGit.Views.CommitRelationTracking">
<Grid RowDefinitions="Auto,Auto,Auto">
<TextBlock Grid.Row="0" Classes="info_label" Text="{DynamicResource Text.CommitDetail.Info.ContainsIn.Title}" HorizontalAlignment="Center"/>
<Rectangle Grid.Row="1" Height="1" HorizontalAlignment="Stretch" Margin="0,8" Fill="{DynamicResource Brush.Border2}"/>
<ScrollViewer Grid.Row="2" MinWidth="300" MaxWidth="500" MaxHeight="200" HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Auto">
<ItemsControl x:Name="Container">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate DataType="m:Decorator">
<Border Height="20" Margin="0,4,6,0" BorderThickness="1" BorderBrush="{DynamicResource Brush.Border2}" CornerRadius="12">
<StackPanel Orientation="Horizontal" Margin="8,0" VerticalAlignment="Center">
<Path Width="10" Height="10" Data="{StaticResource Icons.Branch}" IsVisible="{Binding !IsTag}"/>
<Path Width="10" Height="10" Data="{StaticResource Icons.Tag}" IsVisible="{Binding IsTag}"/>
<TextBlock Classes="primary" Text="{Binding Name}" Margin="2,0,0,0"/>
</StackPanel>
</Border>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</ScrollViewer>
<v:LoadingIcon x:Name="LoadingIcon" Grid.Row="2" HorizontalAlignment="Center" Margin="0,8" Width="14" Height="14" IsVisible="False"/>
</Grid>
</UserControl>

View file

@ -0,0 +1,32 @@
using System.Threading.Tasks;
using Avalonia.Controls;
using Avalonia.Threading;
namespace SourceGit.Views
{
public partial class CommitRelationTracking : UserControl
{
public CommitRelationTracking()
{
InitializeComponent();
}
public CommitRelationTracking(ViewModels.CommitDetail detail)
{
InitializeComponent();
LoadingIcon.IsVisible = true;
Task.Run(() =>
{
var containsIn = detail.GetRefsContainsThisCommit();
Dispatcher.UIThread.Invoke(() =>
{
Container.ItemsSource = containsIn;
LoadingIcon.IsVisible = false;
});
});
}
}
}

View file

@ -67,15 +67,15 @@
BehindBrush="{DynamicResource Brush.FG1}"
VerticalAlignment="Center"/>
<v:CommitRefsPresenter IsVisible="{Binding HasDecorators}"
IconBackground="{DynamicResource Brush.DecoratorIconBG}"
<v:CommitRefsPresenter IconBackground="{DynamicResource Brush.DecoratorIconBG}"
IconForeground="{DynamicResource Brush.DecoratorIcon}"
BranchNameBackground="{DynamicResource Brush.DecoratorBranch}"
TagNameBackground="{DynamicResource Brush.DecoratorTag}"
LabelForeground="{DynamicResource Brush.DecoratorFG}"
FontFamily="{DynamicResource Fonts.Monospace}"
FontSize="10"
VerticalAlignment="Center"/>
VerticalAlignment="Center"
Refs="{Binding Decorators}"/>
<v:CommitSubjectPresenter Classes="primary"
Subject="{Binding Subject}"

View file

@ -3,6 +3,7 @@ using System;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Input;
using Avalonia.VisualTree;
namespace SourceGit.Views
{
@ -160,6 +161,19 @@ namespace SourceGit.Views
return;
}
}
else
{
var welcome = this.FindDescendantOfType<Welcome>();
if (welcome != null)
{
if (e.Key == Key.F)
{
welcome.SearchBox.Focus();
e.Handled = true;
return;
}
}
}
}
else if (e.Key == Key.Escape)
{

View file

@ -45,13 +45,6 @@ namespace SourceGit.Views
TreeContainer.Focus(NavigationMethod.Directional);
e.Handled = true;
}
else if (e.Key == Key.F &&
((OperatingSystem.IsMacOS() && e.KeyModifiers.HasFlag(KeyModifiers.Meta)) ||
(!OperatingSystem.IsMacOS() && e.KeyModifiers.HasFlag(KeyModifiers.Control))))
{
SearchBox.Focus();
e.Handled = true;
}
else if (e.Key == Key.Escape)
{
ViewModels.Welcome.Instance.ClearSearchFilter();