mirror of
https://github.com/gitbutlerapp/gitbutler.git
synced 2024-12-24 01:51:57 +03:00
order branch listing by last modified
also fixes an error in last modified computation
This commit is contained in:
parent
2d0fa99452
commit
3033c7e7f5
@ -1,4 +1,5 @@
|
||||
import { invoke } from '$lib/backend/ipc';
|
||||
import { Transform } from 'class-transformer';
|
||||
import { plainToInstance } from 'class-transformer';
|
||||
|
||||
export class BranchListingService {
|
||||
@ -47,6 +48,7 @@ export class BranchListing {
|
||||
numberOfCommits!: number;
|
||||
/// Timestamp in milliseconds since the branch was last updated.
|
||||
/// This includes any commits, uncommited changes or even updates to the branch metadata (e.g. renaming).
|
||||
@Transform((obj) => new Date(obj.value))
|
||||
updatedAt!: number;
|
||||
/// A list of authors that have contributes commits to this branch.
|
||||
/// In the case of multiple remote tracking branches, it takes the full list of unique authors.
|
||||
|
@ -16,12 +16,11 @@ use gitbutler_command_context::ProjectRepository;
|
||||
use crate::{VirtualBranch, VirtualBranchesExt};
|
||||
use gitbutler_reference::normalize_branch_name;
|
||||
use gitbutler_repo::RepoActionsExt;
|
||||
use itertools::Itertools;
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
|
||||
/// Returns a list of branches associated with this project.
|
||||
// TODO: Implement pagination for this thing
|
||||
// TODO: The results should be sortedb by updated_at
|
||||
pub fn list_branches(
|
||||
ctx: &ProjectRepository,
|
||||
filter: Option<BranchListingFilter>,
|
||||
@ -75,6 +74,7 @@ pub fn list_branches(
|
||||
let branches: Vec<BranchListing> = branches
|
||||
.into_iter()
|
||||
.filter(|branch| matches_all(branch, &filter))
|
||||
.sorted_by(|a, b| b.updated_at.cmp(&a.updated_at))
|
||||
.collect();
|
||||
Ok(branches)
|
||||
}
|
||||
@ -214,6 +214,10 @@ fn branch_group_to_branch(
|
||||
.map(|vb| normalize_branch_name(&vb.name))
|
||||
.unwrap_or_default(),
|
||||
);
|
||||
let last_modified_ms = max(
|
||||
(repo.find_commit(head)?.time().seconds() * 1000) as u128,
|
||||
virtual_branch.map_or(0, |x| x.updated_timestamp_ms),
|
||||
);
|
||||
let repo_head = repo.head()?.peel_to_commit()?;
|
||||
// If no merge base can be found, return with zero stats
|
||||
let branch = if let Ok(base) = repo.merge_base(repo_head.id(), head) {
|
||||
@ -222,14 +226,11 @@ fn branch_group_to_branch(
|
||||
revwalk.hide(base)?;
|
||||
let mut commits = Vec::new();
|
||||
let mut authors = HashSet::new();
|
||||
let mut last_commit_time_ms = i64::MIN;
|
||||
for oid in revwalk {
|
||||
let commit = repo.find_commit(oid?)?;
|
||||
last_commit_time_ms = max(last_commit_time_ms, commit.time().seconds() * 1000);
|
||||
authors.insert(commit.author().into());
|
||||
commits.push(commit);
|
||||
}
|
||||
|
||||
// If there are no commits (i.e. virtual branch only) it is considered the users own
|
||||
let own_branch = commits.is_empty()
|
||||
|| commits.iter().any(|commit| {
|
||||
@ -238,11 +239,6 @@ fn branch_group_to_branch(
|
||||
&& local_author.email_bytes() == commit_author.email_bytes()
|
||||
});
|
||||
|
||||
let last_modified_ms = max(
|
||||
last_commit_time_ms as u128,
|
||||
virtual_branch.map_or(0, |x| x.updated_timestamp_ms),
|
||||
);
|
||||
|
||||
BranchListing {
|
||||
name: identity,
|
||||
remotes,
|
||||
@ -253,7 +249,6 @@ fn branch_group_to_branch(
|
||||
own_branch,
|
||||
}
|
||||
} else {
|
||||
let last_modified_ms = (repo.find_commit(head)?.time().seconds() * 1000) as u128;
|
||||
BranchListing {
|
||||
name: identity,
|
||||
remotes,
|
||||
|
Loading…
Reference in New Issue
Block a user