refactor: convert to interpolated strings

This commit is contained in:
Philippe Miossec
2024-04-04 16:44:05 +02:00
parent 4d665823b0
commit 3d49f26005
12 changed files with 24 additions and 38 deletions
+1 -2
View File
@@ -483,8 +483,7 @@ namespace GitTfs.VsCommon
public int TargetChangeset;
public string TargetItem;
public override string ToString() => string.Format("`{0}` C{1} `{2}` Source `{3}` C{4} `{5}`", TargetChangeType, TargetChangeset, TargetItem,
SourceChangeType, SourceChangeset, SourceItem);
public override string ToString() => $"`{TargetChangeType}` C{TargetChangeset} `{TargetItem}` Source `{SourceChangeType}` C{SourceChangeset} `{SourceItem}`";
}
private IEnumerable<MergeInfo> GetMergeInfo(string tfsPathBranchToCreate, string tfsPathParentBranch,
+2 -2
View File
@@ -27,12 +27,12 @@ namespace GitTfs.Commands
if (_checkinOptions.NoMerge)
{
Trace.TraceInformation("TFS Changeset #" + newChangesetId + " was created.");
Trace.TraceInformation($"TFS Changeset #{newChangesetId} was created.");
parentChangeset.Remote.Fetch();
}
else
{
Trace.TraceInformation("TFS Changeset #" + newChangesetId + " was created. Marking it as a merge commit...");
Trace.TraceInformation($"TFS Changeset #{newChangesetId} was created. Marking it as a merge commit...");
parentChangeset.Remote.FetchWithMerge(newChangesetId, false, refToCheckin);
if (refToCheckin == "HEAD")
+2 -2
View File
@@ -86,13 +86,13 @@ namespace GitTfs.Commands
catch (IOException e)
{
// swallow IOException. Smth went wrong before this and we're much more interested in that error
string msg = string.Format("warning: Something went wrong while cleaning file after internal error (See below).\n Can't clean up files because of IOException:\n{0}\n", e.IndentExceptionMessage());
string msg = $"warning: Something went wrong while cleaning file after internal error (See below).\n Can't clean up files because of IOException:\n{e.IndentExceptionMessage()}\n";
Trace.WriteLine(msg);
}
catch (UnauthorizedAccessException e)
{
// swallow it also
string msg = string.Format("warning: Something went wrong while cleaning file after internal error (See below).\n Can't clean up files because of UnauthorizedAccessException:\n{0}\n", e.IndentExceptionMessage());
string msg = $"warning: Something went wrong while cleaning file after internal error (See below).\n Can't clean up files because of UnauthorizedAccessException:\n{e.IndentExceptionMessage()}\n";
Trace.WriteLine(msg);
}
}
+4 -8
View File
@@ -142,15 +142,11 @@ namespace GitTfs.Commands
int latest = Math.Max(owner.MaxChangesetId, remote.MaxChangesetId);
string msg = string.Format(GitTfsConstants.TfsCommitInfoFormat, owner.TfsUrl, owner.TfsRepositoryPath, latest);
msg = string.Format(@"Add '{0}/' from commit '{1}'
msg = $@"Add '{Prefix}/' from commit '{remote.MaxCommitHash}'
{2}", Prefix, remote.MaxCommitHash, msg);
{msg}";
_globals.Repository.CommandNoisy(
"subtree", "add",
"--prefix=" + p,
string.Format("-m {0}", msg),
remote.RemoteRef);
_globals.Repository.CommandNoisy("subtree", "add", "--prefix=" + p, $"-m {msg}", remote.RemoteRef);
//update the owner remote to point at the commit where the newly created subtree was merged.
var commit = _globals.Repository.GetCurrentCommit();
@@ -207,7 +203,7 @@ namespace GitTfs.Commands
{
if (!Directory.Exists(Prefix))
{
throw new GitTfsException(string.Format("Directory {0} does not exist", Prefix))
throw new GitTfsException($"Directory {Prefix} does not exist")
.WithRecommendation("Add the subtree using 'git tfs subtree add -p=<prefix> [tfs-server] [tfs-repository]'");
}
}
+2 -2
View File
@@ -139,7 +139,7 @@ namespace GitTfs.Core
finally
{
var end = DateTime.Now;
Trace.WriteLine(string.Format("[{0}] {1}", end - start, string.Join(" ", command)), "git command time");
Trace.WriteLine($"[{end - start}] {string.Join(" ", command)}", "git command time");
}
}
@@ -158,7 +158,7 @@ namespace GitTfs.Core
if (!process.WaitForExit((int)TimeSpan.FromSeconds(10).TotalMilliseconds))
throw new GitCommandException("Command did not terminate.", process);
if (process.ExitCode != 0)
throw new GitCommandException(string.Format("Command exited with error code: {0}\n{1}", process.ExitCode, process.StandardErrorString), process);
throw new GitCommandException($"Command exited with error code: {process.ExitCode}\n{process.StandardErrorString}", process);
}
private void RedirectStdout(ProcessStartInfo startInfo)
+2 -2
View File
@@ -196,11 +196,11 @@ namespace GitTfs.Core
throw new GitTfsException("error: the new name of the remote is invalid!");
if (HasRemote(newRemoteName))
throw new GitTfsException(string.Format("error: this remote name \"{0}\" is already used!", newRemoteName));
throw new GitTfsException($"error: this remote name \"{newRemoteName}\" is already used!");
var oldRemote = ReadTfsRemote(oldRemoteName);
if (oldRemote == null)
throw new GitTfsException(string.Format("error: the remote \"{0}\" doesn't exist!", oldRemoteName));
throw new GitTfsException($"error: the remote \"{oldRemoteName}\" doesn't exist!");
var remoteInfo = oldRemote.RemoteInfo;
remoteInfo.Id = newRemoteName;
+1 -1
View File
@@ -497,7 +497,7 @@ namespace GitTfs.Core
workitemUrl = workitemUrl.Replace(oldWorkitemId, workitemId);
}
}
workitemNote += string.Format("[{0}] {1}\n {2}\n", workitemId, workitem.Title, workitemUrl);
workitemNote += $"[{workitemId}] {workitem.Title}\n {workitemUrl}\n";
}
metadatas.Append(workitemNote);
}
+1 -4
View File
@@ -13,10 +13,7 @@ namespace GitTfs.Core
_tfsHelper = tfsHelper;
}
public string GetVersionString() => string.Format("git-tfs version {0} (TFS client library {1}) ({2}-bit)",
GetType().Assembly.GetName().Version,
_tfsHelper.TfsClientLibraryVersion,
(Environment.Is64BitProcess ? "64" : "32"));
public string GetVersionString() => $"git-tfs version {GetType().Assembly.GetName().Version} (TFS client library {_tfsHelper.TfsClientLibraryVersion}) ({(Environment.Is64BitProcess ? "64" : "32")}-bit)";
public string GetPathToGitTfsExecutable() => Assembly.GetExecutingAssembly().Location;
}
+5 -11
View File
@@ -78,19 +78,13 @@ namespace GitTfs.Core
}
}
private void Ignore(string pathInGitRepo) => Trace.TraceInformation(string.Format("C{0} ! No changes applied to '{1}', file ignored", _changeset.ChangesetId, pathInGitRepo));
private void Ignore(string pathInGitRepo) => Trace.TraceInformation($"C{_changeset.ChangesetId} ! No changes applied to '{pathInGitRepo}', file ignored");
public IEnumerable<TfsTreeEntry> GetTree() => GetFullTree().Where(item => item.Item.ItemType == TfsItemType.File && !Summary.Remote.ShouldSkip(item.FullName));
public bool IsMergeChangeset
{
get
{
if (_changeset == null || _changeset.Changes == null || !_changeset.Changes.Any())
return false;
return _changeset.Changes.Any(c => c.ChangeType.IncludesOneOf(TfsChangeType.Merge));
}
}
public bool IsMergeChangeset => _changeset == null || _changeset.Changes == null || !_changeset.Changes.Any()
? false
: _changeset.Changes.Any(c => c.ChangeType.IncludesOneOf(TfsChangeType.Merge));
public IEnumerable<TfsTreeEntry> GetFullTree()
{
@@ -201,7 +195,7 @@ namespace GitTfs.Core
if (split.Length == 2)
{
name = split[1].ToLower();
email = string.Format("{0}@{1}.tfs.local", name, split[0].ToLower());
email = $"{name}@{split[0].ToLower()}.tfs.local";
}
}
// committer's & author's name and email MUST NOT be empty as otherwise they would be picked
+1 -1
View File
@@ -40,7 +40,7 @@ namespace GitTfs.Core.TfsInterop
public string ParentPath => Branch.ParentPath;
public bool IsRoot => Branch.IsRoot;
public override string ToString() => string.Format("{0} [{1} children]", Path, ChildBranches.Count);
public override string ToString() => $"{Path} [{ChildBranches.Count} children]";
}
public static class BranchExtensions
+1 -1
View File
@@ -25,7 +25,7 @@ namespace GitTfs.Core.TfsInterop
private string DebuggerDisplay => string.Format("{0} C{1}{2}{3}",
/* {0} */ TfsBranchPath,
/* {1} */ SourceBranchChangesetId,
/* {2} */ TargetBranchChangesetId > -1 ? string.Format(" (target C{0})", TargetBranchChangesetId) : string.Empty,
/* {2} */ TargetBranchChangesetId > -1 ? $" (target C{TargetBranchChangesetId})" : string.Empty,
/* {3} */ IsRenamedBranch ? " renamed" : ""
);
}
+2 -2
View File
@@ -194,14 +194,14 @@ namespace GitTfs.Util
var previousChange = history.FirstOrDefault();
if (previousChange == null)
{
Trace.WriteLine(string.Format("No history found for item {0} changesetId {1}", item.ServerItem, item.ChangesetId));
Trace.WriteLine($"No history found for item {item.ServerItem} changesetId {item.ChangesetId}");
return null;
}
oldItem = previousChange.Changes[0].Item;
}
catch
{
Trace.WriteLine(string.Format("No history found for item {0} changesetId {1}", item.ServerItem, item.ChangesetId));
Trace.WriteLine($"No history found for item {item.ServerItem} changesetId {item.ChangesetId}");
return null;
}
}