{"thread":{"id":"20350","subject":"[PATCH 2/3] sequencer: add \"--reset-hard\" option to \"git sequencer--helper\"","startedAt":"2009-08-03T02:40:21Z","lastAt":"2009-08-04T23:09:23Z","messageCount":4,"participants":["Christian Couder","Daniel Barkalow"],"isPatch":true,"patchVersion":1,"patchTotal":3},"messages":[{"id":"119393","messageId":"20090803024023.3794.44226.chriscool@tuxfamily.org","threadId":"20350","inReplyTo":null,"subject":"[PATCH 2/3] sequencer: add \"--reset-hard\" option to \"git sequencer--helper\"","fromName":"Christian Couder","fromEmail":"chriscool@tuxfamily.org","sentAt":"2009-08-03T02:40:21Z","receivedAt":"2009-08-03T02:40:21Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"This new option uses the \"reset_almost_hard()\" function to perform\na reset.\n\nSigned-off-by: Christian Couder <chriscool@tuxfamily.org>\n---\n builtin-sequencer--helper.c |   65 ++++++++++++++++++++++++++++++++++++------\n 1 files changed, 55 insertions(+), 10 deletions(-)\n\ndiff --git a/builtin-sequencer--helper.c b/builtin-sequencer--helper.c\nindex 82a830d..e173671 100644\n--- a/builtin-sequencer--helper.c\n+++ b/builtin-sequencer--helper.c\n@@ -18,6 +18,7 @@ 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+\t\"git sequencer--helper --reset-hard <commit> <reflog-msg> <verbosity>\",\n \tNULL\n };\n \n@@ -172,27 +173,71 @@ static int set_verbosity(int verbose)\n \treturn 0;\n }\n \n+/* v should be \"\" or \"t\" or \"\\d\" */\n+static int parse_verbosity(const char *v)\n+{\n+\t/* \"\" means verbosity = 1 */\n+\tif (!v[0])\n+\t\treturn set_verbosity(1);\n+\n+\tif (v[1])\n+\t\treturn 1;\n+\n+\tif (v[0] == 't')\n+\t\treturn set_verbosity(2);\n+\n+\tif (!isdigit(v[0]))\n+\t\treturn 1;\n+\n+\treturn set_verbosity(v[0] - '0');\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+\tchar *patch_commit = NULL;\n+\tchar *reset_commit = NULL;\n \tstruct option options[] = {\n-\t\tOPT_STRING(0, \"make-patch\", &commit, \"commit\",\n+\t\tOPT_STRING(0, \"make-patch\", &patch_commit, \"commit\",\n \t\t\t   \"create a patch from commit\"),\n+\t\tOPT_STRING(0, \"reset-hard\", &reset_commit, \"commit\",\n+\t\t\t   \"reset to 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+\tif (patch_commit) {\n+\t\tstruct commit *c = get_commit(patch_commit);\n+\t\tif (!c)\n+\t\t\treturn 1;\n \n-\tc = get_commit(commit);\n-\tif (!c)\n-\t\treturn 1;\n+\t\tmake_patch(c);\n \n-\tmake_patch(c);\n+\t\treturn 0;\n+\t}\n \n-\treturn 0;\n+\tif (reset_commit) {\n+\t\tunsigned char sha1[20];\n+\n+\t\tif (argc != 2)\n+\t\t\tusage_with_options(git_sequencer_helper_usage,\n+\t\t\t\t\t   options);\n+\n+\t\tif (get_sha1(reset_commit, sha1)) {\n+\t\t\terror(\"Could not find '%s'\", reset_commit);\n+\t\t\treturn 1;\n+\t\t}\n+\n+\t\treflog = (char *)argv[0];\n+\n+\t\tif (parse_verbosity(argv[1])) {\n+\t\t\terror(\"bad verbosity '%s'\", argv[1]);\n+\t\t\treturn 1;\n+\t\t}\n+\n+\t\treturn reset_almost_hard(sha1);\n+\t}\n+\n+\tusage_with_options(git_sequencer_helper_usage, options);\n }\n-- \n1.6.4.133.g8a5c8\n"},{"id":"119501","messageId":"alpine.LNX.2.00.0908041111550.2147@iabervon.org","threadId":"20350","inReplyTo":"20090803024023.3794.44226.chriscool@tuxfamily.org","subject":"Re: [PATCH 2/3] sequencer: add \"--reset-hard\" option to \"git sequencer--helper\"","fromName":"Daniel Barkalow","fromEmail":"barkalow@iabervon.org","sentAt":"2009-08-04T15:34:15Z","receivedAt":"2009-08-04T15:34:15Z","isPatch":true,"sender":{"key":"barkalow@iabervon.org","avatar":"https://avatars.githubusercontent.com/u/55364219?v=4"},"body":"On Mon, 3 Aug 2009, Christian Couder wrote:\n\n> This new option uses the \"reset_almost_hard()\" function to perform\n> a reset.\n\nShouldn't it make it possible to do an almost-hard reset (that is, keep a \ndirty working tree's changes while changing the index and HEAD to a \ndifferent commit)? AFAICT, this series doesn't expose the interesting new\nfunctionality it provides.\n\nAlso, I thought that we'd found that other built-ins could be simplified \nthrough the use of functions you're adding here. In particular, checkout \nwants to change the index and working tree while preserving dirty working \ntree changes. So it would probably be better for it to go in a library \nobject, where sequencer--helper would just make it available to shell \ncode.\n\t-Daniel\n*This .sig left intentionally blank*\n"},{"id":"119525","messageId":"200908042317.26408.chriscool@tuxfamily.org","threadId":"20350","inReplyTo":"alpine.LNX.2.00.0908041111550.2147@iabervon.org","subject":"Re: [PATCH 2/3] sequencer: add \"--reset-hard\" option to \"git sequencer--helper\"","fromName":"Christian Couder","fromEmail":"chriscool@tuxfamily.org","sentAt":"2009-08-04T21:17:26Z","receivedAt":"2009-08-04T21:17:26Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"On Tuesday 04 August 2009, Daniel Barkalow wrote:\n> On Mon, 3 Aug 2009, Christian Couder wrote:\n> > This new option uses the \"reset_almost_hard()\" function to perform\n> > a reset.\n>\n> Shouldn't it make it possible to do an almost-hard reset (that is, keep a\n> dirty working tree's changes while changing the index and HEAD to a\n> different commit)?\n\nYeah, I will improve the documentation of this function as Junio requested.\n\n> AFAICT, this series doesn't expose the interesting new \n> functionality it provides.\n>\n> Also, I thought that we'd found that other built-ins could be simplified\n> through the use of functions you're adding here. In particular, checkout\n> wants to change the index and working tree while preserving dirty working\n> tree changes. So it would probably be better for it to go in a library\n> object, where sequencer--helper would just make it available to shell\n> code.\n\nYeah, I agree, but right now I'd rather keep the code quite close to what it \nis on the sequencer repo if possible.\n\nThanks,\nChristian.\n"},{"id":"119540","messageId":"alpine.LNX.2.00.0908041719060.2147@iabervon.org","threadId":"20350","inReplyTo":"200908042317.26408.chriscool@tuxfamily.org","subject":"Re: [PATCH 2/3] sequencer: add \"--reset-hard\" option to \"git sequencer--helper\"","fromName":"Daniel Barkalow","fromEmail":"barkalow@iabervon.org","sentAt":"2009-08-04T23:09:23Z","receivedAt":"2009-08-04T23:09:23Z","isPatch":true,"sender":{"key":"barkalow@iabervon.org","avatar":"https://avatars.githubusercontent.com/u/55364219?v=4"},"body":"On Tue, 4 Aug 2009, Christian Couder wrote:\n\n> On Tuesday 04 August 2009, Daniel Barkalow wrote:\n> > On Mon, 3 Aug 2009, Christian Couder wrote:\n> > > This new option uses the \"reset_almost_hard()\" function to perform\n> > > a reset.\n> >\n> > Shouldn't it make it possible to do an almost-hard reset (that is, keep a\n> > dirty working tree's changes while changing the index and HEAD to a\n> > different commit)?\n> \n> Yeah, I will improve the documentation of this function as Junio requested.\n\nIt's not just the documentation; AFAICT, there's no way to get allow_dirty \nset, which in turn makes a bunch of this code unreachable. It would be \ngood to expose that from the start, even if nothing uses it immediately, \nso that people to see whether it behaves as expected.\n\n\t-Daniel\n*This .sig left intentionally blank*\n"}]}