Skip to content

code_style: general cleanup #1565

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

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion build/scripts/localization-check.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ async function calculateTranslationRate() {
const badgeColor = progress >= 75 ? 'yellow' : 'red';

lines.push(`### ![${locale}](https://img.shields.io/badge/${locale}-${progress.toFixed(2)}%25-${badgeColor})`);
lines.push(`<details>\n<summary>Missing keys in ${file}</summary>\n\n${missingKeys.map(key => `- ${key}`).join('\n')}\n\n</details>`)
lines.push(`<details>\n<summary>Missing keys in ${file}</summary>\n\n${missingKeys.map(key => `- \`${key}\``).join('\n')}\n\n</details>`)
} else {
lines.push(`### ![${locale}](https://img.shields.io/badge/${locale}-%E2%88%9A-brightgreen)`);
}
Expand Down
12 changes: 5 additions & 7 deletions src/App.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ public override void OnFrameworkInitializationCompleted()
if (!string.IsNullOrEmpty(arg))
{
if (arg.StartsWith('"') && arg.EndsWith('"'))
arg = arg.Substring(1, arg.Length - 2).Trim();
arg = arg[1..^1].Trim();

if (arg.Length > 0 && !Path.IsPathFullyQualified(arg))
arg = Path.GetFullPath(arg);
Expand Down Expand Up @@ -687,12 +687,10 @@ private string FixFontFamilyName(string input)
}

var name = sb.ToString();
if (name.Contains('#'))
{
if (!name.Equals("fonts:Inter#Inter", StringComparison.Ordinal) &&
!name.Equals("fonts:SourceGit#JetBrains Mono", StringComparison.Ordinal))
continue;
}
if (name.Contains('#') &&
!name.Equals("fonts:Inter#Inter", StringComparison.Ordinal) &&
!name.Equals("fonts:SourceGit#JetBrains Mono", StringComparison.Ordinal))
continue;

trimmed.Add(name);
}
Expand Down
15 changes: 9 additions & 6 deletions src/Commands/Apply.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
namespace SourceGit.Commands
using System.Text;

namespace SourceGit.Commands
{
public class Apply : Command
{
public Apply(string repo, string file, bool ignoreWhitespace, string whitespaceMode, string extra)
{
WorkingDirectory = repo;
Context = repo;
Args = "apply ";

var builder = new StringBuilder("apply ");
if (ignoreWhitespace)
Args += "--ignore-whitespace ";
builder.Append("--ignore-whitespace ");
else
Args += $"--whitespace={whitespaceMode} ";
builder.Append("--whitespace=").Append(whitespaceMode).Append(' ');
if (!string.IsNullOrEmpty(extra))
Args += $"{extra} ";
Args += $"{file.Quoted()}";
builder.Append(extra).Append(' ');
Args = builder.Append(file.Quoted()).ToString();
}
}
}
14 changes: 8 additions & 6 deletions src/Commands/CherryPick.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace SourceGit.Commands
using System.Text;

namespace SourceGit.Commands
{
public class CherryPick : Command
{
Expand All @@ -7,14 +9,14 @@ public CherryPick(string repo, string commits, bool noCommit, bool appendSourceT
WorkingDirectory = repo;
Context = repo;

Args = "cherry-pick ";
var builder = new StringBuilder("cherry-pick ");
if (noCommit)
Args += "-n ";
builder.Append("-n ");
if (appendSourceToMessage)
Args += "-x ";
builder.Append("-x ");
if (!string.IsNullOrEmpty(extraParams))
Args += $"{extraParams} ";
Args += commits;
builder.Append(extraParams).Append(' ');
Args = builder.Append(commits).ToString();
}
}
}
15 changes: 8 additions & 7 deletions src/Commands/Clone.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace SourceGit.Commands
using System.Text;

namespace SourceGit.Commands
{
public class Clone : Command
{
Expand All @@ -7,15 +9,14 @@ public Clone(string ctx, string path, string url, string localName, string sshKe
Context = ctx;
WorkingDirectory = path;
SSHKey = sshKey;
Args = "clone --progress --verbose ";

var builder = new StringBuilder("clone --progress --verbose ");
if (!string.IsNullOrEmpty(extraArgs))
Args += $"{extraArgs} ";

Args += $"{url} ";

builder.Append(extraArgs).Append(' ');
builder.Append(url);
if (!string.IsNullOrEmpty(localName))
Args += localName;
builder.Append(' ').Append(localName);
Args = builder.ToString();
}
}
}
13 changes: 10 additions & 3 deletions src/Commands/Commit.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.IO;
using System.Text;
using System.Threading.Tasks;

namespace SourceGit.Commands
Expand All @@ -12,11 +13,17 @@ public Commit(string repo, string message, bool signOff, bool amend, bool resetA

WorkingDirectory = repo;
Context = repo;
Args = $"commit --allow-empty --file={_tmpFile.Quoted()}";

var builder = new StringBuilder("commit --allow-empty --file=").Append(_tmpFile.Quoted());
if (signOff)
Args += " --signoff";
builder.Append(" --signoff");
if (amend)
Args += resetAuthor ? " --amend --reset-author --no-edit" : " --amend --no-edit";
{
builder.Append(" --amend --no-edit");
if (resetAuthor)
builder.Append(" --reset-author");
}
Args = builder.ToString();
}

public async Task<bool> RunAsync()
Expand Down
28 changes: 11 additions & 17 deletions src/Commands/CompareRevisions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,24 +64,18 @@ private void ParseLine(List<Models.Change> outs, string line)
var change = new Models.Change() { Path = match.Groups[2].Value };
var status = match.Groups[1].Value;

switch (status[0])
var state = status[0] switch
{
case 'M':
change.Set(Models.ChangeState.Modified);
outs.Add(change);
break;
case 'A':
change.Set(Models.ChangeState.Added);
outs.Add(change);
break;
case 'D':
change.Set(Models.ChangeState.Deleted);
outs.Add(change);
break;
case 'C':
change.Set(Models.ChangeState.Copied);
outs.Add(change);
break;
'M' => Models.ChangeState.Modified,
'A' => Models.ChangeState.Added,
'D' => Models.ChangeState.Deleted,
'C' => Models.ChangeState.Copied,
_ => Models.ChangeState.None
};
if (state != Models.ChangeState.None)
{
change.Set(state);
outs.Add(change);
}
}
}
Expand Down
15 changes: 6 additions & 9 deletions src/Commands/Fetch.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Threading.Tasks;
using System.Text;
using System.Threading.Tasks;

namespace SourceGit.Commands
{
Expand All @@ -10,18 +11,14 @@ public Fetch(string repo, string remote, bool noTags, bool force)

WorkingDirectory = repo;
Context = repo;
Args = "fetch --progress --verbose ";

if (noTags)
Args += "--no-tags ";
else
Args += "--tags ";
var builder = new StringBuilder("fetch --progress --verbose ");
builder.Append(noTags ? "--no-tags " : "--tags ");

if (force)
Args += "--force ";

Args += remote;
builder.Append("--force ");

Args = builder.Append(remote).ToString();
}

public Fetch(string repo, Models.Branch local, Models.Branch remote)
Expand Down
16 changes: 8 additions & 8 deletions src/Commands/Push.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Threading.Tasks;
using System.Text;
using System.Threading.Tasks;

namespace SourceGit.Commands
{
Expand All @@ -10,18 +11,17 @@ public Push(string repo, string local, string remote, string remoteBranch, bool

WorkingDirectory = repo;
Context = repo;
Args = "push --progress --verbose ";

var builder = new StringBuilder("push --progress --verbose ");
if (withTags)
Args += "--tags ";
builder.Append("--tags ");
if (checkSubmodules)
Args += "--recurse-submodules=check ";
builder.Append("--recurse-submodules=check ");
if (track)
Args += "-u ";
builder.Append("-u ");
if (force)
Args += "--force-with-lease ";

Args += $"{remote} {local}:{remoteBranch}";
builder.Append("--force-with-lease ");
Args = builder.Append(remote).Append(' ').Append(local).Append(':').Append(remoteBranch).ToString();
}

public Push(string repo, string remote, string refname, bool isDelete)
Expand Down
Loading