@matheusbsbs / matheus-bagliano / commits / ce1a79b6a7
Fork 0

tar-tree: add the "tar.umask" config option

By default, git-tar-tree(1) sets file and directories modes to 0666 or 0777. While this is both useful and acceptable for projects such as the Linux Kernel, it might be excessive for other projects. With this variable, it becomes possible to tell git-tar-tree(1) to apply a specific umask to the modes above. The special value "user" indicates that the user's current umask will be used. This should be enough for most projects, as it will lead to the same permissions as git-checkout(1) would use. The default value remains 0, which means world read-write. Signed-off-by: Willy Tarreau <w@1wt.eu> Acked-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx> Signed-off-by: Junio C Hamano <junkio@cox.net>

Willy Tarreau committed Jul 20, 2006 at 11:30 UTC ce1a79b6a74b031213d8efd4f72cb0e954e261d5
3 files changed +43 -4
Documentation/config.txt
+11
@@ -208,6 +208,17 @@ showbranch.default::
208 The default set of branches for gitlink:git-show-branch[1].
209 See gitlink:git-show-branch[1].
210
211 +tar.umask::
212 + By default, git-link:git-tar-tree[1] sets file and directories modes
213 + to 0666 or 0777. While this is both useful and acceptable for projects
214 + such as the Linux Kernel, it might be excessive for other projects.
215 + With this variable, it becomes possible to tell
216 + git-link:git-tar-tree[1] to apply a specific umask to the modes above.
217 + The special value "user" indicates that the user's current umask will
218 + be used. This should be enough for most projects, as it will lead to
219 + the same permissions as git-link:git-checkout[1] would use. The default
220 + value remains 0, which means world read-write.
221 +
222 user.email::
223 Your email address to be recorded in any newly created commits.
224 Can be overridden by the 'GIT_AUTHOR_EMAIL' and 'GIT_COMMITTER_EMAIL'
Documentation/git-tar-tree.txt
+14 -1
@@ -37,7 +37,20 @@ OPTIONS
37 Instead of making a tar archive from local repository,
38 retrieve a tar archive from a remote repository.
39
40 -Examples
40 +CONFIGURATION
41 +-------------
42 +By default, file and directories modes are set to 0666 or 0777. It is
43 +possible to change this by setting the "umask" variable in the
44 +repository configuration as follows :
45 +
46 +[tar]
47 + umask = 002 ;# group friendly
48 +
49 +The special umask value "user" indicates that the user's current umask
50 +will be used instead. The default value remains 0, which means world
51 +readable/writable files and directories.
52 +
53 +EXAMPLES
54 --------
55 git tar-tree HEAD junk | (cd /var/tmp/ && tar xf -)::
56
builtin-tar-tree.c
+18 -3
@@ -20,6 +20,7 @@ static char block[BLOCKSIZE];
20 static unsigned long offset;
21
22 static time_t archive_time;
23 +static int tar_umask;
24
25 /* tries hard to write, either succeeds or dies in the attempt */
26 static void reliable_write(const void *data, unsigned long size)
@@ -188,13 +189,13 @@ static void write_entry(const unsigned char *sha1, struct strbuf *path,
189 } else {
190 if (S_ISDIR(mode)) {
191 *header.typeflag = TYPEFLAG_DIR;
191 - mode |= 0777;
192 + mode = (mode | 0777) & ~tar_umask;
193 } else if (S_ISLNK(mode)) {
194 *header.typeflag = TYPEFLAG_LNK;
195 mode |= 0777;
196 } else if (S_ISREG(mode)) {
197 *header.typeflag = TYPEFLAG_REG;
197 - mode |= (mode & 0100) ? 0777 : 0666;
198 + mode = (mode | ((mode & 0100) ? 0777 : 0666)) & ~tar_umask;
199 } else {
200 error("unsupported file mode: 0%o (SHA1: %s)",
201 mode, sha1_to_hex(sha1));
@@ -293,6 +294,20 @@ static void traverse_tree(struct tree_desc *tree, struct strbuf *path)
294 }
295 }
296
297 +int git_tar_config(const char *var, const char *value)
298 +{
299 + if (!strcmp(var, "tar.umask")) {
300 + if (!strcmp(value, "user")) {
301 + tar_umask = umask(0);
302 + umask(tar_umask);
303 + } else {
304 + tar_umask = git_config_int(var, value);
305 + }
306 + return 0;
307 + }
308 + return git_default_config(var, value);
309 +}
310 +
311 static int generate_tar(int argc, const char **argv, char** envp)
312 {
313 unsigned char sha1[20], tree_sha1[20];
@@ -305,7 +320,7 @@ static int generate_tar(int argc, const char **argv, char** envp)
320 current_path.len = current_path.eof = 0;
321
322 setup_git_directory();
308 - git_config(git_default_config);
323 + git_config(git_tar_config);
324
325 switch (argc) {
326 case 3: