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 .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -71,20 +71,20 @@ dotnet_style_predefined_type_for_member_access = true:suggestion

# name all constant fields using PascalCase
dotnet_naming_rule.constant_fields_should_be_pascal_case.severity = suggestion
dotnet_naming_rule.constant_fields_should_be_pascal_case.symbols = constant_fields
dotnet_naming_rule.constant_fields_should_be_pascal_case.symbols = constant_fields
dotnet_naming_rule.constant_fields_should_be_pascal_case.style = pascal_case_style

dotnet_naming_symbols.constant_fields.applicable_kinds = field
dotnet_naming_symbols.constant_fields.applicable_kinds = field
dotnet_naming_symbols.constant_fields.required_modifiers = const

dotnet_naming_style.pascal_case_style.capitalization = pascal_case

# private static fields should have s_ prefix
dotnet_naming_rule.private_static_fields_should_have_prefix.severity = suggestion
dotnet_naming_rule.private_static_fields_should_have_prefix.symbols = private_static_fields
dotnet_naming_rule.private_static_fields_should_have_prefix.symbols = private_static_fields
dotnet_naming_rule.private_static_fields_should_have_prefix.style = private_static_prefix_style

dotnet_naming_symbols.private_static_fields.applicable_kinds = field
dotnet_naming_symbols.private_static_fields.applicable_kinds = field
dotnet_naming_symbols.private_static_fields.required_modifiers = static
dotnet_naming_symbols.private_static_fields.applicable_accessibilities = private

Expand All @@ -93,7 +93,7 @@ dotnet_naming_style.private_static_prefix_style.capitalization = camel_case

# internal and private fields should be _camelCase
dotnet_naming_rule.camel_case_for_private_internal_fields.severity = suggestion
dotnet_naming_rule.camel_case_for_private_internal_fields.symbols = private_internal_fields
dotnet_naming_rule.camel_case_for_private_internal_fields.symbols = private_internal_fields
dotnet_naming_rule.camel_case_for_private_internal_fields.style = camel_case_underscore_style

dotnet_naming_symbols.private_internal_fields.applicable_kinds = field
Expand Down
2 changes: 1 addition & 1 deletion src/App.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ private static bool TryLaunchAsRebaseMessageEditor(string[] args, out int exitCo
private bool TryLaunchAsCoreEditor(IClassicDesktopStyleApplicationLifetime desktop)
{
var args = desktop.Args;
if (args == null || args.Length <= 1 || !args[0].Equals("--core-editor", StringComparison.Ordinal))
if (args is not { Length: > 1 } || !args[0].Equals("--core-editor", StringComparison.Ordinal))
return false;

var file = args[1];
Expand Down
8 changes: 2 additions & 6 deletions src/Commands/QueryBranches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,12 @@ public QueryBranches(string repo)
if (remoteHeads.TryGetValue(b.Upstream, out var upstreamHead))
{
b.IsUpstreamGone = false;

if (b.TrackStatus == null)
b.TrackStatus = new QueryTrackStatus(WorkingDirectory, b.Head, upstreamHead).Result();
b.TrackStatus ??= new QueryTrackStatus(WorkingDirectory, b.Head, upstreamHead).Result();
}
else
{
b.IsUpstreamGone = true;

if (b.TrackStatus == null)
b.TrackStatus = new Models.BranchTrackStatus();
b.TrackStatus ??= new Models.BranchTrackStatus();
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/QueryTags.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public QueryTags(string repo)
var records = rs.StdOut.Split(_boundary, StringSplitOptions.RemoveEmptyEntries);
foreach (var record in records)
{
var subs = record.Split('\0', StringSplitOptions.None);
var subs = record.Split('\0');
if (subs.Length != 6)
continue;

Expand Down
6 changes: 1 addition & 5 deletions src/Commands/SaveRevisionFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public static void Run(string repo, string revision, string file, string saveTo)
}
}

private static bool ExecCmd(string repo, string args, string outputFile, Stream input = null)
private static void ExecCmd(string repo, string args, string outputFile, Stream input = null)
{
var starter = new ProcessStartInfo();
starter.WorkingDirectory = repo;
Expand All @@ -45,18 +45,14 @@ private static bool ExecCmd(string repo, string args, string outputFile, Stream
proc.StandardInput.Write(new StreamReader(input).ReadToEnd());
proc.StandardOutput.BaseStream.CopyTo(sw);
proc.WaitForExit();
var rs = proc.ExitCode == 0;
proc.Close();

return rs;
}
catch (Exception e)
{
Dispatcher.UIThread.Invoke(() =>
{
App.RaiseException(repo, "Save file failed: " + e.Message);
});
return false;
}
}
}
Expand Down
5 changes: 1 addition & 4 deletions src/Models/AvatarManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@ public static AvatarManager Instance
{
get
{
if (_instance == null)
_instance = new AvatarManager();

return _instance;
return _instance ??= new AvatarManager();
}
}

Expand Down
26 changes: 6 additions & 20 deletions src/Models/DiffResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@ public enum TextDiffLineType
Deleted,
}

