-
I want get a file's last commit date, how do I get it? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 8 replies
-
|
Beta Was this translation helpful? Give feedback.
-
thanks, I'll try it later😃
…________________________________
From: Sebastian Thiel ***@***.***>
Sent: Wednesday, May 24, 2023 7:16:25 PM
To: Byron/gitoxide ***@***.***>
Cc: DragonBillow ***@***.***>; Author ***@***.***>
Subject: Re: [Byron/gitoxide] How do I get commit info by gix? (Discussion #859)
One can retrieve the message of a commit with the Commit::message()<https://docs.rs/gix/0.44.1/gix/struct.Commit.html#method.message> method.
—
Reply to this email directly, view it on GitHub<#859 (reply in thread)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AKBJ6AOFBDJ3XCEUCTJQSMDXHXUYTANCNFSM6AAAAAAYL6454U>.
You are receiving this because you authored the thread.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
thanks to #613 , then I'm able to get all file's last modify time: fn new(repo_dir: &str) -> Option<Self> {
let repo = ThreadSafeRepository::discover(repo_dir)
.ok()?
.to_thread_local();
let rewalk = repo.rev_walk(Some(repo.head_id().unwrap().detach()));
let mut changes = rewalk.all().ok()?.filter_map(Result::ok);
let mut mtimes: HashMap<String, u32> = HashMap::new();
let mut last = Self::id_to_commit(changes.next()?.id())?;
for next in changes {
let next_shad = Self::id_to_commit(next.id()).unwrap();
match Self::change_from_commit(&last, Some(&next_shad)) {
Some((time, set)) => {
set.iter().for_each(|filename| {
mtimes.entry(filename.into()).or_insert_with(|| time);
});
}
None => {}
}
last = next_shad;
}
let systime = std::time::SystemTime::UNIX_EPOCH
.checked_add(Duration::new(
last.time().ok()?.seconds_since_unix_epoch as u64,
0,
))
.unwrap();
let default_time: chrono::DateTime<Utc> = systime.into();
}
fn id_to_commit(id: Id) -> Option<Commit> {
let object = id.try_object().ok()?;
let object = object.expect("empty");
let commit = object.try_into_commit().ok()?;
Some(commit)
}
fn change_from_commit(last: &Commit, next: Option<&Commit>) -> Option<(u32, HashSet<String>)> {
let tree = last.tree().ok()?;
let mut changes = tree.changes().ok()?;
let changes = changes.track_path();
let last_tree = next?.tree().ok()?;
let mut filenames = HashSet::new();
changes
.for_each_to_obtain_tree(
&last_tree,
|change| -> Result<gix::object::tree::diff::Action, _> {
let is_file_change = match change.event {
Event::Deletion {
entry_mode: _,
id: _,
} => false,
_ => true,
};
if is_file_change {
let path = change.location.to_os_str().unwrap().to_string_lossy();
filenames.insert(format!("{}", path));
}
Ok::<Action, Utf8Error>(Action::Continue)
},
)
.ok()?;
let time = last.time().ok()?;
Some((time.seconds_since_unix_epoch, filenames))
} But as an interesting result, the original author's code has a big performance problem, I don't quite understand why when I delay id_to_commit, the performance has been greatly improved (before it was about the same speed as fork git, now it is close to libgit2) just like rust-lang/git2-rs#588 (comment) , This code also has a problem with the first submission, I simply save the time of the first submission, and all files that are not found use this time。 |
Beta Was this translation helpful? Give feedback.
thanks to #613 , then I'm able to get all file's last modify time: