1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
//! Change (commit) data model
use super::id::{ChangeId, CommitId};
/// Represents a jj change (similar to a Git commit)
#[derive(Debug, Clone, PartialEq, Eq, Default)]
pub struct Change {
/// Short change ID (jj's unique identifier)
pub change_id: ChangeId,
/// Short commit ID (Git-compatible)
pub commit_id: CommitId,
/// Author email
pub author: String,
/// Timestamp (ISO 8601 format)
pub timestamp: String,
/// First line of the description
pub description: String,
/// Is this the current working copy?
pub is_working_copy: bool,
/// Is this change empty (no file changes)?
pub is_empty: bool,
/// Associated bookmarks (branch names)
pub bookmarks: Vec<String>,
/// DAG graph prefix from jj log output
///
/// Examples:
/// - `"@ "` (working copy, simple)
/// - `"│ ○ "` (1-level branch)
/// - `"│ │ ○ "` (2-level branch)
/// - `"├─╮"` (graph-only, branch start)
pub graph_prefix: String,
/// True if this is a graph-only line (no change data, just branch lines)
pub is_graph_only: bool,
/// True if this change has unresolved conflicts
pub has_conflict: bool,
}
impl Change {
/// Get a display-friendly short ID
pub fn short_id(&self) -> &str {
self.change_id.as_str()
}
/// Get a display string for the description
pub fn display_description(&self) -> &str {
if self.description.is_empty() {
"(no description set)"
} else {
&self.description
}
}
}
#[cfg(test)]
mod tests {
use super::*;
impl Change {
/// Get the marker character for this change (test-only helper)
pub fn marker(&self) -> char {
if self.is_working_copy { '@' } else { '○' }
}
}
fn sample_change() -> Change {
Change {
change_id: ChangeId::new("abc12345".to_string()),
commit_id: CommitId::new("def67890".to_string()),
author: "user@example.com".to_string(),
timestamp: "2024-01-29T15:30:00+0900".to_string(),
description: "Initial commit".to_string(),
is_working_copy: false,
is_empty: false,
bookmarks: vec!["main".to_string()],
graph_prefix: String::new(),
is_graph_only: false,
has_conflict: false,
}
}
#[test]
fn test_short_id() {
let change = sample_change();
assert_eq!(change.short_id(), "abc12345");
}
#[test]
fn test_display_description() {
let change = sample_change();
assert_eq!(change.display_description(), "Initial commit");
let empty_desc = Change {
description: String::new(),
..sample_change()
};
assert_eq!(empty_desc.display_description(), "(no description set)");
}
#[test]
fn test_marker_working_copy() {
let working_copy = Change {
is_working_copy: true,
..sample_change()
};
assert_eq!(working_copy.marker(), '@');
}
#[test]
fn test_marker_regular() {
let regular = sample_change();
assert_eq!(regular.marker(), '○');
}
}