{"thread":{"id":"28102","subject":"[PATCH] Configurable diff context in merge-tree command","startedAt":"2011-08-15T06:17:21Z","lastAt":"2011-08-15T06:17:21Z","messageCount":1,"participants":["Erik van Zijst"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"173527","messageId":"CA+69USvBXGoDMp_v2hF6v6QM3-GjF42pFiaBX912txW-e5n7=g@mail.gmail.com","threadId":"28102","inReplyTo":null,"subject":"[PATCH] Configurable diff context in merge-tree command","fromName":"Erik van Zijst","fromEmail":"erik.van.zijst@gmail.com","sentAt":"2011-08-15T06:17:21Z","receivedAt":"2011-08-15T06:17:21Z","isPatch":true,"sender":{"key":"erik.van.zijst@gmail.com","avatar":null},"body":"Added support for the -U/--unified command line arguments to the\ngit-merge-tree command to change the number of context lines that\nare generated.\n\nSigned-off-by: Erik van Zijst <erik.van.zijst@gmail.com>\n---\n Documentation/git-merge-tree.txt |    8 +++++++-\n builtin/merge-tree.c             |   26 +++++++++++++++++++-------\n 2 files changed, 26 insertions(+), 8 deletions(-)\n\ndiff --git a/Documentation/git-merge-tree.txt b/Documentation/git-merge-tree.txt\nindex c5f84b6..7a0d927 100644\n--- a/Documentation/git-merge-tree.txt\n+++ b/Documentation/git-merge-tree.txt\n@@ -9,7 +9,7 @@ git-merge-tree - Show three-way merge without touching index\n SYNOPSIS\n --------\n [verse]\n-'git merge-tree' <base-tree> <branch1> <branch2>\n+'git merge-tree' [-U<n> | --unified=<n>] <base-tree> <branch1> <branch2>\n\n DESCRIPTION\n -----------\n@@ -24,6 +24,12 @@ merge results outside of the index, and stuff the\nresults back into the\n index.  For this reason, the output from the command omits\n entries that match the <branch1> tree.\n\n+OPTIONS\n+-------\n+-U<n>::\n+--unified=<n>::\n+\tGenerate diffs with <n> lines of context instead of the usual three.\n+\n GIT\n ---\n Part of the linkgit:git[1] suite\ndiff --git a/builtin/merge-tree.c b/builtin/merge-tree.c\nindex 897a563..0a5c8c9 100644\n--- a/builtin/merge-tree.c\n+++ b/builtin/merge-tree.c\n@@ -4,9 +4,15 @@\n #include \"blob.h\"\n #include \"exec_cmd.h\"\n #include \"merge-file.h\"\n+#include \"parse-options.h\"\n+\n+static const char * const merge_tree_usage[] = {\n+\t\"git merge-tree [options] <base-tree> <branch1> <branch2>\",\n+\tNULL\n+};\n\n-static const char merge_tree_usage[] = \"git merge-tree <base-tree>\n<branch1> <branch2>\";\n static int resolve_directories = 1;\n+static long ctxlen = 3;\n\n struct merge_list {\n \tstruct merge_list *next;\n@@ -108,7 +114,7 @@ static void show_diff(struct merge_list *entry)\n\n \txpp.flags = 0;\n \tmemset(&xecfg, 0, sizeof(xecfg));\n-\txecfg.ctxlen = 3;\n+\txecfg.ctxlen = ctxlen;\n \tecb.outf = show_outf;\n \tecb.priv = NULL;\n\n@@ -341,13 +347,19 @@ int cmd_merge_tree(int argc, const char **argv,\nconst char *prefix)\n {\n \tstruct tree_desc t[3];\n \tvoid *buf1, *buf2, *buf3;\n+\tconst struct option opts[] = {\n+\t\tOPT_INTEGER('U', \"unified\", &ctxlen, \"number of diff context lines\"),\n+\t\tOPT_END()\n+\t};\n+\n+\targc = parse_options(argc, argv, prefix, opts, merge_tree_usage, 0);\n\n-\tif (argc != 4)\n-\t\tusage(merge_tree_usage);\n+\tif (argc != 3)\n+\t\tusage(*merge_tree_usage);\n\n-\tbuf1 = get_tree_descriptor(t+0, argv[1]);\n-\tbuf2 = get_tree_descriptor(t+1, argv[2]);\n-\tbuf3 = get_tree_descriptor(t+2, argv[3]);\n+\tbuf1 = get_tree_descriptor(t+0, argv[0]);\n+\tbuf2 = get_tree_descriptor(t+1, argv[1]);\n+\tbuf3 = get_tree_descriptor(t+2, argv[2]);\n \tmerge_trees(t, \"\");\n \tfree(buf1);\n \tfree(buf2);\n-- \n1.7.1\n"}]}