{"thread":{"id":"10034","subject":"[PATCH] Add --no-rename to git-apply","startedAt":"2007-09-26T21:26:44Z","lastAt":"2007-09-27T19:12:29Z","messageCount":6,"participants":["Robin Rosenberg","Junio C Hamano","Johannes Schindelin"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"54119","messageId":"11908420041596-git-send-email-robin.rosenberg@dewire.com","threadId":"10034","inReplyTo":null,"subject":"[PATCH] Add --no-rename to git-apply","fromName":"Robin Rosenberg","fromEmail":"robin.rosenberg@dewire.com","sentAt":"2007-09-26T21:26:44Z","receivedAt":"2007-09-26T21:26:44Z","isPatch":true,"sender":{"key":"robin.rosenberg@dewire.com","avatar":"https://avatars.githubusercontent.com/u/46357?v=4"},"body":"With this option git-apply can apply a patch with a rename\nonto the original file(s).\n\nSigned-off-by: Robin Rosenberg <robin.rosenberg@dewire.com>\n---\n Documentation/git-apply.txt       |    6 ++-\n builtin-apply.c                   |   17 +++++++-\n t/t4123-apply-renames-norename.sh |   85 +++++++++++++++++++++++++++++++++++++\n 3 files changed, 106 insertions(+), 2 deletions(-)\n create mode 100755 t/t4123-apply-renames-norename.sh\n\ndiff --git a/Documentation/git-apply.txt b/Documentation/git-apply.txt\nindex 4c7e3a2..b691c55 100644\n--- a/Documentation/git-apply.txt\n+++ b/Documentation/git-apply.txt\n@@ -10,7 +10,7 @@ SYNOPSIS\n --------\n [verse]\n 'git-apply' [--stat] [--numstat] [--summary] [--check] [--index]\n-\t  [--apply] [--no-add] [--index-info] [-R | --reverse]\n+\t  [--apply] [--no-add] [--no-rename] [--index-info] [-R | --reverse]\n \t  [--allow-binary-replacement | --binary] [--reject] [-z]\n \t  [-pNUM] [-CNUM] [--inaccurate-eof] [--cached]\n \t  [--whitespace=<nowarn|warn|error|error-all|strip>]\n@@ -121,6 +121,10 @@ discouraged.\n \tthe result with this option, which would apply the\n \tdeletion part but not addition part.\n \n+--no-rename::\n+\tWhen applying patches with renames, this patch applies\n+\tthe patch to the original file.\n+\n --allow-binary-replacement, --binary::\n \tHistorically we did not allow binary patch applied\n \twithout an explicit permission from the user, and this\ndiff --git a/builtin-apply.c b/builtin-apply.c\nindex 25b1447..73134e8 100644\n--- a/builtin-apply.c\n+++ b/builtin-apply.c\n@@ -41,11 +41,12 @@ static int apply_in_reverse;\n static int apply_with_reject;\n static int apply_verbosely;\n static int no_add;\n+static int no_rename;\n static int show_index_info;\n static int line_termination = '\\n';\n static unsigned long p_context = ULONG_MAX;\n static const char apply_usage[] =\n-\"git-apply [--stat] [--numstat] [--summary] [--check] [--index] [--cached] [--apply] [--no-add] [--index-info] [--allow-binary-replacement] [--reverse] [--reject] [--verbose] [-z] [-pNUM] [-CNUM] [--whitespace=<nowarn|warn|error|error-all|strip>] <patch>...\";\n+\"git-apply [--stat] [--numstat] [--summary] [--check] [--index] [--cached] [--apply] [--no-add] [--no-rename] [--index-info]   [--allow-binary-replacement] [--reverse [--reject] [--verbose] [-z] [-pNUM] [-CNUM] [--whitespace=<nowarn|warn|error|error-all|strip>]  <patch>...\";\n \n static enum whitespace_eol {\n \tnowarn_whitespace,\n@@ -495,6 +496,8 @@ static int gitdiff_copydst(const char *line, struct patch *patch)\n \n static int gitdiff_renamesrc(const char *line, struct patch *patch)\n {\n+\tif (no_rename)\n+\t\treturn 0;\n \tpatch->is_rename = 1;\n \tpatch->old_name = find_name(line, NULL, 0, 0);\n \treturn 0;\n@@ -502,6 +505,8 @@ static int gitdiff_renamesrc(const char *line, struct patch *patch)\n \n static int gitdiff_renamedst(const char *line, struct patch *patch)\n {\n+\tif (no_rename)\n+\t\treturn 0;\n \tpatch->is_rename = 1;\n \tpatch->new_name = find_name(line, NULL, 0, 0);\n \treturn 0;\n@@ -2103,6 +2108,11 @@ static int check_patch(struct patch *patch, struct patch *prev_patch)\n \tstruct cache_entry *ce = NULL;\n \tint ok_if_exists;\n \n+\tif (no_rename) {\n+\t\tnew_name = old_name;\n+\t\tpatch->new_name = old_name;\n+\t}\n+\n \tpatch->rejected = 1; /* we will drop this after we succeed */\n \n \t/*\n@@ -2843,6 +2853,11 @@ int cmd_apply(int argc, const char **argv, const char *unused_prefix)\n \t\t\tno_add = 1;\n \t\t\tcontinue;\n \t\t}\n+\t\tif (!strcmp(arg, \"--no-rename\")) {\n+\t\t\tno_rename = 1;\n+\t\t\tcontinue;\n+\t\t}\n+\n \t\tif (!strcmp(arg, \"--stat\")) {\n \t\t\tapply = 0;\n \t\t\tdiffstat = 1;\ndiff --git a/t/t4123-apply-renames-norename.sh b/t/t4123-apply-renames-norename.sh\nnew file mode 100755\nindex 0000000..8c0d523\n--- /dev/null\n+++ b/t/t4123-apply-renames-norename.sh\n@@ -0,0 +1,85 @@\n+#!/bin/sh\n+#\n+# Copyright (c) 2007 Robin Rosenberg\n+#\n+\n+test_description='git apply --no-rename.\n+\n+'\n+\n+. ./test-lib.sh\n+\n+# setup\n+\n+mkdir -p klibc/arch/x86_64/include/klibc\n+\n+cat >klibc/arch/x86_64/include/klibc/archsetjmp.h <<\\EOF\n+/*\n+ * arch/x86_64/include/klibc/archsetjmp.h\n+ */\n+\n+#ifndef _KLIBC_ARCHSETJMP_H\n+#define _KLIBC_ARCHSETJMP_H\n+\n+struct __jmp_buf {\n+  unsigned long __rbx;\n+  unsigned long __rsp;\n+  unsigned long __rbp;\n+  unsigned long __r12;\n+  unsigned long __r13;\n+  unsigned long __r14;\n+  unsigned long __r15;\n+  unsigned long __rip;\n+};\n+\n+typedef struct __jmp_buf jmp_buf[1];\n+\n+#endif /* _SETJMP_H */\n+EOF\n+\n+cat >patch <<\\EOF\n+diff --git a/klibc/arch/x86_64/include/klibc/archsetjmp.h b/include/arch/m32r/klibc/archsetjmp.h\n+similarity index 66%\n+rename from klibc/arch/x86_64/include/klibc/archsetjmp.h\n+rename to include/arch/m32r/klibc/archsetjmp.h\n+--- a/klibc/arch/x86_64/include/klibc/archsetjmp.h\n++++ b/include/arch/m32r/klibc/archsetjmp.h\n+@@ -1,21 +1,21 @@\n+ /*\n+- * arch/x86_64/include/klibc/archsetjmp.h\n++ * arch/m32r/include/klibc/archsetjmp.h\n+  */\n+\n+ #ifndef _KLIBC_ARCHSETJMP_H\n+ #define _KLIBC_ARCHSETJMP_H\n+\n+ struct __jmp_buf {\n+-  unsigned long __rbx;\n+-  unsigned long __rsp;\n+-  unsigned long __rbp;\n++  unsigned long __r8;\n++  unsigned long __r9;\n++  unsigned long __r10;\n++  unsigned long __r11;\n+   unsigned long __r12;\n+   unsigned long __r13;\n+   unsigned long __r14;\n+   unsigned long __r15;\n+-  unsigned long __rip;\n+ };\n+\n+ typedef struct __jmp_buf jmp_buf[1];\n+\n+-#endif /* _SETJMP_H */\n++#endif /* _KLIBC_ARCHSETJMP_H */\n+EOF\n+\n+find klibc -type f -print | xargs git update-index --add --\n+\n+test_expect_success 'apply rename patch, without doing rename' \\\n+'git apply --no-rename patch &&\n+git diff --numstat >stat.diff &&\n+test \"$(cat stat.diff)\" = \"6\t6\tklibc/arch/x86_64/include/klibc/archsetjmp.h\"\n+'\n+\n+test_done\n-- \n1.5.3.1.g80926\n"},{"id":"54124","messageId":"200709270031.09739.robin.rosenberg@dewire.com","threadId":"10034","inReplyTo":"11908420041596-git-send-email-robin.rosenberg@dewire.com","subject":"Re: [PATCH] Add --no-rename to git-apply","fromName":"Robin Rosenberg","fromEmail":"robin.rosenberg@dewire.com","sentAt":"2007-09-26T22:31:08Z","receivedAt":"2007-09-26T22:31:08Z","isPatch":true,"sender":{"key":"robin.rosenberg@dewire.com","avatar":"https://avatars.githubusercontent.com/u/46357?v=4"},"body":"onsdag 26 september 2007 skrev Robin Rosenberg:\n> With this option git-apply can apply a patch with a rename\n> onto the original file(s).\n\nThe reason (off the record) is that I use it for exporting to another\nmore expen$ive SCM, that does rename tracking so I need to keep\nthe file with the original name until telling the other SCM to rename\nthe file. It may be useful for others doing similar things.\n\n-- robin\n"},{"id":"54132","messageId":"7vbqbozo7t.fsf@gitster.siamese.dyndns.org","threadId":"10034","inReplyTo":"11908420041596-git-send-email-robin.rosenberg@dewire.com","subject":"Re: [PATCH] Add --no-rename to git-apply","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2007-09-27T05:12:06Z","receivedAt":"2007-09-27T05:12:06Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Robin Rosenberg <robin.rosenberg@dewire.com> writes:\n\n> With this option git-apply can apply a patch with a rename\n> onto the original file(s).\n\nThis is troubling from both design and implementation point of\nview.\n\n * Why would this be useful?  What's the point of producing the\n   renaming patch if you know you would want to apply while\n   ignoring the rename?\n\n * The change looks too special purpose to me.  If you are\n   giving the ability to deposit the result to somewhere other\n   than where the patch intendes to, why limit it only to the\n   preimage name?  Aren't there cases where A is renamed to B\n   sometime in the history, and you have a patch that talks\n   about the content change A->A but the tree you have has the\n   contents already in B, and you would want to apply that\n   patch?  It feels that this and your \"ignore rename\" could be\n   handled much more cleanly and flexibly by preprocessing the\n   patchfile.\n\n * By disabling the parsing of rename header lines, you are\n   disabling the sanity checking of the input done in\n   gitdiff_verify_name() called from gitdiff_oldname() and\n   gitdiff_newname().  I think it is wrong for --no-rename\n   option to affect the parsing of the input.  If we were to do\n   this, perhaps write_out_results() or one of its callee would\n   be a better place to do so.\n"},{"id":"54151","messageId":"Pine.LNX.4.64.0709271107530.28395@racer.site","threadId":"10034","inReplyTo":"7vbqbozo7t.fsf@gitster.siamese.dyndns.org","subject":"Re: [PATCH] Add --no-rename to git-apply","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2007-09-27T10:24:38Z","receivedAt":"2007-09-27T10:24:38Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Wed, 26 Sep 2007, Junio C Hamano wrote:\n\n> Robin Rosenberg <robin.rosenberg@dewire.com> writes:\n> \n> > With this option git-apply can apply a patch with a rename\n> > onto the original file(s).\n> \n> This is troubling from both design and implementation point of\n> view.\n> \n>  * Why would this be useful?  What's the point of producing the\n>    renaming patch if you know you would want to apply while\n>    ignoring the rename?\n\nRobin said in a follow-up mail that he needs it for a payed-for SCM \n(let's describe it as TransparentBox here), which insists on explicit \nrenames.\n\nBut I suggest a simple script here which extracts from the diff the \nrenames, which outputs a script which renames the file(s) back and then \nuses the TransparentBox' mv command:\n\nsed -n -e \"/^rename from/N\" \\\n  -e \"s/^rename from \\(.*\\)\\nrename to \\(.*\\)/mv \\2 \\1 \\&\\& tb mv \\1 \\2/p\" \\\n  < diff.patch\n\nCiao,\nDscho\n"},{"id":"54182","messageId":"200709272104.18510.robin.rosenberg@dewire.com","threadId":"10034","inReplyTo":"Pine.LNX.4.64.0709271107530.28395@racer.site","subject":"Re: [PATCH] Add --no-rename to git-apply","fromName":"Robin Rosenberg","fromEmail":"robin.rosenberg@dewire.com","sentAt":"2007-09-27T19:04:18Z","receivedAt":"2007-09-27T19:04:18Z","isPatch":true,"sender":{"key":"robin.rosenberg@dewire.com","avatar":"https://avatars.githubusercontent.com/u/46357?v=4"},"body":"torsdag 27 september 2007 skrev Johannes Schindelin:\n> Robin said in a follow-up mail that he needs it for a payed-for SCM \n> (let's describe it as TransparentBox here), which insists on explicit \n> renames.\n> \n> But I suggest a simple script here which extracts from the diff the \n> renames, which outputs a script which renames the file(s) back and then \n> uses the TransparentBox' mv command:\n> \n> sed -n -e \"/^rename from/N\" \\\n>   -e \"s/^rename from \\(.*\\)\\nrename to \\(.*\\)/mv \\2 \\1 \\&\\& tb mv \\1 \\2/p\" \\\n>   < diff.patch\n> \n\nI tried something like that (integrated in the script), and the bugger noticed \nit and refused to work as exepected, but now that I think about it should be\npossible to fool it. I have to give it a go again and see what really actually\nwent wrong.\n\n-- robin\n"},{"id":"54183","messageId":"200709272112.29608.robin.rosenberg@dewire.com","threadId":"10034","inReplyTo":"7vbqbozo7t.fsf@gitster.siamese.dyndns.org","subject":"Re: [PATCH] Add --no-rename to git-apply","fromName":"Robin Rosenberg","fromEmail":"robin.rosenberg@dewire.com","sentAt":"2007-09-27T19:12:29Z","receivedAt":"2007-09-27T19:12:29Z","isPatch":true,"sender":{"key":"robin.rosenberg@dewire.com","avatar":"https://avatars.githubusercontent.com/u/46357?v=4"},"body":"torsdag 27 september 2007 skrev Junio C Hamano:\n> Robin Rosenberg <robin.rosenberg@dewire.com> writes:\n> \n> > With this option git-apply can apply a patch with a rename\n> > onto the original file(s).\n> \n> This is troubling from both design and implementation point of\n> view.\n> \n>  * Why would this be useful?  What's the point of producing the\n>    renaming patch if you know you would want to apply while\n>    ignoring the rename?\nThe point of producing the rename info is to find out which renames\nare in it. It's only that I don't want to perform them straight away.\n\n>  * The change looks too special purpose to me.  If you are\n>    giving the ability to deposit the result to somewhere other\n>    than where the patch intendes to, why limit it only to the\n>    preimage name?  Aren't there cases where A is renamed to B\n>    sometime in the history, and you have a patch that talks\n>    about the content change A->A but the tree you have has the\n>    contents already in B, and you would want to apply that\n>    patch?  It feels that this and your \"ignore rename\" could be\n>    handled much more cleanly and flexibly by preprocessing the\n>    patchfile.\nWell it is special *purpose*, but not tied to a particuar tool. I'm\nnot sure whether it is necessary with other tools though. I'll\nconsider the preprocessing and will retry the rename-back that\nJohannes suggested.\n\n> \n>  * By disabling the parsing of rename header lines, you are\n>    disabling the sanity checking of the input done in\n>    gitdiff_verify_name() called from gitdiff_oldname() and\n>    gitdiff_newname().  I think it is wrong for --no-rename\n>    option to affect the parsing of the input.  If we were to do\n>    this, perhaps write_out_results() or one of its callee would\n>    be a better place to do so.\n\nHopefully git produces sane things so the checking shouldn't be that\nimportant, but I also do a check before beginning with checkouts and\nso on, much like git-cvsexportcommit. The check  is performed without\nthe switch.\n\n-- robin\n"}]}