{"thread":{"id":"19946","subject":"[PATCH 0/4] start using sequencer code to port \"rebase -i\"","startedAt":"2009-06-26T21:08:42Z","lastAt":"2009-06-28T12:13:21Z","messageCount":6,"participants":["Christian Couder"],"isPatch":true,"patchVersion":1,"patchTotal":4},"messages":[{"id":"117043","messageId":"20090626205319.3885.91532.chriscool@tuxfamily.org","threadId":"19946","inReplyTo":null,"subject":"[PATCH 0/4] start using sequencer code to port \"rebase -i\"","fromName":"Christian Couder","fromEmail":"chriscool@tuxfamily.org","sentAt":"2009-06-26T21:08:42Z","receivedAt":"2009-06-26T21:08:42Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"This patch series create a new \"git sequencer--helper\" plumber\ncommand to help port \"git-rebase--interactive.sh\" to C using\ncode from the sequencer GSoC project at :\n\ngit://repo.or.cz/git/sbeyer.git\n\nIn this series only a few functions from the sequencer are used.\n\nChristian Couder (3):\n  sequencer: add \"builtin-sequencer--helper.c\"\n  sequencer: free memory used in \"make_patch\" function\n  rebase -i: use \"git sequencer--helper --make-patch\"\n\nStephan Beyer (1):\n  sequencer: add \"make_patch\" function to save a patch\n\n .gitignore                  |    1 +\n Makefile                    |    1 +\n builtin-sequencer--helper.c |  104 +++++++++++++++++++++++++++++++++++++++++++\n builtin.h                   |    1 +\n git-rebase--interactive.sh  |   13 +-----\n git.c                       |    1 +\n 6 files changed, 109 insertions(+), 12 deletions(-)\n create mode 100644 builtin-sequencer--helper.c\n"},{"id":"117046","messageId":"20090626210847.3885.55343.chriscool@tuxfamily.org","threadId":"19946","inReplyTo":"20090626205319.3885.91532.chriscool@tuxfamily.org","subject":"[PATCH 1/4] sequencer: add \"builtin-sequencer--helper.c\"","fromName":"Christian Couder","fromEmail":"chriscool@tuxfamily.org","sentAt":"2009-06-26T21:08:43Z","receivedAt":"2009-06-26T21:08:43Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"This a helper builtin that will be used to port some parts of\n\"git-rebase--interactive.sh\" to C.\n\nIt currently does nothing except checking arguments it is passed.\n\nSigned-off-by: Christian Couder <chriscool@tuxfamily.org>\n---\n .gitignore                  |    1 +\n Makefile                    |    1 +\n builtin-sequencer--helper.c |   27 +++++++++++++++++++++++++++\n builtin.h                   |    1 +\n git.c                       |    1 +\n 5 files changed, 31 insertions(+), 0 deletions(-)\n create mode 100644 builtin-sequencer--helper.c\n\ndiff --git a/.gitignore b/.gitignore\nindex 04926fc..98711c3 100644\n--- a/.gitignore\n+++ b/.gitignore\n@@ -117,6 +117,7 @@ git-revert\n git-rm\n git-send-email\n git-send-pack\n+git-sequencer--helper\n git-sh-setup\n git-shell\n git-shortlog\ndiff --git a/Makefile b/Makefile\nindex 4e8f45d..10bb7f5 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -632,6 +632,7 @@ BUILTIN_OBJS += builtin-rev-parse.o\n BUILTIN_OBJS += builtin-revert.o\n BUILTIN_OBJS += builtin-rm.o\n BUILTIN_OBJS += builtin-send-pack.o\n+BUILTIN_OBJS += builtin-sequencer--helper.o\n BUILTIN_OBJS += builtin-shortlog.o\n BUILTIN_OBJS += builtin-show-branch.o\n BUILTIN_OBJS += builtin-show-ref.o\ndiff --git a/builtin-sequencer--helper.c b/builtin-sequencer--helper.c\nnew file mode 100644\nindex 0000000..721c0d8\n--- /dev/null\n+++ b/builtin-sequencer--helper.c\n@@ -0,0 +1,27 @@\n+#include \"builtin.h\"\n+#include \"cache.h\"\n+#include \"parse-options.h\"\n+\n+static const char * const git_sequencer_helper_usage[] = {\n+\t\"git sequencer--helper --make-patch <commit>\",\n+\tNULL\n+};\n+\n+int cmd_sequencer__helper(int argc, const char **argv, const char *prefix)\n+{\n+\tchar *commit = NULL;\n+\tstruct option options[] = {\n+\t\tOPT_STRING(0, \"make-patch\", &commit, \"commit\",\n+\t\t\t   \"create a patch from commit\"),\n+\t\tOPT_END()\n+\t};\n+\n+\targc = parse_options(argc, argv, prefix, options,\n+\t\t\t     git_sequencer_helper_usage, 0);\n+\n+\tif (!commit)\n+\t\tusage_with_options(git_sequencer_helper_usage, options);\n+\n+\t/* Nothing to do yet */\n+\treturn 0;\n+}\ndiff --git a/builtin.h b/builtin.h\nindex 38ceddc..d181669 100644\n--- a/builtin.h\n+++ b/builtin.h\n@@ -92,6 +92,7 @@ extern int cmd_rev_parse(int argc, const char **argv, const char *prefix);\n extern int cmd_revert(int argc, const char **argv, const char *prefix);\n extern int cmd_rm(int argc, const char **argv, const char *prefix);\n extern int cmd_send_pack(int argc, const char **argv, const char *prefix);\n+extern int cmd_sequencer__helper(int argc, const char **argv, const char *prefix);\n extern int cmd_shortlog(int argc, const char **argv, const char *prefix);\n extern int cmd_show(int argc, const char **argv, const char *prefix);\n extern int cmd_show_branch(int argc, const char **argv, const char *prefix);\ndiff --git a/git.c b/git.c\nindex 479279b..3e4b4ad 100644\n--- a/git.c\n+++ b/git.c\n@@ -349,6 +349,7 @@ static void handle_internal_command(int argc, const char **argv)\n \t\t{ \"revert\", cmd_revert, RUN_SETUP | NEED_WORK_TREE },\n \t\t{ \"rm\", cmd_rm, RUN_SETUP },\n \t\t{ \"send-pack\", cmd_send_pack, RUN_SETUP },\n+\t\t{ \"sequencer--helper\", cmd_sequencer__helper, RUN_SETUP | NEED_WORK_TREE },\n \t\t{ \"shortlog\", cmd_shortlog, USE_PAGER },\n \t\t{ \"show-branch\", cmd_show_branch, RUN_SETUP },\n \t\t{ \"show\", cmd_show, RUN_SETUP | USE_PAGER },\n-- \n1.6.3.GIT\n"},{"id":"117045","messageId":"20090626210847.3885.18347.chriscool@tuxfamily.org","threadId":"19946","inReplyTo":"20090626205319.3885.91532.chriscool@tuxfamily.org","subject":"[PATCH 2/4] sequencer: add \"make_patch\" function to save a patch","fromName":"Christian Couder","fromEmail":"chriscool@tuxfamily.org","sentAt":"2009-06-26T21:08:44Z","receivedAt":"2009-06-26T21:08:44Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"This function generates an informational patch file.\n\nThe \"make_patch\" and the \"get_commit\" functions are copied from the\nGSoC sequencer project:\n\ngit://repo.or.cz/git/sbeyer.git\n\n(commit e7b8dab0c2a73ade92017a52bb1405ea1534ef20)\n\nMentored-by: Christian Couder <chriscool@tuxfamily.org>\nMentored-by: Daniel Barkalow <barkalow@iabervon.org>\nSigned-off-by: Christian Couder <chriscool@tuxfamily.org>\n---\n builtin-sequencer--helper.c |   75 ++++++++++++++++++++++++++++++++++++++++++-\n 1 files changed, 74 insertions(+), 1 deletions(-)\n\ndiff --git a/builtin-sequencer--helper.c b/builtin-sequencer--helper.c\nindex 721c0d8..8d32480 100644\n--- a/builtin-sequencer--helper.c\n+++ b/builtin-sequencer--helper.c\n@@ -1,15 +1,83 @@\n #include \"builtin.h\"\n #include \"cache.h\"\n #include \"parse-options.h\"\n+#include \"run-command.h\"\n+\n+#define SEQ_DIR \"rebase-merge\"\n+\n+#define PATCH_FILE\tgit_path(SEQ_DIR \"/patch\")\n \n static const char * const git_sequencer_helper_usage[] = {\n \t\"git sequencer--helper --make-patch <commit>\",\n \tNULL\n };\n \n+/* Generate purely informational patch file */\n+static void make_patch(struct commit *commit)\n+{\n+\tstruct commit_list *parents = commit->parents;\n+\tconst char **args;\n+\tstruct child_process chld;\n+\tint fd = open(PATCH_FILE, O_WRONLY | O_CREAT, 0666);\n+\tif (fd < 0)\n+\t\treturn;\n+\n+\tmemset(&chld, 0, sizeof(chld));\n+\tif (!parents) {\n+\t\twrite(fd, \"Root commit\\n\", 12);\n+\t\tclose(fd);\n+\t\treturn;\n+\t} else if (!parents->next) {\n+\t\targs = xcalloc(5, sizeof(char *));\n+\t\targs[0] = \"diff-tree\";\n+\t\targs[1] = \"-p\";\n+\t\targs[2] = xstrdup(sha1_to_hex(parents->item->object.sha1));\n+\t\targs[3] = xstrdup(sha1_to_hex(((struct object *)commit)->sha1));\n+\t} else {\n+\t\tint i = 0;\n+\t\tint count = 1;\n+\n+\t\tfor (; parents; parents = parents->next)\n+\t\t\t++count;\n+\t\targs = xcalloc(count + 3, sizeof(char *));\n+\t\targs[i++] = \"diff\";\n+\t\targs[i++] = \"--cc\";\n+\t\targs[i++] = xstrdup(sha1_to_hex(commit->object.sha1));\n+\n+\t\tfor (parents = commit->parents; parents;\n+\t\t     parents = parents->next)\n+\t\t\targs[i++] = xstrdup(sha1_to_hex(\n+\t\t\t\t\t    parents->item->object.sha1));\n+\t}\n+\n+\tchld.argv = args;\n+\tchld.git_cmd = 1;\n+\tchld.out = fd;\n+\n+\t/* Run, ignore errors. */\n+\tif (start_command(&chld))\n+\t\treturn;\n+\tfinish_command(&chld);\n+\n+\t/* TODO: free dup'ed SHAs in argument list */\n+}\n+\n+/* Return a commit object of \"arg\" */\n+static struct commit *get_commit(const char *arg)\n+{\n+\tunsigned char sha1[20];\n+\n+\tif (get_sha1(arg, sha1)) {\n+\t\terror(\"Could not find '%s'\", arg);\n+\t\treturn NULL;\n+\t}\n+\treturn lookup_commit_reference(sha1);\n+}\n+\n int cmd_sequencer__helper(int argc, const char **argv, const char *prefix)\n {\n \tchar *commit = NULL;\n+\tstruct commit *c;\n \tstruct option options[] = {\n \t\tOPT_STRING(0, \"make-patch\", &commit, \"commit\",\n \t\t\t   \"create a patch from commit\"),\n@@ -22,6 +90,11 @@ int cmd_sequencer__helper(int argc, const char **argv, const char *prefix)\n \tif (!commit)\n \t\tusage_with_options(git_sequencer_helper_usage, options);\n \n-\t/* Nothing to do yet */\n+\tc = get_commit(commit);\n+\tif (!c)\n+\t\treturn 1;\n+\n+\tmake_patch(c);\n+\n \treturn 0;\n }\n-- \n1.6.3.GIT\n"},{"id":"117044","messageId":"20090626210847.3885.22240.chriscool@tuxfamily.org","threadId":"19946","inReplyTo":"20090626205319.3885.91532.chriscool@tuxfamily.org","subject":"[PATCH 3/4] sequencer: free memory used in \"make_patch\" function","fromName":"Christian Couder","fromEmail":"chriscool@tuxfamily.org","sentAt":"2009-06-26T21:08:45Z","receivedAt":"2009-06-26T21:08:45Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"\nSigned-off-by: Christian Couder <chriscool@tuxfamily.org>\n---\n builtin-sequencer--helper.c |   20 ++++++++++++--------\n 1 files changed, 12 insertions(+), 8 deletions(-)\n\ndiff --git a/builtin-sequencer--helper.c b/builtin-sequencer--helper.c\nindex 8d32480..1dda525 100644\n--- a/builtin-sequencer--helper.c\n+++ b/builtin-sequencer--helper.c\n@@ -18,6 +18,7 @@ static void make_patch(struct commit *commit)\n \tstruct commit_list *parents = commit->parents;\n \tconst char **args;\n \tstruct child_process chld;\n+\tint i;\n \tint fd = open(PATCH_FILE, O_WRONLY | O_CREAT, 0666);\n \tif (fd < 0)\n \t\treturn;\n@@ -34,20 +35,22 @@ static void make_patch(struct commit *commit)\n \t\targs[2] = xstrdup(sha1_to_hex(parents->item->object.sha1));\n \t\targs[3] = xstrdup(sha1_to_hex(((struct object *)commit)->sha1));\n \t} else {\n-\t\tint i = 0;\n \t\tint count = 1;\n \n \t\tfor (; parents; parents = parents->next)\n \t\t\t++count;\n+\n+\t\ti = 0;\n \t\targs = xcalloc(count + 3, sizeof(char *));\n \t\targs[i++] = \"diff\";\n \t\targs[i++] = \"--cc\";\n \t\targs[i++] = xstrdup(sha1_to_hex(commit->object.sha1));\n \n \t\tfor (parents = commit->parents; parents;\n-\t\t     parents = parents->next)\n-\t\t\targs[i++] = xstrdup(sha1_to_hex(\n-\t\t\t\t\t    parents->item->object.sha1));\n+\t\t     parents = parents->next) {\n+\t\t\tchar *hex = sha1_to_hex(parents->item->object.sha1);\n+\t\t\targs[i++] = xstrdup(hex);\n+\t\t}\n \t}\n \n \tchld.argv = args;\n@@ -55,11 +58,12 @@ static void make_patch(struct commit *commit)\n \tchld.out = fd;\n \n \t/* Run, ignore errors. */\n-\tif (start_command(&chld))\n-\t\treturn;\n-\tfinish_command(&chld);\n+\tif (!start_command(&chld))\n+\t\tfinish_command(&chld);\n \n-\t/* TODO: free dup'ed SHAs in argument list */\n+\tfor (i = 2; args[i]; i++)\n+\t\tfree((char *)args[i]);\n+\tfree(args);\n }\n \n /* Return a commit object of \"arg\" */\n-- \n1.6.3.GIT\n"},{"id":"117047","messageId":"20090626210847.3885.97099.chriscool@tuxfamily.org","threadId":"19946","inReplyTo":"20090626205319.3885.91532.chriscool@tuxfamily.org","subject":"[PATCH 4/4] rebase -i: use \"git sequencer--helper --make-patch\"","fromName":"Christian Couder","fromEmail":"chriscool@tuxfamily.org","sentAt":"2009-06-26T21:08:46Z","receivedAt":"2009-06-26T21:08:46Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"to simplify the \"make_patch\" function.\n\nSigned-off-by: Christian Couder <chriscool@tuxfamily.org>\n---\n git-rebase--interactive.sh |   13 +------------\n 1 files changed, 1 insertions(+), 12 deletions(-)\n\ndiff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh\nindex 3be49dd..82f1133 100755\n--- a/git-rebase--interactive.sh\n+++ b/git-rebase--interactive.sh\n@@ -146,18 +146,7 @@ load_author_ident () {\n }\n \n make_patch () {\n-\tsha1_and_parents=\"$(git rev-list --parents -1 \"$1\")\"\n-\tcase \"$sha1_and_parents\" in\n-\t?*' '?*' '?*)\n-\t\tgit diff --cc $sha1_and_parents\n-\t\t;;\n-\t?*' '?*)\n-\t\tgit diff-tree -p \"$1^!\"\n-\t\t;;\n-\t*)\n-\t\techo \"Root commit\"\n-\t\t;;\n-\tesac > \"$DOTEST\"/patch\n+\tgit sequencer--helper --make-patch \"$1\"\n \ttest -f \"$DOTEST\"/message ||\n \t\tgit cat-file commit \"$1\" | sed \"1,/^$/d\" > \"$DOTEST\"/message\n \ttest -f \"$SAVE_AUTHOR_INFO\" || {\n-- \n1.6.3.GIT\n"},{"id":"117121","messageId":"200906281413.21454.chriscool@tuxfamily.org","threadId":"19946","inReplyTo":"20090626210847.3885.18347.chriscool@tuxfamily.org","subject":"Re: [PATCH 2/4] sequencer: add \"make_patch\" function to save a patch","fromName":"Christian Couder","fromEmail":"chriscool@tuxfamily.org","sentAt":"2009-06-28T12:13:21Z","receivedAt":"2009-06-28T12:13:21Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"Ooops, there should be a:\n\nFrom: Stephan Beyer <s-beyer@gmx.net>\n\nheader in this patch.\n\nRegards,\nChristian.\n\nOn Friday 26 June 2009, Christian Couder wrote:\n> This function generates an informational patch file.\n>\n> The \"make_patch\" and the \"get_commit\" functions are copied from the\n> GSoC sequencer project:\n>\n> git://repo.or.cz/git/sbeyer.git\n>\n> (commit e7b8dab0c2a73ade92017a52bb1405ea1534ef20)\n>\n> Mentored-by: Christian Couder <chriscool@tuxfamily.org>\n> Mentored-by: Daniel Barkalow <barkalow@iabervon.org>\n> Signed-off-by: Christian Couder <chriscool@tuxfamily.org>\n> ---\n>  builtin-sequencer--helper.c |   75\n> ++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 74\n> insertions(+), 1 deletions(-)\n>\n> diff --git a/builtin-sequencer--helper.c b/builtin-sequencer--helper.c\n> index 721c0d8..8d32480 100644\n> --- a/builtin-sequencer--helper.c\n> +++ b/builtin-sequencer--helper.c\n> @@ -1,15 +1,83 @@\n>  #include \"builtin.h\"\n>  #include \"cache.h\"\n>  #include \"parse-options.h\"\n> +#include \"run-command.h\"\n> +\n> +#define SEQ_DIR \"rebase-merge\"\n> +\n> +#define PATCH_FILE\tgit_path(SEQ_DIR \"/patch\")\n>\n>  static const char * const git_sequencer_helper_usage[] = {\n>  \t\"git sequencer--helper --make-patch <commit>\",\n>  \tNULL\n>  };\n>\n> +/* Generate purely informational patch file */\n> +static void make_patch(struct commit *commit)\n> +{\n> +\tstruct commit_list *parents = commit->parents;\n> +\tconst char **args;\n> +\tstruct child_process chld;\n> +\tint fd = open(PATCH_FILE, O_WRONLY | O_CREAT, 0666);\n> +\tif (fd < 0)\n> +\t\treturn;\n> +\n> +\tmemset(&chld, 0, sizeof(chld));\n> +\tif (!parents) {\n> +\t\twrite(fd, \"Root commit\\n\", 12);\n> +\t\tclose(fd);\n> +\t\treturn;\n> +\t} else if (!parents->next) {\n> +\t\targs = xcalloc(5, sizeof(char *));\n> +\t\targs[0] = \"diff-tree\";\n> +\t\targs[1] = \"-p\";\n> +\t\targs[2] = xstrdup(sha1_to_hex(parents->item->object.sha1));\n> +\t\targs[3] = xstrdup(sha1_to_hex(((struct object *)commit)->sha1));\n> +\t} else {\n> +\t\tint i = 0;\n> +\t\tint count = 1;\n> +\n> +\t\tfor (; parents; parents = parents->next)\n> +\t\t\t++count;\n> +\t\targs = xcalloc(count + 3, sizeof(char *));\n> +\t\targs[i++] = \"diff\";\n> +\t\targs[i++] = \"--cc\";\n> +\t\targs[i++] = xstrdup(sha1_to_hex(commit->object.sha1));\n> +\n> +\t\tfor (parents = commit->parents; parents;\n> +\t\t     parents = parents->next)\n> +\t\t\targs[i++] = xstrdup(sha1_to_hex(\n> +\t\t\t\t\t    parents->item->object.sha1));\n> +\t}\n> +\n> +\tchld.argv = args;\n> +\tchld.git_cmd = 1;\n> +\tchld.out = fd;\n> +\n> +\t/* Run, ignore errors. */\n> +\tif (start_command(&chld))\n> +\t\treturn;\n> +\tfinish_command(&chld);\n> +\n> +\t/* TODO: free dup'ed SHAs in argument list */\n> +}\n> +\n> +/* Return a commit object of \"arg\" */\n> +static struct commit *get_commit(const char *arg)\n> +{\n> +\tunsigned char sha1[20];\n> +\n> +\tif (get_sha1(arg, sha1)) {\n> +\t\terror(\"Could not find '%s'\", arg);\n> +\t\treturn NULL;\n> +\t}\n> +\treturn lookup_commit_reference(sha1);\n> +}\n> +\n>  int cmd_sequencer__helper(int argc, const char **argv, const char\n> *prefix) {\n>  \tchar *commit = NULL;\n> +\tstruct commit *c;\n>  \tstruct option options[] = {\n>  \t\tOPT_STRING(0, \"make-patch\", &commit, \"commit\",\n>  \t\t\t   \"create a patch from commit\"),\n> @@ -22,6 +90,11 @@ int cmd_sequencer__helper(int argc, const char **argv,\n> const char *prefix) if (!commit)\n>  \t\tusage_with_options(git_sequencer_helper_usage, options);\n>\n> -\t/* Nothing to do yet */\n> +\tc = get_commit(commit);\n> +\tif (!c)\n> +\t\treturn 1;\n> +\n> +\tmake_patch(c);\n> +\n>  \treturn 0;\n>  }\n"}]}