Skip to content

Commit 70d76de

Browse files
committed
Remove the usage of the ws3 feature flag
1 parent 8c92102 commit 70d76de

File tree

11 files changed

+124
-221
lines changed

11 files changed

+124
-221
lines changed

crates/but-action/src/lib.rs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -222,18 +222,8 @@ fn default_target_setting_if_none(
222222
}
223223

224224
fn stacks(ctx: &CommandContext, repo: &gix::Repository) -> anyhow::Result<Vec<StackEntry>> {
225-
let project = ctx.project();
226-
if ctx.app_settings().feature_flags.ws3 {
227-
let meta = ref_metadata_toml(ctx.project())?;
228-
but_workspace::stacks_v3(repo, &meta, but_workspace::StacksFilter::InWorkspace)
229-
} else {
230-
but_workspace::stacks(
231-
ctx,
232-
&project.gb_dir(),
233-
repo,
234-
but_workspace::StacksFilter::InWorkspace,
235-
)
236-
}
225+
let meta = ref_metadata_toml(ctx.project())?;
226+
but_workspace::stacks_v3(repo, &meta, but_workspace::StacksFilter::InWorkspace)
237227
}
238228

239229
fn ref_metadata_toml(project: &Project) -> anyhow::Result<VirtualBranchesTomlMetadata> {

crates/but-action/src/reword.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,8 @@ pub async fn commit(
7979

8080
fn stacks(ctx: &CommandContext) -> anyhow::Result<Vec<StackEntry>> {
8181
let repo = ctx.gix_repo_for_merging_non_persisting()?;
82-
if ctx.app_settings().feature_flags.ws3 {
83-
let meta = VirtualBranchesTomlMetadata::from_path(
84-
ctx.project().gb_dir().join("virtual_branches.toml"),
85-
)?;
86-
but_workspace::stacks_v3(&repo, &meta, StacksFilter::default())
87-
} else {
88-
but_workspace::stacks(ctx, &ctx.project().gb_dir(), &repo, StacksFilter::default())
89-
}
82+
let meta = VirtualBranchesTomlMetadata::from_path(
83+
ctx.project().gb_dir().join("virtual_branches.toml"),
84+
)?;
85+
but_workspace::stacks_v3(&repo, &meta, StacksFilter::default())
9086
}

crates/but-api/src/commands/stack.rs

Lines changed: 62 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -102,56 +102,51 @@ pub fn create_reference(app: &App, params: create_reference::Params) -> Result<(
102102
pub fn create_branch(app: &App, params: CreateBranchParams) -> Result<(), Error> {
103103
let project = gitbutler_project::get(params.project_id)?;
104104
let ctx = CommandContext::open(&project, app.app_settings.get()?.clone())?;
105-
if app.app_settings.get()?.feature_flags.ws3 {
106-
use ReferencePosition::Above;
107-
let (repo, mut meta, graph) = ctx.graph_and_meta_and_repo()?;
108-
let ws = graph.to_workspace()?;
109-
let stack = ws.try_find_stack_by_id(params.stack_id)?;
110-
let new_ref = Category::LocalBranch
111-
.to_full_name(params.request.name.as_str())
112-
.map_err(anyhow::Error::from)?;
113-
if params.request.preceding_head.is_some() {
114-
return Err(anyhow!(
115-
"BUG: cannot have preceding head name set - let's use the new API instead"
116-
)
117-
.into());
118-
}
105+
use ReferencePosition::Above;
106+
let (repo, mut meta, graph) = ctx.graph_and_meta_and_repo()?;
107+
let ws = graph.to_workspace()?;
108+
let stack = ws.try_find_stack_by_id(params.stack_id)?;
109+
let new_ref = Category::LocalBranch
110+
.to_full_name(params.request.name.as_str())
111+
.map_err(anyhow::Error::from)?;
112+
if params.request.preceding_head.is_some() {
113+
return Err(anyhow!(
114+
"BUG: cannot have preceding head name set - let's use the new API instead"
115+
)
116+
.into());
117+
}
119118

120-
let mut guard = project.exclusive_worktree_access();
121-
ctx.snapshot_create_dependent_branch(&params.request.name, guard.write_permission())
122-
.ok();
123-
_ = but_workspace::branch::create_reference(
124-
new_ref.as_ref(),
125-
{
126-
let segment = stack.segments.first().context("BUG: no empty stacks")?;
127-
segment
128-
.ref_name
129-
.as_ref()
130-
.map(|rn| ReferenceAnchor::AtSegment {
131-
ref_name: Cow::Borrowed(rn.as_ref()),
119+
let mut guard = project.exclusive_worktree_access();
120+
ctx.snapshot_create_dependent_branch(&params.request.name, guard.write_permission())
121+
.ok();
122+
_ = but_workspace::branch::create_reference(
123+
new_ref.as_ref(),
124+
{
125+
let segment = stack.segments.first().context("BUG: no empty stacks")?;
126+
segment
127+
.ref_name
128+
.as_ref()
129+
.map(|rn| ReferenceAnchor::AtSegment {
130+
ref_name: Cow::Borrowed(rn.as_ref()),
131+
position: Above,
132+
})
133+
.or_else(|| {
134+
Some(ReferenceAnchor::AtCommit {
135+
commit_id: graph.tip_skip_empty(segment.id)?.id,
132136
position: Above,
133137
})
134-
.or_else(|| {
135-
Some(ReferenceAnchor::AtCommit {
136-
commit_id: graph.tip_skip_empty(segment.id)?.id,
137-
position: Above,
138-
})
139-
})
140-
.with_context(|| {
141-
format!(
142-
"TODO: UI should migrate to new version of `create_branch()` instead,\
138+
})
139+
.with_context(|| {
140+
format!(
141+
"TODO: UI should migrate to new version of `create_branch()` instead,\
143142
couldn't handle {params:?}"
144-
)
145-
})?
146-
},
147-
&repo,
148-
&ws,
149-
&mut meta,
150-
)?;
151-
} else {
152-
// NOTE: locking is built-in here.
153-
gitbutler_branch_actions::stack::create_branch(&ctx, params.stack_id, params.request)?;
154-
}
143+
)
144+
})?
145+
},
146+
&repo,
147+
&ws,
148+
&mut meta,
149+
)?;
155150
Ok(())
156151
}
157152

@@ -166,31 +161,27 @@ pub struct RemoveBranchParams {
166161
pub fn remove_branch(app: &App, params: RemoveBranchParams) -> Result<(), Error> {
167162
let project = gitbutler_project::get(params.project_id)?;
168163
let ctx = CommandContext::open(&project, app.app_settings.get()?.clone())?;
169-
if app.app_settings.get()?.feature_flags.ws3 {
170-
let (repo, mut meta, graph) = ctx.graph_and_meta_and_repo()?;
171-
let ws = graph.to_workspace()?;
172-
let ref_name = Category::LocalBranch
173-
.to_full_name(params.branch_name.as_str())
174-
.map_err(anyhow::Error::from)?;
175-
let mut guard = project.exclusive_worktree_access();
176-
ctx.snapshot_remove_dependent_branch(&params.branch_name, guard.write_permission())
177-
.ok();
178-
but_workspace::branch::remove_reference(
179-
ref_name.as_ref(),
180-
&repo,
181-
&ws,
182-
&mut meta,
183-
but_workspace::branch::remove_reference::Options {
184-
avoid_anonymous_stacks: true,
185-
// The UI kind of keeps it, but we can't do that somehow
186-
// the object id is null, and stuff breaks. Fine for now.
187-
// Delete is delete.
188-
keep_metadata: false,
189-
},
190-
)?;
191-
} else {
192-
gitbutler_branch_actions::stack::remove_branch(&ctx, params.stack_id, params.branch_name)?;
193-
}
164+
let (repo, mut meta, graph) = ctx.graph_and_meta_and_repo()?;
165+
let ws = graph.to_workspace()?;
166+
let ref_name = Category::LocalBranch
167+
.to_full_name(params.branch_name.as_str())
168+
.map_err(anyhow::Error::from)?;
169+
let mut guard = project.exclusive_worktree_access();
170+
ctx.snapshot_remove_dependent_branch(&params.branch_name, guard.write_permission())
171+
.ok();
172+
but_workspace::branch::remove_reference(
173+
ref_name.as_ref(),
174+
&repo,
175+
&ws,
176+
&mut meta,
177+
but_workspace::branch::remove_reference::Options {
178+
avoid_anonymous_stacks: true,
179+
// The UI kind of keeps it, but we can't do that somehow
180+
// the object id is null, and stuff breaks. Fine for now.
181+
// Delete is delete.
182+
keep_metadata: false,
183+
},
184+
)?;
194185
Ok(())
195186
}
196187

crates/but-api/src/commands/virtual_branches.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,8 @@ pub fn create_virtual_branch(
4040
params: CreateVirtualBranchParams,
4141
) -> Result<StackEntryNoOpt, Error> {
4242
let project = gitbutler_project::get(params.project_id)?;
43-
let ws3_enabled = app.app_settings.get()?.feature_flags.ws3;
4443
let ctx = CommandContext::open(&project, app.app_settings.get()?.clone())?;
45-
let stack_entry = if ws3_enabled {
44+
let stack_entry = {
4645
let (repo, mut meta, graph) = ctx.graph_and_meta_and_repo()?;
4746
let ws = graph.to_workspace()?;
4847
let new_ref = Category::LocalBranch
@@ -73,12 +72,6 @@ pub fn create_virtual_branch(
7372
tip,
7473
order: Some(stack_idx),
7574
}
76-
} else {
77-
gitbutler_branch_actions::create_virtual_branch(
78-
&ctx,
79-
&params.branch,
80-
ctx.project().exclusive_worktree_access().write_permission(),
81-
)?
8275
};
8376
Ok(stack_entry)
8477
}

crates/but-api/src/commands/workspace.rs

Lines changed: 16 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,8 @@ pub fn stacks(app: &App, params: StacksParams) -> Result<Vec<StackEntry>, Error>
3232
let project = gitbutler_project::get(params.project_id)?;
3333
let ctx = CommandContext::open(&project, app.app_settings.get()?.clone())?;
3434
let repo = ctx.gix_repo_for_merging_non_persisting()?;
35-
if ctx.app_settings().feature_flags.ws3 {
36-
let meta = ref_metadata_toml(ctx.project())?;
37-
but_workspace::stacks_v3(&repo, &meta, params.filter.unwrap_or_default())
38-
} else {
39-
but_workspace::stacks(
40-
&ctx,
41-
&project.gb_dir(),
42-
&repo,
43-
params.filter.unwrap_or_default(),
44-
)
45-
}
46-
.map_err(Into::into)
35+
let meta = ref_metadata_toml(ctx.project())?;
36+
but_workspace::stacks_v3(&repo, &meta, params.filter.unwrap_or_default()).map_err(Into::into)
4737
}
4838

4939
#[derive(Deserialize)]
@@ -105,18 +95,9 @@ pub fn stack_details(
10595
) -> Result<but_workspace::ui::StackDetails, Error> {
10696
let project = gitbutler_project::get(params.project_id)?;
10797
let ctx = CommandContext::open(&project, app.app_settings.get()?.clone())?;
108-
if ctx.app_settings().feature_flags.ws3 {
109-
let repo = ctx.gix_repo_for_merging_non_persisting()?;
110-
let meta = ref_metadata_toml(ctx.project())?;
111-
but_workspace::stack_details_v3(params.stack_id, &repo, &meta)
112-
} else {
113-
but_workspace::stack_details(
114-
&project.gb_dir(),
115-
params.stack_id.context("BUG(opt-stack-id)")?,
116-
&ctx,
117-
)
118-
}
119-
.map_err(Into::into)
98+
let repo = ctx.gix_repo_for_merging_non_persisting()?;
99+
let meta = ref_metadata_toml(ctx.project())?;
100+
but_workspace::stack_details_v3(params.stack_id, &repo, &meta).map_err(Into::into)
120101
}
121102

122103
#[derive(Deserialize)]
@@ -133,29 +114,19 @@ pub fn branch_details(
133114
) -> Result<but_workspace::ui::BranchDetails, Error> {
134115
let project = gitbutler_project::get(params.project_id)?;
135116
let ctx = CommandContext::open(&project, app.app_settings.get()?.clone())?;
136-
if ctx.app_settings().feature_flags.ws3 {
137-
let repo = ctx.gix_repo_for_merging_non_persisting()?;
138-
let meta = ref_metadata_toml(ctx.project())?;
139-
let ref_name: gix::refs::FullName = match params.remote.as_deref() {
140-
None => {
141-
format!("refs/heads/{}", params.branch_name)
142-
}
143-
Some(remote) => {
144-
format!("refs/remotes/{remote}/{}", params.branch_name)
145-
}
117+
let repo = ctx.gix_repo_for_merging_non_persisting()?;
118+
let meta = ref_metadata_toml(ctx.project())?;
119+
let ref_name: gix::refs::FullName = match params.remote.as_deref() {
120+
None => {
121+
format!("refs/heads/{}", params.branch_name)
122+
}
123+
Some(remote) => {
124+
format!("refs/remotes/{remote}/{}", params.branch_name)
146125
}
147-
.try_into()
148-
.map_err(anyhow::Error::from)?;
149-
but_workspace::branch_details_v3(&repo, ref_name.as_ref(), &meta)
150-
} else {
151-
but_workspace::branch_details(
152-
&project.gb_dir(),
153-
&params.branch_name,
154-
params.remote.as_deref(),
155-
&ctx,
156-
)
157126
}
158-
.map_err(Into::into)
127+
.try_into()
128+
.map_err(anyhow::Error::from)?;
129+
but_workspace::branch_details_v3(&repo, ref_name.as_ref(), &meta).map_err(Into::into)
159130
}
160131

161132
#[derive(Deserialize)]

crates/but-claude/src/hooks/mod.rs

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -524,25 +524,17 @@ impl OutputAsJson for Result<ClaudeHookOutput> {
524524
}
525525

526526
fn stack_details(ctx: &CommandContext, stack_id: StackId) -> anyhow::Result<StackDetails> {
527-
if ctx.app_settings().feature_flags.ws3 {
528-
let repo = ctx.gix_repo_for_merging_non_persisting()?;
529-
let meta = VirtualBranchesTomlMetadata::from_path(
530-
ctx.project().gb_dir().join("virtual_branches.toml"),
531-
)?;
532-
but_workspace::stack_details_v3(Some(stack_id), &repo, &meta)
533-
} else {
534-
but_workspace::stack_details(&ctx.project().gb_dir(), stack_id, ctx)
535-
}
527+
let repo = ctx.gix_repo_for_merging_non_persisting()?;
528+
let meta = VirtualBranchesTomlMetadata::from_path(
529+
ctx.project().gb_dir().join("virtual_branches.toml"),
530+
)?;
531+
but_workspace::stack_details_v3(Some(stack_id), &repo, &meta)
536532
}
537533

538534
fn list_stacks(ctx: &CommandContext) -> anyhow::Result<Vec<StackEntry>> {
539535
let repo = ctx.gix_repo_for_merging_non_persisting()?;
540-
if ctx.app_settings().feature_flags.ws3 {
541-
let meta = VirtualBranchesTomlMetadata::from_path(
542-
ctx.project().gb_dir().join("virtual_branches.toml"),
543-
)?;
544-
but_workspace::stacks_v3(&repo, &meta, StacksFilter::default())
545-
} else {
546-
but_workspace::stacks(ctx, &ctx.project().gb_dir(), &repo, StacksFilter::default())
547-
}
536+
let meta = VirtualBranchesTomlMetadata::from_path(
537+
ctx.project().gb_dir().join("virtual_branches.toml"),
538+
)?;
539+
but_workspace::stacks_v3(&repo, &meta, StacksFilter::default())
548540
}

crates/but-rules/src/handler.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,11 @@ pub fn process_workspace_rules(
3131
}
3232

3333
let repo = ctx.gix_repo_for_merging_non_persisting()?;
34-
let stacks_in_ws = if ctx.app_settings().feature_flags.ws3 {
34+
let stacks_in_ws = {
3535
let meta = VirtualBranchesTomlMetadata::from_path(
3636
ctx.project().gb_dir().join("virtual_branches.toml"),
3737
)?;
3838
but_workspace::stacks_v3(&repo, &meta, StacksFilter::InWorkspace)
39-
} else {
40-
but_workspace::stacks(ctx, &ctx.project().gb_dir(), &repo, StacksFilter::default())
4139
}?;
4240

4341
for rule in rules {

crates/but-tools/src/workspace.rs

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1991,7 +1991,7 @@ pub struct AbsorbSpec {
19911991
<description>
19921992
The title of the commit to use in the amended commit.
19931993
</description>
1994-
1994+
19951995
<important_notes>
19961996
The title should be concise and descriptive.
19971997
Don't use more than 50 characters.
@@ -2042,16 +2042,6 @@ fn stacks(
20422042
ctx: &CommandContext,
20432043
repo: &gix::Repository,
20442044
) -> anyhow::Result<Vec<but_workspace::ui::StackEntry>> {
2045-
let project = ctx.project();
2046-
if ctx.app_settings().feature_flags.ws3 {
2047-
let meta = ref_metadata_toml(ctx.project())?;
2048-
but_workspace::stacks_v3(repo, &meta, but_workspace::StacksFilter::InWorkspace)
2049-
} else {
2050-
but_workspace::stacks(
2051-
ctx,
2052-
&project.gb_dir(),
2053-
repo,
2054-
but_workspace::StacksFilter::InWorkspace,
2055-
)
2056-
}
2045+
let meta = ref_metadata_toml(ctx.project())?;
2046+
but_workspace::stacks_v3(repo, &meta, but_workspace::StacksFilter::InWorkspace)
20572047
}

0 commit comments

Comments
 (0)