Skip to content

Commit 3af256c

Browse files
cruesslerextrawurst
authored andcommitted
Show remote branches in revlog
1 parent b15d24c commit 3af256c

File tree

3 files changed

+96
-30
lines changed

3 files changed

+96
-30
lines changed

asyncgit/src/sync/branch/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ pub(crate) fn get_branch_name_repo(
4848
}
4949

5050
///
51-
#[derive(Debug)]
51+
#[derive(Clone, Debug)]
5252
pub struct LocalBranch {
5353
///
5454
pub is_head: bool,
@@ -59,14 +59,14 @@ pub struct LocalBranch {
5959
}
6060

6161
///
62-
#[derive(Debug)]
62+
#[derive(Clone, Debug)]
6363
pub struct RemoteBranch {
6464
///
6565
pub has_tracking: bool,
6666
}
6767

6868
///
69-
#[derive(Debug)]
69+
#[derive(Clone, Debug)]
7070
pub enum BranchDetails {
7171
///
7272
Local(LocalBranch),
@@ -75,7 +75,7 @@ pub enum BranchDetails {
7575
}
7676

7777
///
78-
#[derive(Debug)]
78+
#[derive(Clone, Debug)]
7979
pub struct BranchInfo {
8080
///
8181
pub name: String,

src/components/commitlist.rs

Lines changed: 62 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ pub struct CommitList {
4242
marked: Vec<(usize, CommitId)>,
4343
scroll_state: (Instant, f32),
4444
tags: Option<Tags>,
45-
branches: BTreeMap<CommitId, Vec<String>>,
45+
local_branches: BTreeMap<CommitId, Vec<BranchInfo>>,
46+
remote_branches: BTreeMap<CommitId, Vec<BranchInfo>>,
4647
current_size: Cell<Option<(u16, u16)>>,
4748
scroll_top: Cell<usize>,
4849
theme: SharedTheme,
@@ -67,7 +68,8 @@ impl CommitList {
6768
count_total: 0,
6869
scroll_state: (Instant::now(), 0_f32),
6970
tags: None,
70-
branches: BTreeMap::default(),
71+
local_branches: BTreeMap::default(),
72+
remote_branches: BTreeMap::default(),
7173
current_size: Cell::new(None),
7274
scroll_top: Cell::new(0),
7375
theme,
@@ -297,7 +299,8 @@ impl CommitList {
297299
e: &'a LogEntry,
298300
selected: bool,
299301
tags: Option<String>,
300-
branches: Option<String>,
302+
local_branches: Option<String>,
303+
remote_branches: Option<String>,
301304
theme: &Theme,
302305
width: usize,
303306
now: DateTime<Local>,
@@ -358,10 +361,18 @@ impl CommitList {
358361
txt.push(Span::styled(tags, theme.tags(selected)));
359362
}
360363

361-
if let Some(branches) = branches {
364+
if let Some(local_branches) = local_branches {
362365
txt.push(splitter.clone());
363366
txt.push(Span::styled(
364-
branches,
367+
local_branches,
368+
theme.branch(selected, true),
369+
));
370+
}
371+
372+
if let Some(remote_branches) = remote_branches {
373+
txt.push(splitter.clone());
374+
txt.push(Span::styled(
375+
remote_branches,
365376
theme.branch(selected, true),
366377
));
367378
}
@@ -406,12 +417,27 @@ impl CommitList {
406417
},
407418
);
408419

409-
let branches = self.branches.get(&e.id).map(|names| {
410-
names
411-
.iter()
412-
.map(|name| format!("{{{name}}}"))
413-
.join(" ")
414-
});
420+
let local_branches =
421+
self.local_branches.get(&e.id).map(|local_branch| {
422+
local_branch
423+
.iter()
424+
.map(|local_branch| {
425+
format!("{{{0}}}", local_branch.name)
426+
})
427+
.join(" ")
428+
});
429+
430+
let remote_branches = self
431+
.remote_branches
432+
.get(&e.id)
433+
.map(|remote_branches| {
434+
remote_branches
435+
.iter()
436+
.map(|remote_branch| {
437+
format!("[{0}]", remote_branch.name)
438+
})
439+
.join(" ")
440+
});
415441

416442
let marked = if any_marked {
417443
self.is_marked(&e.id)
@@ -423,7 +449,8 @@ impl CommitList {
423449
e,
424450
idx + self.scroll_top.get() == selection,
425451
tags,
426-
branches,
452+
local_branches,
453+
remote_branches,
427454
&self.theme,
428455
width,
429456
now,
@@ -455,14 +482,31 @@ impl CommitList {
455482
}
456483
}
457484

458-
pub fn set_branches(&mut self, branches: Vec<BranchInfo>) {
459-
self.branches.clear();
485+
pub fn set_local_branches(
486+
&mut self,
487+
local_branches: Vec<BranchInfo>,
488+
) {
489+
self.local_branches.clear();
490+
491+
for local_branch in local_branches {
492+
self.local_branches
493+
.entry(local_branch.top_commit)
494+
.or_default()
495+
.push(local_branch);
496+
}
497+
}
498+
499+
pub fn set_remote_branches(
500+
&mut self,
501+
remote_branches: Vec<BranchInfo>,
502+
) {
503+
self.remote_branches.clear();
460504

461-
for b in branches {
462-
self.branches
463-
.entry(b.top_commit)
505+
for remote_branch in remote_branches {
506+
self.remote_branches
507+
.entry(remote_branch.top_commit)
464508
.or_default()
465-
.push(b.name);
509+
.push(remote_branch);
466510
}
467511
}
468512
}

src/tabs/revlog.rs

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ pub struct Revlog {
3636
list: CommitList,
3737
git_log: AsyncLog,
3838
git_tags: AsyncTags,
39-
git_branches: AsyncSingleJob<AsyncBranchesJob>,
39+
git_local_branches: AsyncSingleJob<AsyncBranchesJob>,
40+
git_remote_branches: AsyncSingleJob<AsyncBranchesJob>,
4041
queue: Queue,
4142
visible: bool,
4243
key_config: SharedKeyConfig,
@@ -74,7 +75,8 @@ impl Revlog {
7475
None,
7576
),
7677
git_tags: AsyncTags::new(repo.borrow().clone(), sender),
77-
git_branches: AsyncSingleJob::new(sender.clone()),
78+
git_local_branches: AsyncSingleJob::new(sender.clone()),
79+
git_remote_branches: AsyncSingleJob::new(sender.clone()),
7880
visible: false,
7981
key_config,
8082
}
@@ -84,7 +86,8 @@ impl Revlog {
8486
pub fn any_work_pending(&self) -> bool {
8587
self.git_log.is_pending()
8688
|| self.git_tags.is_pending()
87-
|| self.git_branches.is_pending()
89+
|| self.git_local_branches.is_pending()
90+
|| self.git_remote_branches.is_pending()
8891
|| self.commit_details.any_work_pending()
8992
}
9093

@@ -136,12 +139,26 @@ impl Revlog {
136139
}
137140
}
138141
AsyncGitNotification::Branches => {
139-
if let Some(branches) =
140-
self.git_branches.take_last()
142+
if let Some(local_branches) =
143+
self.git_local_branches.take_last()
141144
{
142-
if let Some(Ok(branches)) = branches.result()
145+
if let Some(Ok(local_branches)) =
146+
local_branches.result()
143147
{
144-
self.list.set_branches(branches);
148+
self.list
149+
.set_local_branches(local_branches);
150+
self.update()?;
151+
}
152+
}
153+
154+
if let Some(remote_branches) =
155+
self.git_remote_branches.take_last()
156+
{
157+
if let Some(Ok(remote_branches)) =
158+
remote_branches.result()
159+
{
160+
self.list
161+
.set_remote_branches(remote_branches);
145162
self.update()?;
146163
}
147164
}
@@ -505,11 +522,16 @@ impl Component for Revlog {
505522
self.visible = true;
506523
self.list.clear();
507524

508-
self.git_branches.spawn(AsyncBranchesJob::new(
525+
self.git_local_branches.spawn(AsyncBranchesJob::new(
509526
self.repo.borrow().clone(),
510527
true,
511528
));
512529

530+
self.git_remote_branches.spawn(AsyncBranchesJob::new(
531+
self.repo.borrow().clone(),
532+
false,
533+
));
534+
513535
self.update()?;
514536

515537
Ok(())

0 commit comments

Comments
 (0)