Skip to content

Commit 0545b77

Browse files
committed
Use new versions of ref_info and head_info everywhere so UI can be using it.
1 parent 3a3bebf commit 0545b77

File tree

10 files changed

+329
-107
lines changed

10 files changed

+329
-107
lines changed

crates/but-graph/src/init/post.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,13 @@ impl Graph {
2727
.and_then(|s| s.commit_index_of(tip));
2828
}
2929

30-
// TODO: swap these expressions and tests validation will fail.
30+
self.workspace_upgrades(meta)?;
31+
self.fill_flags_at_border_segments()?;
3132
self.non_workspace_adjustments(
3233
repo,
3334
symbolic_remote_names,
3435
configured_remote_tracking_branches,
3536
)?;
36-
self.workspace_upgrades(meta)?;
37-
self.fill_flags_at_border_segments()?;
3837

3938
Ok(self)
4039
}

crates/but-graph/tests/fixtures/scenarios.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,5 +568,21 @@ EOF
568568
git checkout gitbutler/workspace
569569
setup_remote_tracking soon-remote-main main "move"
570570
)
571+
572+
git init three-branches-one-advanced-ws-commit-advanced-fully-pushed-empty-dependant
573+
(cd three-branches-one-advanced-ws-commit-advanced-fully-pushed-empty-dependant
574+
git commit -m "init" --allow-empty
575+
setup_target_to_match_main
576+
git checkout -b lane main
577+
578+
git checkout -b advanced-lane
579+
git commit -m "change" --allow-empty
580+
# This works without an official remote setup as we go by name as fallback.
581+
remote_tracking_caught_up advanced-lane
582+
git branch dependant
583+
git branch on-top-of-dependant
584+
585+
create_workspace_commit_once advanced-lane
586+
)
571587
)
572588

crates/but-graph/tests/graph/init/with_workspace.rs

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1357,6 +1357,72 @@ fn workspace_obeys_limit_when_target_branch_is_missing() -> anyhow::Result<()> {
13571357
Ok(())
13581358
}
13591359

