Improve stash picker ui
This commit is contained in:
parent
d03557748b
commit
4f11b9ef56
5 changed files with 80 additions and 12 deletions
|
@ -994,7 +994,7 @@ impl GitRepository for RealGitRepository {
|
|||
.spawn(async move {
|
||||
let output = new_std_command(&git_binary_path)
|
||||
.current_dir(working_directory?)
|
||||
.args(&["stash", "list", "--pretty=%gd:%H:%s"])
|
||||
.args(&["stash", "list", "--pretty=format:%gd%x00%H%x00%ct%x00%s"])
|
||||
.output()?;
|
||||
if output.status.success() {
|
||||
let stdout = String::from_utf8_lossy(&output.stdout);
|
||||
|
|
|
@ -7,6 +7,8 @@ pub struct StashEntry {
|
|||
pub index: usize,
|
||||
pub oid: Oid,
|
||||
pub message: String,
|
||||
pub branch: Option<String>,
|
||||
pub timestamp: i64,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Default, Eq, Hash, PartialEq)]
|
||||
|
@ -28,7 +30,7 @@ impl FromStr for GitStash {
|
|||
let entries = s
|
||||
.split('\n')
|
||||
.filter_map(|entry| {
|
||||
let mut parts = entry.splitn(3, ':');
|
||||
let mut parts = entry.splitn(4, '\0');
|
||||
let raw_idx = parts.next().and_then(|i| {
|
||||
let trimmed = i.trim();
|
||||
if trimmed.starts_with("stash@{") && trimmed.ends_with('}') {
|
||||
|
@ -40,15 +42,21 @@ impl FromStr for GitStash {
|
|||
}
|
||||
});
|
||||
let raw_oid = parts.next();
|
||||
let raw_date = parts.next().and_then(|d| d.parse().ok());
|
||||
let message = parts.next();
|
||||
|
||||
if let (Some(raw_idx), Some(raw_oid), Some(message)) = (raw_idx, raw_oid, message) {
|
||||
if let (Some(raw_idx), Some(raw_oid), Some(raw_date), Some(message)) =
|
||||
(raw_idx, raw_oid, raw_date, message)
|
||||
{
|
||||
let (branch, message) = parse_stash_entry(message);
|
||||
let index = raw_idx.parse::<usize>().ok()?;
|
||||
let oid = Oid::from_str(raw_oid).ok()?;
|
||||
let entry = StashEntry {
|
||||
index,
|
||||
oid,
|
||||
message: message.to_string(),
|
||||
branch: branch.map(Into::into),
|
||||
timestamp: raw_date,
|
||||
};
|
||||
return Some(entry);
|
||||
}
|
||||
|
@ -60,3 +68,26 @@ impl FromStr for GitStash {
|
|||
})
|
||||
}
|
||||
}
|
||||
|
||||
fn parse_stash_entry(input: &str) -> (Option<&str>, &str) {
|
||||
// Try to match "WIP on <branch>: <message>" pattern
|
||||
if let Some(stripped) = input.strip_prefix("WIP on ") {
|
||||
if let Some(colon_pos) = stripped.find(": ") {
|
||||
let branch = &stripped[..colon_pos];
|
||||
let message = &stripped[colon_pos + 2..];
|
||||
return (Some(branch), message);
|
||||
}
|
||||
}
|
||||
|
||||
// Try to match "On <branch>: <message>" pattern
|
||||
if let Some(stripped) = input.strip_prefix("On ") {
|
||||
if let Some(colon_pos) = stripped.find(": ") {
|
||||
let branch = &stripped[..colon_pos];
|
||||
let message = &stripped[colon_pos + 2..];
|
||||
return (Some(branch), message);
|
||||
}
|
||||
}
|
||||
|
||||
// Edge case: format doesn't match, return None for branch and full string as message
|
||||
(None, input)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue