Skip to content

Commit

Permalink
add tag support, initially readonly
Browse files Browse the repository at this point in the history
  • Loading branch information
gulbanana committed Mar 19, 2024
1 parent 708a73c commit 418dafa
Show file tree
Hide file tree
Showing 27 changed files with 282 additions and 161 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Added
- Git remotes in the status bar, with push & fetch commands.
- "Create branch" command on revisions.
- Display Git tags (readonly; they aren't really a Jujutsu concept).
- Display edges to commits that aren't in the queried revset, by drawing a line to nowhere.
- Detect changes made by other Jujutsu clients and merge the operation log automatically.
- Window title includes the workspace path (when one is open).
Expand Down
3 changes: 2 additions & 1 deletion TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Desirable things
These changes may or may not be implemented in the future.
* bug: proper fix for https://github.com/tauri-apps/tauri/issues/9127 (currently worked-around via fork; fix may be in beta12, or it might not work)
* bug: open menu command sometimes opens multiple dialogues
* bug: no CLI output on windows
* edge case: mutations can fail due to ambiguity due to other writers; this should update the UI. maybe use a special From on resolve_change
* perf: optimise revdetail loads - we already have the header
* perf: better solution to slow immutability check - jj-lib will have a revset contains cache soon
Expand All @@ -15,7 +16,6 @@ These changes may or may not be implemented in the future.
* feat: sub-file hunk changes
* feat: diffs and/or difftool
* feat: resolve workflow
* feat: tags display (readonly, perhaps - look at jj support)
* feat: view commit ids in log (configurable?)
* feat: view repo at different ops (slider? entire pane?)
* feat: progress display (probably in statusbar); useful for git & snapshot
Expand All @@ -27,6 +27,7 @@ These changes may or may not be implemented in the future.
- delete branch
- push branch
- fetch branch?
- create/delete tags? even moving them is implemented, but may be a bad idea
* feat: more settings
- log revsets
* design: decide whether to remove edit menu and maybe add others
Expand Down
24 changes: 12 additions & 12 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ use tauri::{State, Window, WindowEvent, Wry};
use tauri_plugin_window_state::StateFlags;

use messages::{
AbandonRevisions, CheckoutRevision, CopyChanges, CreateBranch, CreateRevision, DeleteBranch,
DescribeRevision, DuplicateRevisions, FetchRemote, InputResponse, InsertRevision, MoveBranch,
MoveChanges, MoveRevision, MoveSource, MutationResult, PushRemote, RevId, TrackBranch,
AbandonRevisions, CheckoutRevision, CopyChanges, CreateRef, CreateRevision, DeleteRef,
DescribeRevision, DuplicateRevisions, FetchRemote, InputResponse, InsertRevision, MoveChanges,
MoveRef, MoveRevision, MoveSource, MutationResult, PushRemote, RevId, TrackBranch,
UndoOperation, UntrackBranch,
};
use worker::{Mutation, Session, SessionEvent, WorkerSession};
Expand Down Expand Up @@ -135,9 +135,9 @@ fn main() -> Result<()> {
copy_changes,
track_branch,
untrack_branch,
create_branch,
delete_branch,
move_branch,
create_ref,
delete_ref,
move_ref,
push_remote,
fetch_remote,
undo_operation
Expand Down Expand Up @@ -407,28 +407,28 @@ fn untrack_branch(
}

#[tauri::command(async)]
fn create_branch(
fn create_ref(
window: Window,
app_state: State<AppState>,
mutation: CreateBranch,
mutation: CreateRef,
) -> Result<MutationResult, InvokeError> {
try_mutate(window, app_state, mutation)
}

#[tauri::command(async)]
fn delete_branch(
fn delete_ref(
window: Window,
app_state: State<AppState>,
mutation: DeleteBranch,
mutation: DeleteRef,
) -> Result<MutationResult, InvokeError> {
try_mutate(window, app_state, mutation)
}

#[tauri::command(async)]
fn move_branch(
fn move_ref(
window: Window,
app_state: State<AppState>,
mutation: MoveBranch,
mutation: MoveRef,
) -> Result<MutationResult, InvokeError> {
try_mutate(window, app_state, mutation)
}
Expand Down
10 changes: 5 additions & 5 deletions src-tauri/src/menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use tauri_plugin_dialog::DialogExt;

use crate::{
handler,
messages::{Operand, RefName, RevHeader},
messages::{Operand, RevHeader, StoreRef},
AppState,
};

Expand Down Expand Up @@ -310,7 +310,7 @@ pub fn handle_context(window: Window, ctx: Operand) -> Result<()> {

window.popup_menu(context_menu)?;
}
Operand::Branch { name, .. } => {
Operand::Ref { r#ref: name, .. } => {
let context_menu = &guard
.get(window.label())
.expect("session not found")
Expand All @@ -320,7 +320,7 @@ pub fn handle_context(window: Window, ctx: Operand) -> Result<()> {
"branch_track",
matches!(
name,
RefName::RemoteBranch {
StoreRef::RemoteBranch {
is_tracked: false,
..
}
Expand All @@ -330,10 +330,10 @@ pub fn handle_context(window: Window, ctx: Operand) -> Result<()> {
"branch_untrack",
matches!(
name,
RefName::RemoteBranch {
StoreRef::RemoteBranch {
is_tracked: true,
..
} | RefName::LocalBranch {
} | StoreRef::LocalBranch {
is_tracking: true,
..
}
Expand Down
11 changes: 7 additions & 4 deletions src-tauri/src/messages/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ pub struct RepoStatus {
derive(TS),
ts(export, export_to = "../src/messages/")
)]
pub enum RefName {
pub enum StoreRef {
LocalBranch {
branch_name: String,
has_conflict: bool,
Expand All @@ -126,14 +126,17 @@ pub enum RefName {
},
RemoteBranch {
branch_name: String,
remote_name: String,
has_conflict: bool,
/// Tracking remote ref is synchronized with local ref
is_synced: bool,
/// Has local ref
is_tracked: bool,
/// Local ref has been deleted
is_deleted: bool,
remote_name: String,
},
Tag {
tag_name: String,
},
}

Expand Down Expand Up @@ -161,9 +164,9 @@ pub enum Operand {
header: RevHeader,
path: TreePath, // someday: hunks
},
Branch {
Ref {
header: RevHeader,
name: RefName,
r#ref: StoreRef,
},
}

Expand Down
16 changes: 8 additions & 8 deletions src-tauri/src/messages/mutations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ pub struct CopyChanges {
ts(export, export_to = "../src/messages/")
)]
pub struct TrackBranch {
pub name: RefName,
pub r#ref: StoreRef,
}

#[derive(Deserialize, Debug)]
Expand All @@ -156,7 +156,7 @@ pub struct TrackBranch {
ts(export, export_to = "../src/messages/")
)]
pub struct UntrackBranch {
pub name: RefName,
pub r#ref: StoreRef,
}

#[derive(Deserialize, Debug)]
Expand All @@ -165,9 +165,9 @@ pub struct UntrackBranch {
derive(TS),
ts(export, export_to = "../src/messages/")
)]
pub struct CreateBranch {
pub struct CreateRef {
pub id: RevId,
pub name: String,
pub r#ref: StoreRef,
}

#[derive(Deserialize, Debug)]
Expand All @@ -176,8 +176,8 @@ pub struct CreateBranch {
derive(TS),
ts(export, export_to = "../src/messages/")
)]
pub struct DeleteBranch {
pub name: RefName,
pub struct DeleteRef {
pub r#ref: StoreRef,
}

#[derive(Deserialize, Debug)]
Expand All @@ -186,8 +186,8 @@ pub struct DeleteBranch {
derive(TS),
ts(export, export_to = "../src/messages/")
)]
pub struct MoveBranch {
pub name: RefName,
pub struct MoveRef {
pub r#ref: StoreRef,
pub to_id: RevId,
}

Expand Down
2 changes: 1 addition & 1 deletion src-tauri/src/messages/queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ pub struct RevHeader {
pub has_conflict: bool,
pub is_working_copy: bool,
pub is_immutable: bool,
pub branches: Vec<RefName>,
pub refs: Vec<StoreRef>,
pub parent_ids: Vec<CommitId>,
}

Expand Down
40 changes: 23 additions & 17 deletions src-tauri/src/worker/gui_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ pub struct WorkspaceSession<'a> {
pub struct SessionOperation {
pub repo: Arc<ReadonlyRepo>,
pub wc_id: CommitId,
branches_index: OnceCell<Rc<BranchIndex>>,
ref_index: OnceCell<Rc<RefIndex>>,
prefix_context: OnceCell<Rc<IdPrefixContext>>,
immutable_revisions: OnceCell<Rc<RevsetExpression>>
}
Expand Down Expand Up @@ -318,9 +318,9 @@ impl WorkspaceSession<'_> {
self.operation.immutable_revisions.get_or_init(|| build_immutable_revisions(&self.operation.repo, &self.aliases_map, &self.parse_context()).expect("init immutable heads"))
}

pub fn branches_index(&self) -> &Rc<BranchIndex> {
self.operation.branches_index
.get_or_init(|| Rc::new(build_branches_index(self.operation.repo.as_ref())))
pub fn ref_index(&self) -> &Rc<RefIndex> {
self.operation.ref_index
.get_or_init(|| Rc::new(build_ref_index(self.operation.repo.as_ref())))
}

/************************************
Expand Down Expand Up @@ -398,7 +398,7 @@ impl WorkspaceSession<'_> {
}

pub fn format_header(&self, commit: &Commit, known_immutable: Option<bool>) -> Result<messages::RevHeader> {
let index = self.branches_index();
let index = self.ref_index();
let branches = index.get(commit.id()).iter().cloned().collect();

let is_immutable = known_immutable
Expand All @@ -412,7 +412,7 @@ impl WorkspaceSession<'_> {
has_conflict: commit.has_conflict()?,
is_working_copy: *commit.id() == self.operation.wc_id,
is_immutable,
branches,
refs: branches,
parent_ids: commit.parent_ids().iter().map(|commit_id| self.format_commit_id(commit_id)).collect()
})
}
Expand Down Expand Up @@ -748,7 +748,7 @@ impl SessionOperation {
SessionOperation {
repo,
wc_id,
branches_index: OnceCell::default(),
ref_index: OnceCell::default(),
prefix_context: OnceCell::default(),
immutable_revisions: OnceCell::default()
}
Expand Down Expand Up @@ -892,19 +892,19 @@ fn parse_revset(
/*************************/

#[derive(Default)]
pub struct BranchIndex {
index: HashMap<CommitId, Vec<messages::RefName>>,
pub struct RefIndex {
index: HashMap<CommitId, Vec<messages::StoreRef>>,
}

impl BranchIndex {
fn insert<'a>(&mut self, ids: impl IntoIterator<Item = &'a CommitId>, name: messages::RefName) {
impl RefIndex {
fn insert<'a>(&mut self, ids: impl IntoIterator<Item = &'a CommitId>, r#ref: messages::StoreRef) {
for id in ids {
let ref_names = self.index.entry(id.clone()).or_default();
ref_names.push(name.clone());
ref_names.push(r#ref.clone());
}
}

fn get(&self, id: &CommitId) -> &[messages::RefName] {
fn get(&self, id: &CommitId) -> &[messages::StoreRef] {
if let Some(names) = self.index.get(id) {
names
} else {
Expand All @@ -913,13 +913,14 @@ impl BranchIndex {
}
}

fn build_branches_index(repo: &ReadonlyRepo) -> BranchIndex {
let mut index = BranchIndex::default();
fn build_ref_index(repo: &ReadonlyRepo) -> RefIndex {
let mut index = RefIndex::default();

for (branch_name, branch_target) in repo.view().branches() {
let local_target = branch_target.local_target;
let remote_refs = branch_target.remote_refs;
if local_target.is_present() {
index.insert(local_target.added_ids(), messages::RefName::LocalBranch {
index.insert(local_target.added_ids(), messages::StoreRef::LocalBranch {
branch_name: branch_name.to_owned(),
has_conflict: local_target.has_conflict(),
is_synced: remote_refs.iter().all(|&(_, remote_ref)| {
Expand All @@ -929,7 +930,7 @@ fn build_branches_index(repo: &ReadonlyRepo) -> BranchIndex {
});
}
for &(remote_name, remote_ref) in &remote_refs {
index.insert(remote_ref.target.added_ids(), messages::RefName::RemoteBranch {
index.insert(remote_ref.target.added_ids(), messages::StoreRef::RemoteBranch {
branch_name: branch_name.to_owned(),
remote_name: remote_name.to_owned(),
has_conflict: remote_ref.target.has_conflict(),
Expand All @@ -939,6 +940,11 @@ fn build_branches_index(repo: &ReadonlyRepo) -> BranchIndex {
});
}
}

for (tag_name, tag_target) in repo.view().tags() {
index.insert(tag_target.added_ids(), messages::StoreRef::Tag { tag_name: tag_name.clone() });
}

index
}

Expand Down
Loading

0 comments on commit 418dafa

Please sign in to comment.