{"thread":{"id":"20351","subject":"[PATCH 1/3] sequencer: add \"reset_almost_hard()\" and related functions","startedAt":"2009-08-03T02:40:20Z","lastAt":"2009-08-04T13:03:11Z","messageCount":3,"participants":["Christian Couder","Johannes Schindelin"],"isPatch":true,"patchVersion":1,"patchTotal":3},"messages":[{"id":"119394","messageId":"20090803024023.3794.90748.chriscool@tuxfamily.org","threadId":"20351","inReplyTo":null,"subject":"[PATCH 1/3] sequencer: add \"reset_almost_hard()\" and related functions","fromName":"Christian Couder","fromEmail":"chriscool@tuxfamily.org","sentAt":"2009-08-03T02:40:20Z","receivedAt":"2009-08-03T02:40:20Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"From: Stephan Beyer <s-beyer@gmx.net>\n\nThis patch adds some code that comes as is from the sequencer GSoC\nproject:\n\ngit://repo.or.cz/git/sbeyer.git\n\n(commit e7b8dab0c2a73ade92017a52bb1405ea1534ef20)\n\nIt adds some static variables and the following functions:\n\n\t- parse_and_init_tree_desc()\n\t- reset_index_file()\n\t- reset_almost_hard()\n\t- set_verbosity()\n\nMentored-by: Daniel Barkalow <barkalow@iabervon.org>\nMentored-by: Christian Couder <chriscool@tuxfamily.org>\nSigned-off-by: Stephan Beyer <s-beyer@gmx.net>\nSigned-off-by: Christian Couder <chriscool@tuxfamily.org>\n---\n builtin-sequencer--helper.c |   94 +++++++++++++++++++++++++++++++++++++++++++\n 1 files changed, 94 insertions(+), 0 deletions(-)\n\ndiff --git a/builtin-sequencer--helper.c b/builtin-sequencer--helper.c\nindex 1dda525..82a830d 100644\n--- a/builtin-sequencer--helper.c\n+++ b/builtin-sequencer--helper.c\n@@ -2,16 +2,95 @@\n #include \"cache.h\"\n #include \"parse-options.h\"\n #include \"run-command.h\"\n+#include \"refs.h\"\n+#include \"diff.h\"\n+#include \"unpack-trees.h\"\n \n #define SEQ_DIR \"rebase-merge\"\n \n #define PATCH_FILE\tgit_path(SEQ_DIR \"/patch\")\n \n+static char *reflog;\n+\n+static int allow_dirty = 0, verbosity = 1, advice = 1;\n+\n+static unsigned char head_sha1[20];\n+\n static const char * const git_sequencer_helper_usage[] = {\n \t\"git sequencer--helper --make-patch <commit>\",\n \tNULL\n };\n \n+static int parse_and_init_tree_desc(const unsigned char *sha1,\n+\t\t\t\t    struct tree_desc *desc)\n+{\n+\tstruct tree *tree = parse_tree_indirect(sha1);\n+\tif (!tree)\n+\t\treturn 1;\n+\tinit_tree_desc(desc, tree->buffer, tree->size);\n+\treturn 0;\n+}\n+\n+static int reset_index_file(const unsigned char *sha1, int update, int dirty)\n+{\n+\tint nr = 1;\n+\tint newfd;\n+\tstruct tree_desc desc[2];\n+\tstruct unpack_trees_options opts;\n+\tstruct lock_file *lock = xcalloc(1, sizeof(struct lock_file));\n+\n+\tmemset(&opts, 0, sizeof(opts));\n+\topts.head_idx = 1;\n+\topts.src_index = &the_index;\n+\topts.dst_index = &the_index;\n+\topts.reset = 1; /* ignore unmerged entries and overwrite wt files */\n+\topts.merge = 1;\n+\topts.fn = oneway_merge;\n+\tif (verbosity > 2)\n+\t\topts.verbose_update = 1;\n+\tif (update) /* update working tree */\n+\t\topts.update = 1;\n+\n+\tnewfd = hold_locked_index(lock, 1);\n+\n+\tread_cache_unmerged();\n+\n+\tif (dirty) {\n+\t\tif (get_sha1(\"HEAD\", head_sha1))\n+\t\t\treturn error(\"You do not have a valid HEAD.\");\n+\t\tif (parse_and_init_tree_desc(head_sha1, desc))\n+\t\t\treturn error(\"Failed to find tree of HEAD.\");\n+\t\tnr++;\n+\t\topts.fn = twoway_merge;\n+\t}\n+\n+\tif (parse_and_init_tree_desc(sha1, desc + nr - 1))\n+\t\treturn error(\"Failed to find tree of %s.\", sha1_to_hex(sha1));\n+\tif (unpack_trees(nr, desc, &opts))\n+\t\treturn -1;\n+\tif (write_cache(newfd, active_cache, active_nr) ||\n+\t    commit_locked_index(lock))\n+\t\treturn error(\"Could not write new index file.\");\n+\n+\treturn 0;\n+}\n+\n+/*\n+ * Realize reset --hard behavior.\n+ * If allow_dirty is set and there is a dirty working tree,\n+ * then the changes are to be kept.\n+ */\n+static int reset_almost_hard(const unsigned char *sha)\n+{\n+\tint err = allow_dirty ?\n+\t\t(reset_index_file(sha, 1, 1) || reset_index_file(sha, 0, 0)) :\n+\t\treset_index_file(sha, 1, 0);\n+\tif (err)\n+\t\treturn error(\"Could not reset index.\");\n+\n+\treturn update_ref(reflog, \"HEAD\", sha, NULL, 0, MSG_ON_ERR);\n+}\n+\n /* Generate purely informational patch file */\n static void make_patch(struct commit *commit)\n {\n@@ -78,6 +157,21 @@ static struct commit *get_commit(const char *arg)\n \treturn lookup_commit_reference(sha1);\n }\n \n+static int set_verbosity(int verbose)\n+{\n+\tchar tmp[] = \"0\";\n+\tverbosity = verbose;\n+\tif (verbosity <= 0) {\n+\t\tverbosity = 0;\n+\t\tadvice = 0;\n+\t} else if (verbosity > 5)\n+\t\tverbosity = 5;\n+\t/* Git does not run on EBCDIC, so we rely on ASCII: */\n+\ttmp[0] += verbosity;\n+\tsetenv(\"GIT_MERGE_VERBOSITY\", tmp, 1);\n+\treturn 0;\n+}\n+\n int cmd_sequencer__helper(int argc, const char **argv, const char *prefix)\n {\n \tchar *commit = NULL;\n-- \n1.6.4.133.g8a5c8\n"},{"id":"119492","messageId":"alpine.DEB.1.00.0908041443310.8306@pacific.mpi-cbg.de","threadId":"20351","inReplyTo":"20090803024023.3794.90748.chriscool@tuxfamily.org","subject":"Re: [PATCH 1/3] sequencer: add \"reset_almost_hard()\" and related functions","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2009-08-04T12:45:30Z","receivedAt":"2009-08-04T12:45:30Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Mon, 3 Aug 2009, Christian Couder wrote:\n\n> diff --git a/builtin-sequencer--helper.c b/builtin-sequencer--helper.c\n> index 1dda525..82a830d 100644\n> --- a/builtin-sequencer--helper.c\n> +++ b/builtin-sequencer--helper.c\n> @@ -2,16 +2,95 @@\n\nI do not have that file in my tree.  Yet your 1/3 already expects it to be \nthere.\n\nWell, I guess I will work on finishing my rebase-i-p branch next week, and \nthen see what is there in Stephan's repository, and ask him why he went so \nsilent (after all, his code should have been polished  enough to be \nincluded 11 months ago).\n\nCiao,\nDscho\n"},{"id":"119494","messageId":"c07716ae0908040603t12daa900l18178770a17780b1@mail.gmail.com","threadId":"20351","inReplyTo":"alpine.DEB.1.00.0908041443310.8306@pacific.mpi-cbg.de","subject":"Re: [PATCH 1/3] sequencer: add \"reset_almost_hard()\" and related functions","fromName":"Christian Couder","fromEmail":"christian.couder@gmail.com","sentAt":"2009-08-04T13:03:11Z","receivedAt":"2009-08-04T13:03:11Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"Hi,\n\nOn Tue, Aug 4, 2009 at 2:45 PM, Johannes\nSchindelin<Johannes.Schindelin@gmx.de> wrote:\n> Hi,\n>\n> On Mon, 3 Aug 2009, Christian Couder wrote:\n>\n>> diff --git a/builtin-sequencer--helper.c b/builtin-sequencer--helper.c\n>> index 1dda525..82a830d 100644\n>> --- a/builtin-sequencer--helper.c\n>> +++ b/builtin-sequencer--helper.c\n>> @@ -2,16 +2,95 @@\n>\n> I do not have that file in my tree.  Yet your 1/3 already expects it to be\n> there.\n\nThis file is in pu. One of my previous patch added it.\n\n> Well, I guess I will work on finishing my rebase-i-p branch next week, and\n> then see what is there in Stephan's repository, and ask him why he went so\n> silent (after all, his code should have been polished  enough to be\n> included 11 months ago).\n\nStephan started to work again on his repository a few days ago. He\nintegrated some of the changes I posted to this list and some\ninformation about what is left to do to complete his work. That will\nmake it easier for me or anyone who wants to work on this. Thanks\nStephan!\n\nBest regards,\nChristian.\n"}]}