Skip to content

Commit 418dafa

Browse files
committed
add tag support, initially readonly
1 parent 708a73c commit 418dafa

27 files changed

+282
-161
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
### Added
66
- Git remotes in the status bar, with push & fetch commands.
77
- "Create branch" command on revisions.
8+
- Display Git tags (readonly; they aren't really a Jujutsu concept).
89
- Display edges to commits that aren't in the queried revset, by drawing a line to nowhere.
910
- Detect changes made by other Jujutsu clients and merge the operation log automatically.
1011
- Window title includes the workspace path (when one is open).

TODO.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Desirable things
44
These changes may or may not be implemented in the future.
55
* 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)
66
* bug: open menu command sometimes opens multiple dialogues
7+
* bug: no CLI output on windows
78
* 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
89
* perf: optimise revdetail loads - we already have the header
910
* perf: better solution to slow immutability check - jj-lib will have a revset contains cache soon
@@ -15,7 +16,6 @@ These changes may or may not be implemented in the future.
1516
* feat: sub-file hunk changes
1617
* feat: diffs and/or difftool
1718
* feat: resolve workflow
18-
* feat: tags display (readonly, perhaps - look at jj support)
1919
* feat: view commit ids in log (configurable?)
2020
* feat: view repo at different ops (slider? entire pane?)
2121
* feat: progress display (probably in statusbar); useful for git & snapshot
@@ -27,6 +27,7 @@ These changes may or may not be implemented in the future.
2727
- delete branch
2828
- push branch
2929
- fetch branch?
30+
- create/delete tags? even moving them is implemented, but may be a bad idea
3031
* feat: more settings
3132
- log revsets
3233
* design: decide whether to remove edit menu and maybe add others

src-tauri/src/main.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ use tauri::{State, Window, WindowEvent, Wry};
2222
use tauri_plugin_window_state::StateFlags;
2323

