{"thread":{"id":"15020","subject":"[TopGit PATCH] tg redepend: New command.","startedAt":"2008-08-15T13:53:47Z","lastAt":"2008-09-01T10:36:47Z","messageCount":7,"participants":["Jan Nieuwenhuizen","Bert Wesarg","Jonathan Nieder"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"87303","messageId":"1218808427.25300.2.camel@heerbeest","threadId":"15020","inReplyTo":null,"subject":"[TopGit PATCH] tg redepend: New command.","fromName":"Jan Nieuwenhuizen","fromEmail":"janneke-list@xs4all.nl","sentAt":"2008-08-15T13:53:47Z","receivedAt":"2008-08-15T13:53:47Z","isPatch":true,"sender":{"key":"janneke-list@xs4all.nl","avatar":null},"body":"As discussed previously\n\n    http://kerneltrap.org/mailarchive/git/2008/8/13/2925144\n\nChange a topgit branch's dependencies by doing a rebase-by-merge.\n\n\nSigned-off-by: Jan Nieuwenhuizen <janneke@gnu.org>\n---\n Makefile       |    2 +-\n README         |    5 ++\n tg-redepend.sh |  154 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n 3 files changed, 160 insertions(+), 1 deletions(-)\n create mode 100644 tg-redepend.sh\n\ndiff --git a/Makefile b/Makefile\nindex ea6489e..3988251 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -5,7 +5,7 @@ sharedir = $(prefix)/share/topgit\n hooksdir = $(cmddir)/hooks\n \n \n-commands_in = tg-create.sh tg-delete.sh tg-export.sh tg-info.sh tg-patch.sh tg-summary.sh tg-update.sh\n+commands_in = tg-create.sh tg-delete.sh tg-export.sh tg-info.sh tg-patch.sh tg-redepend.sh tg-summary.sh tg-update.sh\n hooks_in = hooks/pre-commit.sh\n \n commands_out = $(patsubst %.sh,%,$(commands_in))\ndiff --git a/README b/README\nindex b58a1b4..3528602 100644\n--- a/README\n+++ b/README\n@@ -330,6 +330,11 @@ tg export\n \tTODO: Make stripping of [PATCH] and other prefixes configurable\n \tTODO: --mbox option for other mode of operation\n \n+tg redepend\n+~~~~~~~~~~~\n+\tChange the current topic branch's list of dependencies\n+\tby doing a rebase-by-merge onto the new dependencies.\n+\n tg update\n ~~~~~~~~~\n \tUpdate the current topic branch wrt. changes in the branches\ndiff --git a/tg-redepend.sh b/tg-redepend.sh\nnew file mode 100644\nindex 0000000..e1612ea\n--- /dev/null\n+++ b/tg-redepend.sh\n@@ -0,0 +1,154 @@\n+#! /bin/sh\n+# TopGit - A different patch queue manager\n+# (c) 2008  Jan Nieuwenhuizen <janneke@gnu.org>\n+# GNU GPL version 2\n+\n+add=\n+remove=\n+redeps=\n+restarted=\n+\n+## Parse options\n+\n+while [ -n \"$1\" ]; do\n+\targ=\"$1\"; shift\n+\tcase \"$arg\" in\n+\t\t--add)\n+\t\t\t[ -z \"$redeps\" ] || die \"already specified new list of dependencies ($redeps)\"\n+\t\t\t[ -z \"$remove\" ] || die \"already specified dependencies to remove ($remove)\"\n+\t\t\tadd=\"$add \"\n+\t\t\t;;\n+\t\t-h|--help)\n+\t\t\techo \"Usage: tg [--add|--remove] DEPENDENCY...\" >&2\n+\t\t\t;;\n+\t\t--remove)\n+\t\t\t[ -z \"$redeps\" ] || die \"already specified new list of dependencies ($redeps)\"\n+\t\t\t[ -z \"$add\" ] || die \"already specified dependencies to add ($add)\"\n+\t\t\tremove=\"$remove \"\n+\t\t\t;;\n+\t\t*)\n+\t\t\t[ -z \"$add\" ] || add=\"$add$arg \"\n+\t\t\t[ -z \"$remove\" ] || remove=\"$remove$arg \"\n+\t\t\t[ ! -z \"$add$remove\" ] || redeps=\"$redeps$arg \"\n+\tesac\n+done\n+\n+if [ -n \"$add\" ]; then\n+\tadd=\"${add/# }\"\n+\tadd=\"${add//  / }\"\n+\tdupes=$(grep -E \"^${add// /|}/\\$\" \"$root_dir/.topdeps\" | tr '\\n' ' ')\n+\t[ -z \"$dupes\" ] || die \"already depend on: $dupes\"\n+\tredeps=$(echo \"$add\" | cat \"$root_dir/.topdeps\" - | tr '\\n' ' ' | sed -e 's/ \\+$//')\n+elif [ -n \"$remove\" ]; then\n+\tremove=\"${remove//  / }\"\n+\tremove=\"${remove/# }\"\n+\tavail=$(grep -E \"^${remove// /|}/\\$\" \"$root_dir/.topdeps\" | sort | tr '\\n' ' ')\n+\tremove_sorted=$(echo \"$remove\" | tr ' ' '\\n' | grep -v '^$' | sort | tr '\\n' ' ')\n+\t[ \"$avail\" = \"$remove_sorted\" ] || die \"not depending on some of: $remove\"\n+\tredeps=$(grep -vE \"^${remove// /|}/\\$\" \"$root_dir/.topdeps\" | tr '\\n' ' ')\n+fi\n+\n+redeps=\"${redeps/# }\"\n+redeps=\"${redeps/# }\"\n+\n+if [ -z \"$redeps\" ]; then\n+\tif [ -s \"$git_dir/top-name\" -a -s \"$git_dir/top-redeps\" -a -f \"$git_dir/top-rebase\" ]; then\n+\t\trestarted=rebase\n+\telif [ -s \"$git_dir/top-name\" -a -s \"$git_dir/top-redeps\" -a -f \"$git_dir/top-merge\" ]; then\n+\t\trestarted=merge\n+\telse\n+\t\techo \"Usage: tg [--add|--remove] DEPENDENCY...\" >&2\n+\t\texit 2\n+\tfi\n+fi\n+\n+function fail () {\n+\tinfo \"Please resolve conflicts and call: tg redepend\"\n+\tinfo \"It is also safe to abort this operation using:\"\n+\tinfo \"tg delete $b_; git reset --hard some_branch\"\n+\techo \"$p\" > \"$git_dir/top-name\"\n+\techo \"$redeps\" > \"$git_dir/top-redeps\"\n+\ttouch \"$git_dir/top-$1\"\n+\texit 1\n+}\n+\n+# See http://kerneltrap.org/mailarchive/git/2008/8/13/2925144\n+#\n+# B -- (some mess) -- P\n+#\n+# Do \"git rebase --onto B' B P\" while preserving history to get\n+#\n+# B -- (some mess) -- old P -- P\n+#                             /\n+#                           B'\n+\n+if [ -z \"$restarted\" ]; then\n+\tinfo \"New list of dependencies: $redeps.\"\n+\tp=$(git symbolic-ref HEAD | cut -b 12-)\n+else\n+\tp=\"$(cat \"$git_dir/top-name\")\"\n+\tredeps=\"$(cat \"$git_dir/top-redeps\")\"\n+fi\n+\n+# Clean up any restart stuff\n+rm -f \"$git_dir/top-name\" \"$git_dir/top-redeps\" \"$git_dir/top-rebase\" \"$git_dir/top-merge\"\n+\n+b=\"$(git rev-parse --short --verify \"refs/top-bases/$p\" 2>/dev/null)\" \\\n+\t|| die \"not a TopGit-controlled branch\"\n+p_=tg-redepend/tmp/${p}_\n+b_=tg-redepend/tmp/$p.base_\n+\n+# Create new base B' -- does not have to be a topgit branch, but that's easiest\n+if [ -z \"$restarted\" ]; then\n+\tgit branch -D $p_  > /dev/null 2>&1 || :\n+\n+\ttg create $b_ $redeps\n+\tgit commit -m 'tg redepend: add TopGit .top* info.'\n+\n+# Do \"git rebase --onto B' B P\" while preserving history\n+\tgit checkout -b $p_ $p\n+\n+\tif ! git rebase --onto $b_ $b; then\n+\t\tfail rebase\n+\tfi\n+elif [ \"$restarted\" = \"rebase\" ]; then\n+\t[ ! -d \"$git_dir/rebase-apply\" ] || git add \"$root_dir\"\n+\t[ ! -d \"$git_dir/rebase-apply\" ] || git add -u \"$root_dir\"\n+\t[ ! -d \"$git_dir/rebase-apply\" ] || if ! git rebase --continue; then\n+\t\tfail rebase\n+\tfi\n+\trm -f \"$git_dir/top-name\" \"$git_dir/top-redeps\"\n+\trestarted=\n+fi\n+\n+if [ \"$restarted\" != \"merge\" ]; then\n+\tgit checkout $(git rev-parse $p)\n+\tif ! git merge --no-ff --no-commit $b_; then\n+\t\ttouch \"$git_dir/top-merge\"\n+\t\tfail merge\n+\tfi\n+elif ! git status | grep 'nothing to commit' > /dev/null; then\n+\tgit add \"$root_dir\"\n+\tgit add -u \"$root_dir\"\n+\tgit commit -m 'tg redepend: resolve merge.' > /dev/null 2>&1\n+fi\n+git read-tree -m -u $(git rev-parse $p_)\n+\n+echo \"$redeps\" | tr ' ' '\\n' > \"$root_dir/.topdeps\"\n+\n+git add \"$root_dir\"\n+git add -u \"$root_dir\"\n+\n+git commit -m \"Rebased-using-merge onto new dependencies: $redeps.\"  > /dev/null 2>&1\n+\n+git branch -f $p\n+git checkout $p\n+\n+tg delete $b_  > /dev/null 2>&1\n+git branch -D $p_\n+\n+info \"Rebased-using-merge onto new dependencies: $redeps.\"\n+\n+# Local Variables:\n+# sh-basic-offset:8\n+# End:\n-- \n1.6.0.rc0.44.g67270\n\n\n-- \nJan Nieuwenhuizen <janneke@gnu.org> | GNU LilyPond - The music typesetter\nhttp://www.xs4all.nl/~jantien       | http://www.lilypond.org\n"},{"id":"87325","messageId":"36ca99e90808151016q619ce147h8dcdc449e9def476@mail.gmail.com","threadId":"15020","inReplyTo":"1218808427.25300.2.camel@heerbeest","subject":"Re: [TopGit PATCH] tg redepend: New command.","fromName":"Bert Wesarg","fromEmail":"bert.wesarg@googlemail.com","sentAt":"2008-08-15T17:16:43Z","receivedAt":"2008-08-15T17:16:43Z","isPatch":true,"sender":{"key":"bert.wesarg@googlemail.com","avatar":"https://avatars.githubusercontent.com/u/111934?v=4"},"body":"On Fri, Aug 15, 2008 at 15:53, Jan Nieuwenhuizen <janneke-list@xs4all.nl> wrote:\nWhy don't you call this command 'depend', as per README TODO?\n\n> +\n> +# Local Variables:\n> +# sh-basic-offset:8\n> +# End:\nThis would be the first file in this project with such editor infos.\nIMHO this shouldn't belong to a patch.\n\nRegards\nBert\n"},{"id":"87334","messageId":"Pine.GSO.4.62.0808151241300.17250@harper.uchicago.edu","threadId":"15020","inReplyTo":"1218808427.25300.2.camel@heerbeest","subject":"Re: [TopGit PATCH] tg redepend: New command.","fromName":"Jonathan Nieder","fromEmail":"jrnieder@uchicago.edu","sentAt":"2008-08-15T18:20:01Z","receivedAt":"2008-08-15T18:20:01Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Hi,\n\nJan Nieuwenhuizen wrote:\n\n> As discussed previously\n> \n>     http://kerneltrap.org/mailarchive/git/2008/8/13/2925144\n> \n> Change a topgit branch's dependencies by doing a rebase-by-merge.\n> \n> Signed-off-by: Jan Nieuwenhuizen <janneke@gnu.org>\n> ---\n>  Makefile       |    2 +-\n>  README         |    5 ++\n>  tg-redepend.sh |  154 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n>  3 files changed, 160 insertions(+), 1 deletions(-)\n>  create mode 100644 tg-redepend.sh\n\n[...]\n> +\t\t-h|--help)\n> +\t\t\techo \"Usage: tg [--add|--remove] DEPENDENCY...\" >&2\n\ns/tg/tg redepend/?\n\n[...]\n> +# Create new base B' -- does not have to be a topgit branch, but that's easiest\n> +if [ -z \"$restarted\" ]; then\n> +\tgit branch -D $p_  > /dev/null 2>&1 || :\n> +\n> +\ttg create $b_ $redeps\n\nWhy not move the base-creation code in tg-create.sh to a new\nfunction in tg.sh to use here?\n\n[...]\n> +if [ \"$restarted\" != \"merge\" ]; then\n> +\tgit checkout $(git rev-parse $p)\n> +\tif ! git merge --no-ff --no-commit $b_; then\n> +\t\ttouch \"$git_dir/top-merge\"\n> +\t\tfail merge\n> +\tfi\n[snip continuing-a-merge case]\n> +fi\n> +git read-tree -m -u $(git rev-parse $p_)\n[snip topdeps juggling]\n> +git commit -m \"Rebased-using-merge onto new dependencies: $redeps.\"  > /dev/null 2>&1\n\nI know I suggested that code before, but the merge with B' is wasted, so\nperhaps\n\n\tgit checkout P\n\thead=$(git rev-parse --verify HEAD^0)\n\tresult_tree=$(git log -1 --pretty=format:%T P')\n\tresult_commit=$(git commit-tree \"$result_tree\" -p P -p B')\n\tgit update-ref -m \"commit (merge): tg-redepend\" HEAD \\\n\t\t\t\"$result_commit\" \"$head\" || ... (fail)\n\ttest -x \"$GIT_DIR/hooks/post-merge\" && $GIT_DIR/hooks/post-merge 0\n\nI'm not sure.  Is there some more porcelain-ish way to do this (create a\nmerge commit when you already know the resulting and parents)?\n\nBut with that change the entire restarted=merge branch would go away,\nso I hope there is a nice way to do it.  I'll think more.\n\nHope that helps,\nJonathan\n\n> +\n> +git branch -f $p\n> +git checkout $p\n> +\n> +tg delete $b_  > /dev/null 2>&1\n> +git branch -D $p_\n> +\n> +info \"Rebased-using-merge onto new dependencies: $redeps.\"\n> +\n> +# Local Variables:\n> +# sh-basic-offset:8\n> +# End:\n> \n"},{"id":"87531","messageId":"1219051408.8816.34.camel@heerbeest","threadId":"15020","inReplyTo":"Pine.GSO.4.62.0808151241300.17250@harper.uchicago.edu","subject":"Re: [TopGit PATCH] tg redepend: New command.","fromName":"Jan Nieuwenhuizen","fromEmail":"janneke-list@xs4all.nl","sentAt":"2008-08-18T09:23:28Z","receivedAt":"2008-08-18T09:23:28Z","isPatch":true,"sender":{"key":"janneke-list@xs4all.nl","avatar":null},"body":"On vr, 2008-08-15 at 13:20 -0500, Jonathan Nieder wrote:\n\nHi,\n\n> s/tg/tg redepend/?\n\nYes.\n\n> Why not move the base-creation code in tg-create.sh to a new\n> function in tg.sh to use here?\n\nYes, that's better.\n \n> I know I suggested that code before, but the merge with B' is wasted, so\n> perhaps\n> \n> \tgit checkout P\n> \thead=$(git rev-parse --verify HEAD^0)\n> \tresult_tree=$(git log -1 --pretty=format:%T P')\n> \tresult_commit=$(git commit-tree \"$result_tree\" -p P -p B')\n> \tgit update-ref -m \"commit (merge): tg-redepend\" HEAD \\\n> \t\t\t\"$result_commit\" \"$head\" || ... (fail)\n> \ttest -x \"$GIT_DIR/hooks/post-merge\" && $GIT_DIR/hooks/post-merge 0\n> \n> I'm not sure.  Is there some more porcelain-ish way to do this (create a\n> merge commit when you already know the resulting and parents)?\n> \n> But with that change the entire restarted=merge branch would go away,\n> so I hope there is a nice way to do it.  I'll think more.\n\nYes, the user should get a nice chance to resolve any conflicts...\n\nThanks!\nJan.\n\n-- \nJan Nieuwenhuizen <janneke@gnu.org> | GNU LilyPond - The music typesetter\nhttp://www.xs4all.nl/~jantien       | http://www.lilypond.org\n"},{"id":"89379","messageId":"36ca99e90809010231o439ab4acsaa3027366c551ff6@mail.gmail.com","threadId":"15020","inReplyTo":"1218808427.25300.2.camel@heerbeest","subject":"Re: [TopGit PATCH] tg redepend: New command.","fromName":"Bert Wesarg","fromEmail":"bert.wesarg@googlemail.com","sentAt":"2008-09-01T09:31:15Z","receivedAt":"2008-09-01T09:31:15Z","isPatch":true,"sender":{"key":"bert.wesarg@googlemail.com","avatar":"https://avatars.githubusercontent.com/u/111934?v=4"},"body":"Hi,\n\nOn Fri, Aug 15, 2008 at 15:53, Jan Nieuwenhuizen <janneke-list@xs4all.nl> wrote:\n> As discussed previously\n>\n>    http://kerneltrap.org/mailarchive/git/2008/8/13/2925144\n>\n> Change a topgit branch's dependencies by doing a rebase-by-merge.\n>\n>\nis this script in use by you, or is it abandoned in favor of another idea?\n\nAnyway, I have tried it today but it looks like the top-bases wasn't\nupdated to the new deps. It points still to the old base. Second, I\ngot an empty line in my .topdeps file.\n\n> +\n> +if [ -n \"$add\" ]; then\n> +       add=\"${add/# }\"\n> +       add=\"${add//  / }\"\n> +       dupes=$(grep -E \"^${add// /|}/\\$\" \"$root_dir/.topdeps\" | tr '\\n' ' ')\n> +       [ -z \"$dupes\" ] || die \"already depend on: $dupes\"\n> +       redeps=$(echo \"$add\" | cat \"$root_dir/.topdeps\" - | tr '\\n' ' ' | sed -e 's/ \\+$//')\n> +elif [ -n \"$remove\" ]; then\n> +       remove=\"${remove//  / }\"\n> +       remove=\"${remove/# }\"\n> +       avail=$(grep -E \"^${remove// /|}/\\$\" \"$root_dir/.topdeps\" | sort | tr '\\n' ' ')\n> +       remove_sorted=$(echo \"$remove\" | tr ' ' '\\n' | grep -v '^$' | sort | tr '\\n' ' ')\n> +       [ \"$avail\" = \"$remove_sorted\" ] || die \"not depending on some of: $remove\"\n> +       redeps=$(grep -vE \"^${remove// /|}/\\$\" \"$root_dir/.topdeps\" | tr '\\n' ' ')\n> +fi\nIMHO all these \"| tr '\\n' ' '\" aren't needed. bash do the right thing here.\n\nBert\n"},{"id":"89389","messageId":"1220263905.6278.13.camel@heerbeest","threadId":"15020","inReplyTo":"36ca99e90809010231o439ab4acsaa3027366c551ff6@mail.gmail.com","subject":"Re: [TopGit PATCH] tg redepend: New command.","fromName":"Jan Nieuwenhuizen","fromEmail":"janneke-list@xs4all.nl","sentAt":"2008-09-01T10:11:45Z","receivedAt":"2008-09-01T10:11:45Z","isPatch":true,"sender":{"key":"janneke-list@xs4all.nl","avatar":null},"body":"On ma, 2008-09-01 at 11:31 +0200, Bert Wesarg wrote:\n\nHi Bert,\n\n> \n> On Fri, Aug 15, 2008 at 15:53, Jan Nieuwenhuizen <janneke-list@xs4all.nl> wrote:\n> > As discussed previously\n> >\n> >    http://kerneltrap.org/mailarchive/git/2008/8/13/2925144\n> >\n> > Change a topgit branch's dependencies by doing a rebase-by-merge.\n> >\n> >\n> is this script in use by you, or is it abandoned in favor of another idea?\n\nI haven't had the time to digest the several new takes on this, esp.\nhttp://kerneltrap.org/mailarchive/git/2008/8/15/2954214 and combining\nmy previous attempt's use of git revert and git cherry-pick with git\nread-tree to make for a much faster adding or removal of\ndependencies.\n\n> Anyway, I have tried it today but it looks like the top-bases wasn't\n> updated to the new deps.\n\nHow odd.  It also looks like \"redeps\" contains the new set of\ndependencies, which is written to .topdeps.  I guess that most of\nthis script will be abandoned anyway, but a nice bug report ie: how to\nreproduce this error never hurts ;-)\n\n> IMHO all these \"| tr '\\n' ' '\" aren't needed. bash do the right thing\n> here.\n\nThanks, I'll have a look.  You did try --add, --remove and \"new dep\nlist\" right? \n\nGreetings,\nJan.\n\n-- \nJan Nieuwenhuizen <janneke@gnu.org> | GNU LilyPond - The music typesetter\nhttp://www.xs4all.nl/~jantien       | http://www.lilypond.org\n"},{"id":"89399","messageId":"36ca99e90809010336k2afd1253vfcdb754b6af97143@mail.gmail.com","threadId":"15020","inReplyTo":"1220263905.6278.13.camel@heerbeest","subject":"Re: [TopGit PATCH] tg redepend: New command.","fromName":"Bert Wesarg","fromEmail":"bert.wesarg@googlemail.com","sentAt":"2008-09-01T10:36:47Z","receivedAt":"2008-09-01T10:36:47Z","isPatch":true,"sender":{"key":"bert.wesarg@googlemail.com","avatar":"https://avatars.githubusercontent.com/u/111934?v=4"},"body":"On Mon, Sep 1, 2008 at 12:11, Jan Nieuwenhuizen <janneke-list@xs4all.nl> wrote:\n> On ma, 2008-09-01 at 11:31 +0200, Bert Wesarg wrote:\n>\n> Hi Bert,\n>\n>>\n>> On Fri, Aug 15, 2008 at 15:53, Jan Nieuwenhuizen <janneke-list@xs4all.nl> wrote:\n>> > As discussed previously\n>> >\n>> >    http://kerneltrap.org/mailarchive/git/2008/8/13/2925144\n>> >\n>> > Change a topgit branch's dependencies by doing a rebase-by-merge.\n>> >\n>> >\n>> is this script in use by you, or is it abandoned in favor of another idea?\n>\n> I haven't had the time to digest the several new takes on this, esp.\n> http://kerneltrap.org/mailarchive/git/2008/8/15/2954214 and combining\n> my previous attempt's use of git revert and git cherry-pick with git\n> read-tree to make for a much faster adding or removal of\n> dependencies.\n>\n>> Anyway, I have tried it today but it looks like the top-bases wasn't\n>> updated to the new deps.\n>\n> How odd.  It also looks like \"redeps\" contains the new set of\n> dependencies, which is written to .topdeps.  I guess that most of\n> this script will be abandoned anyway, but a nice bug report ie: how to\n> reproduce this error never hurts ;-)\nYeah, sorry, here comes part two:\n\nI have tried to switch the order of two topics, which are the only two\nin this 'series'. T1 depdens on master, and T2 on T1 with definitive\nmerge conflicts.\n\nfirst step was to redepend T2 to master:\n$ tg redepend master\n\nafter that, I saw the above odds, i.e.:\n * the refs/top-bases/T2 points still to T1 not master\n * (NEW) the .topmsg is lost (which I discovered after step two)\n * a trailing empty line is in .topdeps\n\n(NEW) step two was to redpend T1 on T2:\n$ git checkout T2\n$ tg redepend T2\n\nafter that, my T1 changes were lost, i.e. the worktree is in state of T2.\n\nI have attached the log of this session (slightly edited).\n\nThanks anyway for working on this.\n\nRegards\nBert\n\n> Greetings,\n> Jan.\n"}]}