8000 feature: show branches count in branch tree (#1306) · sourcegit-scm/sourcegit@7bb4e35 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7bb4e35

Browse files
committed
feature: show branches count in branch tree (#1306)
1 parent 57d15dc commit 7bb4e35

File tree

5 files changed

+38
-6
lines changed

5 files changed

+38
-6
lines changed

src/Commands/QueryBranches.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@ public QueryBranches(string repo)
1717
Args = "branch -l --all -v --format=\"%(refname)%00%(committerdate:unix)%00%(objectname)%00%(HEAD)%00%(upstream)%00%(upstream:trackshort)\"";
1818
}
1919

20-
public List<Models.Branch> Result()
20+
public List<Models.Branch> Result(out int localBranchesCount)
2121
{
22+
localBranchesCount = 0;
23+
2224
var branches = new List<Models.Branch>();
2325
var rs = ReadToEnd();
2426
if (!rs.IsSuccess)
@@ -34,6 +36,8 @@ public QueryBranches(string repo)
3436
branches.Add(b);
3537
if (!b.IsLocal)
3638
remoteBranches.Add(b.FullName);
39+
else
40+
localBranchesCount++;
3741
}
3842
}
3943

src/ViewModels/BranchTreeNode.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public class BranchTreeNode : ObservableObject
1414
public int Depth { get; set; } = 0;
1515
public bool IsSelected { get; set; } = false;
1616
public List<BranchTreeNode> Children { get; private set; } = new List<BranchTreeNode>();
17+
public int Counter { get; set; } = 0;
1718

1819
public Models.FilterMode FilterMode
1920
{
@@ -48,6 +49,11 @@ public bool ShowUpstreamGoneTip
4849
get => Backend is Models.Branch { IsUpstreamGone: true };
4950
}
5051

