diff --git a/giterated-daemon/src/backend/git.rs b/giterated-daemon/src/backend/git.rs index a9861c2..4eaa5ce 100644 --- a/giterated-daemon/src/backend/git.rs +++ b/giterated-daemon/src/backend/git.rs @@ -278,6 +278,8 @@ impl GitBackend { git: &git2::Repository, start_commit: &git2::Commit, ) -> anyhow::Result { + trace!("Getting last commit for file: {}", path); + let mut revwalk = git.revwalk()?; revwalk.set_sorting(git2::Sort::TIME)?; revwalk.push(start_commit.id())?; @@ -514,7 +516,8 @@ impl RepositoryBackend for GitBackend { let commit = git.find_commit(tree_id).unwrap(); // this is stupid - let mut current_path = request.rev.clone().unwrap_or_else(|| "master".to_string()); + let rev = request.rev.clone().unwrap_or_else(|| "master".to_string()); + let mut current_path = rev.clone(); // Get the commit tree let git_tree = if let Some(path) = &request.path { @@ -559,16 +562,22 @@ impl RepositoryBackend for GitBackend { tree_entry.size = Some(blob.size()); } - // Could possibly be done better - let path = if let Some(path) = current_path.split_once('/') { - format!("{}/{}", path.1, entry.name().unwrap()) - } else { + // Get the path to the folder the file is in by removing the rev from current_path + let mut path = current_path.replace(&rev, ""); + if path.starts_with('/') { + path.remove(0); + } + + // Format it as the path + file name + let full_path = if path.is_empty() { entry.name().unwrap().to_string() + } else { + format!("{}/{}", path, entry.name().unwrap()) }; // Get the last commit made to the entry if let Ok(last_commit) = - GitBackend::get_last_commit_of_file(&path, &git, &commit) + GitBackend::get_last_commit_of_file(&full_path, &git, &commit) { tree_entry.last_commit = Some(last_commit); }