{"thread":{"id":"10983","subject":"[PATCH] Converted git-merge-ours.sh -> builtin-merge-ours.c","startedAt":"2007-11-22T20:19:40Z","lastAt":"2007-11-23T09:42:25Z","messageCount":3,"participants":["Thomas Harning","Junio C Hamano","Jakub Narebski"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"60705","messageId":"4745E45C.7@gmail.com","threadId":"10983","inReplyTo":null,"subject":"[PATCH] Converted git-merge-ours.sh -> builtin-merge-ours.c","fromName":"Thomas Harning","fromEmail":"harningt@gmail.com","sentAt":"2007-11-22T20:19:40Z","receivedAt":"2007-11-22T20:19:40Z","isPatch":true,"sender":{"key":"harningt@gmail.com","avatar":"https://gravatar.com/avatar/a79ddd43da8c8f1f899cd75b7b95cc5f3b2ba5643400468988b1a12c86b75d08?d=mp&s=160"},"body":"Here's a simple patch to make git-merge-ours.sh into a builtin.\n\nI figure this would be a simple way of getting in the git-development flow.\n\nSigned-off-by: Thomas Harning Jr <harningt@gmail.com>\n---\n Makefile             |    3 ++-\n builtin-merge-ours.c |   32 ++++++++++++++++++++++++++++++++\n builtin.h            |    1 +\n git-merge-ours.sh    |   14 --------------\n git.c                |    1 +\n 5 files changed, 36 insertions(+), 15 deletions(-)\n create mode 100644 builtin-merge-ours.c\n delete mode 100755 git-merge-ours.sh\n\ndiff --git a/Makefile b/Makefile\nindex cabde81..7a0ee78 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -221,7 +221,7 @@ SCRIPT_SH = \\\n \tgit-sh-setup.sh \\\n \tgit-am.sh \\\n \tgit-merge.sh git-merge-stupid.sh git-merge-octopus.sh \\\n-\tgit-merge-resolve.sh git-merge-ours.sh \\\n+\tgit-merge-resolve.sh \\\n \tgit-lost-found.sh git-quiltimport.sh git-submodule.sh \\\n \tgit-filter-branch.sh \\\n \tgit-stash.sh\n@@ -353,6 +353,7 @@ BUILTIN_OBJS = \\\n \tbuiltin-mailsplit.o \\\n \tbuiltin-merge-base.o \\\n \tbuiltin-merge-file.o \\\n+\tbuiltin-merge-ours.o \\\n \tbuiltin-mv.o \\\n \tbuiltin-name-rev.o \\\n \tbuiltin-pack-objects.o \\\ndiff --git a/builtin-merge-ours.c b/builtin-merge-ours.c\nnew file mode 100644\nindex 0000000..fbfe183\n--- /dev/null\n+++ b/builtin-merge-ours.c\n@@ -0,0 +1,32 @@\n+/*\n+ * Implementation of git-merge-ours.sh as builtin\n+ * \n+ * Copyright (c) 2007 Thomas Harning Jr\n+ * Original:\n+ * Original Copyright (c) 2005 Junio C Hamano\n+ *\n+ * Pretend we resolved the heads, but declare our tree trumps everybody else.\n+ */\n+#include \"git-compat-util.h\"\n+#include \"builtin.h\"\n+\n+int cmd_merge_ours(int argc, const char **argv, const char *prefix)\n+{\n+\tconst char *nargv[] = {\n+\t\t\"diff-index\",\n+\t\t\"--quiet\",\n+\t\t\"--cached\",\n+\t\t\"HEAD\",\n+\t\tNULL\n+\t};\n+\tint i;\n+\n+\tint ret = cmd_diff_index(4, nargv, prefix);\n+\tprintf(\"GOT: %i\\n\", ret);\n+\t/* We need to exit with 2 if the index does not match our HEAD tree,\n+\t * because the current index is what we will be committing as the\n+\t * merge result.\n+\t */\n+\tif(ret) ret = 2;\n+\treturn ret;\n+}\ndiff --git a/builtin.h b/builtin.h\nindex 9a6213a..bcb54aa 100644\n--- a/builtin.h\n+++ b/builtin.h\n@@ -51,6 +51,7 @@ extern int cmd_ls_tree(int argc, const char **argv, const char *prefix);\n extern int cmd_mailinfo(int argc, const char **argv, const char *prefix);\n extern int cmd_mailsplit(int argc, const char **argv, const char *prefix);\n extern int cmd_merge_base(int argc, const char **argv, const char *prefix);\n+extern int cmd_merge_ours(int argc, const char **argv, const char *prefix);\n extern int cmd_merge_file(int argc, const char **argv, const char *prefix);\n extern int cmd_mv(int argc, const char **argv, const char *prefix);\n extern int cmd_name_rev(int argc, const char **argv, const char *prefix);\ndiff --git a/git-merge-ours.sh b/git-merge-ours.sh\ndeleted file mode 100755\nindex c81a790..0000000\n--- a/git-merge-ours.sh\n+++ /dev/null\n@@ -1,14 +0,0 @@\n-#!/bin/sh\n-#\n-# Copyright (c) 2005 Junio C Hamano\n-#\n-# Pretend we resolved the heads, but declare our tree trumps everybody else.\n-#\n-\n-# We need to exit with 2 if the index does not match our HEAD tree,\n-# because the current index is what we will be committing as the\n-# merge result.\n-\n-git diff-index --quiet --cached HEAD || exit 2\n-\n-exit 0\ndiff --git a/git.c b/git.c\nindex 7604319..80c2f14 100644\n--- a/git.c\n+++ b/git.c\n@@ -325,6 +325,7 @@ static void handle_internal_command(int argc, const char **argv)\n \t\t{ \"mailsplit\", cmd_mailsplit },\n \t\t{ \"merge-base\", cmd_merge_base, RUN_SETUP },\n \t\t{ \"merge-file\", cmd_merge_file },\n+\t\t{ \"merge-ours\", cmd_merge_ours, RUN_SETUP },\n \t\t{ \"mv\", cmd_mv, RUN_SETUP | NEED_WORK_TREE },\n \t\t{ \"name-rev\", cmd_name_rev, RUN_SETUP },\n \t\t{ \"pack-objects\", cmd_pack_objects, RUN_SETUP },\n-- \n1.5.3.6.861.gd794\n"},{"id":"60739","messageId":"7voddluz13.fsf@gitster.siamese.dyndns.org","threadId":"10983","inReplyTo":"4745E45C.7@gmail.com","subject":"Re: [PATCH] Converted git-merge-ours.sh -> builtin-merge-ours.c","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2007-11-23T08:49:44Z","receivedAt":"2007-11-23T08:49:44Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Thomas Harning <harningt@gmail.com> writes:\n\n> Here's a simple patch to make git-merge-ours.sh into a builtin.\n>\n> I figure this would be a simple way of getting in the git-development flow.\n>\n> Signed-off-by: Thomas Harning Jr <harningt@gmail.com>\n\nHave you tried to read this proposed commit log message in the\ncontext of \"git log\", after applying it on top of 'master'?\n\"Here's a simple patch to\" and \"I figure ...\" are of not much\nuse.\n\nThe patch looks good except for minor style nits.\n\n> diff --git a/builtin-merge-ours.c b/builtin-merge-ours.c\n> new file mode 100644\n> index 0000000..fbfe183\n> --- /dev/null\n> +++ b/builtin-merge-ours.c\n> @@ -0,0 +1,32 @@\n> +/*\n> + * Implementation of git-merge-ours.sh as builtin\n> + * \n\nTraling whitespace.\n\n> +int cmd_merge_ours(int argc, const char **argv, const char *prefix)\n> +{\n> +\tconst char *nargv[] = {\n> +\t\t\"diff-index\",\n> +\t\t\"--quiet\",\n> +\t\t\"--cached\",\n> +\t\t\"HEAD\",\n> +\t\tNULL\n> +\t};\n> +\tint i;\n> +\n> +\tint ret = cmd_diff_index(4, nargv, prefix);\n> +\tprintf(\"GOT: %i\\n\", ret);\n\nUnused variable \"i\".\n\nAn unwanted blank line still in the sequence of variable\ndefinitions, and a missing blank line after the definitions.\n\nA leftover debug printf() is not very welcomed.\n\n\t[Not a nit but a comment]\n\n        The call to cmd_diff_index() here raised my eyebrow a\n\tbit.  I would have skipped all the parameter parsing and\n\tarranged it to directly call into run_diff_index()\n\tinstead.  \n\n\tAs the result of literally translating the scripted\n\tversion of git-merge-ours, the code inherits a\n\tcorner-case bug.  Can you spot it?\n\n> +\t/* We need to exit with 2 if the index does not match our HEAD tree,\n> +\t * because the current index is what we will be committing as the\n> +\t * merge result.\n> +\t */\n\nWe tend to format a multi-line comment block as:\n\n\t/*\n         * We need to ...\n         * ... merge result.\n         */\n\n> +\tif(ret) ret = 2;\n\nA SP between \"if\" and \"(\"; put the body of the \"if\" on a\nseparate line.\n\nThanks.  No need to resend; all these minor nits can be fixed\nhere easily.\n"},{"id":"60746","messageId":"fi67a2$6jh$1@ger.gmane.org","threadId":"10983","inReplyTo":"4745E45C.7@gmail.com","subject":"Re: [PATCH] Converted git-merge-ours.sh -> builtin-merge-ours.c","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2007-11-23T09:42:25Z","receivedAt":"2007-11-23T09:42:25Z","isPatch":true,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"Thomas Harning wrote:\n\n> diff --git a/git-merge-ours.sh b/git-merge-ours.sh\n> deleted file mode 100755\n> index c81a790..0000000\n> --- a/git-merge-ours.sh\n> +++ /dev/null\n\nShouldn't script version be moved to contrib/examples/ as is git.git\npolicy, or is it too simple script?\n\n-- \nJakub Narebski\nWarsaw, Poland\nShadeHawk on #git\n"}]}