Fix path when branch has a / in it
We now just replace the current_path by using the rev instead of doing sketchy logic splitting on /
parent: tbd commit: d1b0ff7
Showing 1 changed file with 15 insertions and 6 deletions
giterated-daemon/src/backend/git.rs
@@ -278,6 +278,8 @@ impl GitBackend { | ||
278 | 278 | git: &git2::Repository, |
279 | 279 | start_commit: &git2::Commit, |
280 | 280 | ) -> anyhow::Result<Commit> { |
281 | trace!("Getting last commit for file: {}", path); | |
282 | ||
281 | 283 | let mut revwalk = git.revwalk()?; |
282 | 284 | revwalk.set_sorting(git2::Sort::TIME)?; |
283 | 285 | revwalk.push(start_commit.id())?; |
@@ -514,7 +516,8 @@ impl RepositoryBackend for GitBackend { | ||
514 | 516 | let commit = git.find_commit(tree_id).unwrap(); |
515 | 517 | |
516 | 518 | // this is stupid |
517 | let mut current_path = request.rev.clone().unwrap_or_else(|| "master".to_string()); | |
519 | let rev = request.rev.clone().unwrap_or_else(|| "master".to_string()); | |
520 | let mut current_path = rev.clone(); | |
518 | 521 | |
519 | 522 | // Get the commit tree |
520 | 523 | let git_tree = if let Some(path) = &request.path { |
@@ -559,16 +562,22 @@ impl RepositoryBackend for GitBackend { | ||
559 | 562 | tree_entry.size = Some(blob.size()); |
560 | 563 | } |
561 | 564 | |
562 | // Could possibly be done better | |
563 | let path = if let Some(path) = current_path.split_once('/') { | |
564 | format!("{}/{}", path.1, entry.name().unwrap()) | |
565 | } else { | |
565 | // Get the path to the folder the file is in by removing the rev from current_path | |
566 | let mut path = current_path.replace(&rev, ""); | |
567 | if path.starts_with('/') { | |
568 | path.remove(0); | |
569 | } | |
570 | ||
571 | // Format it as the path + file name | |
572 | let full_path = if path.is_empty() { | |
566 | 573 | entry.name().unwrap().to_string() |
574 | } else { | |
575 | format!("{}/{}", path, entry.name().unwrap()) | |
567 | 576 | }; |
568 | 577 | |
569 | 578 | // Get the last commit made to the entry |
570 | 579 | if let Ok(last_commit) = |
571 | GitBackend::get_last_commit_of_file(&path, &git, &commit) | |
580 | GitBackend::get_last_commit_of_file(&full_path, &git, &commit) | |
572 | 581 | { |
573 | 582 | tree_entry.last_commit = Some(last_commit); |
574 | 583 | } |