52+
public string BranchesCount
53+
{
54+
get => Counter > 0 ? $"({Counter})" : string.Empty;
55+
}
56+
5157
public string Tooltip
5258
{
5359
get => Backend is Models.Branch b ? b.FriendlyName : null;
@@ -107,7 +113,10 @@ public void Run(List<Models.Branch> branches, List<Models.Remote> remotes, bool
107113

108114
var rk = $"refs/remotes/{branch.Remote}";
109115
if (folders.TryGetValue(rk, out var remote))
116+
{
117+
remote.Counter++;
110118
MakeBranchNode(branch, remote.Children, folders, rk, bForceExpanded);
119+
}
111120
}
112121

113122
foreach (var path in _expanded)
@@ -157,6 +166,7 @@ private void MakeBranchNode(Models.Branch branch, List<BranchTreeNode> roots, Di
157166
if (folders.TryGetValue(folder, out var val))
158167
{
159168
lastFolder = val;
169+
lastFolder.Counter++;
160170
lastFolder.TimeToSort = Math.Max(lastFolder.TimeToSort, time);
161171
if (!lastFolder.IsExpanded)
162172
lastFolder.IsExpanded |= (branch.IsCurrent || _expanded.Contains(folder));
@@ -169,6 +179,7 @@ private void MakeBranchNode(Models.Branch branch, List<BranchTreeNode> roots, Di
169179
Path = folder,
170180
IsExpanded = bForceExpanded || branch.IsCurrent || _expanded.Contains(folder),
171181
TimeToSort = time,
182+
Counter = 1,
172183
};
173184
roots.Add(lastFolder);
174185
folders.Add(folder, lastFolder);
@@ -181,6 +192,7 @@ private void MakeBranchNode(Models.Branch branch, List<BranchTreeNode> roots, Di
181192
Path = folder,
182193
IsExpanded = bForceExpanded || branch.IsCurrent || _expanded.Contains(folder),
183194
TimeToSort = time,
195+
Counter = 1,
184196
};
185197
lastFolder.Children.Add(cur);
186198
folders.Add(folder, cur);

src/ViewModels/Repository.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,12 @@ public int StashesCount
228228
private set => SetProperty(ref _stashesCount, value);
229229
}
230230

231+
public int LocalBranchesCount
232+
{
233+
get => _localBranchesCount;
234+
private set => SetProperty(ref _localBranchesCount, value);
235+
}
236+
231237
public bool IncludeUntracked
232238
{
233239
get => _settings.IncludeUntrackedInLocalChanges;
@@ -1020,7 +1026,7 @@ public void Bisect(string subcmd)
10201026

10211027
public void RefreshBranches()
10221028
{
1023-
var branches = new Commands.QueryBranches(_fullpath).Result();
1029+
var branches = new Commands.QueryBranches(_fullpath).Result(out var localBranchesCount);
10241030
var remotes = new Commands.QueryRemotes(_fullpath).Result();
10251031
var builder = BuildBranchTree(branches, remotes);
10261032

@@ -1033,6 +1039,7 @@ public void RefreshBranches()
10331039
CurrentBranch = branches.Find(x => x.IsCurrent);
10341040
LocalBranchTrees = builder.Locals;
10351041
RemoteBranchTrees = builder.Remotes;
1042+
LocalBranchesCount = localBranchesCount;
10361043

10371044
if (_workingCopy != null)
10381045
_workingCopy.HasRemotes = remotes.Count > 0;
@@ -2726,6 +2733,7 @@ private void AutoFetchImpl(object sender)
27262733
private int _selectedViewIndex = 0;
27272734
private object _selectedView = null;
27282735

2736+
private int _localBranchesCount = 0;
27292737
private int _localChangesCount = 0;
27302738
private int _stashesCount = 0;
27312739

src/Views/BranchTree.axaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,11 @@
6060
<!-- Name -->
6161
<TextBlock Grid.Column="1"
6262
Classes="primary"
63-
Text="{Binding Name}"
6463
FontWeight="{Binding IsCurrent, Converter={x:Static c:BoolConverters.IsBoldToFontWeight}}"
65-
TextTrimming="CharacterEllipsis"/>
64+
TextTrimming="CharacterEllipsis">
65+
<Run Text="{Binding Name}"/>
66+
<Run Text="{Binding BranchesCount}" Foreground="{DynamicResource Brush.FG2}"/>
67+
</TextBlock>
6668

6769
<!-- Upstream invalid tip -->
6870
<Border Grid.Column="2"

src/Views/Repository.axaml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,10 @@
204204
<ToggleButton Grid.Row="0" Classes="group_expander" IsChecked="{Binding IsLocalBranchGroupExpanded, Mode=TwoWay}">
205205
<Grid ColumnDefinitions="16,*,Auto,Auto">
206206
<Path Grid.Column="0" Width="11" Height="11" HorizontalAlignment="Left" Data="{StaticResource Icons.Local}" Fill="{DynamicResource Brush.FG2}"/>
207-
<TextBlock Grid.Column="1" Classes="group_header_label" Margin="0" Text="{DynamicResource Text.Repository.LocalBranches}"/>
207+
<TextBlock Grid.Column="1" Classes="group_header_label" Margin="0">
208+
<Run Text="{DynamicResource Text.Repository.LocalBranches}"/>
209+
<Run Text="{Binding LocalBranchesCount, StringFormat='({0})'}"/>
210+
</TextBlock>
208211
<Button Grid.Column="2"
209212
Classes="icon_button"
210213
Width="14"
@@ -231,7 +234,10 @@
231234
<ToggleButton Grid.Row="2" Classes="group_expander" IsChecked="{Binding IsRemoteGroupExpanded, Mode=TwoWay}">
232235
<Grid ColumnDefinitions="16,*,Auto,Auto">
233236
<Path Grid.Column="0" Width="12" Height="12" HorizontalAlignment="Left" Data="{StaticResource Icons.Remotes}" Fill="{DynamicResource Brush.FG2}"/>
234-
<TextBlock Grid.Column="1" Classes="group_header_label" Margin="0" Text="{DynamicResource Text.Repository.Remotes}"/>
237+
<TextBlock Grid.Column="1" Classes="group_header_label" Margin="0">
238+
<Run Text="{DynamicResource Text.Repository.Remotes}"/>
239+
<Run Text="{Binding Remotes, Converter={x:Static c:ListConverters.ToCount}}"/>
240+
</TextBlock>
235241
<Button Grid.Column="2"
236242
Classes="icon_button"
237243
Width="14"

0 commit comments

Comments
 (0)
0