Skip to content

Commit

Permalink
Add UI for feature flag
Browse files Browse the repository at this point in the history
  • Loading branch information
Caleb-T-Owens committed Jan 8, 2025
1 parent c663b50 commit b25047e
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 1 deletion.
1 change: 1 addition & 0 deletions apps/desktop/src/lib/backend/projects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export class Project {
use_diff_context: boolean | undefined;
snapshot_lines_threshold!: number | undefined;
use_new_branch_integration_algorithm: boolean | undefined;
use_new_integration_check!: boolean;
// Produced just for the frontend to determine if the project is open in any window.
is_open!: boolean;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script lang="ts">
import { Project, ProjectsService } from '$lib/backend/projects';
import { Project, ProjectService, ProjectsService } from '$lib/backend/projects';
import { projectRunCommitHooks } from '$lib/config/config';
import Section from '$lib/settings/Section.svelte';
import { getContext } from '@gitbutler/shared/context';
Expand All @@ -8,14 +8,23 @@
import Toggle from '@gitbutler/ui/Toggle.svelte';
const projectsService = getContext(ProjectsService);
const projectService = getContext(ProjectService);
const project = getContext(Project);
const projectStore = projectService.project;
let snaphotLinesThreshold = project?.snapshot_lines_threshold || 20; // when undefined, the default is 20
let omitCertificateCheck = project?.omit_certificate_check;
let useNewBranchIntegrationAlgorithm = project?.use_new_branch_integration_algorithm;
const runCommitHooks = projectRunCommitHooks(project.id);
function toggleUseNewIntegrationCheck() {
const updatedProject = structuredClone($projectStore);
if (!updatedProject) return;
updatedProject.use_new_integration_check = !updatedProject.use_new_integration_check;
projectsService.updateProject(updatedProject);
}
async function setOmitCertificateCheck(value: boolean | undefined) {
project.omit_certificate_check = !!value;
await projectsService.updateProject(project);
Expand Down Expand Up @@ -112,4 +121,18 @@
/>
{/snippet}
</SectionCard>

<SectionCard labelFor="newIntegrationAlgorithm" orientation="row">
{#snippet title()}New Integration Algorithm{/snippet}
{#snippet caption()}
A new algorithm for finding integrated commits
{/snippet}
{#snippet actions()}
<Toggle
id="newIntegrationAlgorithm"
checked={$projectStore?.use_new_integration_check}
onclick={toggleUseNewIntegrationCheck}
/>
{/snippet}
</SectionCard>
</Section>
12 changes: 12 additions & 0 deletions crates/gitbutler-branch-actions/src/integration_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use gitbutler_commit::commit_ext::CommitExt as _;
use gitbutler_oxidize::{git2_to_gix_object_id, GixRepositoryExt as _, ObjectIdExt as _, OidExt};
use gitbutler_repo::{signature, GixRepositoryExt};
use itertools::Itertools as _;
use tracing::instrument;

use crate::commit_ops::{get_exclusive_tree, get_first_parent, is_subset, SubsetKind};

Expand Down Expand Up @@ -103,6 +104,12 @@ fn find_related_commits(
let mut relations: Vec<CommitRelation> = vec![];

for left in lefts {
// Ignore conflicted commits
let left_commit = repository.find_commit(*left)?;
if left_commit.is_conflicted() {
continue;
}

// First identify the list of commits on the RHS which are supersets
// or equal to the current `left` commit.
let mut found_supersets: Vec<CommitRelation> = vec![];
Expand Down Expand Up @@ -313,6 +320,10 @@ impl<'repo, 'cache, 'graph> IsCommitIntegrated<'repo, 'cache, 'graph> {
impl IsCommitIntegrated<'_, '_, '_> {
#[deprecated]
fn is_integrated(&mut self, commit: &git2::Commit<'_>) -> Result<bool> {
if commit.is_conflicted() {
return Ok(false);
}

if self.target_commit_id == git2_to_gix_object_id(commit.id()) {
// could not be integrated if heads are the same.
return Ok(false);
Expand Down Expand Up @@ -377,6 +388,7 @@ impl IsCommitIntegrated<'_, '_, '_> {

/// Used to switch between the old and new algorithms. We will be able to
/// get rid of all of this when we are confident in the new algorithm.
#[instrument(skip(gix_repository, repository, graph))]
pub(crate) fn compat_find_integrated_commits<'repo>(
gix_repository: &'repo gix::Repository,
repository: &'repo git2::Repository,
Expand Down
5 changes: 5 additions & 0 deletions crates/gitbutler-project/src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ pub struct UpdateRequest {
pub use_diff_context: Option<bool>,
pub snapshot_lines_threshold: Option<usize>,
pub use_new_branch_integration_algorithm: Option<bool>,
pub use_new_integration_check: Option<bool>,
}

impl Storage {
Expand Down Expand Up @@ -130,6 +131,10 @@ impl Storage {
project.use_new_branch_integration_algorithm = Some(new_branch_integration_algorithm);
}

if let Some(use_new_integration_check) = update_request.use_new_integration_check {
project.use_new_integration_check = use_new_integration_check;
}

self.inner
.write(PROJECTS_FILE, &serde_json::to_string_pretty(&projects)?)?;

Expand Down

0 comments on commit b25047e

Please sign in to comment.