Skip to content
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
10 changes: 5 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
container: ${{ matrix.container || '' }}
steps:
- name: Install common CLI tools
if: ${{ startsWith(matrix.runtime, 'linux-') }}
if: startsWith(matrix.runtime, 'linux-')
run: |
export DEBIAN_FRONTEND=noninteractive
ln -fs /usr/share/zoneinfo/Etc/UTC /etc/localtime
Expand All @@ -45,7 +45,7 @@ jobs:
with:
dotnet-version: 9.0.x
- name: Configure arm64 packages
if: ${{ matrix.runtime == 'linux-arm64' }}
if: matrix.runtime == 'linux-arm64'
run: |
sudo dpkg --add-architecture arm64
echo 'deb [arch=arm64] http://ports.ubuntu.com/ubuntu-ports/ focal main restricted
Expand All @@ -55,7 +55,7 @@ jobs:
sudo sed -i -e 's/^deb http/deb [arch=amd64] http/g' /etc/apt/sources.list
sudo sed -i -e 's/^deb mirror/deb [arch=amd64] mirror/g' /etc/apt/sources.list
- name: Install cross-compiling dependencies
if: ${{ matrix.runtime == 'linux-arm64' }}
if: matrix.runtime == 'linux-arm64'
run: |
sudo apt-get update
sudo apt-get install -y llvm gcc-aarch64-linux-gnu
Expand All @@ -64,10 +64,10 @@ jobs:
- name: Publish
run: dotnet publish src/SourceGit.csproj -c Release -o publish -r ${{ matrix.runtime }}
- name: Rename executable file
if: ${{ startsWith(matrix.runtime, 'linux-') }}
if: startsWith(matrix.runtime, 'linux-')
run: mv publish/SourceGit publish/sourcegit
- name: Tar artifact
if: ${{ startsWith(matrix.runtime, 'linux-') || startsWith(matrix.runtime, 'osx-') }}
if: startsWith(matrix.runtime, 'linux-') || startsWith(matrix.runtime, 'osx-')
run: |
tar -cvf "sourcegit.${{ matrix.runtime }}.tar" -C publish .
rm -r publish/*
Expand Down
26 changes: 8 additions & 18 deletions src/App.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,23 +148,21 @@ public static void ShowWindow(object data, bool showAsDialog)

public static void RaiseException(string context, string message)
{
if (Current is App app && app._launcher != null)
if (Current is App { _launcher: not null } app)
app._launcher.DispatchNotification(context, message, true);
}

public static void SendNotification(string context, string message)
{
if (Current is App app && app._launcher != null)
if (Current is App { _launcher: not null } app)
app._launcher.DispatchNotification(context, message, false);
}

public static void SetLocale(string localeKey)
{
var app = Current as App;
if (app == null)
return;

var targetLocale = app.Resources[localeKey] as ResourceDictionary;
var targetLocale = app?.Resources[localeKey] as ResourceDictionary;
if (targetLocale == null || targetLocale == app._activeLocale)
return;

Expand Down Expand Up @@ -286,22 +284,14 @@ public static void SetFonts(string defaultFont, string monospaceFont, bool onlyU

public static async void CopyText(string data)
{
if (Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
{
if (desktop.MainWindow?.Clipboard is { } clipboard)
await clipboard.SetTextAsync(data ?? "");
}
if (Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime { MainWindow.Clipboard: { } clipboard })
await clipboard.SetTextAsync(data ?? "");
}

public static async Task<string> GetClipboardTextAsync()
{
if (Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
{
if (desktop.MainWindow?.Clipboard is { } clipboard)
{
return await clipboard.GetTextAsync();
}
}
if (Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime { MainWindow.Clipboard: { } clipboard })
return await clipboard.GetTextAsync();
return null;
}

Expand Down Expand Up @@ -562,7 +552,7 @@ private void TryLaunchAsNormal(IClassicDesktopStyleApplicationLifetime desktop)
Models.AvatarManager.Instance.Start();

string startupRepo = null;
if (desktop.Args != null && desktop.Args.Length == 1 && Directory.Exists(desktop.Args[0]))
if (desktop.Args is { Length: 1 } && Directory.Exists(desktop.Args[0]))
startupRepo = desktop.Args[0];

var pref = ViewModels.Preferences.Instance;
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/Command.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public bool Exec()
proc.OutputDataReceived += (_, e) => HandleOutput(e.Data, errs);
proc.ErrorDataReceived += (_, e) => HandleOutput(e.Data, errs);

var dummy = null as Process;
Process dummy = null;
var dummyProcLock = new object();
try
{
Expand Down
4 changes: 1 addition & 3 deletions src/Commands/QueryCommits.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,7 @@ private void MarkFirstMerged()
if (shas.Length == 0)
return;

var set = new HashSet<string>();
foreach (var sha in shas)
set.Add(sha);
var set = new HashSet<string>(shas);

foreach (var c in _commits)
{
Expand Down
5 changes: 1 addition & 4 deletions src/Commands/QueryRevisionFileNames.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@ public List<string> Result()
return [];

var lines = rs.StdOut.Split('\0', System.StringSplitOptions.RemoveEmptyEntries);
var outs = new List<string>();
foreach (var line in lines)
outs.Add(line);
return outs;
return [.. lines];
}
}
}
2 changes: 1 addition & 1 deletion src/Commands/Worktree.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public Worktree(string repo)

var rs = ReadToEnd();
var worktrees = new List<Models.Worktree>();
var last = null as Models.Worktree;
Models.Worktree last = null;
if (rs.IsSuccess)
{
var lines = rs.StdOut.Split(['\r', '\n'], StringSplitOptions.RemoveEmptyEntries);
Expand Down
6 changes: 3 additions & 3 deletions src/Models/AvatarManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public void Start()
{
while (true)
{
var email = null as string;
string email = null;

lock (_synclock)
{
Expand All @@ -79,7 +79,7 @@ public void Start()
$"https://www.gravatar.com/avatar/{md5}?d=404";

var localFile = Path.Combine(_storePath, md5);
var img = null as Bitmap;
Bitmap img = null;
try
{
var client = new HttpClient() { Timeout = TimeSpan.FromSeconds(2) };
Expand Down Expand Up @@ -113,7 +113,7 @@ public void Start()
_requesting.Remove(email);
}

Dispatcher.UIThread.InvokeAsync(() =>
Dispatcher.UIThread.Post(() =>
{
_resources[email] = img;
NotifyResourceChanged(email, img);
Expand Down
2 changes: 1 addition & 1 deletion src/Models/CommitGraph.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public static CommitGraph Parse(List<Commit> commits, bool firstParentOnlyEnable

foreach (var commit in commits)
{
var major = null as PathHelper;
PathHelper major = null;
var isMerged = commit.IsMerged;

// Update current y offset
Expand Down
14 changes: 7 additions & 7 deletions src/Models/CommitLink.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,19 @@ public static List<CommitLink> Get(List<Remote> remotes)
trimmedUrl = url.AsSpan(0, url.Length - 4);

if (url.StartsWith("https://github.com/", StringComparison.Ordinal))
outs.Add(new($"Github ({trimmedUrl.Slice(19)})", $"{url}/commit/"));
outs.Add(new($"Github ({trimmedUrl[19..]})", $"{url}/commit/"));
else if (url.StartsWith("https://gitlab.", StringComparison.Ordinal))
outs.Add(new($"GitLab ({trimmedUrl.Slice(trimmedUrl.Slice(15).IndexOf('/') + 16)})", $"{url}/-/commit/"));
outs.Add(new($"GitLab ({trimmedUrl[(trimmedUrl[15..].IndexOf('/') + 16)..]})", $"{url}/-/commit/"));
else if (url.StartsWith("https://gitee.com/", StringComparison.Ordinal))
outs.Add(new($"Gitee ({trimmedUrl.Slice(18)})", $"{url}/commit/"));
outs.Add(new($"Gitee ({trimmedUrl[18..]})", $"{url}/commit/"));
else if (url.StartsWith("https://bitbucket.org/", StringComparison.Ordinal))
outs.Add(new($"BitBucket ({trimmedUrl.Slice(22)})", $"{url}/commits/"));
outs.Add(new($"BitBucket ({trimmedUrl[22..]})", $"{url}/commits/"));
else if (url.StartsWith("https://codeberg.org/", StringComparison.Ordinal))
outs.Add(new($"Codeberg ({trimmedUrl.Slice(21)})", $"{url}/commit/"));
outs.Add(new($"Codeberg ({trimmedUrl[21..]})", $"{url}/commit/"));
else if (url.StartsWith("https://gitea.org/", StringComparison.Ordinal))
outs.Add(new($"Gitea ({trimmedUrl.Slice(18)})", $"{url}/commit/"));
outs.Add(new($"Gitea ({trimmedUrl[18..]})", $"{url}/commit/"));
else if (url.StartsWith("https://git.sr.ht/", StringComparison.Ordinal))
outs.Add(new($"sourcehut ({trimmedUrl.Slice(18)})", $"{url}/commit/"));
outs.Add(new($"sourcehut ({trimmedUrl[18..]})", $"{url}/commit/"));
}
}

Expand Down
12 changes: 3 additions & 9 deletions src/Models/DealWithChangesAfterStashing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,15 @@

namespace SourceGit.Models
{
public class DealWithChangesAfterStashing
public class DealWithChangesAfterStashing(string label, string desc)
{
public string Label { get; set; }
public string Desc { get; set; }
public string Label { get; set; } = label;
public string Desc { get; set; } = desc;

public static readonly List<DealWithChangesAfterStashing> Supported = [
new ("Discard", "All (or selected) changes will be discarded"),
new ("Keep Index", "Staged changes are left intact"),
new ("Keep All", "All (or selected) changes are left intact"),
];

public DealWithChangesAfterStashing(string label, string desc)
{
Label = label;
Desc = desc;
}
}
}
4 changes: 2 additions & 2 deletions src/Models/DiffResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ public void GeneratePatchFromSelection(Change change, string fileTreeGuid, TextD
writer.WriteLine($"+++ b/{change.Path}");

// If last line of selection is a change. Find one more line.
var tail = null as string;
string tail = null;
if (selection.EndLine < Lines.Count)
{
var lastLine = Lines[selection.EndLine - 1];
Expand Down Expand Up @@ -323,7 +323,7 @@ public void GeneratePatchFromSelectionSingleSide(Change change, string fileTreeG
writer.WriteLine($"+++ b/{change.Path}");

// If last line of selection is a change. Find one more line.
var tail = null as string;
string tail = null;
if (selection.EndLine < Lines.Count)
{
var lastLine = Lines[selection.EndLine - 1];
Expand Down
13 changes: 3 additions & 10 deletions src/Models/ExternalMerger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,16 +96,9 @@ public string[] GetPatterns()
{
return Exec.Split(';');
}
else
{
var patterns = new List<string>();
var choices = Exec.Split(';', StringSplitOptions.RemoveEmptyEntries);
foreach (var c in choices)
{
patterns.Add(Path.GetFileName(c));
}
return patterns.ToArray();
}

var choices = Exec.Split(';', StringSplitOptions.RemoveEmptyEntries);
return Array.ConvertAll(choices, Path.GetFileName);
}
}
}
2 changes: 1 addition & 1 deletion src/Models/TextInlineChange.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public static List<TextInlineChange> Compare(string oldValue, string newValue)
var ret = new List<TextInlineChange>();
var posOld = 0;
var posNew = 0;
var last = null as TextInlineChange;
TextInlineChange last = null;
do
{
while (posOld < sizeOld && posNew < sizeNew && !chunksOld[posOld].Modified && !chunksNew[posNew].Modified)
Expand Down
2 changes: 1 addition & 1 deletion src/Native/Windows.cs
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ private void FixWindowFrameOnWin10(Window w)
{
// Schedule the DWM frame extension to run in the next render frame
// to ensure proper timing with the window initialization sequence
Dispatcher.UIThread.InvokeAsync(() =>
Dispatcher.UIThread.Post(() =>
{
var platformHandle = w.TryGetPlatformHandle();
if (platformHandle == null)
Expand Down
2 changes: 1 addition & 1 deletion src/ViewModels/Blame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ private set

public bool IsBinary
{
get => _data != null && _data.IsBinary;
get => _data?.IsBinary ?? false;
}

public bool CanBack
Expand Down
2 changes: 1 addition & 1 deletion src/ViewModels/BranchCompare.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public List<Models.Change> SelectedChanges
{
if (SetProperty(ref _selectedChanges, value))
{
if (value != null && value.Count == 1)
if (value?.Count == 1)
DiffContext = new DiffContext(_repo, new Models.DiffOption(_based.Head, _to.Head, value[0]), _diffContext);
else
DiffContext = null;
Expand Down
9 changes: 4 additions & 5 deletions src/ViewModels/BranchTreeNode.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using Avalonia;
using AvaloniaEdit.Utils;
using CommunityToolkit.Mvvm.ComponentModel;

namespace SourceGit.ViewModels
Expand Down Expand Up @@ -86,8 +87,7 @@ public Builder(Models.BranchSortMode localSortMode, Models.BranchSortMode remote

public void SetExpandedNodes(List<string> expanded)
{
foreach (var node in expanded)
_expanded.Add(node);
_expanded.AddRange(expanded);
}

public void Run(List<Models.Branch> branches, List<Models.Remote> remotes, bool bForceExpanded)
Expand Down Expand Up @@ -165,7 +165,7 @@ private void MakeBranchNode(Models.Branch branch, List<BranchTreeNode> roots, Di
return;
}

var lastFolder = null as BranchTreeNode;
BranchTreeNode lastFolder = null;
var start = 0;

while (sepIdx != -1)
Expand Down Expand Up @@ -250,8 +250,7 @@ private void SortNodesByTime(List<BranchTreeNode> nodes)
{
if (r.Backend is Models.Branch)
return r.TimeToSort == l.TimeToSort ? Models.NumericSort.Compare(l.Name, r.Name) : r.TimeToSort.CompareTo(l.TimeToSort);
else
return 1;
return 1;
}

if (r.Backend is Models.Branch)
Expand Down
2 changes: 1 addition & 1 deletion src/ViewModels/CheckoutAndFastForward.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public override Task<bool> Sure()
var updateSubmodules = IsRecurseSubmoduleVisible && RecurseSubmodules;
return Task.Run(() =>
{
var succ = false;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to keep the orignal one, since the following line is also a boolean definition

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I only removed it because the false value is never used.

bool succ;
var needPopStash = false;

if (!_repo.ConfirmCheckoutBranch())
Expand Down
2 changes: 1 addition & 1 deletion src/ViewModels/Clone.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public override Task<bool> Sure()
{
var node = Preferences.Instance.FindOrAddNodeByRepositoryPath(path, null, true);
var launcher = App.GetLauncher();
var page = null as LauncherPage;
LauncherPage page = null;
foreach (var one in launcher.Pages)
{
if (one.Node.Id == _pageId)
Expand Down
2 changes: 1 addition & 1 deletion src/ViewModels/ConfigureWorkspace.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public Workspace Selected
set
{
if (SetProperty(ref _selected, value))
CanDeleteSelected = value != null && !value.IsActive;
CanDeleteSelected = value is { IsActive: false };
}
}

Expand Down
7 changes: 3 additions & 4 deletions src/ViewModels/ConventionalCommitMessageBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,9 @@ public bool Apply()
builder.Append(")");
}

if (string.IsNullOrEmpty(_breakingChanges))
builder.Append(": ");
else
builder.Append("!: ");
if (!string.IsNullOrEmpty(_breakingChanges))
builder.Append("!");
builder.Append(": ");

builder.Append(_description);
builder.Append("\n\n");
Expand Down
Loading