Skip to content

Commit 473d404

Browse files
author
Junio C Hamano
committed
tar-tree: file/dirmode fix.
This fixes two bugs introduced when we switched to generic tree traversal code. (1) directory mode recorded silently became 0755, not 0777 (2) if passed a tree object (not a commit), it emitted an alarming error message (but proceeded anyway). Signed-off-by: Junio C Hamano <junkio@cox.net>
1 parent 1142038 commit 473d404

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

tar-tree.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -304,9 +304,11 @@ static void write_header(const unsigned char *sha1, char typeflag, const char *b
304304
}
305305

306306
if (S_ISDIR(mode))
307-
mode |= 0755; /* GIT doesn't store permissions of dirs */
308-
if (S_ISLNK(mode))
309-
mode |= 0777; /* ... nor of symlinks */
307+
mode |= 0777;
308+
else if (S_ISREG(mode))
309+
mode |= (mode & 0100) ? 0777 : 0666;
310+
else if (S_ISLNK(mode))
311+
mode |= 0777;
310312
sprintf(&header[100], "%07o", mode & 07777);
311313

312314
/* XXX: should we provide more meaningful info here? */
@@ -391,7 +393,7 @@ int main(int argc, char **argv)
391393
usage(tar_tree_usage);
392394
}
393395

394-
commit = lookup_commit_reference(sha1);
396+
commit = lookup_commit_reference_gently(sha1, 1);
395397
if (commit) {
396398
write_global_extended_header(commit->object.sha1);
397399
archive_time = commit->date;

0 commit comments

Comments
 (0)