Skip to content

Commit c6e4acb

Browse files
committed
mod: adds new column that shows last hash
1 parent 170c6b1 commit c6e4acb

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

git_better-branch/src/branch_info.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ pub struct BranchInfo {
1414

1515
/// A human-readable representation of the last commit time (e.g. `5 days ago`).
1616
pub relative_time: String,
17+
18+
/// The last commit hash (be4791c696db01729d9ffb54ea69cef15c37c619).
19+
pub last_commit_hash: String,
1720

1821
/// Number of commits this branch is ahead of the base branch.
1922
pub ahead: i32,

git_better-branch/src/report.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ pub fn process_repo_with_refs(dir: &str, refs: &[&str], user_branch: Option<&str
9393
branches.push(BranchInfo {
9494
name: branch.to_string(),
9595
relative_time: time.to_string(),
96+
last_commit_hash: sha.to_string(),
9697
ahead,
9798
behind,
9899
});
@@ -115,48 +116,55 @@ pub fn print_branch_table(branches: &[BranchInfo]) {
115116
let mut max_behind = "Behind".len();
116117
let mut max_name = "Branch".len();
117118
let mut max_time = "Last Commit".len();
118-
119+
let mut max_hash = "Commit".len();
119120
for b in branches {
120121
max_ahead = max_ahead.max(b.ahead.to_string().len());
121122
max_behind = max_behind.max(b.behind.to_string().len());
122123
max_name = max_name.max(b.name.len());
123124
max_time = max_time.max(b.relative_time.len());
125+
max_hash = max_hash.max(b.last_commit_hash.len());
124126
}
125127

126128
println!(
127-
"{}{:>width_a$}{} {}{:>width_b$}{} {}{:<width_n$}{} {}{:<width_t$}{}",
129+
"{}{:>width_a$}{} {}{:>width_b$}{} {}{:<width_n$}{} {}{:<width_h$}{} {}{:<width_t$}{}",
128130
GREEN, "Ahead", NO_COLOR,
129131
RED, "Behind", NO_COLOR,
130132
BLUE, "Branch", NO_COLOR,
133+
NO_COLOR, "Commit", NO_COLOR,
131134
YELLOW, "Last Commit", NO_COLOR,
135+
width_h = max_hash,
132136
width_a = max_ahead,
133137
width_b = max_behind,
134138
width_n = max_name,
135139
width_t = max_time,
136140
);
137141

138142
println!(
139-
"{}{:->width_a$}{} {}{:->width_b$}{} {}{:->width_n$}{} {}{:->width_t$}{}",
143+
"{}{:->width_a$}{} {}{:->width_b$}{} {}{:->width_n$}{} {}{:->width_h$}{} {}{:->width_t$}{}",
140144
GREEN, "", NO_COLOR,
141145
RED, "", NO_COLOR,
142146
BLUE, "", NO_COLOR,
147+
NO_COLOR, "", NO_COLOR,
143148
YELLOW, "", NO_COLOR,
144149
width_a = max_ahead,
145150
width_b = max_behind,
146151
width_n = max_name,
152+
width_h = max_hash,
147153
width_t = max_time,
148154
);
149155

150156
for b in branches {
151157
println!(
152-
"{}{:>width_a$}{} {}{:>width_b$}{} {}{:<width_n$}{} {}{:<width_t$}{}",
158+
"{}{:>width_a$}{} {}{:>width_b$}{} {}{:<width_n$}{} {}{:<width_h$}{} {}{:<width_t$}{}",
153159
GREEN, b.ahead, NO_COLOR,
154160
RED, b.behind, NO_COLOR,
155161
BLUE, b.name, NO_COLOR,
162+
NO_COLOR, b.last_commit_hash, NO_COLOR,
156163
YELLOW, b.relative_time, NO_COLOR,
157164
width_a = max_ahead,
158165
width_b = max_behind,
159166
width_n = max_name,
167+
width_h = max_hash,
160168
width_t = max_time,
161169
);
162170
}

0 commit comments

Comments
 (0)