Skip to content

Commit 4363b8b

Browse files
authored
refactor: add new constant Models.Commit.EmptyTreeSHA1 (#1360)
1 parent f3fe90b commit 4363b8b

File tree

6 files changed

+12
-9
lines changed

6 files changed

+12
-9
lines changed

src/Commands/IsBinary.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public IsBinary(string repo, string commit, string path)
1111
{
1212
WorkingDirectory = repo;
1313
Context = repo;
14-
Args = $"diff 4b825dc642cb6eb9a060e54bf8d69288fbee4904 {commit} --numstat -- \"{path}\"";
14+
Args = $"diff {Models.Commit.EmptyTreeSHA1} {commit} --numstat -- \"{path}\"";
1515
RaiseError = false;
1616
}
1717

src/Models/Commit.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ public enum CommitSearchMethod
1818

1919
public class Commit
2020
{
21+
// As retrieved by: git mktree </dev/null
22+
public static readonly string EmptyTreeSHA1 = "4b825dc642cb6eb9a060e54bf8d69288fbee4904";
23+
2124
public static double OpacityForNotMerged
2225
{
2326
get;

src/Models/DiffOption.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public DiffOption(Change change, bool isUnstaged)
6565
/// <param name="change"></param>
6666
public DiffOption(Commit commit, Change change)
6767
{
68-
var baseRevision = commit.Parents.Count == 0 ? "4b825dc642cb6eb9a060e54bf8d69288fbee4904" : $"{commit.SHA}^";
68+
var baseRevision = commit.Parents.Count == 0 ? Models.Commit.EmptyTreeSHA1 : $"{commit.SHA}^";
6969
_revisions.Add(baseRevision);
7070
_revisions.Add(commit.SHA);
7171
_path = change.Path;
@@ -79,7 +79,7 @@ public DiffOption(Commit commit, Change change)
7979
/// <param name="file"></param>
8080
public DiffOption(Commit commit, string file)
8181
{
82-
var baseRevision = commit.Parents.Count == 0 ? "4b825dc642cb6eb9a060e54bf8d69288fbee4904" : $"{commit.SHA}^";
82+
var baseRevision = commit.Parents.Count == 0 ? Models.Commit.EmptyTreeSHA1 : $"{commit.SHA}^";
8383
_revisions.Add(baseRevision);
8484
_revisions.Add(commit.SHA);
8585
_path = file;

src/ViewModels/CommitDetail.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ public ContextMenu CreateChangeContextMenu(Models.Change change)
336336
options.DefaultExtension = ".patch";
337337
options.FileTypeChoices = [new FilePickerFileType("Patch File") { Patterns = ["*.patch"] }];
338338

339-
var baseRevision = _commit.Parents.Count == 0 ? "4b825dc642cb6eb9a060e54bf8d69288fbee4904" : _commit.Parents[0];
339+
var baseRevision = _commit.Parents.Count == 0 ? Models.Commit.EmptyTreeSHA1 : _commit.Parents[0];
340340
var storageFile = await storageProvider.SaveFilePickerAsync(options);
341341
if (storageFile != null)
342342
{
@@ -595,7 +595,7 @@ private void Refresh()
595595

596596
Task.Run(() =>
597597
{
598-
var parent = _commit.Parents.Count == 0 ? "4b825dc642cb6eb9a060e54bf8d69288fbee4904" : _commit.Parents[0];
598+
var parent = _commit.Parents.Count == 0 ? Models.Commit.EmptyTreeSHA1 : _commit.Parents[0];
599599
var cmd = new Commands.CompareRevisions(_repo.FullPath, parent, _commit.SHA) { CancellationToken = token };
600600
var changes = cmd.Result();
601601
var visible = changes;

src/ViewModels/StashesPage.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public Models.Stash SelectedStash
6969
changes = new Commands.CompareRevisions(_repo.FullPath, $"{value.SHA}^", value.SHA).Result();
7070
if (value.Parents.Count == 3)
7171
{
72-
var untracked = new Commands.CompareRevisions(_repo.FullPath, "4b825dc642cb6eb9a060e54bf8d69288fbee4904", value.Parents[2]).Result();
72+
var untracked = new Commands.CompareRevisions(_repo.FullPath, Models.Commit.EmptyTreeSHA1, value.Parents[2]).Result();
7373
var needSort = changes.Count > 0;
7474

7575
foreach (var c in untracked)
@@ -107,7 +107,7 @@ public Models.Change SelectedChange
107107
if (value == null)
108108
DiffContext = null;
109109
else if (value.Index == Models.ChangeState.Added && _selectedStash.Parents.Count == 3)
110-
DiffContext = new DiffContext(_repo.FullPath, new Models.DiffOption("4b825dc642cb6eb9a060e54bf8d69288fbee4904", _selectedStash.Parents[2], value), _diffContext);
110+
DiffContext = new DiffContext(_repo.FullPath, new Models.DiffOption(Models.Commit.EmptyTreeSHA1, _selectedStash.Parents[2], value), _diffContext);
111111
else
112112
DiffContext = new DiffContext(_repo.FullPath, new Models.DiffOption(_selectedStash.Parents[0], _selectedStash.SHA, value), _diffContext);
113113
}
@@ -182,7 +182,7 @@ public ContextMenu MakeContextMenu(Models.Stash stash)
182182
foreach (var c in _changes)
183183
{
184184
if (c.Index == Models.ChangeState.Added && _selectedStash.Parents.Count == 3)
185-
opts.Add(new Models.DiffOption("4b825dc642cb6eb9a060e54bf8d69288fbee4904", _selectedStash.Parents[2], c));
185+
opts.Add(new Models.DiffOption(Models.Commit.EmptyTreeSHA1, _selectedStash.Parents[2], c));
186186
else
187187
opts.Add(new Models.DiffOption(_selectedStash.Parents[0], _selectedStash.SHA, c));
188188
}

src/ViewModels/WorkingCopy.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1528,7 +1528,7 @@ public ContextMenu CreateContextForOpenAI()
15281528
if (_useAmend)
15291529
{
15301530
var head = new Commands.QuerySingleCommit(_repo.FullPath, "HEAD").Result();
1531-
return new Commands.QueryStagedChangesWithAmend(_repo.FullPath, head.Parents.Count == 0 ? "4b825dc642cb6eb9a060e54bf8d69288fbee4904" : $"{head.SHA}^").Result();
1531+
return new Commands.QueryStagedChangesWithAmend(_repo.FullPath, head.Parents.Count == 0 ? Models.Commit.EmptyTreeSHA1 : $"{head.SHA}^").Result();
15321532
}
15331533

15341534
var rs = new List<Models.Change>();

0 commit comments

Comments
 (0)