@matheusbsbs / matheus-bagliano / commits / 78a8d641c1
Fork 0

Add core.symlinks to mark filesystems that do not support symbolic links.

Some file systems that can host git repositories and their working copies do not support symbolic links. But then if the repository contains a symbolic link, it is impossible to check out the working copy. This patch enables partial support of symbolic links so that it is possible to check out a working copy on such a file system. A new flag core.symlinks (which is true by default) can be set to false to indicate that the filesystem does not support symbolic links. In this case, symbolic links that exist in the trees are checked out as small plain files, and checking in modifications of these files preserve the symlink property in the database (as long as an entry exists in the index). Of course, this does not magically make symbolic links work on such defective file systems; hence, this solution does not help if the working copy relies on that an entry is a real symbolic link. Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at> Signed-off-by: Junio C Hamano <junkio@cox.net>

Johannes Sixt committed Mar 2, 2007 at 22:11 UTC 78a8d641c14dc2f0a306d787fa1e42d400b3af4d
12 files changed +101 -12
Documentation/config.txt
+7
@@ -117,6 +117,13 @@ core.fileMode::
117 the working copy are ignored; useful on broken filesystems like FAT.
118 See gitlink:git-update-index[1]. True by default.
119
120 +core.symlinks::
121 + If false, symbolic links are checked out as small plain files that
122 + contain the link text. gitlink:git-update-index[1] and
123 + gitlink:git-add[1] will not change the recorded type to regular
124 + file. Useful on filesystems like FAT that do not support
125 + symbolic links. True by default.
126 +
127 core.gitProxy::
128 A "proxy command" to execute (as 'command host port') instead
129 of establishing direct connection to the remote server when
Documentation/git-update-index.txt
+5
@@ -295,6 +295,11 @@ in the index and the file mode on the filesystem if they differ only on
295 executable bit. On such an unfortunate filesystem, you may
296 need to use `git-update-index --chmod=`.
297
298 +Quite similarly, if `core.symlinks` configuration variable is set
299 +to 'false' (see gitlink:git-config[1]), symbolic links are checked out
300 +as plain files, and this command does not modify a recorded file mode
301 +from symbolic link to regular file.
302 +
303 The command looks at `core.ignorestat` configuration variable. See
304 'Using "assume unchanged" bit' section above.
305
builtin-apply.c
+1 -1
@@ -2359,7 +2359,7 @@ static int try_create_file(const char *path, unsigned int mode, const char *buf,
2359 char *nbuf;
2360 unsigned long nsize;
2361
2362 - if (S_ISLNK(mode))
2362 + if (has_symlinks && S_ISLNK(mode))
2363 /* Although buf:size is counted string, it also is NUL
2364 * terminated.
2365 */
builtin-update-index.c
+3 -3
@@ -109,11 +109,11 @@ static int add_file_to_cache(const char *path)
109 ce->ce_flags = htons(namelen);
110 fill_stat_cache_info(ce, &st);
111
112 - if (trust_executable_bit)
112 + if (trust_executable_bit && has_symlinks)
113 ce->ce_mode = create_ce_mode(st.st_mode);
114 else {
115 - /* If there is an existing entry, pick the mode bits
116 - * from it, otherwise assume unexecutable.
115 + /* If there is an existing entry, pick the mode bits and type
116 + * from it, otherwise assume unexecutable regular file.
117 */
118 struct cache_entry *ent;
119 int pos = cache_name_pos(path, namelen);
cache.h
+5 -1
@@ -108,7 +108,10 @@ static inline unsigned int create_ce_mode(unsigned int mode)
108 }
109 static inline unsigned int ce_mode_from_stat(struct cache_entry *ce, unsigned int mode)
110 {
111 - extern int trust_executable_bit;
111 + extern int trust_executable_bit, has_symlinks;
112 + if (!has_symlinks && S_ISREG(mode) &&
113 + ce && S_ISLNK(ntohl(ce->ce_mode)))
114 + return ce->ce_mode;
115 if (!trust_executable_bit && S_ISREG(mode)) {
116 if (ce && S_ISREG(ntohl(ce->ce_mode)))
117 return ce->ce_mode;
@@ -215,6 +218,7 @@ extern int delete_ref(const char *, unsigned char *sha1);
218 /* Environment bits from configuration mechanism */
219 extern int use_legacy_headers;
220 extern int trust_executable_bit;
221 +extern int has_symlinks;
222 extern int assume_unchanged;
223 extern int prefer_symlink_refs;
224 extern int log_all_ref_updates;
config.c
+5
@@ -269,6 +269,11 @@ int git_default_config(const char *var, const char *value)
269 return 0;
270 }
271
272 + if (!strcmp(var, "core.symlinks")) {
273 + has_symlinks = git_config_bool(var, value);
274 + return 0;
275 + }
276 +
277 if (!strcmp(var, "core.bare")) {
278 is_bare_repository_cfg = git_config_bool(var, value);
279 return 0;
diff-lib.c
+3
@@ -346,6 +346,9 @@ int run_diff_files(struct rev_info *revs, int silent_on_removed)
346 S_ISREG(newmode) && S_ISREG(oldmode) &&
347 ((newmode ^ oldmode) == 0111))
348 newmode = oldmode;
349 + else if (!has_symlinks &&
350 + S_ISREG(newmode) && S_ISLNK(oldmode))
351 + newmode = oldmode;
352 diff_change(&revs->diffopt, oldmode, newmode,
353 ce->sha1, (changed ? null_sha1 : ce->sha1),
354 ce->name, NULL);
entry.c
+6 -3
@@ -111,9 +111,12 @@ static int write_entry(struct cache_entry *ce, char *path, struct checkout *stat
111 return error("git-checkout-index: unable to write file %s", path);
112 break;
113 case S_IFLNK:
114 - if (to_tempfile) {
115 - strcpy(path, ".merge_link_XXXXXX");
116 - fd = mkstemp(path);
114 + if (to_tempfile || !has_symlinks) {
115 + if (to_tempfile) {
116 + strcpy(path, ".merge_link_XXXXXX");
117 + fd = mkstemp(path);
118 + } else
119 + fd = create_file(path, 0666);
120 if (fd < 0) {
121 free(new);
122 return error("git-checkout-index: unable to create "
environment.c
+1
@@ -13,6 +13,7 @@ char git_default_email[MAX_GITNAME];
13 char git_default_name[MAX_GITNAME];
14 int use_legacy_headers = 1;
15 int trust_executable_bit = 1;
16 +int has_symlinks = 1;
17 int assume_unchanged;
18 int prefer_symlink_refs;
19 int is_bare_repository_cfg = -1; /* unspecified */
read-cache.c
+6 -4
@@ -125,7 +125,9 @@ static int ce_match_stat_basic(struct cache_entry *ce, struct stat *st)
125 changed |= MODE_CHANGED;
126 break;
127 case S_IFLNK:
128 - changed |= !S_ISLNK(st->st_mode) ? TYPE_CHANGED : 0;
128 + if (!S_ISLNK(st->st_mode) &&
129 + (has_symlinks || !S_ISREG(st->st_mode)))
130 + changed |= TYPE_CHANGED;
131 break;
132 default:
133 die("internal error: ce_mode is %o", ntohl(ce->ce_mode));
@@ -344,11 +346,11 @@ int add_file_to_index(const char *path, int verbose)
346 ce->ce_flags = htons(namelen);
347 fill_stat_cache_info(ce, &st);
348
347 - if (trust_executable_bit)
349 + if (trust_executable_bit && has_symlinks)
350 ce->ce_mode = create_ce_mode(st.st_mode);
351 else {
350 - /* If there is an existing entry, pick the mode bits
351 - * from it, otherwise assume unexecutable.
352 + /* If there is an existing entry, pick the mode bits and type
353 + * from it, otherwise assume unexecutable regular file.
354 */
355 struct cache_entry *ent;
356 int pos = cache_name_pos(path, namelen);
t/t2005-checkout-index-symlinks.sh new
+28
@@ -0,0 +1,28 @@
1 +#!/bin/sh
2 +#
3 +# Copyright (c) 2007 Johannes Sixt
4 +#
5 +
6 +test_description='git-checkout-index on filesystem w/o symlinks test.
7 +
8 +This tests that git-checkout-index creates a symbolic link as a plain
9 +file if core.symlinks is false.'
10 +
11 +. ./test-lib.sh
12 +
13 +test_expect_success \
14 +'preparation' '
15 +git-config core.symlinks false &&
16 +l=$(echo -n file | git-hash-object -t blob -w --stdin) &&
17 +echo "120000 $l symlink" | git-update-index --index-info'
18 +
19 +test_expect_success \
20 +'the checked-out symlink must be a file' '
21 +git-checkout-index symlink &&
22 +test -f symlink'
23 +
24 +test_expect_success \
25 +'the file must be the blob we added during the setup' '
26 +test "$(git-hash-object -t blob symlink)" = $l'
27 +
28 +test_done
t/t2102-update-index-symlinks.sh new
+31
@@ -0,0 +1,31 @@
1 +#!/bin/sh
2 +#
3 +# Copyright (c) 2007 Johannes Sixt
4 +#
5 +
6 +test_description='git-update-index on filesystem w/o symlinks test.
7 +
8 +This tests that git-update-index keeps the symbolic link property
9 +even if a plain file is in the working tree if core.symlinks is false.'
10 +
11 +. ./test-lib.sh
12 +
13 +test_expect_success \
14 +'preparation' '
15 +git-config core.symlinks false &&
16 +l=$(echo -n file | git-hash-object -t blob -w --stdin) &&
17 +echo "120000 $l symlink" | git-update-index --index-info'
18 +
19 +test_expect_success \
20 +'modify the symbolic link' '
21 +echo -n new-file > symlink &&
22 +git-update-index symlink'
23 +
24 +test_expect_success \
25 +'the index entry must still be a symbolic link' '
26 +case "`git-ls-files --stage --cached symlink`" in
27 +120000" "*symlink) echo ok;;
28 +*) echo fail; git-ls-files --stage --cached symlink; (exit 1);;
29 +esac'
30 +
31 +test_done