Skip to content

Commit ef2e64c

Browse files
committed
add v3-workspace feature toggle.
That way we can already try out bleeding edge features related to a new implemenation to interpret workspaces.
1 parent 5c492a3 commit ef2e64c

File tree

7 files changed

+64
-10
lines changed

7 files changed

+64
-10
lines changed

apps/desktop/src/lib/config/appSettingsV2.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ export type TelemetrySettings = {
8080
export type FeatureFlags = {
8181
/** Enables the v3 design, as well as the purgatory mode (no uncommitted diff ownership assignments). */
8282
v3: boolean;
83+
/** Enable the usage of the V3 workspace API */
84+
ws3: boolean
8385
};
8486

8587
export type Fetch = {

apps/desktop/src/routes/+layout.svelte

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,10 @@
268268
'v 3': () => {
269269
settingsService.updateFeatureFlags({ v3: !$settingsStore?.featureFlags.v3 });
270270
},
271+
// Toggle v3 workspace APIs on/off
272+
'w s 3': () => {
273+
settingsService.updateFeatureFlags({ ws3: !$settingsStore?.featureFlags.ws3 });
274+
},
271275
// This is a debug tool to learn about environment variables actually present - only available if the backend is in debug mode.
272276
'e n v': async () => {
273277
let env = await invoke('env_vars');

crates/but-cli/src/command/mod.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,11 @@ pub mod stacks {
244244
let project = project_from_path(current_dir)?;
245245
// Enable v3 feature flags for the command context
246246
let app_settings = AppSettings {
247-
feature_flags: but_settings::app_settings::FeatureFlags { v3: true },
247+
feature_flags: but_settings::app_settings::FeatureFlags {
248+
v3: true,
249+
// Keep this off until it caught up at least.
250+
ws3: false,
251+
},
248252
..AppSettings::default()
249253
};
250254

crates/but-settings/assets/defaults.jsonc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
},
1818
"featureFlags": {
1919
// Enables the v3 design, as well as the purgatory mode (no uncommitted diff ownership assignments).
20-
"v3": false
20+
"v3": false,
21+
/// Enable the usage of V3 workspace APIs.
22+
"ws3": false
2123
},
2224
// Allows for additional "connect-src" hosts to be included. Requires app restart.
2325
"extraCsp": {

crates/but-settings/src/api.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ pub struct TelemetryUpdate {
1616
/// Update request for [`crate::app_settings::FeatureFlags`].
1717
pub struct FeatureFlagsUpdate {
1818
pub v3: Option<bool>,
19+
pub ws3: Option<bool>,
1920
}
2021

2122
/// Mutation, immediately followed by writing everything to disk.
@@ -40,11 +41,17 @@ impl AppSettingsWithDiskSync {
4041
settings.save()
4142
}
4243

43-
pub fn update_feature_flags(&self, update: FeatureFlagsUpdate) -> Result<()> {
44+
pub fn update_feature_flags(
45+
&self,
46+
FeatureFlagsUpdate { v3, ws3 }: FeatureFlagsUpdate,
47+
) -> Result<()> {
4448
let mut settings = self.get_mut_enforce_save()?;
45-
if let Some(v3) = update.v3 {
49+
if let Some(v3) = v3 {
4650
settings.feature_flags.v3 = v3;
4751
}
52+
if let Some(ws3) = ws3 {
53+
settings.feature_flags.ws3 = ws3;
54+
}
4855
settings.save()
4956
}
5057
}

crates/but-settings/src/app_settings.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ pub struct GitHubOAuthAppSettings {
2323
pub struct FeatureFlags {
2424
/// Enables the v3 design, as well as the purgatory mode (no uncommitted diff ownership assignments).
2525
pub v3: bool,
26+
/// Enable the usage of V3 workspace APIs.
27+
pub ws3: bool,
2628
}
2729

2830
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]

crates/gitbutler-tauri/src/workspace.rs

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ use but_hunk_dependency::ui::{
99
use but_settings::AppSettingsWithDiskSync;
1010
use but_workspace::commit_engine::StackSegmentId;
1111
use but_workspace::MoveChangesResult;
12-
use but_workspace::{commit_engine, ui::StackEntry};
12+
use but_workspace::{commit_engine, ui::StackEntry, VirtualBranchesTomlMetadata};
1313
use gitbutler_branch_actions::{update_workspace_commit, BranchManagerExt};
1414
use gitbutler_command_context::CommandContext;
1515
use gitbutler_oplog::entry::{OperationKind, SnapshotDetails};
1616
use gitbutler_oplog::{OplogExt, SnapshotExt};
1717
use gitbutler_project as projects;
18-
use gitbutler_project::ProjectId;
18+
use gitbutler_project::{Project, ProjectId};
1919
use gitbutler_stack::{StackId, VirtualBranchesHandle};
2020
use serde::Serialize;
2121
use tauri::State;
@@ -32,8 +32,13 @@ pub fn stacks(
3232
let project = projects.get(project_id)?;
3333
let ctx = CommandContext::open(&project, settings.get()?.clone())?;
3434
let repo = ctx.gix_repo()?;
35-
but_workspace::stacks(&ctx, &project.gb_dir(), &repo, filter.unwrap_or_default())
36-
.map_err(Into::into)
35+
if ctx.app_settings().feature_flags.ws3 {
36+
let meta = ref_metadata_toml(ctx.project())?;
37+
but_workspace::stacks_v3(&repo, &meta, filter.unwrap_or_default())
38+
} else {
39+
but_workspace::stacks(&ctx, &project.gb_dir(), &repo, filter.unwrap_or_default())
40+
}
41+
.map_err(Into::into)
3742
}
3843

3944
#[tauri::command(async)]
@@ -46,7 +51,14 @@ pub fn stack_details(
4651
) -> Result<but_workspace::ui::StackDetails, Error> {
4752
let project = projects.get(project_id)?;
4853
let ctx = CommandContext::open(&project, settings.get()?.clone())?;
49-
but_workspace::stack_details(&project.gb_dir(), stack_id, &ctx).map_err(Into::into)
54+
if ctx.app_settings().feature_flags.ws3 {
55+
let repo = ctx.gix_repo()?;
56+
let meta = ref_metadata_toml(ctx.project())?;
57+
but_workspace::stack_details_v3(stack_id, &repo, &meta)
58+
} else {
59+
but_workspace::stack_details(&project.gb_dir(), stack_id, &ctx)
60+
}
61+
.map_err(Into::into)
5062
}
5163

5264
#[tauri::command(async)]
@@ -60,7 +72,28 @@ pub fn branch_details(
6072
) -> Result<but_workspace::ui::BranchDetails, Error> {
6173
let project = projects.get(project_id)?;
6274
let ctx = CommandContext::open(&project, settings.get()?.clone())?;
63-
but_workspace::branch_details(&project.gb_dir(), branch_name, remote, &ctx).map_err(Into::into)
75+
if ctx.app_settings().feature_flags.ws3 {
76+
let repo = ctx.gix_repo()?;
77+
let meta = ref_metadata_toml(ctx.project())?;
78+
let ref_name: gix::refs::FullName = match remote {
79+
None => {
80+
format!("refs/heads/{branch_name}")
81+
}
82+
Some(remote) => {
83+
format!("refs/remotes/{remote}/{branch_name}")
84+
}
85+
}
86+
.try_into()
87+
.map_err(anyhow::Error::from)?;
88+
but_workspace::branch_details_v3(&repo, ref_name.as_ref(), &meta)
89+
} else {
90+
but_workspace::branch_details(&project.gb_dir(), branch_name, remote, &ctx)
91+
}
92+
.map_err(Into::into)
93+
}
94+
95+
fn ref_metadata_toml(project: &Project) -> anyhow::Result<VirtualBranchesTomlMetadata> {
96+
VirtualBranchesTomlMetadata::from_path(project.gb_dir().join("virtual_branches.toml"))
6497
}
6598

6699
/// Retrieve all changes in the workspace and associate them with commits in the Workspace of `project_id`.

0 commit comments

Comments
 (0)