{"thread":{"id":"7072","subject":"[PATCH 1/2] Handle core.symlinks=false case in merge-recursive.","startedAt":"2007-03-03T19:32:46Z","lastAt":"2007-03-04T03:42:06Z","messageCount":7,"participants":["Johannes Sixt","Johannes Schindelin","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"36198","messageId":"200703032032.47158.johannes.sixt@telecom.at","threadId":"7072","inReplyTo":null,"subject":"[PATCH 1/2] Handle core.symlinks=false case in merge-recursive.","fromName":"Johannes Sixt","fromEmail":"johannes.sixt@telecom.at","sentAt":"2007-03-03T19:32:46Z","receivedAt":"2007-03-03T19:32:46Z","isPatch":true,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"If the file system does not support symbolic links (core.symlinks=false),\nmerge-recursive must write the merged symbolic link text into a regular\nfile.\n\nWhile we are here, fix a tiny memory leak in the if-branch that writes\nreal symbolic links.\n\nSigned-off-by: Johannes Sixt <johannes.sixt@telecom.at>\n---\n merge-recursive.c         |    3 +-\n t/t6025-merge-symlinks.sh |   62 +++++++++++++++++++++++++++++++++++++++++++++\n 2 files changed, 64 insertions(+), 1 deletions(-)\n create mode 100644 t/t6025-merge-symlinks.sh\n\ndiff --git a/merge-recursive.c b/merge-recursive.c\nindex 397a7ad..f8be72e 100644\n--- a/merge-recursive.c\n+++ b/merge-recursive.c\n@@ -570,7 +570,7 @@ static void update_file_flags(const unsigned char *sha,\n \t\tif (strcmp(type, blob_type) != 0)\n \t\t\tdie(\"blob expected for %s '%s'\", sha1_to_hex(sha), path);\n \n-\t\tif (S_ISREG(mode)) {\n+\t\tif (S_ISREG(mode) || (!has_symlinks && S_ISLNK(mode))) {\n \t\t\tint fd;\n \t\t\tif (mkdir_p(path, 0777))\n \t\t\t\tdie(\"failed to create path %s: %s\", path, strerror(errno));\n@@ -591,6 +591,7 @@ static void update_file_flags(const unsigned char *sha,\n \t\t\tmkdir_p(path, 0777);\n \t\t\tunlink(path);\n \t\t\tsymlink(lnk, path);\n+\t\t\tfree(lnk);\n \t\t} else\n \t\t\tdie(\"do not know what to do with %06o %s '%s'\",\n \t\t\t    mode, sha1_to_hex(sha), path);\ndiff --git a/t/t6025-merge-symlinks.sh b/t/t6025-merge-symlinks.sh\nnew file mode 100644\nindex 0000000..3c1a697\n--- /dev/null\n+++ b/t/t6025-merge-symlinks.sh\n@@ -0,0 +1,62 @@\n+#!/bin/sh\n+#\n+# Copyright (c) 2007 Johannes Sixt\n+#\n+\n+test_description='merging symlinks on filesystem w/o symlink support.\n+\n+This tests that git-merge-recursive writes merge results as plain files\n+if core.symlinks is false.'\n+\n+. ./test-lib.sh\n+\n+test_expect_success \\\n+'setup' '\n+git-config core.symlinks false &&\n+> file &&\n+git-add file &&\n+git-commit -m initial &&\n+git-branch b-symlink &&\n+git-branch b-file &&\n+l=$(echo -n file | git-hash-object -t blob -w --stdin) &&\n+echo \"120000 $l\tsymlink\" | git-update-index --index-info &&\n+git-commit -m master &&\n+git-checkout b-symlink &&\n+l=$(echo -n file-different | git-hash-object -t blob -w --stdin) &&\n+echo \"120000 $l\tsymlink\" | git-update-index --index-info &&\n+git-commit -m b-symlink &&\n+git-checkout b-file &&\n+echo plain-file > symlink &&\n+git-add symlink &&\n+git-commit -m b-file'\n+\n+test_expect_failure \\\n+'merge master into b-symlink, which has a different symbolic link' '\n+! git-checkout b-symlink ||\n+git-merge master'\n+\n+test_expect_success \\\n+'the merge result must be a file' '\n+test -f symlink'\n+\n+test_expect_failure \\\n+'merge master into b-file, which has a file instead of a symbolic link' '\n+! (git-reset --hard &&\n+git-checkout b-file) ||\n+git-merge master'\n+\n+test_expect_success \\\n+'the merge result must be a file' '\n+test -f symlink'\n+\n+test_expect_failure \\\n+'merge b-file, which has a file instead of a symbolic link, into master' '\n+! (git-reset --hard &&\n+git-checkout master) ||\n+git-merge b-file'\n+\n+test_expect_success \\\n+'the merge result must be a file' '\n+test -f symlink'\n+\n+test_done\n-- \n1.5.0.2.4.gdd4e4-dirty\n"},{"id":"36199","messageId":"200703032038.00928.johannes.sixt@telecom.at","threadId":"7072","inReplyTo":"200703032032.47158.johannes.sixt@telecom.at","subject":"[PATCH 2/2] Tell multi-parent diff about core.symlinks.","fromName":"Johannes Sixt","fromEmail":"johannes.sixt@telecom.at","sentAt":"2007-03-03T19:38:00Z","receivedAt":"2007-03-03T19:38:00Z","isPatch":true,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"When core.symlinks is false, and a merge of symbolic links had conflicts,\nthe merge result is left as a file in the working directory. A decision\nmust be made whether the file is treated as a regular file or as a\nsymbolic link. This patch treats the file as a symbolic link only if\nall merge parents were also symbolic links.\n\nSigned-off-by: Johannes Sixt <johannes.sixt@telecom.at>\n---\n\nI'm not quite sure whether this patch is worth it. The only thing it seems\nto do is to avoid the mode change line (this is after a merge where 'symlink'\nhad a conflict):\n\nwithout the patch:\n\n  $ git diff\n  diff --cc symlink\n  index 1a010b1,30d67d4..0000000\n  mode 120000,120000..100644\n  --- a/symlink\n  +++ b/symlink\n\nwith the patch:\n\n  $ git diff\n  diff --cc symlink\n  index 1a010b1,30d67d4..0000000\n  --- a/symlink\n  +++ b/symlink\n\n\n combine-diff.c |   10 ++++++++++\n 1 files changed, 10 insertions(+), 0 deletions(-)\n\ndiff --git a/combine-diff.c b/combine-diff.c\nindex 044633d..e6e3969 100644\n--- a/combine-diff.c\n+++ b/combine-diff.c\n@@ -699,8 +699,18 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,\n \t\t\t !fstat(fd, &st)) {\n \t\t\tsize_t len = st.st_size;\n \t\t\tsize_t sz = 0;\n+\t\t\tint is_file, i;\n \n \t\t\telem->mode = canon_mode(st.st_mode);\n+\t\t\t/* if symlinks don't work, assume symlink if all parents\n+\t\t\t * are symlinks\n+\t\t\t */\n+\t\t\tis_file = has_symlinks;\n+\t\t\tfor (i = 0; !is_file && i < num_parent; i++)\n+\t\t\t\tis_file = !S_ISLNK(elem->parent[i].mode);\n+\t\t\tif (!is_file)\n+\t\t\t\telem->mode = canon_mode(S_IFLNK);\n+\n \t\t\tresult_size = len;\n \t\t\tresult = xmalloc(len + 1);\n \t\t\twhile (sz < len) {\n-- \n1.5.0.2.4.gdd4e4-dirty\n"},{"id":"36201","messageId":"Pine.LNX.4.63.0703032110200.22628@wbgn013.biozentrum.uni-wuerzburg.de","threadId":"7072","inReplyTo":"200703032032.47158.johannes.sixt@telecom.at","subject":"Re: [PATCH 1/2] Handle core.symlinks=false case in merge-recursive.","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2007-03-03T20:11:58Z","receivedAt":"2007-03-03T20:11:58Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Sat, 3 Mar 2007, Johannes Sixt wrote:\n\n> If the file system does not support symbolic links \n> (core.symlinks=false), merge-recursive must write the merged symbolic \n> link text into a regular file.\n\nI think regardless of the value of core.symlinks, merging symbolic links \ndoes not make sense at all.\n\nI'd suggest having two versions of the symlÃ¶ink/file, <name>Ã~ours and \n<name>~theirs instead.\n\nCiao,\nDscho\n"},{"id":"36202","messageId":"200703032121.59468.johannes.sixt@telecom.at","threadId":"7072","inReplyTo":"200703032032.47158.johannes.sixt@telecom.at","subject":"Re: [PATCH 1/2] Handle core.symlinks=false case in merge-recursive.","fromName":"Johannes Sixt","fromEmail":"johannes.sixt@telecom.at","sentAt":"2007-03-03T20:21:59Z","receivedAt":"2007-03-03T20:21:59Z","isPatch":true,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"On Saturday 03 March 2007 20:32, Johannes Sixt wrote:\n> If the file system does not support symbolic links (core.symlinks=false),\n> merge-recursive must write the merged symbolic link text into a regular\n> file.\n\nBut how to resolve such a conflict if core.symlinks=false?\n\nIt turns out that git-add cannot honor the symlink property recorded in the \nindex because read_cache.c:add_file_to_index() will find only entries at \nstage 0, but the conflicting entries are at stages 2 and 3. Can there be \nsomething done about that?\n\n-- Hannes\n"},{"id":"36204","messageId":"200703032139.12869.johannes.sixt@telecom.at","threadId":"7072","inReplyTo":"Pine.LNX.4.63.0703032110200.22628@wbgn013.biozentrum.uni-wuerzburg.de","subject":"Re: [PATCH 1/2] Handle core.symlinks=false case in merge-recursive.","fromName":"Johannes Sixt","fromEmail":"johannes.sixt@telecom.at","sentAt":"2007-03-03T20:39:12Z","receivedAt":"2007-03-03T20:39:12Z","isPatch":true,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"On Saturday 03 March 2007 21:11, Johannes Schindelin wrote:\n> I think regardless of the value of core.symlinks, merging symbolic links\n> does not make sense at all.\n\nNo doubt about that. Currently, the version of the \"current\" branch remains in \nthe working tree. My patch does not change this behavior at all, it just does \nnot call symlink(2), but allocates a regular file.\n\n-- Hannes\n"},{"id":"36205","messageId":"Pine.LNX.4.63.0703032143350.22628@wbgn013.biozentrum.uni-wuerzburg.de","threadId":"7072","inReplyTo":"200703032139.12869.johannes.sixt@telecom.at","subject":"Re: [PATCH 1/2] Handle core.symlinks=false case in merge-recursive.","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2007-03-03T20:44:16Z","receivedAt":"2007-03-03T20:44:16Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Sat, 3 Mar 2007, Johannes Sixt wrote:\n\n> On Saturday 03 March 2007 21:11, Johannes Schindelin wrote:\n> > I think regardless of the value of core.symlinks, merging symbolic \n> > links does not make sense at all.\n> \n> No doubt about that. Currently, the version of the \"current\" branch \n> remains in the working tree. My patch does not change this behavior at \n> all, it just does not call symlink(2), but allocates a regular file.\n\nOh, I misunderstood! All is well, then. (I had the impression you put \nconflict markers into the file.)\n\nCiao,\nDscho\n"},{"id":"36224","messageId":"7vwt1x7jzl.fsf@assigned-by-dhcp.cox.net","threadId":"7072","inReplyTo":"200703032121.59468.johannes.sixt@telecom.at","subject":"Re: [PATCH 1/2] Handle core.symlinks=false case in merge-recursive.","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2007-03-04T03:42:06Z","receivedAt":"2007-03-04T03:42:06Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Johannes Sixt <johannes.sixt@telecom.at> writes:\n\n> On Saturday 03 March 2007 20:32, Johannes Sixt wrote:\n>> If the file system does not support symbolic links (core.symlinks=false),\n>> merge-recursive must write the merged symbolic link text into a regular\n>> file.\n>\n> But how to resolve such a conflict if core.symlinks=false?\n>\n> It turns out that git-add cannot honor the symlink property recorded in the \n> index because read_cache.c:add_file_to_index() will find only entries at \n> stage 0, but the conflicting entries are at stages 2 and 3. Can there be \n> something done about that?\n\nYou can always use --index-info.\n"}]}