public class TextInlineRange
public class TextInlineRange(int p, int n)
{
public int Start { get; set; }
public int End { get; set; }
public TextInlineRange(int p, int n) { Start = p; End = p + n - 1; }
public int Start { get; set; } = p;
public int End { get; set; } = p + n - 1;
}

public class TextDiffLine
Expand Down Expand Up @@ -556,7 +555,7 @@ private bool ProcessIndicatorForPatchSingleSide(StringBuilder builder, TextDiffL
}
else if (test.Type == TextDiffLineType.Added)
{
if (i < start - 1)
if (i < start - 1 || isOldSide)
{
if (revert)
{
Expand All @@ -566,18 +565,7 @@ private bool ProcessIndicatorForPatchSingleSide(StringBuilder builder, TextDiffL
}
else
{
if (isOldSide)
{
if (revert)
{
newCount++;
oldCount++;
}
}
else
{
newCount++;
}
newCount++;
}

if (i == end - 1 && tailed)
Expand Down Expand Up @@ -655,9 +643,7 @@ public class ImageDiff
public string NewImageSize => New != null ? $"{New.PixelSize.Width} x {New.PixelSize.Height}" : "0 x 0";
}

public class NoOrEOLChange
{
}
public class NoOrEOLChange;

public class FileModeDiff
{
Expand Down
3 changes: 1 addition & 2 deletions src/Models/ExternalTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,7 @@ public ExternalToolsFinder()
// Ignore
}

if (_customPaths == null)
_customPaths = new ExternalToolPaths();
_customPaths ??= new ExternalToolPaths();
}

public void TryAdd(string name, string icon, Func<string> finder, Func<string, string> execArgsGenerator = null)
Expand Down
10 changes: 3 additions & 7 deletions src/Models/IpcChannel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@ namespace SourceGit.Models
{
public class IpcChannel : IDisposable
{
public bool IsFirstInstance
{
get => _isFirstInstance;
}
public bool IsFirstInstance { get; }

public event Action<string> MessageReceived;

Expand All @@ -20,7 +17,7 @@ public IpcChannel()
try
{
_singletonLock = File.Open(Path.Combine(Native.OS.DataDir, "process.lock"), FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None);
_isFirstInstance = true;
IsFirstInstance = true;
_server = new NamedPipeServerStream(
"SourceGitIPCChannel" + Environment.UserName,
PipeDirection.In,
Expand All @@ -32,7 +29,7 @@ public IpcChannel()
}
catch
{
_isFirstInstance = false;
IsFirstInstance = false;
}
}

Expand Down Expand Up @@ -97,7 +94,6 @@ private async void StartServer()
}

private FileStream _singletonLock = null;
private bool _isFirstInstance = false;
private NamedPipeServerStream _server = null;
private CancellationTokenSource _cancellationTokenSource = null;
}
Expand Down
4 changes: 1 addition & 3 deletions src/Models/Null.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
namespace SourceGit.Models
{
public class Null
{
}
public class Null;
}
4 changes: 1 addition & 3 deletions src/Models/SelfUpdate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ public bool IsNewVersion
}
}

public class AlreadyUpToDate
{
}
public class AlreadyUpToDate;

