summary history branches tags files
commit:4f664e779618b0473658b60457369386d867b20f
author:Trevor Bentley
committer:Trevor Bentley
date:Wed Jan 11 22:43:21 2023 +0100
parents:6ab59fc4e9b6339afd863da66c7d02fc7405cd4b
fix incorrect file names/paths
diff --git a/src/main.rs b/src/main.rs
line changes: +4/-6
index 67208dc..67d87cb
--- a/src/main.rs
+++ b/src/main.rs
@@ -166,7 +166,8 @@ fn walk_file_tree(repo: &git2::Repository, rev: &str, files: &mut Vec<GitFile>,
     let obj = repo.revparse_single(rev)?;
     let tree = obj.peel_to_tree()?;
     for entry in tree.iter() {
-        let name = prefix.to_string() + entry.name().unwrap_or_default();
+        let name = entry.name().unwrap_or_default().to_string();
+        let path = prefix.to_string() + entry.name().unwrap_or_default();
         let kind = match entry.kind() {
             Some(git2::ObjectType::Tree) => "dir",
             Some(git2::ObjectType::Blob) => "file",
@@ -183,10 +184,7 @@ fn walk_file_tree(repo: &git2::Repository, rev: &str, files: &mut Vec<GitFile>,
         files.push(GitFile {
             id: entry.id().to_string(),
             name: name.clone(),
-            path: match depth {
-                0 => name.to_string(),
-                _ => format!("{}/{}", prefix, name),
-            },
+            path: path.clone(),
             kind: kind.to_string(),
             mode: entry.filemode(),
             is_binary,
@@ -197,7 +195,7 @@ fn walk_file_tree(repo: &git2::Repository, rev: &str, files: &mut Vec<GitFile>,
             contents_preformatted: true,
         });
         if recurse && depth < (max_depth - 1) && entry.kind() == Some(git2::ObjectType::Tree) {
-            let prefix = name + "/";
+            let prefix = path + "/";
             walk_file_tree(repo, &entry.id().to_string(), files,
                            depth+1, max_depth, true, &prefix)?;
         }