mirror of
https://github.com/gitbutlerapp/gitbutler.git
synced 2024-12-23 09:33:01 +03:00
Merge pull request #481 from gitbutlerapp/sc-vbranch-commits
Send mtime with hunk
This commit is contained in:
commit
c109a91dc5
@ -5,6 +5,7 @@ pub mod target;
|
||||
use std::{collections::HashMap, time, vec};
|
||||
|
||||
use anyhow::{Context, Result};
|
||||
use filetime::FileTime;
|
||||
use serde::Serialize;
|
||||
|
||||
pub use branch::Branch;
|
||||
@ -256,6 +257,7 @@ pub fn get_status_by_branch(
|
||||
let mut last_path = String::new();
|
||||
let mut last_hunk_id = String::new();
|
||||
let mut hunk_numbers = String::new();
|
||||
let mut mtimes = HashMap::new();
|
||||
|
||||
diff.print(git2::DiffFormat::Patch, |delta, hunk, line| {
|
||||
if let Some(hunk) = hunk {
|
||||
@ -269,13 +271,33 @@ pub fn get_status_by_branch(
|
||||
.unwrap()
|
||||
.to_string();
|
||||
|
||||
let mtime = match mtimes.get(&new_path) {
|
||||
Some(mtime) => *mtime,
|
||||
None => {
|
||||
let file_path = project_repository
|
||||
.git_repository
|
||||
.workdir()
|
||||
.unwrap()
|
||||
.join(new_path.clone());
|
||||
|
||||
let metadata = file_path.metadata().unwrap();
|
||||
let mtime = FileTime::from_last_modification_time(&metadata);
|
||||
println!("mtime: {:?}", mtime);
|
||||
// convert seconds and nanoseconds to milliseconds
|
||||
let mtime = (mtime.seconds() as u128 * 1000) as u128;
|
||||
println!("mtime: {:?}", mtime);
|
||||
mtimes.insert(new_path.clone(), mtime);
|
||||
mtime
|
||||
}
|
||||
};
|
||||
|
||||
let hunk_id = format!("{}:{}", new_path, hunk_numbers);
|
||||
if hunk_id != last_hunk_id {
|
||||
let hunk = VirtualBranchHunk {
|
||||
id: last_hunk_id.clone(),
|
||||
name: "".to_string(),
|
||||
diff: results.clone(),
|
||||
modified_at: 0,
|
||||
modified_at: mtime,
|
||||
file_path: last_path.clone(),
|
||||
};
|
||||
hunks.push(hunk);
|
||||
|
Loading…
Reference in New Issue
Block a user