{"thread":{"id":"5978","subject":"[PATCH] make cg-commit --review restore original tree state afterwards","startedAt":"2006-10-21T01:11:18Z","lastAt":"2006-10-27T02:02:45Z","messageCount":3,"participants":["Sam Vilain","Petr Baudis"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"29456","messageId":"20061021014723.B8E9C13810D@magnus.utsl.gen.nz","threadId":"5978","inReplyTo":null,"subject":"[PATCH] make cg-commit --review restore original tree state afterwards","fromName":"Sam Vilain","fromEmail":"sam@vilain.net","sentAt":"2006-10-21T01:11:18Z","receivedAt":"2006-10-21T01:11:18Z","isPatch":true,"sender":{"key":"sam@vilain.net","avatar":"https://gravatar.com/avatar/8fc840ca854dbf6f7065b4335e3b934951c1dca3b11db688e95e471901f8f4a8?d=mp&s=160"},"body":"If you delete hunks from the patch that 'cg-commit -p' shows you, then\nthey are lost 'forever'.  Let's put back everything how it was\nbeforehand instead.\n---\n cg-commit |   25 +++++++++++++++++--------\n 1 files changed, 17 insertions(+), 8 deletions(-)\n\ndiff --git a/cg-commit b/cg-commit\nindex 01a4eb7..81b3619 100755\n--- a/cg-commit\n+++ b/cg-commit\n@@ -568,18 +568,16 @@ else\n fi\n rm \"$LOGMSG2\"\n \n+pine_for_darcs() {\n+\tdie \"unable to revert the new patch; the original patch is available in $PATCH, your edited patch is available in $PATCH2, your log message is in $LOGMSG, your working copy is in undefined state now and the world is about to end in ten minutes, have a nice day\"\n+}\n+\n if [ \"$review\" ]; then\n \tif ! cmp -s \"$PATCH\" \"$PATCH2\"; then\n \t\techo \"Reverting the original patch...\"\n-\t\tif ! cg-patch -R < \"$PATCH\"; then\n-\t\t\tdie \"unable to revert the original patch; the original patch is available in $PATCH, your edited patch is available in $PATCH2, your log message is in $LOGMSG, your working copy is in undefined state now and the world is about to end in ten minutes, have a nice day\"\n-\t\tfi\n+\t\tcg-patch -R < \"$PATCH\" || pine_for_darcs\n \t\techo \"Applying the edited patch...\"\n-\t\tif ! cg-patch < \"$PATCH2\"; then\n-\t\t\t# FIXME: Do something better to alleviate this situation.\n-\t\t\t# At least restore the tree to the original state.\n-\t\t\tdie \"unable to apply the edited patch; the original patch is available in $PATCH, your edited patch is available in $PATCH2, your log message is in $LOGMSG, your working copy is in undefined state now and the world is about to end in five minutes, have a nice day\"\n-\t\tfi\n+\t\tcg-patch < \"$PATCH2\" || pine_for_darcs\n \tfi\n fi\n \n@@ -625,6 +623,17 @@ if [ \"$amend\" ]; then\n fi\n \n treeid=\"$(git-write-tree ${missingok})\"\n+\n+if [ \"$review\" ]; then\n+        if ! cmp -s \"$PATCH\" \"$PATCH2\"; then\n+                echo \"Reverting the new patch...\"\n+                cg-patch -R < \"$PATCH2\" || pine_for_darcs\n+                echo \"Applying the old patch...\"\n+                cg-patch < \"$PATCH\" || pine_for_darcs\n+        fi\n+fi\n+\n+\n [ \"$treeid\" ] || die \"git-write-tree failed\"\n if [ ! \"$force\" ] && [ ! \"$merging\" ] && [ \"$oldhead\" ] &&\n    [ \"$treeid\" = \"$(cg-object-id -t)\" ]; then\n-- \n1.4.2.g0ea2\n"},{"id":"29479","messageId":"4539EB15.3050405@vilain.net","threadId":"5978","inReplyTo":"20061021014723.B8E9C13810D@magnus.utsl.gen.nz","subject":"Re: [PATCH] make cg-commit --review restore original tree state afterwards","fromName":"Sam Vilain","fromEmail":"sam@vilain.net","sentAt":"2006-10-21T09:40:37Z","receivedAt":"2006-10-21T09:40:37Z","isPatch":true,"sender":{"key":"sam@vilain.net","avatar":"https://gravatar.com/avatar/8fc840ca854dbf6f7065b4335e3b934951c1dca3b11db688e95e471901f8f4a8?d=mp&s=160"},"body":"Ok, I ruined the error message.\n\nThis could also do with some enhancement; if you edit hunks of the\npatch, then the numbers in the hunks could be updated so as to not make\nthe patch abort.  Also, if it does abort you should get the option of\nundoing everything, or editing the patch again...\n\nWill try again with this another time.\n\nSam.\n\nSam Vilain wrote:\n> If you delete hunks from the patch that 'cg-commit -p' shows you, then\n> they are lost 'forever'.  Let's put back everything how it was\n> beforehand instead.\n> ---\n>  cg-commit |   25 +++++++++++++++++--------\n>  1 files changed, 17 insertions(+), 8 deletions(-)\n> \n> diff --git a/cg-commit b/cg-commit\n> index 01a4eb7..81b3619 100755\n> --- a/cg-commit\n> +++ b/cg-commit\n> @@ -568,18 +568,16 @@ else\n>  fi\n>  rm \"$LOGMSG2\"\n>  \n> +pine_for_darcs() {\n> +\tdie \"unable to revert the new patch; the original patch is available in $PATCH, your edited patch is available in $PATCH2, your log message is in $LOGMSG, your working copy is in undefined state now and the world is about to end in ten minutes, have a nice day\"\n> +}\n> +\n>  if [ \"$review\" ]; then\n>  \tif ! cmp -s \"$PATCH\" \"$PATCH2\"; then\n>  \t\techo \"Reverting the original patch...\"\n> -\t\tif ! cg-patch -R < \"$PATCH\"; then\n> -\t\t\tdie \"unable to revert the original patch; the original patch is available in $PATCH, your edited patch is available in $PATCH2, your log message is in $LOGMSG, your working copy is in undefined state now and the world is about to end in ten minutes, have a nice day\"\n> -\t\tfi\n> +\t\tcg-patch -R < \"$PATCH\" || pine_for_darcs\n>  \t\techo \"Applying the edited patch...\"\n> -\t\tif ! cg-patch < \"$PATCH2\"; then\n> -\t\t\t# FIXME: Do something better to alleviate this situation.\n> -\t\t\t# At least restore the tree to the original state.\n> -\t\t\tdie \"unable to apply the edited patch; the original patch is available in $PATCH, your edited patch is available in $PATCH2, your log message is in $LOGMSG, your working copy is in undefined state now and the world is about to end in five minutes, have a nice day\"\n> -\t\tfi\n> +\t\tcg-patch < \"$PATCH2\" || pine_for_darcs\n>  \tfi\n>  fi\n>  \n> @@ -625,6 +623,17 @@ if [ \"$amend\" ]; then\n>  fi\n>  \n>  treeid=\"$(git-write-tree ${missingok})\"\n> +\n> +if [ \"$review\" ]; then\n> +        if ! cmp -s \"$PATCH\" \"$PATCH2\"; then\n> +                echo \"Reverting the new patch...\"\n> +                cg-patch -R < \"$PATCH2\" || pine_for_darcs\n> +                echo \"Applying the old patch...\"\n> +                cg-patch < \"$PATCH\" || pine_for_darcs\n> +        fi\n> +fi\n> +\n> +\n>  [ \"$treeid\" ] || die \"git-write-tree failed\"\n>  if [ ! \"$force\" ] && [ ! \"$merging\" ] && [ \"$oldhead\" ] &&\n>     [ \"$treeid\" = \"$(cg-object-id -t)\" ]; then\n"},{"id":"297081","messageId":"20061027020245.GX20017@pasky.or.cz","threadId":"5978","inReplyTo":"4539EB15.3050405@vilain.net","subject":"Re: [PATCH] make cg-commit --review restore original tree state afterwards","fromName":"Petr Baudis","fromEmail":"pasky@suse.cz","sentAt":"2006-10-27T02:02:45Z","receivedAt":"2006-10-27T02:02:45Z","isPatch":true,"sender":{"key":"pasky@ucw.cz","avatar":"https://avatars.githubusercontent.com/u/18439?v=4"},"body":"Dear diary, on Sat, Oct 21, 2006 at 11:40:37AM CEST, I got a letter\nwhere Sam Vilain <sam@vilain.net> said that...\n> Ok, I ruined the error message.\n> \n> This could also do with some enhancement; if you edit hunks of the\n> patch, then the numbers in the hunks could be updated so as to not make\n> the patch abort.  Also, if it does abort you should get the option of\n> undoing everything, or editing the patch again...\n> \n> Will try again with this another time.\n\nActually, on current master you can now use internal_commit. My idea was\nthat you internal_commit with the local changes as X, then rollback to\nHEAD, apply new patch. If you fail at this point, you can do much saner\nrecovery since you can reset the tree and timewarp back to X and save\nthe modified patch at a suitable place.\n\nBesides, you can just timewarp the tree back to X (w/o updating HEAD) at\nthis point to recover the changes excluded from the committed patch!\n\nI guess timewarping/internal_commit may look like magic to everyone but\nme so if the above is unclear, just say so and I'll try to be more\nthorough. :-)\n\n-- \n\t\t\t\tPetr \"Pasky\" Baudis\nStuff: http://pasky.or.cz/\n#!/bin/perl -sp0777i<X+d*lMLa^*lN%0]dsXx++lMlN/dsM0<j]dsj\n$/=unpack('H*',$_);$_=`echo 16dio\\U$k\"SK$/SM$n\\EsN0p[lN*1\n"}]}