2424
use messages::{
25-
AbandonRevisions, CheckoutRevision, CopyChanges, CreateBranch, CreateRevision, DeleteBranch,
26-
DescribeRevision, DuplicateRevisions, FetchRemote, InputResponse, InsertRevision, MoveBranch,
27-
MoveChanges, MoveRevision, MoveSource, MutationResult, PushRemote, RevId, TrackBranch,
25+
AbandonRevisions, CheckoutRevision, CopyChanges, CreateRef, CreateRevision, DeleteRef,
26+
DescribeRevision, DuplicateRevisions, FetchRemote, InputResponse, InsertRevision, MoveChanges,
27+
MoveRef, MoveRevision, MoveSource, MutationResult, PushRemote, RevId, TrackBranch,
2828
UndoOperation, UntrackBranch,
2929
};
3030
use worker::{Mutation, Session, SessionEvent, WorkerSession};
@@ -135,9 +135,9 @@ fn main() -> Result<()> {
135135
copy_changes,
136136
track_branch,
137137
untrack_branch,
138-
create_branch,
139-
delete_branch,
140-
move_branch,
138+
create_ref,
139+
delete_ref,
140+
move_ref,
141141
push_remote,
142142
fetch_remote,
143143
undo_operation
@@ -407,28 +407,28 @@ fn untrack_branch(
407407
}
408408

409409
#[tauri::command(async)]
410-
fn create_branch(
410+
fn create_ref(
411411
window: Window,
412412
app_state: State<AppState>,
413-
mutation: CreateBranch,
413+
mutation: CreateRef,
414414
) -> Result<MutationResult, InvokeError> {
415415
try_mutate(window, app_state, mutation)
416416
}
417417

418418
#[tauri::command(async)]
419-
fn delete_branch(
419+
fn delete_ref(
420420
window: Window,
421421
app_state: State<AppState>,
422-
mutation: DeleteBranch,
422+
mutation: DeleteRef,
423423
) -> Result<MutationResult, InvokeError> {
424424
try_mutate(window, app_state, mutation)
425425
}
426426

427427
#[tauri::command(async)]
428-
fn move_branch(
428+
fn move_ref(
429429
window: Window,
430430
app_state: State<AppState>,
431-
mutation: MoveBranch,
431+
mutation: MoveRef,
432432
) -> Result<MutationResult, InvokeError> {
433433
try_mutate(window, app_state, mutation)
434434
}

src-tauri/src/menu.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use tauri_plugin_dialog::DialogExt;
99

1010
use crate::{
1111
handler,
12-
messages::{Operand, RefName, RevHeader},
12+
messages::{Operand, RevHeader, StoreRef},
1313
AppState,
1414
};
1515

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

311311
window.popup_menu(context_menu)?;
312312
}
313-
Operand::Branch { name, .. } => {
313+
Operand::Ref { r#ref: name, .. } => {
314314
let context_menu = &guard
315315
.get(window.label())
316316
.expect("session not found")
@@ -320,7 +320,7 @@ pub fn handle_context(window: Window, ctx: Operand) -> Result<()> {
320320
"branch_track",
321321
matches!(
322322
name,
323-
RefName::RemoteBranch {
323+
StoreRef::RemoteBranch {
324324
is_tracked: false,
325325
..
326326
}
@@ -330,10 +330,10 @@ pub fn handle_context(window: Window, ctx: Operand) -> Result<()> {
330330
"branch_untrack",
331331
matches!(
332332
name,
333-
RefName::RemoteBranch {
333+
StoreRef::RemoteBranch {
334334
is_tracked: true,
335335
..
336-
} | RefName::LocalBranch {
336+
} | StoreRef::LocalBranch {
337337
is_tracking: true,
338338
..
339339
}

src-tauri/src/messages/mod.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ pub struct RepoStatus {
115115
derive(TS),
116116
ts(export, export_to = "../src/messages/")
117117
)]
118-
pub enum RefName {
118+
pub enum StoreRef {
119119
LocalBranch {
120120
branch_name: String,
121121
has_conflict: bool,
@@ -126,14 +126,17 @@ pub enum RefName {
126126
},
127127
RemoteBranch {
128128
branch_name: String,
129+
remote_name: String,
129130
has_conflict: bool,
130131
/// Tracking remote ref is synchronized with local ref
131132
is_synced: bool,
132133
/// Has local ref
133134
is_tracked: bool,
134135
/// Local ref has been deleted
135136
is_deleted: bool,
136-
remote_name: String,
137+
},
138+
Tag {
139+
tag_name: String,
137140
},
138141
}
139142

@@ -161,9 +164,9 @@ pub enum Operand {
161164
header: RevHeader,
162165
path: TreePath, // someday: hunks
163166
},
164-
Branch {
167+
Ref {
165168
header: RevHeader,
166-
name: RefName,
169+
r#ref: StoreRef,
167170
},
168171
}
169172

src-tauri/src/messages/mutations.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ pub struct CopyChanges {
146146
ts(export, export_to = "../src/messages/")
147147
)]
148148
pub struct TrackBranch {
149-
pub name: RefName,
149+
pub r#ref: StoreRef,
150150
}
151151

152152
#[derive(Deserialize, Debug)]
@@ -156,7 +156,7 @@ pub struct TrackBranch {
156156
ts(export, export_to = "../src/messages/")
157157
)]
158158
pub struct UntrackBranch {
159-
pub name: RefName,
159+
pub r#ref: StoreRef,
160160
}
161161

162162
#[derive(Deserialize, Debug)]
@@ -165,9 +165,9 @@ pub struct UntrackBranch {
165165
derive(TS),
166166
ts(export, export_to = "../src/messages/")
167167
)]
168-
pub struct CreateBranch {
168+
pub struct CreateRef {
169169
pub id: RevId,
170-
pub name: String,
170+
pub r#ref: StoreRef,
171171
}
172172

173173
#[derive(Deserialize, Debug)]
@@ -176,8 +176,8 @@ pub struct CreateBranch {
176176
derive(TS),
177177
ts(export, export_to = "../src/messages/")
178178
)]
179-
pub struct DeleteBranch {
180-
pub name: RefName,
179+
pub struct DeleteRef {
180+
pub r#ref: StoreRef,
181181
}
182182

183183
#[derive(Deserialize, Debug)]
@@ -186,8 +186,8 @@ pub struct DeleteBranch {
186186
derive(TS),
187187
ts(export, export_to = "../src/messages/")
188188
)]
189-
pub struct MoveBranch {
190-
pub name: RefName,
189+
pub struct MoveRef {
190+
pub r#ref: StoreRef,
191191
pub to_id: RevId,
192192
}
193193

src-tauri/src/messages/queries.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ pub struct RevHeader {
8383
pub has_conflict: bool,
8484
pub is_working_copy: bool,
8585
pub is_immutable: bool,
86-
pub branches: Vec<RefName>,
86+
pub refs: Vec<StoreRef>,
8787
pub parent_ids: Vec<CommitId>,
8888
}
8989

src-tauri/src/worker/gui_util.rs

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ pub struct WorkspaceSession<'a> {
5656
pub struct SessionOperation {
5757
pub repo: Arc<ReadonlyRepo>,
5858
pub wc_id: CommitId,
59-
branches_index: OnceCell<Rc<BranchIndex>>,
59+
ref_index: OnceCell<Rc<RefIndex>>,
6060
prefix_context: OnceCell<Rc<IdPrefixContext>>,
6161
immutable_revisions: OnceCell<Rc<RevsetExpression>>
6262
}
@@ -318,9 +318,9 @@ impl WorkspaceSession<'_> {
318318
self.operation.immutable_revisions.get_or_init(|| build_immutable_revisions(&self.operation.repo, &self.aliases_map, &self.parse_context()).expect("init immutable heads"))
319319
}
320320

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

326326
/************************************
@@ -398,7 +398,7 @@ impl WorkspaceSession<'_> {
398398
}
399399

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

404404
let is_immutable = known_immutable
@@ -412,7 +412,7 @@ impl WorkspaceSession<'_> {
412412
has_conflict: commit.has_conflict()?,
413413
is_working_copy: *commit.id() == self.operation.wc_id,
414414
is_immutable,
415-
branches,
415+
refs: branches,
416416
parent_ids: commit.parent_ids().iter().map(|commit_id| self.format_commit_id(commit_id)).collect()
417417
})
418418
}
@@ -748,7 +748,7 @@ impl SessionOperation {
748748
SessionOperation {
749749
repo,
750750
wc_id,
751-
branches_index: OnceCell::default(),
751+
ref_index: OnceCell::default(),
752752
prefix_context: OnceCell::default(),
753753
immutable_revisions: OnceCell::default()
754754
}
@@ -892,19 +892,19 @@ fn parse_revset(
892892
/*************************/
893893

894894
#[derive(Default)]
895-
pub struct BranchIndex {
896-
index: HashMap<CommitId, Vec<messages::RefName>>,
895+
pub struct RefIndex {
896+
index: HashMap<CommitId, Vec<messages::StoreRef>>,
897897
}
898898

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

907-
fn get(&self, id: &CommitId) -> &[messages::RefName] {
907+
fn get(&self, id: &CommitId) -> &[messages::StoreRef] {
908908
if let Some(names) = self.index.get(id) {
909909
names
910910
} else {
@@ -913,13 +913,14 @@ impl BranchIndex {
913913
}
914914
}
915915

916-
fn build_branches_index(repo: &ReadonlyRepo) -> BranchIndex {
917-
let mut index = BranchIndex::default();
916+
fn build_ref_index(repo: &ReadonlyRepo) -> RefIndex {
917+
let mut index = RefIndex::default();
918+
918919
for (branch_name, branch_target) in repo.view().branches() {
919920
let local_target = branch_target.local_target;
920921
let remote_refs = branch_target.remote_refs;
921922
if local_target.is_present() {
922-
index.insert(local_target.added_ids(), messages::RefName::LocalBranch {
923+
index.insert(local_target.added_ids(), messages::StoreRef::LocalBranch {
923924
branch_name: branch_name.to_owned(),
924925
has_conflict: local_target.has_conflict(),
925926
is_synced: remote_refs.iter().all(|&(_, remote_ref)| {
@@ -929,7 +930,7 @@ fn build_branches_index(repo: &ReadonlyRepo) -> BranchIndex {
929930
});
930931
}
931932
for &(remote_name, remote_ref) in &remote_refs {
932-
index.insert(remote_ref.target.added_ids(), messages::RefName::RemoteBranch {
933+
index.insert(remote_ref.target.added_ids(), messages::StoreRef::RemoteBranch {
933934
branch_name: branch_name.to_owned(),
934935
remote_name: remote_name.to_owned(),
935936
has_conflict: remote_ref.target.has_conflict(),
@@ -939,6 +940,11 @@ fn build_branches_index(repo: &ReadonlyRepo) -> BranchIndex {
939940
});
940941
}
941942
}
943+
944+
for (tag_name, tag_target) in repo.view().tags() {
945+
index.insert(tag_target.added_ids(), messages::StoreRef::Tag { tag_name: tag_name.clone() });
946+
}
947+
942948
index
943949
}
944950

0 commit comments

Comments
 (0)