Skip to content

Commit

Permalink
Propagate the dependency information to the commits
Browse files Browse the repository at this point in the history
Propagate information about commit and uncommited change inter-dependencies to the commits for the FE to access
  • Loading branch information
estib-vega committed Nov 4, 2024
1 parent 80a33ed commit ebf11d0
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
14 changes: 14 additions & 0 deletions apps/desktop/src/lib/vbranches/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,20 @@ export class DetailedCommit {
)
conflictedFiles!: ConflictEntries;

// Dependency tracking
/**
* The commit ids of the dependencies of this commit.
*/
commitDependencies!: string[];
/**
* The ids of the commits that depend on this commit.
*/
inverseCommitDependencies!: string[];
/**
* The hunk hashes of uncommitted changes that depend on this commit.
*/
commitDependentDiffs!: string[];

get status(): CommitStatus {
if (this.isIntegrated) return 'integrated';
if (this.remoteCommitId) {
Expand Down
36 changes: 36 additions & 0 deletions crates/gitbutler-branch-actions/src/commit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,16 @@ pub struct VirtualBranchCommit {
#[serde(with = "gitbutler_serde::oid_opt")]
pub remote_commit_id: Option<git2::Oid>,
pub conflicted_files: ConflictEntries,
// Dependency tracking
// ---
/// Commits depended on.
#[serde(default, with = "gitbutler_serde::oid_vec")]
pub commit_dependencies: Vec<git2::Oid>,
/// Commits that depend on this commit.
#[serde(default, with = "gitbutler_serde::oid_vec")]
pub inverse_commit_dependencies: Vec<git2::Oid>,
/// Hunk hashes of uncommitted files that depend on this commit.
pub commit_dependent_diffs: Vec<BStringForFrontend>,
}

pub(crate) fn commit_to_vbranch_commit(
Expand Down Expand Up @@ -89,6 +99,29 @@ pub(crate) fn commit_to_vbranch_commit(
Default::default()
};

let commit_dependencies = branch
.commit_dependencies
.get(&commit.id())
.map(|v| v.iter().cloned().collect())
.unwrap_or_default();

let inverse_commit_dependencies = branch
.inverse_commit_dependencies
.get(&commit.id())
.map(|v| v.iter().cloned().collect())
.unwrap_or_default();

let commit_dependent_diffs = branch
.commit_dependent_diffs
.get(&commit.id())
.map(|v| {
v.iter()
.cloned()
.map(|hunk_hash| format!("{:x}", hunk_hash).as_str().into())
.collect()
})
.unwrap_or_default();

let commit = VirtualBranchCommit {
id: commit.id(),
created_at: timestamp * 1000,
Expand All @@ -104,6 +137,9 @@ pub(crate) fn commit_to_vbranch_commit(
copied_from_remote_id,
remote_commit_id,
conflicted_files,
commit_dependencies,
inverse_commit_dependencies,
commit_dependent_diffs,
};

Ok(commit)
Expand Down

0 comments on commit ebf11d0

Please sign in to comment.