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
3 changes: 1 addition & 2 deletions src/App.Commands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ public static bool IsCheckForUpdateCommandVisible
public static readonly Command QuitCommand = new Command(_ => Quit(0));
public static readonly Command CopyTextBlockCommand = new Command(async p =>
{
var textBlock = p as TextBlock;
if (textBlock == null)
if (p is not TextBlock textBlock)
return;

if (textBlock.Inlines is { Count: > 0 } inlines)
Expand Down
10 changes: 3 additions & 7 deletions src/App.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,7 @@ public static void SendNotification(string context, string message)

public static void SetLocale(string localeKey)
{
var app = Current as App;
var targetLocale = app?.Resources[localeKey] as ResourceDictionary;
if (targetLocale == null || targetLocale == app._activeLocale)
if (Current is not App app || app.Resources[localeKey] is not ResourceDictionary targetLocale || targetLocale == app._activeLocale)
return;

if (app._activeLocale != null)
Expand All @@ -200,8 +198,7 @@ public static void SetLocale(string localeKey)

public static void SetTheme(string theme, string themeOverridesFile)
{
var app = Current as App;
if (app == null)
if (Current is not App app)
return;

if (theme.Equals("Light", StringComparison.OrdinalIgnoreCase))
Expand Down Expand Up @@ -254,8 +251,7 @@ public static void SetTheme(string theme, string themeOverridesFile)

public static void SetFonts(string defaultFont, string monospaceFont, bool onlyUseMonospaceFontInEditor)
{
var app = Current as App;
if (app == null)
if (Current is not App app)
return;

if (app._fontsOverrides != null)
Expand Down
2 changes: 0 additions & 2 deletions src/Commands/Blame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ public Blame(string repo, string file, string revision)
foreach (var line in _result.LineInfos)
{
if (line.CommitSHA.Length > _minSHALen)
{
line.CommitSHA = line.CommitSHA.Substring(0, _minSHALen);
}
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/Commands/Command.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,9 @@ protected async Task<Result> ReadToEndAsync()
}

var rs = new Result() { IsSuccess = true };
rs.StdOut = await proc.StandardOutput.ReadToEndAsync().ConfigureAwait(false);
rs.StdErr = await proc.StandardError.ReadToEndAsync().ConfigureAwait(false);
await proc.WaitForExitAsync().ConfigureAwait(false);
rs.StdOut = await proc.StandardOutput.ReadToEndAsync(CancellationToken).ConfigureAwait(false);
rs.StdErr = await proc.StandardError.ReadToEndAsync(CancellationToken).ConfigureAwait(false);
await proc.WaitForExitAsync(CancellationToken).ConfigureAwait(false);

rs.IsSuccess = proc.ExitCode == 0;
proc.Close();
Expand Down
4 changes: 0 additions & 4 deletions src/Commands/Diff.cs
Original file line number Diff line number Diff line change
Expand Up @@ -249,14 +249,10 @@ private void ProcessInlineHighlights()
foreach (var chunk in chunks)
{
if (chunk.DeletedCount > 0)
{
left.Highlights.Add(new Models.TextInlineRange(chunk.DeletedStart, chunk.DeletedCount));
}

if (chunk.AddedCount > 0)
{
right.Highlights.Add(new Models.TextInlineRange(chunk.AddedStart, chunk.AddedCount));
}
}
}
}
Expand Down
6 changes: 2 additions & 4 deletions src/Commands/QueryCommits.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ private void ParseParent(string data)
if (data.Length < 8)
return;

_current.Parents.AddRange(data.Split(separator: ' ', options: StringSplitOptions.RemoveEmptyEntries));
_current.Parents.AddRange(data.Split(' ', StringSplitOptions.RemoveEmptyEntries));
}

private async Task MarkFirstMergedAsync()
Expand All @@ -133,9 +133,7 @@ private async Task MarkFirstMergedAsync()
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
2 changes: 1 addition & 1 deletion src/Commands/QueryCommitsForInteractiveRebase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ private void ParseParent(string data)
if (data.Length < 8)
return;

_current.Commit.Parents.AddRange(data.Split(separator: ' ', options: StringSplitOptions.RemoveEmptyEntries));
_current.Commit.Parents.AddRange(data.Split(' ', StringSplitOptions.RemoveEmptyEntries));
}

private List<Models.InteractiveCommit> _commits = [];
Expand Down
7 changes: 1 addition & 6 deletions src/Commands/Submodule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,10 @@ public async Task<bool> AddAsync(string url, string relativePath, bool recursive
return false;

if (recursive)
{
Args = $"submodule update --init --recursive -- \"{relativePath}\"";
return await ExecAsync().ConfigureAwait(false);
}
else
{
Args = $"submodule update --init -- \"{relativePath}\"";
return await ExecAsync().ConfigureAwait(false);
}
return await ExecAsync().ConfigureAwait(false);
}

public async Task<bool> SetURL(string path, string url)
Expand Down
15 changes: 4 additions & 11 deletions src/Models/ApplyWhiteSpaceMode.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace SourceGit.Models
{
public class ApplyWhiteSpaceMode
public class ApplyWhiteSpaceMode(string n, string d, string a)
{
public static readonly ApplyWhiteSpaceMode[] Supported =
[
Expand All @@ -10,15 +10,8 @@ public class ApplyWhiteSpaceMode
new ApplyWhiteSpaceMode("Error All", "Similar to 'error', but shows more", "error-all"),
];

public string Name { get; set; }
public string Desc { get; set; }
public string Arg { get; set; }

public ApplyWhiteSpaceMode(string n, string d, string a)
{
Name = n;
Desc = d;
Arg = a;
}
public string Name { get; set; } = n;
public string Desc { get; set; } = d;
public string Arg { get; set; } = a;
}
}
5 changes: 4 additions & 1 deletion src/Models/AvatarManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,10 @@ public void SetFromLocal(string email, string file)

_resources[email] = image;

_requesting.Remove(email);
lock (_synclock)
{
_requesting.Remove(email);
}

var store = Path.Combine(_storePath, GetEmailHash(email));
File.Copy(file, store, true);
Expand Down
15 changes: 4 additions & 11 deletions src/Models/CRLFMode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,16 @@

namespace SourceGit.Models
{
public class CRLFMode
public class CRLFMode(string name, string value, string desc)
{
public string Name { get; set; }
public string Value { get; set; }
public string Desc { get; set; }
public string Name { get; set; } = name;
public string Value { get; set; } = value;
public string Desc { get; set; } = desc;

public static readonly List<CRLFMode> Supported = new List<CRLFMode>() {
new CRLFMode("TRUE", "true", "Commit as LF, checkout as CRLF"),
new CRLFMode("INPUT", "input", "Only convert for commit"),
new CRLFMode("FALSE", "false", "Do NOT convert"),
};

public CRLFMode(string name, string value, string desc)
{
Name = name;
Value = value;
Desc = desc;
}
}
}
10 changes: 2 additions & 8 deletions src/Models/DiffOption.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public DiffOption(Change change, bool isUnstaged)
{
_workingCopyChange = change;
_isUnstaged = isUnstaged;
_path = change.Path;
_orgPath = change.OriginalPath;

if (isUnstaged)
{
Expand All @@ -37,13 +39,8 @@ public DiffOption(Change change, bool isUnstaged)
case ChangeState.Added:
case ChangeState.Untracked:
_extra = "--no-index";
_path = change.Path;
_orgPath = "/dev/null";
break;
default:
_path = change.Path;
_orgPath = change.OriginalPath;
break;
}
}
else
Expand All @@ -52,9 +49,6 @@ public DiffOption(Change change, bool isUnstaged)
_extra = $"--cached {change.DataForAmend.ParentSHA}";
else
_extra = "--cached";

_path = change.Path;
_orgPath = change.OriginalPath;
}
}