public class SelfUpdateFailed
{
Expand Down
12 changes: 6 additions & 6 deletions src/Models/TemplateEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ private void Reset()
private int? Integer()
{
var start = _pos;
while (Peek() is char c && c >= '0' && c <= '9')
while (Peek() is >= '0' and <= '9')
{
_pos++;
}
Expand All @@ -118,7 +118,7 @@ private void Parse()
// text token start
var tok = _pos;
bool esc = false;
while (Next() is char c)
while (Next() is { } c)
{
if (esc)
{
Expand All @@ -129,7 +129,7 @@ private void Parse()
{
case ESCAPE:
// allow to escape only \ and $
if (Peek() is char nc && (nc == ESCAPE || nc == VARIABLE_ANCHOR))
if (Peek() is { } nc && (nc == ESCAPE || nc == VARIABLE_ANCHOR))
{
esc = true;
FlushText(tok, _pos - 1);
Expand Down Expand Up @@ -173,7 +173,7 @@ private object TryParseVariable()
if (Next() != VARIABLE_START)
return null;
int name_start = _pos;
while (Next() is char c)
while (Next() is { } c)
{
// name character, continue advancing
if (IsNameChar(c))
Expand Down Expand Up @@ -228,7 +228,7 @@ private Regex ParseRegex()
var sb = new StringBuilder();
var tok = _pos;
var esc = false;
while (Next() is char c)
while (Next() is { } c)
{
if (esc)
{
Expand Down Expand Up @@ -277,7 +277,7 @@ private string ParseReplacement()
var sb = new StringBuilder();
var tok = _pos;
var esc = false;
while (Next() is char c)
while (Next() is { } c)
{
if (esc)
{
Expand Down
34 changes: 9 additions & 25 deletions src/Models/TextInlineChange.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,19 @@

namespace SourceGit.Models
{
public class TextInlineChange
public class TextInlineChange(int dp, int dc, int ap, int ac)
{
public int DeletedStart { get; set; }
public int DeletedCount { get; set; }
public int AddedStart { get; set; }
public int AddedCount { get; set; }
public int DeletedStart { get; set; } = dp;
public int DeletedCount { get; set; } = dc;
public int AddedStart { get; set; } = ap;
public int AddedCount { get; set; } = ac;

private class Chunk
private class Chunk(int hash, int start, int size)
{
public int Hash;
public readonly int Hash = hash;
public readonly int Start = start;
public readonly int Size = size;
public bool Modified;
public int Start;
public int Size;

public Chunk(int hash, int start, int size)
{
Hash = hash;
Modified = false;
Start = start;
Size = size;
}
}

private enum Edit
Expand All @@ -43,14 +35,6 @@ private class EditResult
public int AddEnd;
}

public TextInlineChange(int dp, int dc, int ap, int ac)
{
DeletedStart = dp;
DeletedCount = dc;
AddedStart = ap;
AddedCount = ac;
}

public static List<TextInlineChange> Compare(string oldValue, string newValue)
{
var hashes = new Dictionary<string, int>();
Expand Down
6 changes: 3 additions & 3 deletions src/Native/Windows.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ internal struct MARGINS
public void SetupApp(AppBuilder builder)
{
// Fix drop shadow issue on Windows 10
if (!OperatingSystem.IsWindowsVersionAtLeast(10, 22000, 0))
if (!OperatingSystem.IsWindowsVersionAtLeast(10, 22000))
{
Window.WindowStateProperty.Changed.AddClassHandler<Window>((w, _) => FixWindowFrameOnWin10(w));
Control.LoadedEvent.AddClassHandler<Window>((w, _) => FixWindowFrameOnWin10(w));
Expand Down Expand Up @@ -385,11 +385,11 @@ private string FindVisualStudio()
Microsoft.Win32.RegistryView.Registry64);

// Get default class for VisualStudio.Launcher.sln - the handler for *.sln files
if (localMachine.OpenSubKey(@"SOFTWARE\Classes\VisualStudio.Launcher.sln\CLSID") is Microsoft.Win32.RegistryKey launcher)
if (localMachine.OpenSubKey(@"SOFTWARE\Classes\VisualStudio.Launcher.sln\CLSID") is { } launcher)
{
// Get actual path to the executable
if (launcher.GetValue(string.Empty) is string CLSID &&
localMachine.OpenSubKey(@$"SOFTWARE\Classes\CLSID\{CLSID}\LocalServer32") is Microsoft.Win32.RegistryKey devenv &&
localMachine.OpenSubKey(@$"SOFTWARE\Classes\CLSID\{CLSID}\LocalServer32") is { } devenv &&
devenv.GetValue(string.Empty) is string localServer32)
return localServer32!.Trim('\"');
}
Expand Down
15 changes: 2 additions & 13 deletions src/Resources/Styles.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -529,13 +529,7 @@
<Setter Property="MinHeight" Value="24"/>
<Setter Property="Template">
<ControlTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="1" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>

<Grid ColumnDefinitions="*,1,Auto">
<Button x:Name="PART_PrimaryButton"
Grid.Column="0"
Classes="flat primary"
Expand Down Expand Up @@ -1001,12 +995,7 @@
<Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="Template">
<ControlTemplate>
<Grid Background="Transparent">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>

<Grid Background="Transparent" ColumnDefinitions="Auto,*">
<Border x:Name="Border" Grid.Column="0" Width="16" Height="16" VerticalAlignment="Center" BorderBrush="{DynamicResource Brush.Border1}" BorderThickness="1" Background="Transparent" CornerRadius="2">
<Path x:Name="Icon" Height="12" Width="12" Data="{DynamicResource Icons.Check}" Fill="{DynamicResource Brush.Accent}" IsVisible="False" Margin="0,2,0,0"/>
</Border>
Expand Down
2 changes: 1 addition & 1 deletion src/ViewModels/BranchCompare.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public void ClearSearchFilter()

public ContextMenu CreateChangeContextMenu()
{
if (_selectedChanges == null || _selectedChanges.Count != 1)
if (_selectedChanges is not { Count: 1 })
return null;

var change = _selectedChanges[0];
Expand Down
Loading
Loading