{"thread":{"id":"23820","subject":"[StGit PATCH] edit: Allow setting git tree SHA1 of a patch","startedAt":"2010-05-16T17:33:53Z","lastAt":"2010-05-26T21:18:07Z","messageCount":16,"participants":["Gustav Hållberg","Karl Wiberg","Catalin Marinas","David Kågedal"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"141777","messageId":"20100516172738.5043.94039.stgit@localhost.localdomain","threadId":"23820","inReplyTo":null,"subject":"[StGit PATCH] edit: Allow setting git tree SHA1 of a patch","fromName":"Gustav Hållberg","fromEmail":"gustav@gmail.com","sentAt":"2010-05-16T17:33:53Z","receivedAt":"2010-05-16T17:33:53Z","isPatch":true,"sender":{"key":"gustav@gmail.com","avatar":null},"body":"I would like to have something similar to this patch, which allows for\nsetting the (git) tree of a particular patch. I would like to use it\n(from the Emacs mode) to make it easier to split an old patch into two\n(or more).\n\nIt might be that this is too \"powerful\" (read: unsafe), and maybe a\nbetter (safer) command would use whatever is currently in the index\nrather than a SHA1.\n\nAnyway, I'd appreciate any comments, e.g. at\nhttp://github.com/gustavh/stgit/commits/set-tree (pull from\ngit://github.com/gustavh/stgit.git \"set-tree\" branch).\n\n---\nAlso fix capitalization in edit's short description.\n\nSigned-off-by: Gustav Hållberg <gustav@gmail.com>\n---\n stgit/commands/edit.py |   19 ++++++++++++++++---\n t/t3300-edit.sh        |   15 +++++++++++++++\n 2 files changed, 31 insertions(+), 3 deletions(-)\n\ndiff --git a/stgit/commands/edit.py b/stgit/commands/edit.py\nindex f3f731f..55282f4 100644\n--- a/stgit/commands/edit.py\n+++ b/stgit/commands/edit.py\n@@ -24,7 +24,7 @@ from stgit.commands import common\n from stgit.lib import git as gitlib, transaction, edit\n from stgit.out import *\n \n-help = 'edit a patch description or diff'\n+help = 'Edit a patch description or diff'\n kind = 'patch'\n usage = ['[options] [--] [<patch>]']\n description = \"\"\"\n@@ -52,7 +52,11 @@ invoked even if such command-line options are given.)\n \n If the patch diff is edited but does not apply, no changes are made to\n the patch at all. The edited patch is saved to a file which you can\n-feed to \"stg edit --file\", once you have made sure it does apply.\"\"\"\n+feed to \"stg edit --file\", once you have made sure it does apply.\n+\n+With --set-tree you set the git tree of the patch to the specified\n+SHA1, without changing the tree of any other patches. See also the\n+--set-tree flag of stg push.\"\"\"\n \n args = [argparse.applied_patches, argparse.unapplied_patches,\n         argparse.hidden_patches]\n@@ -61,6 +65,9 @@ options = [\n         short = 'Edit the patch diff'),\n     opt('-e', '--edit', action = 'store_true',\n         short = 'Invoke interactive editor'),\n+    opt('-t', '--set-tree', action = 'store',\n+        metavar = 'SHA1',\n+        short = 'Set the git tree of the patch to SHA1'),\n     ] + (argparse.sign_options() +\n          argparse.message_options(save_template = True) +\n          argparse.author_options() + argparse.diff_opts_option())\n@@ -86,6 +93,9 @@ def func(parser, options, args):\n \n     cd = orig_cd = stack.patches.get(patchname).commit.data\n \n+    if options.set_tree:\n+        cd = cd.set_tree(stack.repository.get_tree(options.set_tree))\n+\n     cd, failed_diff = edit.auto_edit_patch(\n         stack.repository, cd, msg = options.message, contains_diff = True,\n         author = options.author, committer = lambda p: p,\n@@ -128,7 +138,10 @@ def func(parser, options, args):\n     trans.patches[patchname] = stack.repository.commit(cd)\n     try:\n         for pn in popped:\n-            trans.push_patch(pn, iw, allow_interactive = True)\n+            if options.set_tree:\n+                trans.push_tree(pn)\n+            else:\n+                trans.push_patch(pn, iw, allow_interactive = True)\n     except transaction.TransactionHalted:\n         pass\n     try:\ndiff --git a/t/t3300-edit.sh b/t/t3300-edit.sh\nindex 7003a27..078d4c3 100755\n--- a/t/t3300-edit.sh\n+++ b/t/t3300-edit.sh\n@@ -212,4 +212,19 @@ test_expect_failure 'Fail to set invalid author date' '\n     test \"$(date HEAD)\" = \"2013-01-28 22:30:00 -0300\"\n '\n \n+test_expect_success 'Set patch tree SHA1' '\n+    p2tree=$(git log -1 --pretty=format:%T $(stg id p2)) &&\n+    p4tree=$(git log -1 --pretty=format:%T $(stg id p4)) &&\n+    stg edit --set-tree $p4tree &&\n+    test $(git write-tree) = $p4tree &&\n+    grep \"^333zz$\" foo &&\n+    stg pop &&\n+    stg edit --set-tree $p2tree p2 &&\n+    stg push --set-tree &&\n+    test $(git write-tree) = $p2tree &&\n+    grep \"^333$\" foo &&\n+    stg edit --set-tree $p2tree p1 &&\n+    test \"$(echo $(stg series --empty --all))\" = \"+ p1 0> p2 - p3 ! p4\"\n+'\n+\n test_done\n"},{"id":"141828","messageId":"AANLkTimBSc35cnmRgDMDhQKtXC2PchcrSGHxMBcBMtuG@mail.gmail.com","threadId":"23820","inReplyTo":"20100516172738.5043.94039.stgit@localhost.localdomain","subject":"Re: [StGit PATCH] edit: Allow setting git tree SHA1 of a patch","fromName":"Karl Wiberg","fromEmail":"kha@treskal.com","sentAt":"2010-05-17T17:14:37Z","receivedAt":"2010-05-17T17:14:37Z","isPatch":true,"sender":{"key":"kha@treskal.com","avatar":"https://gravatar.com/avatar/f0120c734b5279b345075a28521e1ac66acb20c9913ffe9bf6ae97e53f7f3f13?d=mp&s=160"},"body":"2010/5/16 Gustav Hållberg <gustav@gmail.com>:\n> I would like to have something similar to this patch, which allows for\n> setting the (git) tree of a particular patch. I would like to use it\n> (from the Emacs mode) to make it easier to split an old patch into two\n> (or more).\n>\n> It might be that this is too \"powerful\" (read: unsafe), and maybe a\n> better (safer) command would use whatever is currently in the index\n> rather than a SHA1.\n\nI think this is a reasonable idea. (Note that for unapplied\npatches---or any patch that we can pop---the notion of setting the\nbottom tree makes sense too. pick can currently create a patch from a\ngiven commit; it might be reasonable to teach it (or stg new) to take\ntwo trees instead.)\n\n-- \nKarl Wiberg, kha@treskal.com\n   subrabbit.wordpress.com\n   www.treskal.com/kalle\n"},{"id":"142024","messageId":"AANLkTikcG3Chw1cpiKB00MrnZz-HZk9xAF_KtTTiVECi@mail.gmail.com","threadId":"23820","inReplyTo":"20100516172738.5043.94039.stgit@localhost.localdomain","subject":"Re: [StGit PATCH] edit: Allow setting git tree SHA1 of a patch","fromName":"Catalin Marinas","fromEmail":"catalin.marinas@gmail.com","sentAt":"2010-05-21T12:37:59Z","receivedAt":"2010-05-21T12:37:59Z","isPatch":true,"sender":{"key":"catalin.marinas@gmail.com","avatar":null},"body":"Hi Gustav,\n\n2010/5/16 Gustav Hållberg <gustav@gmail.com>:\n> I would like to have something similar to this patch, which allows for\n> setting the (git) tree of a particular patch. I would like to use it\n> (from the Emacs mode) to make it easier to split an old patch into two\n> (or more).\n>\n> It might be that this is too \"powerful\" (read: unsafe), and maybe a\n> better (safer) command would use whatever is currently in the index\n> rather than a SHA1.\n\nI'm not against such option (as long as it is somehow mentioned that's\ndangerous) though I don't fully understand how one would use it,\nespecially when the patch is buried under other patches. With a series\nof patches, any easily accessible tree (sha1) belongs to one of the\npatches.\n\nMy current approach for splitting patches is to \"goto\" the patch I\nneed to split, run \"git reset HEAD^\", add the files I have to the\nindex and then do a \"refresh --index\".\n\nAnother approach is to pop the patch I want split, create individual\npatches and run \"pick --fold\" for each new smaller patch.\n\n-- \nCatalin\n"},{"id":"142031","messageId":"u5tzkzt73us.fsf@beatles.e.vtech","threadId":"23820","inReplyTo":"AANLkTikcG3Chw1cpiKB00MrnZz-HZk9xAF_KtTTiVECi@mail.gmail.com","subject":"Re: [StGit PATCH] edit: Allow setting git tree SHA1 of a patch","fromName":"David Kågedal","fromEmail":"davidk@lysator.liu.se","sentAt":"2010-05-21T13:59:23Z","receivedAt":"2010-05-21T13:59:23Z","isPatch":true,"sender":{"key":"davidk@lysator.liu.se","avatar":"https://avatars.githubusercontent.com/u/60530?v=4"},"body":"Catalin Marinas <catalin.marinas@gmail.com> writes:\n\n> Hi Gustav,\n>\n> 2010/5/16 Gustav Hållberg <gustav@gmail.com>:\n>> I would like to have something similar to this patch, which allows for\n>> setting the (git) tree of a particular patch. I would like to use it\n>> (from the Emacs mode) to make it easier to split an old patch into two\n>> (or more).\n>>\n>> It might be that this is too \"powerful\" (read: unsafe), and maybe a\n>> better (safer) command would use whatever is currently in the index\n>> rather than a SHA1.\n>\n> I'm not against such option (as long as it is somehow mentioned that's\n> dangerous) though I don't fully understand how one would use it,\n> especially when the patch is buried under other patches. With a series\n> of patches, any easily accessible tree (sha1) belongs to one of the\n> patches.\n\nThe idea is that Gustav wants to allow the editing of a file as it\nappears in an earlier version. Lets say you have patches A, B, C and\nD. You realize that one of the changes in to foo.c in C shuold really be\ndone in A. So you open the \"A version of foo.c\" in your editor, do the\nchange, and then save it. The save operation needs to update A to be\nthe new tree that contains the updated foo.c, and the remaining patches\nwill keep their tree. The effect is that the moved change now appears as\na diff in A, but not in C (nor B or D).\n\nWorking like this means that we don't really see the series as a string\nof pateches, but as a series of named commits that we can go back and\nedit. But this is a natural way of working with it once the tools get\npowerful enough to support it.\n\n-- \nDavid Kågedal\n"},{"id":"142037","messageId":"AANLkTilV3VQARdyZ-m9GCXz1Rwt0j6Q6noNyFrmmDzR5@mail.gmail.com","threadId":"23820","inReplyTo":"u5tzkzt73us.fsf@beatles.e.vtech","subject":"Re: [StGit PATCH] edit: Allow setting git tree SHA1 of a patch","fromName":"Catalin Marinas","fromEmail":"catalin.marinas@gmail.com","sentAt":"2010-05-21T15:16:18Z","receivedAt":"2010-05-21T15:16:18Z","isPatch":true,"sender":{"key":"catalin.marinas@gmail.com","avatar":null},"body":"On 21 May 2010 14:59, David Kågedal <davidk@lysator.liu.se> wrote:\n> Catalin Marinas <catalin.marinas@gmail.com> writes:\n>> 2010/5/16 Gustav Hållberg <gustav@gmail.com>:\n>>> I would like to have something similar to this patch, which allows for\n>>> setting the (git) tree of a particular patch. I would like to use it\n>>> (from the Emacs mode) to make it easier to split an old patch into two\n>>> (or more).\n>>>\n>>> It might be that this is too \"powerful\" (read: unsafe), and maybe a\n>>> better (safer) command would use whatever is currently in the index\n>>> rather than a SHA1.\n>>\n>> I'm not against such option (as long as it is somehow mentioned that's\n>> dangerous) though I don't fully understand how one would use it,\n>> especially when the patch is buried under other patches. With a series\n>> of patches, any easily accessible tree (sha1) belongs to one of the\n>> patches.\n>\n> The idea is that Gustav wants to allow the editing of a file as it\n> appears in an earlier version. Lets say you have patches A, B, C and\n> D. You realize that one of the changes in to foo.c in C shuold really be\n> done in A. So you open the \"A version of foo.c\" in your editor, do the\n> change, and then save it. The save operation needs to update A to be\n> the new tree that contains the updated foo.c, and the remaining patches\n> will keep their tree. The effect is that the moved change now appears as\n> a diff in A, but not in C (nor B or D).\n\nThis is currently achieved by \"pop B C D\", edit file, \"refresh\", \"push\n--set-tree B C D\".\n\nCan \"edit --set-tree <sha1>\" make this simpler? Which <sha1> value\nwould be used with \"edit --set-tree\" (unless that's done by Emacs mode\nbehind the scene and it generates the tree that gets passed to edit).\n\n> Working like this means that we don't really see the series as a string\n> of patches, but as a series of named commits that we can go back and\n> edit. But this is a natural way of working with it once the tools get\n> powerful enough to support it.\n\nThat's looks a bit difficult (at least to me) since the commits are\nusually chained. But, yes, as long as the resulting tree remains he\nsame, we could freely edit the tree corresponding to intermediate\npatches.\n\n-- \nCatalin\n"},{"id":"142042","messageId":"u5twrux6znz.fsf@beatles.e.vtech","threadId":"23820","inReplyTo":"AANLkTilV3VQARdyZ-m9GCXz1Rwt0j6Q6noNyFrmmDzR5@mail.gmail.com","subject":"Re: [StGit PATCH] edit: Allow setting git tree SHA1 of a patch","fromName":"David Kågedal","fromEmail":"davidk@lysator.liu.se","sentAt":"2010-05-21T15:29:52Z","receivedAt":"2010-05-21T15:29:52Z","isPatch":true,"sender":{"key":"davidk@lysator.liu.se","avatar":"https://avatars.githubusercontent.com/u/60530?v=4"},"body":"Catalin Marinas <catalin.marinas@gmail.com> writes:\n\n> On 21 May 2010 14:59, David Kågedal <davidk@lysator.liu.se> wrote:\n>> Catalin Marinas <catalin.marinas@gmail.com> writes:\n>>> 2010/5/16 Gustav Hållberg <gustav@gmail.com>:\n>>>> I would like to have something similar to this patch, which allows for\n>>>> setting the (git) tree of a particular patch. I would like to use it\n>>>> (from the Emacs mode) to make it easier to split an old patch into two\n>>>> (or more).\n>>>>\n>>>> It might be that this is too \"powerful\" (read: unsafe), and maybe a\n>>>> better (safer) command would use whatever is currently in the index\n>>>> rather than a SHA1.\n>>>\n>>> I'm not against such option (as long as it is somehow mentioned that's\n>>> dangerous) though I don't fully understand how one would use it,\n>>> especially when the patch is buried under other patches. With a series\n>>> of patches, any easily accessible tree (sha1) belongs to one of the\n>>> patches.\n>>\n>> The idea is that Gustav wants to allow the editing of a file as it\n>> appears in an earlier version. Lets say you have patches A, B, C and\n>> D. You realize that one of the changes in to foo.c in C shuold really be\n>> done in A. So you open the \"A version of foo.c\" in your editor, do the\n>> change, and then save it. The save operation needs to update A to be\n>> the new tree that contains the updated foo.c, and the remaining patches\n>> will keep their tree. The effect is that the moved change now appears as\n>> a diff in A, but not in C (nor B or D).\n>\n> This is currently achieved by \"pop B C D\", edit file, \"refresh\", \"push\n> --set-tree B C D\".\n\nExactly. But I realize that my example was poor, since this will make B\nrevert the change and then C reintroduce it. But perhaps this is\nactually a defect of the propsed usage model. Gustav, did you think\nabout this?\n\n> Can \"edit --set-tree <sha1>\" make this simpler?\n\nOne think I can think of is that it doesn't have to worry about\nmodifications to the work tree or the index.\n\n> Which <sha1> value would be used with \"edit --set-tree\" (unless that's\n> done by Emacs mode behind the scene and it generates the tree that\n> gets passed to edit).\n\nYes, that would be up to the tool (emacs in this case) to figure out. I\ncould probably give a couple of examples when a user could do it\nmanually, but for those cases the normal push/pop/refresh operations\nshould be good enough.\n\n-- \nDavid Kågedal\n"},{"id":"142044","messageId":"AANLkTimYCxzT16aI96dztmcKYuVrvKikSkrkRHT-Ckcd@mail.gmail.com","threadId":"23820","inReplyTo":"AANLkTilV3VQARdyZ-m9GCXz1Rwt0j6Q6noNyFrmmDzR5@mail.gmail.com","subject":"Re: [StGit PATCH] edit: Allow setting git tree SHA1 of a patch","fromName":"Gustav Hållberg","fromEmail":"gustav@gmail.com","sentAt":"2010-05-21T15:32:28Z","receivedAt":"2010-05-21T15:32:28Z","isPatch":true,"sender":{"key":"gustav@gmail.com","avatar":null},"body":"> On 21 May 2010 14:59, David Kågedal <davidk@lysator.liu.se> wrote:\n>> The idea is that Gustav wants to allow the editing of a file as it\n>> appears in an earlier version. Lets say you have patches A, B, C and\n>> D. You realize that one of the changes in to foo.c in C shuold really be\n>> done in A. So you open the \"A version of foo.c\" in your editor, do the\n>> change, and then save it. The save operation needs to update A to be\n>> the new tree that contains the updated foo.c, and the remaining patches\n>> will keep their tree. The effect is that the moved change now appears as\n>> a diff in A, but not in C (nor B or D).\n\nDavid's example does not exactly describe the situation I have in\nmind. I was only envisaging the possibility to move a change from one\npatch to one of its neighbours. This is enforced by keeping all other\ntrees intact.\n\nOn Fri, May 21, 2010 at 5:16 PM, Catalin Marinas\n<catalin.marinas@gmail.com> wro> This is currently achieved by \"pop B\nC D\", edit file, \"refresh\", \"push\n> --set-tree B C D\".\n>\n> Can \"edit --set-tree <sha1>\" make this simpler? Which <sha1> value\n> would be used with \"edit --set-tree\" (unless that's done by Emacs mode\n> behind the scene and it generates the tree that gets passed to edit).\n\nThis is indeed my assumption. Without a \"smart\" user interface to hide\nthe intricacies this operation becomes too complicated. At least\nunless you work exclusively with the index. My prototype for the Emacs\nmode approximately does 'read-tree <old patch sha1>', 'update-index\n--cache-info <new blob>', 'stg edit --set-tree $(write-tree)'.\n\nI actually think it is the use of the Emacs user interface that really\nenabled us (me and my colleagues) to see the stack as a living set of\nchanges that are very easy to edit. This lead to the conclusion that\none wants to make it much easier, light-weight and faster to move\nindividual changes between (for a start, neighbouring) patches.\n\nAs you point out, there are a number of ways to do these things\nalready; this is all about making it very easy.\n\n- Gustav\n"},{"id":"142047","messageId":"AANLkTimIxtmaUNxp-LNy_ui5__BEBetcjTYE17ygIXD2@mail.gmail.com","threadId":"23820","inReplyTo":"AANLkTimYCxzT16aI96dztmcKYuVrvKikSkrkRHT-Ckcd@mail.gmail.com","subject":"Re: [StGit PATCH] edit: Allow setting git tree SHA1 of a patch","fromName":"Catalin Marinas","fromEmail":"catalin.marinas@gmail.com","sentAt":"2010-05-21T15:58:22Z","receivedAt":"2010-05-21T15:58:22Z","isPatch":true,"sender":{"key":"catalin.marinas@gmail.com","avatar":null},"body":"On 21 May 2010 16:32, Gustav Hållberg <gustav@gmail.com> wrote:\n>> On 21 May 2010 14:59, David Kågedal <davidk@lysator.liu.se> wrote:\n>>> The idea is that Gustav wants to allow the editing of a file as it\n>>> appears in an earlier version. Lets say you have patches A, B, C and\n>>> D. You realize that one of the changes in to foo.c in C shuold really be\n>>> done in A. So you open the \"A version of foo.c\" in your editor, do the\n>>> change, and then save it. The save operation needs to update A to be\n>>> the new tree that contains the updated foo.c, and the remaining patches\n>>> will keep their tree. The effect is that the moved change now appears as\n>>> a diff in A, but not in C (nor B or D).\n>\n> David's example does not exactly describe the situation I have in\n> mind. I was only envisaging the possibility to move a change from one\n> patch to one of its neighbours. This is enforced by keeping all other\n> trees intact.\n\nYes, that's something commonly needed.\n\n> On Fri, May 21, 2010 at 5:16 PM, Catalin Marinas\n> <catalin.marinas@gmail.com> wro> This is currently achieved by \"pop B\n> C D\", edit file, \"refresh\", \"push\n>> --set-tree B C D\".\n>>\n>> Can \"edit --set-tree <sha1>\" make this simpler? Which <sha1> value\n>> would be used with \"edit --set-tree\" (unless that's done by Emacs mode\n>> behind the scene and it generates the tree that gets passed to edit).\n>\n> This is indeed my assumption. Without a \"smart\" user interface to hide\n> the intricacies this operation becomes too complicated. At least\n> unless you work exclusively with the index. My prototype for the Emacs\n> mode approximately does 'read-tree <old patch sha1>', 'update-index\n> --cache-info <new blob>', 'stg edit --set-tree $(write-tree)'.\n\nOK. As I said, I don't have  a problem with the patch. Maybe you could\nmention in the help that it's usually meant for tools like Emacs,\notherwise people would wonder how to use it from the command line but\nas it is, the patch looks fine.\n\n> I actually think it is the use of the Emacs user interface that really\n> enabled us (me and my colleagues) to see the stack as a living set of\n> changes that are very easy to edit. This lead to the conclusion that\n> one wants to make it much easier, light-weight and faster to move\n> individual changes between (for a start, neighbouring) patches.\n\nI try to reduce the patch editing as much as possible since I need to\nhave some public branches that have an immutable history (hence the\nstg publish command).\n\nBTW, since you are a group of people using stgit, have you found a\nuseful way to share patches/series easily?\n\nFor example, one colleague works on a set of patches and I'd like his\nincluded in my series but I don't want me to maintain those, so\nperiodically I would have to re-import his patches. There is a way to\nuse a combination of export and sync but it's not always easy to\nfollow.\n\nStGit has the patches (diffs) in the a *.stgit branch but solving\nconflicts in diff is problematic, so not sure how to use that for easy\nsynchronisation.\n\n-- \nCatalin\n"},{"id":"142062","messageId":"u5tpr0p6t8v.fsf@beatles.e.vtech","threadId":"23820","inReplyTo":"AANLkTimIxtmaUNxp-LNy_ui5__BEBetcjTYE17ygIXD2@mail.gmail.com","subject":"Re: [StGit PATCH] edit: Allow setting git tree SHA1 of a patch","fromName":"David Kågedal","fromEmail":"davidk@lysator.liu.se","sentAt":"2010-05-21T17:48:32Z","receivedAt":"2010-05-21T17:48:32Z","isPatch":true,"sender":{"key":"davidk@lysator.liu.se","avatar":"https://avatars.githubusercontent.com/u/60530?v=4"},"body":"Catalin Marinas <catalin.marinas@gmail.com> writes:\n\n> BTW, since you are a group of people using stgit, have you found a\n> useful way to share patches/series easily?\n\nNot really. It is complicated by the fact that we are really using\nsubversion, and people are using git as a frontend to that with no\ncommon git-svn import. But it hasn't been a big problem either.\n\nStgit is used to work on a set of changes that will sooner or later be\ncommitted to svn. Shared \"topic branches\" that several people work on\nlive in svn.\n\nI often mail patches for review using stg mail, and sometimes import\npatches mailed to me. I have also used stg export a few times.\n\n-- \nDavid Kågedal\n"},{"id":"142067","messageId":"AANLkTinPDGsSEQeY1jfBDLAuQD42fEUoUeGXuvgJ8ZI3@mail.gmail.com","threadId":"23820","inReplyTo":"AANLkTimIxtmaUNxp-LNy_ui5__BEBetcjTYE17ygIXD2@mail.gmail.com","subject":"Re: [StGit PATCH] edit: Allow setting git tree SHA1 of a patch","fromName":"Gustav Hållberg","fromEmail":"gustav@gmail.com","sentAt":"2010-05-21T18:45:27Z","receivedAt":"2010-05-21T18:45:27Z","isPatch":true,"sender":{"key":"gustav@gmail.com","avatar":null},"body":"On Fri, May 21, 2010 at 5:58 PM, Catalin Marinas\n<catalin.marinas@gmail.com> wrote:\n> OK. As I said, I don't have  a problem with the patch. Maybe you could\n> mention in the help that it's usually meant for tools like Emacs,\n> otherwise people would wonder how to use it from the command line but\n> as it is, the patch looks fine.\n\nHere's an updated patch. The only difference to the previous patch is\nin the help text.\n\nNote that it doesn't handle incorrect SHA1 sums very well.\nIn fact they often end up causing EPIPE as 'git commit-tree' exits\nbefore all data has been written to it.\n\nFrom a brief glance I cannot find any previous code that verifies the\ncorrectness of a SHA1.\nAny pointers to how I would add this would be welcome.\nWould a new flag to Repository.get_tree() that makes it verify the\ncorrectness be appropriate?\nOr a new method in Repository?\n\n- Gustav\n\n----\n\nAlso fix capitalization in edit's short description.\n\nSigned-off-by: Gustav Hållberg <gustav@gmail.com>\n---\n stgit/commands/edit.py |   22 +++++++++++++++++++---\n t/t3300-edit.sh        |   15 +++++++++++++++\n 2 files changed, 34 insertions(+), 3 deletions(-)\n\ndiff --git a/stgit/commands/edit.py b/stgit/commands/edit.py\nindex f3f731f..a863611 100644\n--- a/stgit/commands/edit.py\n+++ b/stgit/commands/edit.py\n@@ -24,7 +24,7 @@ from stgit.commands import common\n from stgit.lib import git as gitlib, transaction, edit\n from stgit.out import *\n\n-help = 'edit a patch description or diff'\n+help = 'Edit a patch description or diff'\n kind = 'patch'\n usage = ['[options] [--] [<patch>]']\n description = \"\"\"\n@@ -52,7 +52,14 @@ invoked even if such command-line options are given.)\n\n If the patch diff is edited but does not apply, no changes are made to\n the patch at all. The edited patch is saved to a file which you can\n-feed to \"stg edit --file\", once you have made sure it does apply.\"\"\"\n+feed to \"stg edit --file\", once you have made sure it does apply.\n+\n+With --set-tree you set the git tree of the patch to the specified\n+SHA1, without changing the tree of any other patches. When used on the\n+top patch, the index and work tree will be updated to match the tree.\n+This low-level option is primarily meant to be used by tools built on\n+top of stgit, such as the Emacs mode. See also the --set-tree flag of\n+stg push.\"\"\"\n\n args = [argparse.applied_patches, argparse.unapplied_patches,\n         argparse.hidden_patches]\n@@ -61,6 +68,9 @@ options = [\n         short = 'Edit the patch diff'),\n     opt('-e', '--edit', action = 'store_true',\n         short = 'Invoke interactive editor'),\n+    opt('-t', '--set-tree', action = 'store',\n+        metavar = 'SHA1',\n+        short = 'Set the git tree of the patch to SHA1'),\n     ] + (argparse.sign_options() +\n          argparse.message_options(save_template = True) +\n          argparse.author_options() + argparse.diff_opts_option())\n@@ -86,6 +96,9 @@ def func(parser, options, args):\n\n     cd = orig_cd = stack.patches.get(patchname).commit.data\n\n+    if options.set_tree:\n+        cd = cd.set_tree(stack.repository.get_tree(options.set_tree))\n+\n     cd, failed_diff = edit.auto_edit_patch(\n         stack.repository, cd, msg = options.message, contains_diff = True,\n         author = options.author, committer = lambda p: p,\n@@ -128,7 +141,10 @@ def func(parser, options, args):\n     trans.patches[patchname] = stack.repository.commit(cd)\n     try:\n         for pn in popped:\n-            trans.push_patch(pn, iw, allow_interactive = True)\n+            if options.set_tree:\n+                trans.push_tree(pn)\n+            else:\n+                trans.push_patch(pn, iw, allow_interactive = True)\n     except transaction.TransactionHalted:\n         pass\n     try:\ndiff --git a/t/t3300-edit.sh b/t/t3300-edit.sh\nindex 7003a27..078d4c3 100755\n--- a/t/t3300-edit.sh\n+++ b/t/t3300-edit.sh\n@@ -212,4 +212,19 @@ test_expect_failure 'Fail to set invalid author date' '\n     test \"$(date HEAD)\" = \"2013-01-28 22:30:00 -0300\"\n '\n\n+test_expect_success 'Set patch tree SHA1' '\n+    p2tree=$(git log -1 --pretty=format:%T $(stg id p2)) &&\n+    p4tree=$(git log -1 --pretty=format:%T $(stg id p4)) &&\n+    stg edit --set-tree $p4tree &&\n+    test $(git write-tree) = $p4tree &&\n+    grep \"^333zz$\" foo &&\n+    stg pop &&\n+    stg edit --set-tree $p2tree p2 &&\n+    stg push --set-tree &&\n+    test $(git write-tree) = $p2tree &&\n+    grep \"^333$\" foo &&\n+    stg edit --set-tree $p2tree p1 &&\n+    test \"$(echo $(stg series --empty --all))\" = \"+ p1 0> p2 - p3 ! p4\"\n+'\n+\n test_done\n-- \n1.7.0.4\n"},{"id":"142211","messageId":"20100524184908.30884.65042.stgit@sambuntu","threadId":"23820","inReplyTo":"AANLkTimIxtmaUNxp-LNy_ui5__BEBetcjTYE17ygIXD2@mail.gmail.com","subject":"[PATCH 0/2] Setting git tree of a patch (improved version)","fromName":"Gustav Hållberg","fromEmail":"gustav@gmail.com","sentAt":"2010-05-24T18:52:09Z","receivedAt":"2010-05-24T18:52:09Z","isPatch":true,"sender":{"key":"gustav@gmail.com","avatar":null},"body":"I solved (I think) how to accept (and verify the correctness of) a\ntree-ish as argument for 'edit --set-tree'. The first patch in the\nseries adds support to Repository.rev_parse() for doing that.\n\nThe main (the second) is essentially the same as before.\n\nI moved the --set-tree option to be last in the list of options,\nmaking it even more obscure-looking.\n\n---\n\nGustav Hållberg (2):\n      Repository.rev_parse: support commits, trees, and blobs\n      edit: Allow setting git tree of a patch\n\n\n stgit/commands/edit.py |   39 ++++++++++++++++++++++++++++-----------\n stgit/lib/git.py       |   10 ++++++----\n t/t3300-edit.sh        |   15 +++++++++++++++\n 3 files changed, 49 insertions(+), 15 deletions(-)\n\n-- \n"},{"id":"142213","messageId":"20100524185219.30884.66896.stgit@sambuntu","threadId":"23820","inReplyTo":"20100524184908.30884.65042.stgit@sambuntu","subject":"[PATCH 1/2] Repository.rev_parse: support commits, trees, and blobs","fromName":"Gustav Hållberg","fromEmail":"gustav@gmail.com","sentAt":"2010-05-24T18:52:19Z","receivedAt":"2010-05-24T18:52:19Z","isPatch":true,"sender":{"key":"gustav@gmail.com","avatar":null},"body":"\n---\n stgit/lib/git.py |   10 ++++++----\n 1 files changed, 6 insertions(+), 4 deletions(-)\n\ndiff --git a/stgit/lib/git.py b/stgit/lib/git.py\nindex 65d2a6c..899c1a2 100644\n--- a/stgit/lib/git.py\n+++ b/stgit/lib/git.py\n@@ -581,13 +581,15 @@ class Repository(RunWithEnv):\n     refs = property(lambda self: self.__refs)\n     def cat_object(self, sha1):\n         return self.run(['git', 'cat-file', '-p', sha1]).raw_output()\n-    def rev_parse(self, rev, discard_stderr = False):\n+    def rev_parse(self, rev, discard_stderr = False, object_type = 'commit'):\n+        assert object_type in ('commit', 'tree', 'blob')\n+        getter = getattr(self, 'get_' + object_type)\n         try:\n-            return self.get_commit(self.run(\n-                    ['git', 'rev-parse', '%s^{commit}' % rev]\n+            return getter(self.run(\n+                    ['git', 'rev-parse', '%s^{%s}' % (rev, object_type)]\n                     ).discard_stderr(discard_stderr).output_one_line())\n         except run.RunException:\n-            raise RepositoryException('%s: No such revision' % rev)\n+            raise RepositoryException('%s: No such %s' % (rev, object_type))\n     def get_blob(self, sha1):\n         return self.__blobs[sha1]\n     def get_tree(self, sha1):\n"},{"id":"142212","messageId":"20100524185228.30884.50567.stgit@sambuntu","threadId":"23820","inReplyTo":"20100524184908.30884.65042.stgit@sambuntu","subject":"[PATCH 2/2] edit: Allow setting git tree of a patch","fromName":"Gustav Hållberg","fromEmail":"gustav@gmail.com","sentAt":"2010-05-24T18:52:28Z","receivedAt":"2010-05-24T18:52:28Z","isPatch":true,"sender":{"key":"gustav@gmail.com","avatar":null},"body":"Also fix capitalization in edit's short description.\n\nSigned-off-by: Gustav Hållberg <gustav@gmail.com>\n---\n stgit/commands/edit.py |   39 ++++++++++++++++++++++++++++-----------\n t/t3300-edit.sh        |   15 +++++++++++++++\n 2 files changed, 43 insertions(+), 11 deletions(-)\n\ndiff --git a/stgit/commands/edit.py b/stgit/commands/edit.py\nindex f3f731f..79335d0 100644\n--- a/stgit/commands/edit.py\n+++ b/stgit/commands/edit.py\n@@ -24,7 +24,7 @@ from stgit.commands import common\n from stgit.lib import git as gitlib, transaction, edit\n from stgit.out import *\n \n-help = 'edit a patch description or diff'\n+help = 'Edit a patch description or diff'\n kind = 'patch'\n usage = ['[options] [--] [<patch>]']\n description = \"\"\"\n@@ -52,18 +52,28 @@ invoked even if such command-line options are given.)\n \n If the patch diff is edited but does not apply, no changes are made to\n the patch at all. The edited patch is saved to a file which you can\n-feed to \"stg edit --file\", once you have made sure it does apply.\"\"\"\n+feed to \"stg edit --file\", once you have made sure it does apply.\n+\n+With --set-tree you set the git tree of the patch to the specified\n+TREE-ISH without changing the tree of any other patches. When used on\n+the top patch, the index and work tree will be updated to match the\n+tree.  This low-level option is primarily meant to be used by tools\n+built on top of StGit, such as the Emacs mode. See also the --set-tree\n+flag of stg push.\"\"\"\n \n args = [argparse.applied_patches, argparse.unapplied_patches,\n         argparse.hidden_patches]\n-options = [\n-    opt('-d', '--diff', action = 'store_true',\n-        short = 'Edit the patch diff'),\n-    opt('-e', '--edit', action = 'store_true',\n-        short = 'Invoke interactive editor'),\n-    ] + (argparse.sign_options() +\n-         argparse.message_options(save_template = True) +\n-         argparse.author_options() + argparse.diff_opts_option())\n+options = (\n+    [ opt('-d', '--diff', action = 'store_true',\n+          short = 'Edit the patch diff'),\n+      opt('-e', '--edit', action = 'store_true',\n+          short = 'Invoke interactive editor') ] +\n+    argparse.sign_options() +\n+    argparse.message_options(save_template = True) +\n+    argparse.author_options() + argparse.diff_opts_option() +\n+    [ opt('-t', '--set-tree', action = 'store',\n+          metavar = 'TREE-ISH',\n+          short = 'Set the git tree of the patch to TREE-ISH') ])\n \n directory = common.DirectoryHasRepositoryLib()\n \n@@ -86,6 +96,10 @@ def func(parser, options, args):\n \n     cd = orig_cd = stack.patches.get(patchname).commit.data\n \n+    if options.set_tree:\n+        cd = cd.set_tree(stack.repository.rev_parse(\n+                options.set_tree, discard_stderr = True, object_type = 'tree'))\n+\n     cd, failed_diff = edit.auto_edit_patch(\n         stack.repository, cd, msg = options.message, contains_diff = True,\n         author = options.author, committer = lambda p: p,\n@@ -128,7 +142,10 @@ def func(parser, options, args):\n     trans.patches[patchname] = stack.repository.commit(cd)\n     try:\n         for pn in popped:\n-            trans.push_patch(pn, iw, allow_interactive = True)\n+            if options.set_tree:\n+                trans.push_tree(pn)\n+            else:\n+                trans.push_patch(pn, iw, allow_interactive = True)\n     except transaction.TransactionHalted:\n         pass\n     try:\ndiff --git a/t/t3300-edit.sh b/t/t3300-edit.sh\nindex 7003a27..09a2f25 100755\n--- a/t/t3300-edit.sh\n+++ b/t/t3300-edit.sh\n@@ -212,4 +212,19 @@ test_expect_failure 'Fail to set invalid author date' '\n     test \"$(date HEAD)\" = \"2013-01-28 22:30:00 -0300\"\n '\n \n+test_expect_success 'Set patch tree' '\n+    p2tree=$(git log -1 --pretty=format:%T $(stg id p2)) &&\n+    p4commit=$(stg id p4) &&\n+    stg edit --set-tree $p4commit &&\n+    test $(git write-tree) = $(git rev-parse ${p4commit}^{tree}) &&\n+    grep \"^333zz$\" foo &&\n+    stg pop &&\n+    stg edit --set-tree $p2tree p2 &&\n+    stg push --set-tree &&\n+    test $(git write-tree) = $p2tree &&\n+    grep \"^333$\" foo &&\n+    stg edit --set-tree $p2tree p1 &&\n+    test \"$(echo $(stg series --empty --all))\" = \"+ p1 0> p2 - p3 ! p4\"\n+'\n+\n test_done\n"},{"id":"142279","messageId":"AANLkTimgpjn5KZpujtmXfd7UtEfJTg-3UcmIjvFor0bX@mail.gmail.com","threadId":"23820","inReplyTo":"20100524184908.30884.65042.stgit@sambuntu","subject":"Re: [PATCH 0/2] Setting git tree of a patch (improved version)","fromName":"Catalin Marinas","fromEmail":"catalin.marinas@gmail.com","sentAt":"2010-05-25T12:26:36Z","receivedAt":"2010-05-25T12:26:36Z","isPatch":true,"sender":{"key":"catalin.marinas@gmail.com","avatar":null},"body":"On 24 May 2010 19:52, Gustav Hållberg <gustav@gmail.com> wrote:\n> I solved (I think) how to accept (and verify the correctness of) a\n> tree-ish as argument for 'edit --set-tree'. The first patch in the\n> series adds support to Repository.rev_parse() for doing that.\n>\n> The main (the second) is essentially the same as before.\n>\n> I moved the --set-tree option to be last in the list of options,\n> making it even more obscure-looking.\n\nThe patches look fine to me.\n\nDo you want me to merge them directly or I grab them via some git tree\n(or Karl's).\n\nThanks.\n\n-- \nCatalin\n"},{"id":"142376","messageId":"AANLkTiltxW_teNgNxZnJLqbiO3Du6al3K48wlcDooVZd@mail.gmail.com","threadId":"23820","inReplyTo":"AANLkTimgpjn5KZpujtmXfd7UtEfJTg-3UcmIjvFor0bX@mail.gmail.com","subject":"Re: [PATCH 0/2] Setting git tree of a patch (improved version)","fromName":"Gustav Hållberg","fromEmail":"gustav@gmail.com","sentAt":"2010-05-26T15:34:22Z","receivedAt":"2010-05-26T15:34:22Z","isPatch":true,"sender":{"key":"gustav@gmail.com","avatar":null},"body":"On Tue, May 25, 2010 at 2:26 PM, Catalin Marinas\n<catalin.marinas@gmail.com> wrote:\n> The patches look fine to me.\n>\n> Do you want me to merge them directly or I grab them via some git tree\n> (or Karl's).\n\nYou can grab them from git://github.com/gustavh/stgit.git in the\n'set-tree' branch.\n\nSomewhat unrelated, I have a string of patches in my 'proposed' branch\n(same repository) which contain various fixes to the Emacs mode.\nWould you like me to post them here as one patch series or would you\nprefer to handle it some other way?\n\nKarl has a bit too high latency these days, so it's inconvenient to go\nvia his branch(es).\n\n- Gustav\n"},{"id":"142395","messageId":"AANLkTinKpW7cN-hQoCDpHLprPxgqwngSrk077sxp59Na@mail.gmail.com","threadId":"23820","inReplyTo":"AANLkTiltxW_teNgNxZnJLqbiO3Du6al3K48wlcDooVZd@mail.gmail.com","subject":"Re: [PATCH 0/2] Setting git tree of a patch (improved version)","fromName":"Catalin Marinas","fromEmail":"catalin.marinas@gmail.com","sentAt":"2010-05-26T21:18:07Z","receivedAt":"2010-05-26T21:18:07Z","isPatch":true,"sender":{"key":"catalin.marinas@gmail.com","avatar":null},"body":"On 26 May 2010 16:34, Gustav Hållberg <gustav@gmail.com> wrote:\n> On Tue, May 25, 2010 at 2:26 PM, Catalin Marinas\n> <catalin.marinas@gmail.com> wrote:\n>> The patches look fine to me.\n>>\n>> Do you want me to merge them directly or I grab them via some git tree\n>> (or Karl's).\n>\n> You can grab them from git://github.com/gustavh/stgit.git in the\n> 'set-tree' branch.\n\nI merged it. Thanks.\n\n> Somewhat unrelated, I have a string of patches in my 'proposed' branch\n> (same repository) which contain various fixes to the Emacs mode.\n> Would you like me to post them here as one patch series or would you\n> prefer to handle it some other way?\n\nWell, I don't have the knowledge to review the emacs mode patches -\nyou are the maintainer. Just let me know when and where to pull the\npatches from.\n\nThanks.\n\n-- \nCatalin\n"}]}