Expand Down
23 changes: 5 additions & 18 deletions src/Models/DiffResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -210,21 +210,12 @@ public void GeneratePatchFromSelection(Change change, string fileTreeGuid, TextD
var line = Lines[i];
if (line.Type == TextDiffLineType.Indicator)
break;
if (revert)
{
if (line.Type == TextDiffLineType.Normal || line.Type == TextDiffLineType.Added)
{
tail = line.Content;
break;
}
}
else
if (line.Type == TextDiffLineType.Normal ||
(revert && line.Type == TextDiffLineType.Added) ||
(!revert && line.Type == TextDiffLineType.Deleted))
{
if (line.Type == TextDiffLineType.Normal || line.Type == TextDiffLineType.Deleted)
{
tail = line.Content;
break;
}
tail = line.Content;
break;
}
}
}
Expand Down Expand Up @@ -290,9 +281,7 @@ public void GeneratePatchFromSelection(Change change, string fileTreeGuid, TextD
if (line.Type == TextDiffLineType.Indicator)
{
if (!ProcessIndicatorForPatch(writer, line, i, selection.StartLine, selection.EndLine, selection.IgnoredDeletes, selection.IgnoredAdds, revert, tail != null))
{
break;
}
}
else if (line.Type == TextDiffLineType.Normal)
{
Expand Down Expand Up @@ -414,9 +403,7 @@ public void GeneratePatchFromSelectionSingleSide(Change change, string fileTreeG
if (line.Type == TextDiffLineType.Indicator)
{
if (!ProcessIndicatorForPatchSingleSide(writer, line, i, selection.StartLine, selection.EndLine, selection.IgnoredDeletes, selection.IgnoredAdds, revert, isOldSide, tail != null))
{
break;
}
}
else if (line.Type == TextDiffLineType.Normal)
{
Expand Down
2 changes: 0 additions & 2 deletions src/Models/ExternalMerger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,7 @@ public ExternalMerger(int type, string icon, string name, string exec, string cm
public string[] GetPatterns()
{
if (OperatingSystem.IsWindows())
{
return Exec.Split(';');
}

var choices = Exec.Split(';', StringSplitOptions.RemoveEmptyEntries);
return Array.ConvertAll(choices, Path.GetFileName);
Expand Down
15 changes: 4 additions & 11 deletions src/Models/MergeMode.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace SourceGit.Models
{
public class MergeMode
public class MergeMode(string n, string d, string a)
{
public static readonly MergeMode Default =
new MergeMode("Default", "Fast-forward if possible", "");
Expand All @@ -26,15 +26,8 @@ public static readonly MergeMode DontCommit
DontCommit,
];

public string Name { get; set; }
public string Desc { get; set; }
public string Arg { get; set; }

public MergeMode(string n, string d, string a)
{
Name = n;
Desc = d;
Arg = a;
}
public string Name { get; set; } = n;
public string Desc { get; set; } = d;
public string Arg { get; set; } = a;
}
}
21 changes: 6 additions & 15 deletions src/Models/ResetMode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace SourceGit.Models
{
public class ResetMode
public class ResetMode(string n, string d, string a, string k, IBrush b)
{
public static readonly ResetMode[] Supported =
[
Expand All @@ -13,19 +13,10 @@ public class ResetMode
new ResetMode("Hard", "Discard all changes", "--hard", "H", Brushes.Red),
];

public string Name { get; set; }
public string Desc { get; set; }
public string Arg { get; set; }
public string Key { get; set; }
public IBrush Color { get; set; }

public ResetMode(string n, string d, string a, string k, IBrush b)
{
Name = n;
Desc = d;
Arg = a;
Key = k;
Color = b;
}
public string Name { get; set; } = n;
public string Desc { get; set; } = d;
public string Arg { get; set; } = a;
public string Key { get; set; } = k;
public IBrush Color { get; set; } = b;
}
}
8 changes: 1 addition & 7 deletions src/Models/TemplateEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,7 @@ private void Reset()
{
var c = Peek();
if (c is not null)
{
_pos++;
}
return c;
}

Expand Down Expand Up @@ -129,7 +127,7 @@ private void Parse()
{
case ESCAPE:
// allow to escape only \ and $
if (Peek() is { } nc && (nc == ESCAPE || nc == VARIABLE_ANCHOR))
if (Peek() is ESCAPE or VARIABLE_ANCHOR)
{
esc = true;
FlushText(tok, _pos - 1);
Expand Down Expand Up @@ -320,9 +318,7 @@ private static bool IsNameChar(char c)
private static string EvalVariable(Context context, string name)
{
if (!s_variables.TryGetValue(name, out var getter))
{
return string.Empty;
}
return getter(context);
}

Expand All @@ -334,9 +330,7 @@ private static string EvalVariable(Context context, Variable variable)
private static string EvalVariable(Context context, SlicedVariable variable)
{
if (!s_slicedVariables.TryGetValue(variable.name, out var getter))
{
return string.Empty;
}
return getter(context, variable.count);
}

Expand Down
Loading