1360+
#[test]
1361+
fn three_branches_one_advanced_ws_commit_advanced_fully_pushed_empty_dependant()
1362+
-> anyhow::Result<()> {
1363+
let (repo, mut meta) = read_only_in_memory_scenario(
1364+
"ws/three-branches-one-advanced-ws-commit-advanced-fully-pushed-empty-dependant",
1365+
)?;
1366+
insta::assert_snapshot!(visualize_commit_graph_all(&repo)?, @r"
1367+
* f8f33a7 (HEAD -> gitbutler/workspace) GitButler Workspace Commit
1368+
* cbc6713 (origin/advanced-lane, on-top-of-dependant, dependant, advanced-lane) change
1369+
* fafd9d0 (origin/main, main, lane) init
1370+
");
1371+
1372+
add_workspace(&mut meta);
1373+
let graph = Graph::from_head(&repo, &*meta, standard_options())?.validated()?;
1374+
insta::assert_snapshot!(graph_tree(&graph), @r"
1375+
├── 👉📕►►►:0:gitbutler/workspace
1376+
│ └── ·f8f33a7 (⌂|🏘️|1)
1377+
│ └── ►:3:advanced-lane <> origin/advanced-lane
1378+
│ └── ·cbc6713 (⌂|🏘️|11) ►dependant, ►on-top-of-dependant
1379+
│ └── ►:1:origin/main
1380+
│ └── ·fafd9d0 (⌂|🏘️|✓|11) ►lane, ►main
1381+
└── ►:2:origin/advanced-lane
1382+
└── →:3: (advanced-lane)
1383+
");
1384+
1385+
// By default, the advanced lane is simply frozen as its remote contains the commit.
1386+
insta::assert_snapshot!(graph_workspace(&graph.to_workspace()?), @r"
1387+
📕🏘️:0:gitbutler/workspace <> ✓refs/remotes/origin/main
1388+
└── ≡:3:advanced-lane <> origin/advanced-lane
1389+
└── :3:advanced-lane <> origin/advanced-lane
1390+
└── ❄️cbc6713 (🏘️) ►dependant, ►on-top-of-dependant
1391+
");
1392+
1393+
add_stack_with_segments(
1394+
&mut meta,
1395+
StackId::from_number_for_testing(1),
1396+
"dependant",
1397+
StackState::InWorkspace,
1398+
&["advanced-lane"],
1399+
);
1400+
1401+
// Lanes are properly ordered
1402+
let graph = Graph::from_head(&repo, &*meta, standard_options())?.validated()?;
1403+
insta::assert_snapshot!(graph_tree(&graph), @r"
1404+
├── 👉📕►►►:0:gitbutler/workspace
1405+
│ └── ·f8f33a7 (⌂|🏘️|1)
1406+
│ └── 📙►:4:dependant
1407+
│ └── 📙►:5:advanced-lane <> origin/advanced-lane
1408+
│ └── ·cbc6713 (⌂|🏘️|11) ►on-top-of-dependant
1409+
│ └── ►:1:origin/main
1410+
│ └── ·fafd9d0 (⌂|🏘️|✓|11) ►lane, ►main
1411+
└── ►:2:origin/advanced-lane
1412+
└── →:4: (dependant)
1413+
");
1414+
1415+
// When putting the dependent branch on top as empty segment, the frozen state is retained.
1416+
insta::assert_snapshot!(graph_workspace(&graph.to_workspace()?), @r"
1417+
📕🏘️:0:gitbutler/workspace <> ✓refs/remotes/origin/main
1418+
└── ≡📙:4:dependant
1419+
├── 📙:4:dependant
1420+
└── 📙:5:advanced-lane <> origin/advanced-lane
1421+
└── ❄️cbc6713 (🏘️) ►on-top-of-dependant
1422+
");
1423+
Ok(())
1424+
}
1425+
13601426
#[test]
13611427
fn on_top_of_target_with_history() -> anyhow::Result<()> {
13621428
let (repo, mut meta) = read_only_in_memory_scenario("ws/on-top-of-target-with-history")?;

crates/but-workspace/src/branch_details.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ pub fn branch_details(
120120
///
121121
/// - `push_status` - `Integrated` variant is not computed for now (but it's conceivably doable later).
122122
/// - `is_conflicted` - only local commits contribute.
123+
// TODO: make use of `but-graph` here: traverse with `name` as entrypoint, maybe even try to cache the
124+
// graph and find its segment in there.
123125
pub fn branch_details_v3(
124126
repo: &gix::Repository,
125127
name: &gix::refs::FullNameRef,

crates/but-workspace/src/lib.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,10 @@ pub struct RefInfo {
178178
/// It's never present in single-branch mode.
179179
pub target_ref: Option<gix::refs::FullName>,
180180
/// The `workspace_ref_name` is `Some(_)` and belongs to GitButler, because it had metadata attached.
181-
pub is_managed: bool,
181+
pub is_managed_ref: bool,
182+
/// The `workspace_ref_name` points to a commit that was specifically created by us.
183+
/// If the user advanced the workspace head by hand, this would be `false`.
184+
pub is_managed_commit: bool,
182185
/// The workspace represents what `HEAD` is pointing to.
183186
pub is_entrypoint: bool,
184187
}

crates/but-workspace/src/ref_info.rs

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,8 @@ pub(crate) mod function {
365365
stash_status: None,
366366
}],
367367
is_entrypoint: true,
368-
is_managed,
368+
is_managed_ref: is_managed,
369+
is_managed_commit: false,
369370
});
370371
}
371372
gix::head::Kind::Detached { .. } => {
@@ -374,7 +375,8 @@ pub(crate) mod function {
374375
stacks: vec![],
375376
target_ref: None,
376377
is_entrypoint: true,
377-
is_managed: false,
378+
is_managed_ref: false,
379+
is_managed_commit: false,
378380
});
379381
}
380382
gix::head::Kind::Symbolic(name) => name.attach(repo),
@@ -438,13 +440,28 @@ pub(crate) mod function {
438440
let cache = repo.commit_graph_if_enabled()?;
439441
let mut graph_cache = repo.revision_graph(cache.as_ref());
440442

443+
let (workspace_ref_name, is_managed_commit) = match head {
444+
HeadLocation::Workspace { ref_name } => {
445+
let is_managed = try_refname_to_id(repo, ref_name.as_ref())?
446+
.map(|id| WorkspaceCommit::from_id(id.attach(repo)))
447+
.transpose()?
448+
.map_or(false, |wsc| wsc.is_managed());
449+
(Some(ref_name), is_managed)
450+
}
451+
HeadLocation::Segment { segment_index } => {
452+
(graph[segment_index].ref_name.clone(), false)
453+
}
454+
};
441455
Ok(RefInfo {
442-
workspace_ref_name: match head {
443-
HeadLocation::Workspace { ref_name } => Some(ref_name),
444-
HeadLocation::Segment { segment_index } => graph[segment_index].ref_name.clone(),
445-
},
456+
workspace_ref_name,
446457
stacks: stacks
447458
.into_iter()
459+
// `but-graph` produces the order as seen by the merge commit,
460+
// but GB traditionally shows it the other way around.
461+
// TODO: validate that this is still correct to do here if the workspace
462+
// was generated from 'virtual' stacks only, i.e. stacks not from real
463+
// merges.
464+
.rev()
448465
.map(|stack| {
449466
branch::Stack::try_from_graph_stack(
450467
stack,
@@ -458,7 +475,8 @@ pub(crate) mod function {
458475
})
459476
.collect::<anyhow::Result<_>>()?,
460477
target_ref: target.map(|t| t.ref_name),
461-
is_managed: metadata.is_some(),
478+
is_managed_ref: metadata.is_some(),
479+
is_managed_commit,
462480
is_entrypoint: graph.lookup_entrypoint()?.segment_index == id,
463481
})
464482
}
@@ -928,7 +946,8 @@ pub(crate) mod function {
928946
stacks,
929947
target_ref,
930948
is_entrypoint: false,
931-
is_managed,
949+
is_managed_commit: false,
950+
is_managed_ref: is_managed,
932951
})
933952
}
934953

crates/but-workspace/src/stacks.rs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ use crate::ref_info::ui::{Commit, Segment};
33
use crate::ref_info::ui::{LocalCommit, LocalCommitRelation};
44
use crate::ui::{CommitState, PushStatus, StackDetails};
55
use crate::{
6-
RefInfo, StacksFilter, branch, head_info, id_from_name_v2_to_v3, ref_info, state_handle, ui,
6+
RefInfo, StacksFilter, branch, head_info2, id_from_name_v2_to_v3, ref_info, ref_info2,
7+
state_handle, ui,
78
};
89
use anyhow::Context;
910
use bstr::BString;
@@ -173,14 +174,19 @@ pub fn stacks_v3(
173174
Ok(out)
174175
}
175176

176-
let info = head_info(
177+
let info = head_info2(
177178
repo,
178179
meta,
179180
ref_info::Options {
180181
// TODO: set this to a good value for the UI to not slow down, and also a value that forces us to re-investigate this.
181182
stack_commit_limit: 100,
182183
expensive_commit_info: false,
183-
..Default::default()
184+
traversal: but_graph::init::Options {
185+
collect_tags: false,
186+
commits_limit_hint: Some(300),
187+
commits_limit_recharge_location: vec![],
188+
hard_limit: None,
189+
},
184190
},
185191
)?;
186192

@@ -390,7 +396,12 @@ pub fn stack_details_v3(
390396
let ref_info_options = ref_info::Options {
391397
stack_commit_limit: 0,
392398
expensive_commit_info: true,
393-
..Default::default()
399+
traversal: but_graph::init::Options {
400+
collect_tags: false,
401+
commits_limit_hint: Some(300),
402+
commits_limit_recharge_location: vec![],
403+
hard_limit: None,
404+
},
394405
};
395406
let stack = meta.data().branches.get(&stack_id).with_context(|| {
396407
format!("Couldn't find {stack_id} even when looking at virtual_branches.toml directly")
@@ -400,7 +411,7 @@ pub fn stack_details_v3(
400411
shortname = stack.derived_name()?
401412
))?;
402413
let existing_ref = repo.find_reference(&full_name)?;
403-
let stack = stack_by_id(ref_info(existing_ref, meta, ref_info_options)?, stack_id, meta)?
414+
let stack = stack_by_id(ref_info2(existing_ref, meta, ref_info_options)?, stack_id, meta)?
404415
.with_context(|| format!("Really couldn't find {stack_id} in current HEAD or when searching virtual_branches.toml plainly"))?;
405416

406417
let branch_details = stack

crates/but-workspace/tests/workspace/ref_info/mod.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ fn unborn_untracked() -> anyhow::Result<()> {
3434
},
3535
],
3636
target_ref: None,
37-
is_managed: false,
37+
is_managed_ref: false,
38+
is_managed_commit: false,
3839
is_entrypoint: true,
3940
}
4041
"#);
@@ -69,7 +70,8 @@ fn detached() -> anyhow::Result<()> {
6970
},
7071
],
7172
target_ref: None,
72-
is_managed: false,
73+
is_managed_ref: false,
74+
is_managed_commit: false,
7375
is_entrypoint: true,
7476
}
7577
"#);
@@ -108,7 +110,8 @@ fn conflicted_in_local_branch() -> anyhow::Result<()> {
108110
},
109111
],
110112
target_ref: None,
111-
is_managed: false,
113+
is_managed_ref: false,
114+
is_managed_commit: false,
112115
is_entrypoint: true,
113116
}
114117
"#);
@@ -160,7 +163,8 @@ fn single_branch() -> anyhow::Result<()> {
160163
},
161164
],
162165
target_ref: None,
163-
is_managed: false,
166+
is_managed_ref: false,
167+
is_managed_commit: false,
164168
is_entrypoint: true,
165169
}
166170
"#);
@@ -243,7 +247,8 @@ fn single_branch_multiple_segments() -> anyhow::Result<()> {
243247
},
244248
],
245249
target_ref: None,
246-
is_managed: false,
250+
is_managed_ref: false,
251+
is_managed_commit: false,
247252
is_entrypoint: true,
248253
}
249254
"#);

0 commit comments

Comments
 (0)