fix file tree handling
Do not forget to keep previous path when recursing or we end up with filenames only.
1 files changed, 10 insertions(+), 8 deletions(-) | |||
---|---|---|---|
M | stagit.c | +10 | -8 |
1@@ -662,8 +662,8 @@ int
2 writefilestree(FILE *fp, git_tree *tree, const char *branch, const char *path)
3 {
4 const git_tree_entry *entry = NULL;
5- const char *filename;
6- char filepath[PATH_MAX];
7+ const char *entryname;
8+ char filepath[PATH_MAX], entrypath[PATH_MAX];
9 git_object *obj = NULL;
10 git_off_t filesize;
11 size_t count, i;
12@@ -674,14 +674,16 @@ writefilestree(FILE *fp, git_tree *tree, const char *branch, const char *path)
13 if (!(entry = git_tree_entry_byindex(tree, i)) ||
14 git_tree_entry_to_object(&obj, repo, entry))
15 return -1;
16- filename = git_tree_entry_name(entry);
17+ entryname = git_tree_entry_name(entry);
18+ snprintf(entrypath, sizeof(entrypath), "%s%s%s",
19+ path, path[0] ? "/" : "", entryname);
20 switch (git_object_type(obj)) {
21 case GIT_OBJ_BLOB:
22 break;
23 case GIT_OBJ_TREE:
24 /* NOTE: recurses */
25 ret = writefilestree(fp, (git_tree *)obj, branch,
26- filename);
27+ entrypath);
28 git_object_free(obj);
29 if (ret)
30 return ret;
31@@ -692,18 +694,18 @@ writefilestree(FILE *fp, git_tree *tree, const char *branch, const char *path)
32 }
33 if (path[0])
34 snprintf(filepath, sizeof(filepath), "file/%s/%s.html",
35- path, filename);
36+ path, entryname);
37 else
38 snprintf(filepath, sizeof(filepath), "file/%s.html",
39- filename);
40+ entryname);
41 filesize = git_blob_rawsize((git_blob *)obj);
42
43- lc = writeblob(obj, filepath, filename, filesize);
44+ lc = writeblob(obj, filepath, entryname, filesize);
45
46 fputs("<tr><td>", fp);
47 fputs(filemode(git_tree_entry_filemode(entry)), fp);
48 fprintf(fp, "</td><td><a href=\"%s%s\">", relpath, filepath);
49- xmlencode(fp, filename, strlen(filename));
50+ xmlencode(fp, entrypath, strlen(entrypath));
51 fputs("</a></td><td class=\"num\">", fp);
52 if (showlinecount && lc > 0)
53 fprintf(fp, "%dL", lc);