{"thread":{"id":"9179","subject":"[PATCH] filter-branch: Big syntax change; support rewriting multiple refs","startedAt":"2007-07-23T17:34:13Z","lastAt":"2007-07-24T19:52:08Z","messageCount":20,"participants":["Johannes Schindelin","Junio C Hamano","Johannes Sixt"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"48321","messageId":"Pine.LNX.4.64.0707231829210.14781@racer.site","threadId":"9179","inReplyTo":null,"subject":"[PATCH] filter-branch: Big syntax change; support rewriting multiple refs","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2007-07-23T17:34:13Z","receivedAt":"2007-07-23T17:34:13Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"\nWe used to take the first non-option argument as the name for the new \nbranch.  This syntax is not extensible to support rewriting more than just \nHEAD.\n\nInstead, we now have the following syntax:\n\n\tgit filter-branch [<filter options>...] [<rev-list options>]\n\nAll positive refs given in <rev-list options> are rewritten.  Yes, \nin-place.  If a ref was changed, the original head is stored in \nrefs/original/$ref now, for your inspecting pleasure, in addition to the \nreflogs (since it is easier to inspect \"git show-ref | grep original\" than \nto inspect all the reflogs).\n\nThis commit also adds the --force option to remove .git-rewrite/ and all \nrefs from refs/original/ before filtering.\n\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n\n\tJunio, I know that this comes quite late in the game, but I really\n\tthink that the \"first arg is new branch name\" was a bad syntax.\n\n\tCould you please consider taking this patch (or whatever version\n\tcomes out after review ;-) or keeping filter-branch of 1.5.3?  I \n\tdo not want people to get used to the borked syntax...\n\n\tBTW I considered \"git log -g --all\" as an alternative to \n\tinspecting refs/original/, but ATM this die()s if just _one_ of \n\tthe refs has no logs.  Probably should fix that, too.\n\n Documentation/git-filter-branch.txt |   51 +++++++------\n git-filter-branch.sh                |  150 +++++++++++++++++++++++++++++-----\n t/t7003-filter-branch.sh            |   41 ++++++----\n 3 files changed, 182 insertions(+), 60 deletions(-)\n\ndiff --git a/Documentation/git-filter-branch.txt b/Documentation/git-filter-branch.txt\nindex eaea82d..915258f 100644\n--- a/Documentation/git-filter-branch.txt\n+++ b/Documentation/git-filter-branch.txt\n@@ -12,7 +12,7 @@ SYNOPSIS\n \t[--index-filter <command>] [--parent-filter <command>]\n \t[--msg-filter <command>] [--commit-filter <command>]\n \t[--tag-name-filter <command>] [--subdirectory-filter <directory>]\n-\t[-d <directory>] <new-branch-name> [<rev-list options>...]\n+\t[-d <directory>] [-f | --force] [<rev-list options>...]\n \n DESCRIPTION\n -----------\n@@ -26,10 +26,9 @@ information) will be preserved.\n The command takes the new branch name as a mandatory argument and\n the filters as optional arguments.  If you specify no filters, the\n commits will be recommitted without any changes, which would normally\n-have no effect and result in the new branch pointing to the same\n-branch as your current branch.  Nevertheless, this may be useful in\n-the future for compensating for some git bugs or such, therefore\n-such a usage is permitted.\n+have no effect.  Nevertheless, this may be useful in the future for\n+compensating for some git bugs or such, therefore such a usage is\n+permitted.\n \n *WARNING*! The rewritten history will have different object names for all\n the objects and will not converge with the original branch.  You will not\n@@ -38,8 +37,9 @@ original branch.  Please do not use this command if you do not know the\n full implications, and avoid using it anyway, if a simple single commit\n would suffice to fix your problem.\n \n-Always verify that the rewritten version is correct before disposing\n-the original branch.\n+Always verify that the rewritten version is correct: The original refs,\n+if different from the rewritten ones, will be stored in the namespace\n+'refs/original/'.\n \n Note that since this operation is extensively I/O expensive, it might\n be a good idea to redirect the temporary directory off-disk, e.g. on\n@@ -142,6 +142,11 @@ definition impossible to preserve signatures at any rate.)\n \tdoes this in the '.git-rewrite/' directory but you can override\n \tthat choice by this parameter.\n \n+-f\\|--force::\n+\t`git filter-branch` refuses to start with an existing temporary\n+\tdirectory or when there are already refs starting with\n+\t'refs/original/', unless forced.\n+\n <rev-list-options>::\n \tWhen options are given after the new branch name, they will\n \tbe passed to gitlink:git-rev-list[1].  Only commits in the resulting\n@@ -156,14 +161,14 @@ Suppose you want to remove a file (containing confidential information\n or copyright violation) from all commits:\n \n -------------------------------------------------------\n-git filter-branch --tree-filter 'rm filename' newbranch\n+git filter-branch --tree-filter 'rm filename' HEAD\n -------------------------------------------------------\n \n A significantly faster version:\n \n--------------------------------------------------------------------------------\n-git filter-branch --index-filter 'git update-index --remove filename' newbranch\n--------------------------------------------------------------------------------\n+--------------------------------------------------------------------------\n+git filter-branch --index-filter 'git update-index --remove filename' HEAD\n+--------------------------------------------------------------------------\n \n Now, you will get the rewritten history saved in the branch 'newbranch'\n (your current branch is left untouched).\n@@ -172,25 +177,25 @@ To set a commit (which typically is at the tip of another\n history) to be the parent of the current initial commit, in\n order to paste the other history behind the current history:\n \n-------------------------------------------------------------------------\n-git filter-branch --parent-filter 'sed \"s/^\\$/-p <graft-id>/\"' newbranch\n-------------------------------------------------------------------------\n+-------------------------------------------------------------------\n+git filter-branch --parent-filter 'sed \"s/^\\$/-p <graft-id>/\"' HEAD\n+-------------------------------------------------------------------\n \n (if the parent string is empty - therefore we are dealing with the\n initial commit - add graftcommit as a parent).  Note that this assumes\n history with a single root (that is, no merge without common ancestors\n happened).  If this is not the case, use:\n \n--------------------------------------------------------------------------------\n+--------------------------------------------------------------------------\n git filter-branch --parent-filter \\\n-\t'cat; test $GIT_COMMIT = <commit-id> && echo \"-p <graft-id>\"' newbranch\n--------------------------------------------------------------------------------\n+\t'cat; test $GIT_COMMIT = <commit-id> && echo \"-p <graft-id>\"' HEAD\n+--------------------------------------------------------------------------\n \n or even simpler:\n \n -----------------------------------------------\n echo \"$commit-id $graft-id\" >> .git/info/grafts\n-git filter-branch newbranch $graft-id..\n+git filter-branch $graft-id..HEAD\n -----------------------------------------------\n \n To remove commits authored by \"Darl McBribe\" from the history:\n@@ -208,7 +213,7 @@ git filter-branch --commit-filter '\n \t\tdone;\n \telse\n \t\tgit commit-tree \"$@\";\n-\tfi' newbranch\n+\tfi' HEAD\n ------------------------------------------------------------------------------\n \n The shift magic first throws away the tree id and then the -p\n@@ -238,14 +243,14 @@ A--B-----C\n To rewrite only commits D,E,F,G,H, but leave A, B and C alone, use:\n \n --------------------------------\n-git filter-branch ... new-H C..H\n+git filter-branch ... C..H\n --------------------------------\n \n To rewrite commits E,F,G,H, use one of these:\n \n ----------------------------------------\n-git filter-branch ... new-H C..H --not D\n-git filter-branch ... new-H D..H --not C\n+git filter-branch ... C..H --not D\n+git filter-branch ... D..H --not C\n ----------------------------------------\n \n To move the whole tree into a subdirectory, or remove it from there:\n@@ -255,7 +260,7 @@ git filter-branch --index-filter \\\n \t'git ls-files -s | sed \"s-\\t-&newsubdir/-\" |\n \t\tGIT_INDEX_FILE=$GIT_INDEX_FILE.new \\\n \t\t\tgit update-index --index-info &&\n-\t mv $GIT_INDEX_FILE.new $GIT_INDEX_FILE' directorymoved\n+\t mv $GIT_INDEX_FILE.new $GIT_INDEX_FILE' HEAD\n ---------------------------------------------------------------\n \n \ndiff --git a/git-filter-branch.sh b/git-filter-branch.sh\nindex 0d000ed..0ff3475 100755\n--- a/git-filter-branch.sh\n+++ b/git-filter-branch.sh\n@@ -78,6 +78,8 @@ filter_msg=cat\n filter_commit='git commit-tree \"$@\"'\n filter_tag_name=\n filter_subdir=\n+orig_namespace=refs/original/\n+force=\n while case \"$#\" in 0) usage;; esac\n do\n \tcase \"$1\" in\n@@ -85,6 +87,11 @@ do\n \t\tshift\n \t\tbreak\n \t\t;;\n+\t--force|-f)\n+\t\tshift\n+\t\tforce=t\n+\t\tcontinue\n+\t\t;;\n \t-*)\n \t\t;;\n \t*)\n@@ -126,24 +133,43 @@ do\n \t--subdirectory-filter)\n \t\tfilter_subdir=\"$OPTARG\"\n \t\t;;\n+\t--original)\n+\t\torig_namespace=\"$OPTARG\"\n+\t\t;;\n \t*)\n \t\tusage\n \t\t;;\n \tesac\n done\n \n-dstbranch=\"$1\"\n-shift\n-test -n \"$dstbranch\" || die \"missing branch name\"\n-git show-ref \"refs/heads/$dstbranch\" 2> /dev/null &&\n-\tdie \"branch $dstbranch already exists\"\n-\n-test ! -e \"$tempdir\" || die \"$tempdir already exists, please remove it\"\n+case \"$force\" in\n+t)\n+\trm -rf \"$tempdir\"\n+;;\n+'')\n+\ttest -d \"$tempdir\" &&\n+\t\tdie \"$tempdir already exists, please remove it\"\n+esac\n mkdir -p \"$tempdir/t\" &&\n+tempdir=\"$(cd \"$tempdir\"; pwd)\" &&\n cd \"$tempdir/t\" &&\n workdir=\"$(pwd)\" ||\n die \"\"\n \n+# Make sure refs/original is empty\n+git for-each-ref > \"$tempdir\"/backup-refs\n+while read sha1 type name\n+do\n+\tcase \"$force,$name\" in\n+\t,$orig_namespace*)\n+\t\tdie \"Namespace $orig_namespace not empty\"\n+\t;;\n+\tt,$orig_namespace*)\n+\t\tgit update-ref -d \"$name\" $sha1\n+\t;;\n+\tesac\n+done < \"$tempdir\"/backup-refs\n+\n case \"$GIT_DIR\" in\n /*)\n \t;;\n@@ -153,6 +179,29 @@ case \"$GIT_DIR\" in\n esac\n export GIT_DIR GIT_WORK_TREE=.\n \n+# These refs should be updated if their heads were rewritten\n+\n+git rev-parse --revs-only --symbolic \"$@\" |\n+while read ref\n+do\n+\t# normalize ref\n+\tcase \"$ref\" in\n+\tHEAD)\n+\t\tref=\"$(git symbolic-ref \"$ref\")\"\n+\t;;\n+\trefs/*)\n+\t;;\n+\t*)\n+\t\tref=\"$(git for-each-ref --format='%(refname)' |\n+\t\t\tgrep /\"$ref\")\"\n+\tesac\n+\n+\tgit check-ref-format \"$ref\" && echo \"$ref\"\n+done > \"$tempdir\"/heads\n+\n+test -s \"$tempdir\"/heads ||\n+\tdie \"Which ref do you want to rewrite?\"\n+\n export GIT_INDEX_FILE=\"$(pwd)/../index\"\n git read-tree || die \"Could not seed the index\"\n \n@@ -174,6 +223,8 @@ commits=$(wc -l <../revs | tr -d \" \")\n \n test $commits -eq 0 && die \"Found nothing to rewrite\"\n \n+# Rewrite the commits\n+\n i=0\n while read commit parents; do\n \ti=$(($i+1))\n@@ -234,22 +285,75 @@ while read commit parents; do\n \t\t$(git write-tree) $parentstr < ../message > ../map/$commit\n done <../revs\n \n-src_head=$(tail -n 1 ../revs | sed -e 's/ .*//')\n-target_head=$(head -n 1 ../map/$src_head)\n-case \"$target_head\" in\n-'')\n-\techo Nothing rewritten\n+# In case of a subdirectory filter, it is possible that a specified head\n+# is not in the set of rewritten commits, because it was pruned by the\n+# revision walker.  Fix it by mapping these heads to the next rewritten\n+# ancestor(s), i.e. the boundaries in the set of rewritten commits.\n+\n+# NEEDSWORK: we should sort the unmapped refs topologically first\n+while read ref\n+do\n+\tsha1=$(git rev-parse \"$ref\"^0)\n+\ttest -f \"$workdir\"/../map/$sha1 && continue\n+\t# Assign the boundarie(s) in the set of rewritten commits\n+\t# as the replacement commit(s).\n+\t# (This would look a bit nicer if --not --stdin worked.)\n+\tfor p in $((cd \"$workdir\"/../map; ls | sed \"s/^/^/\") |\n+\t\tgit rev-list $ref --boundary --stdin |\n+\t\tsed -n \"s/^-//p\")\n+\tdo\n+\t\tmap $p >> \"$workdir\"/../map/$sha1\n+\tdone\n+done < \"$tempdir\"/heads\n+\n+# Finally update the refs\n+\n+_x40='[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]'\n+_x40=\"$_x40$_x40$_x40$_x40$_x40$_x40$_x40$_x40\"\n+count=0\n+echo\n+while read ref\n+do\n+\t# avoid rewriting a ref twice\n+\ttest -f \"$orig_namespace$ref\" && continue\n+\n+\tsha1=$(git rev-parse \"$ref\"^0)\n+\trewritten=$(map $sha1)\n+\n+\ttest $sha1 = \"$rewritten\" &&\n+\t\twarn \"WARNING: Ref '$ref' is unchanged\" &&\n+\t\tcontinue\n+\n+\tcase \"$rewritten\" in\n+\t'')\n+\t\techo \"Ref '$ref' was deleted\"\n+\t\tgit update-ref -m \"filter-branch: delete\" -d \"$ref\" $sha1 ||\n+\t\t\tdie \"Could not delete $ref\"\n \t;;\n-*)\n-\tgit update-ref refs/heads/\"$dstbranch\" $target_head ||\n-\t\tdie \"Could not update $dstbranch with $target_head\"\n-\tif [ $(wc -l <../map/$src_head) -gt 1 ]; then\n-\t\techo \"WARNING: Your commit filter caused the head commit to expand to several rewritten commits. Only the first such commit was recorded as the current $dstbranch head but you will need to resolve the situation now (probably by manually merging the other commits). These are all the commits:\" >&2\n-\t\tsed 's/^/\t/' ../map/$src_head >&2\n-\t\tret=1\n-\tfi\n+\t$_x40)\n+\t\techo \"Ref '$ref' was rewritten\"\n+\t\tgit update-ref -m \"filter-branch: rewrite\" \\\n+\t\t\t\t\"$ref\" $rewritten $sha1 ||\n+\t\t\tdie \"Could not rewrite $ref\"\n \t;;\n-esac\n+\t*)\n+\t\t# NEEDSWORK: possibly add -Werror, making this an error\n+\t\twarn \"WARNING: '$ref' was rewritten into multiple commits:\"\n+\t\twarn \"$rewritten\"\n+\t\twarn \"WARNING: Ref '$ref' points to the first one now.\"\n+\t\trewritten=$(echo \"$rewritten\" | head -n 1)\n+\t\tgit update-ref -m \"filter-branch: rewrite to first\" \\\n+\t\t\t\t\"$ref\" $rewritten $sha1 ||\n+\t\t\tdie \"Could not rewrite $ref\"\n+\t;;\n+\tesac\n+\tgit update-ref -m \"filter-branch: backup\" \"$orig_namespace$ref\" $sha1\n+\tcount=$(($count+1))\n+done < \"$tempdir\"/heads\n+\n+# TODO: This should possibly go, with the semantics that all positive given\n+#       refs are updated, and their original heads stored in refs/original/\n+# Filter tags\n \n if [ \"$filter_tag_name\" ]; then\n \tgit for-each-ref --format='%(objectname) %(objecttype) %(refname)' refs/tags |\n@@ -286,6 +390,8 @@ fi\n \n cd ../..\n rm -rf \"$tempdir\"\n-printf \"\\nRewritten history saved to the $dstbranch branch\\n\"\n+echo\n+test $count -gt 0 && echo \"These refs were rewritten:\"\n+git show-ref | grep ^\"$orig_namespace\"\n \n exit $ret\ndiff --git a/t/t7003-filter-branch.sh b/t/t7003-filter-branch.sh\nindex 4ddd656..bc6e2dd 100755\n--- a/t/t7003-filter-branch.sh\n+++ b/t/t7003-filter-branch.sh\n@@ -30,24 +30,24 @@ test_expect_success 'setup' '\n H=$(git rev-parse H)\n \n test_expect_success 'rewrite identically' '\n-\tgit-filter-branch H2\n+\tgit-filter-branch branch\n '\n-\n test_expect_success 'result is really identical' '\n-\ttest $H = $(git rev-parse H2)\n+\ttest $H = $(git rev-parse HEAD)\n '\n \n test_expect_success 'rewrite, renaming a specific file' '\n-\tgit-filter-branch --tree-filter \"mv d doh || :\" H3\n+\tgit-filter-branch -f --tree-filter \"mv d doh || :\" HEAD\n '\n \n test_expect_success 'test that the file was renamed' '\n-\ttest d = $(git show H3:doh)\n+\ttest d = $(git show HEAD:doh)\n '\n \n-git tag oldD H3~4\n+git tag oldD HEAD~4\n test_expect_success 'rewrite one branch, keeping a side branch' '\n-\tgit-filter-branch --tree-filter \"mv b boh || :\" modD D..oldD\n+\tgit branch modD oldD &&\n+\tgit-filter-branch -f --tree-filter \"mv b boh || :\" D..modD\n '\n \n test_expect_success 'common ancestor is still common (unchanged)' '\n@@ -69,7 +69,8 @@ test_expect_success 'filter subdirectory only' '\n \tgit rm a &&\n \ttest_tick &&\n \tgit commit -m \"again not subdir\" &&\n-\tgit-filter-branch --subdirectory-filter subdir sub\n+\tgit branch sub &&\n+\tgit-filter-branch -f --subdirectory-filter subdir refs/heads/sub\n '\n \n test_expect_success 'subdirectory filter result looks okay' '\n@@ -89,7 +90,8 @@ test_expect_success 'setup and filter history that requires --full-history' '\n \ttest_tick &&\n \tgit commit -m \"again subdir on master\" &&\n \tgit merge branch &&\n-\tgit-filter-branch --subdirectory-filter subdir sub-master\n+\tgit branch sub-master &&\n+\tgit-filter-branch -f --subdirectory-filter subdir sub-master\n '\n \n test_expect_success 'subdirectory filter result looks okay' '\n@@ -100,7 +102,8 @@ test_expect_success 'subdirectory filter result looks okay' '\n '\n \n test_expect_success 'use index-filter to move into a subdirectory' '\n-\tgit-filter-branch --index-filter \\\n+\tgit branch directorymoved &&\n+\tgit-filter-branch -f --index-filter \\\n \t\t \"git ls-files -s | sed \\\"s-\\\\t-&newsubdir/-\\\" |\n \t          GIT_INDEX_FILE=\\$GIT_INDEX_FILE.new \\\n \t\t\tgit update-index --index-info &&\n@@ -108,9 +111,10 @@ test_expect_success 'use index-filter to move into a subdirectory' '\n \ttest -z \"$(git diff HEAD directorymoved:newsubdir)\"'\n \n test_expect_success 'stops when msg filter fails' '\n-\t! git-filter-branch --msg-filter false nonono &&\n-\trm -rf .git-rewrite &&\n-\t! git rev-parse nonono\n+\told=$(git rev-parse HEAD) &&\n+\t! git-filter-branch -f --msg-filter false &&\n+\ttest $old = $(git rev-parse HEAD) &&\n+\trm -rf .git-rewrite\n '\n \n test_expect_success 'author information is preserved' '\n@@ -118,7 +122,8 @@ test_expect_success 'author information is preserved' '\n \tgit add i &&\n \ttest_tick &&\n \tGIT_AUTHOR_NAME=\"B V Uips\" git commit -m bvuips &&\n-\tgit-filter-branch --msg-filter \"cat; \\\n+\tgit branch preserved-author &&\n+\tgit-filter-branch -f --msg-filter \"cat; \\\n \t\t\ttest \\$GIT_COMMIT != $(git rev-parse master) || \\\n \t\t\techo Hallo\" \\\n \t\tpreserved-author &&\n@@ -129,7 +134,8 @@ test_expect_success \"remove a certain author's commits\" '\n \techo i > i &&\n \ttest_tick &&\n \tgit commit -m i i &&\n-\tgit-filter-branch --commit-filter \"\\\n+\tgit branch removed-author &&\n+\tgit-filter-branch -f --commit-filter \"\\\n \t\tif [ \\\"\\$GIT_AUTHOR_NAME\\\" = \\\"B V Uips\\\" ];\\\n \t\tthen\\\n \t\t\tshift;\\\n@@ -148,4 +154,9 @@ test_expect_success \"remove a certain author's commits\" '\n \ttest 0 = $(git rev-list --author=\"B V Uips\" removed-author | wc -l)\n '\n \n+test_expect_success 'barf on invalid name' '\n+\t! git filter-branch -f master xy-problem &&\n+\t! git filter-branch -f HEAD^\n+'\n+\n test_done\n-- \n1.5.3.rc2.32.g35c5b\n"},{"id":"48395","messageId":"7vfy3ejre3.fsf@assigned-by-dhcp.cox.net","threadId":"9179","inReplyTo":"Pine.LNX.4.64.0707231829210.14781@racer.site","subject":"Re: [PATCH] filter-branch: Big syntax change; support rewriting multiple refs","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2007-07-24T05:35:16Z","receivedAt":"2007-07-24T05:35:16Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:\n\n> \tJunio, I know that this comes quite late in the game, but I really\n> \tthink that the \"first arg is new branch name\" was a bad syntax.\n>\n> \tCould you please consider taking this patch (or whatever version\n> \tcomes out after review ;-) or keeping filter-branch of 1.5.3?  I \n> \tdo not want people to get used to the borked syntax...\n\nYeah, \"No new features after -rc\" should not apply to this one.\n\nI was actually going to ask you about it, since this is a\nfeature we have already advertised to the public, but still is a\nnew feature, and we'd be better off getting it right in the\nfirst public version.\n\n> \tBTW I considered \"git log -g --all\" as an alternative to \n> \tinspecting refs/original/, but ATM this die()s if just _one_ of \n> \tthe refs has no logs.  Probably should fix that, too.\n\nI do not think refs/original/ is such a hot feature.  What's\nwrong with \"gitk mine@{1}...mine\"?\n"},{"id":"48411","messageId":"Pine.LNX.4.64.0707241010060.14781@racer.site","threadId":"9179","inReplyTo":"7vfy3ejre3.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH] filter-branch: Big syntax change; support rewriting multiple refs","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2007-07-24T09:10:12Z","receivedAt":"2007-07-24T09:10:12Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Mon, 23 Jul 2007, Junio C Hamano wrote:\n\n> Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:\n> \n> > \tJunio, I know that this comes quite late in the game, but I really\n> > \tthink that the \"first arg is new branch name\" was a bad syntax.\n> >\n> > \tCould you please consider taking this patch (or whatever version\n> > \tcomes out after review ;-) or keeping filter-branch of 1.5.3?  I \n> > \tdo not want people to get used to the borked syntax...\n> \n> Yeah, \"No new features after -rc\" should not apply to this one.\n> \n> I was actually going to ask you about it, since this is a feature we \n> have already advertised to the public, but still is a new feature, and \n> we'd be better off getting it right in the first public version.\n\nThanks.\n\n> > \tBTW I considered \"git log -g --all\" as an alternative to\n> > \tinspecting refs/original/, but ATM this die()s if just _one_ of \n> > \tthe refs has no logs.  Probably should fix that, too.\n> \n> I do not think refs/original/ is such a hot feature.  What's wrong with \n> \"gitk mine@{1}...mine\"?\n\nIf you are saying\n\n\t$ git filter-branch <some-filters> --all <rev-list-options>\n\npotentially all refs are rewritten.\n\nTo find out which ones actually changed, you can use \"git show-ref | grep \n^refs/original/\" ATM.\n\nIt is not really easy to do it otherwise.  With the patches I sent out \nyesterday,\n\n\t$ git log -g --no-walk --all --decorate --abbrev-commit \n\t  --pretty=oneline --since=<before-the-last-filter-branch-call>\n\nwould be similar, but not as comfortable, would it?\n\nOf course, we could teach filter-branch an option, say --show-changed, \nwhich will not actually filter branches, but instead look at the reflogs \nitself and show the refs which were recently changed by filter-branch.\n\nBut note that you can switch off reflogs.\n\nCiao,\nDscho\n"},{"id":"48417","messageId":"46A5C615.24C24F0F@eudaptics.com","threadId":"9179","inReplyTo":"Pine.LNX.4.64.0707231829210.14781@racer.site","subject":"Re: [PATCH] filter-branch: Big syntax change; support rewriting multiplerefs","fromName":"Johannes Sixt","fromEmail":"j.sixt@eudaptics.com","sentAt":"2007-07-24T09:27:49Z","receivedAt":"2007-07-24T09:27:49Z","isPatch":true,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Johannes Schindelin wrote:\n> +# These refs should be updated if their heads were rewritten\n> +\n> +git rev-parse --revs-only --symbolic \"$@\" |\n> +while read ref\n> +do\n> +       # normalize ref\n> +       case \"$ref\" in\n> +       HEAD)\n> +               ref=\"$(git symbolic-ref \"$ref\")\"\n> +       ;;\n> +       refs/*)\n> +       ;;\n> +       *)\n> +               ref=\"$(git for-each-ref --format='%(refname)' |\n> +                       grep /\"$ref\")\"\n> +       esac\n> +\n> +       git check-ref-format \"$ref\" && echo \"$ref\"\n> +done > \"$tempdir\"/heads\n\nThis does not work as I'd expected it: I can't successfully say:\n\n   git-filter-branch master\n\nIt tells me:\n\n   Which ref do you want to rewrite?\n\n> +# NEEDSWORK: we should sort the unmapped refs topologically first\n> +while read ref\n> +do\n> +       sha1=$(git rev-parse \"$ref\"^0)\n> +       test -f \"$workdir\"/../map/$sha1 && continue\n> +       # Assign the boundarie(s) in the set of rewritten commits\n> +       # as the replacement commit(s).\n> +       # (This would look a bit nicer if --not --stdin worked.)\n> +       for p in $((cd \"$workdir\"/../map; ls | sed \"s/^/^/\") |\n> +               git rev-list $ref --boundary --stdin |\n> +               sed -n \"s/^-//p\")\n> +       do\n> +               map $p >> \"$workdir\"/../map/$sha1\n> +       done\n> +done < \"$tempdir\"/heads\n\nThis logic seems to be borked, and I don't grok it. I was trying this:\n\n   git-filter-branch -- --since=2007.01.10 \\\n\t\trefs/heads/topic refs/heads/master\n\nwhere topic's last change is from before 2007.01.10, i.e. it is not\namong the rewritten commits. And I get this:\n\nWARNING: Ref 'refs/heads/master' is unchanged\nWARNING: 'refs/heads/topic' was rewritten into multiple commits:\n329325526647503382ae7dee41c12fe6b81bbe43\n2bdf3349b76f72ceb71755c75a555d60bc7c73aa\nce6c9dfeac5ddbd64da2d9360d6552717df81d1f\n\nThe first 2 of these 3 sha1s happen to be merge bases of topic and\nmaster, but none of them appear anywhere in\n\n   git rev-list --parents --boundary --since=2007.07.10 \\\n\t\trefs/heads/topic refs/heads/master\n\nWhat's up?\n\n-- Hannes\n"},{"id":"48432","messageId":"Pine.LNX.4.64.0707241134330.14781@racer.site","threadId":"9179","inReplyTo":"46A5C615.24C24F0F@eudaptics.com","subject":"[PATCH] filter-branch: when dwim'ing a ref, only allow heads and tags","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2007-07-24T10:36:15Z","receivedAt":"2007-07-24T10:36:15Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"\nPreviously, we matched all refs that had /$ref in them.  And tried to\nverify the result as a ref.  If more than one match was found, the result\nwas not a ref, though.\n\nSo only allow tags and heads to be dwim'ed.  If both a tag and a head with\nthat name exist, it will be ignored again.\n\nCaught by Johannes Sixt.\n\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n\n\tOn Tue, 24 Jul 2007, Johannes Sixt wrote:\n\n\t> Johannes Schindelin wrote:\n\t> > +# These refs should be updated if their heads were rewritten\n\t> > +\n\t> > +git rev-parse --revs-only --symbolic \"$@\" |\n\t> > +while read ref\n\t> > +do\n\t> > +       # normalize ref\n\t> > +       case \"$ref\" in\n\t> > +       HEAD)\n\t> > +               ref=\"$(git symbolic-ref \"$ref\")\"\n\t> > +       ;;\n\t> > +       refs/*)\n\t> > +       ;;\n\t> > +       *)\n\t> > +               ref=\"$(git for-each-ref --format='%(refname)' |\n\t> > +                       grep /\"$ref\")\"\n\t> > +       esac\n\t> > +\n\t> > +       git check-ref-format \"$ref\" && echo \"$ref\"\n\t> > +done > \"$tempdir\"/heads\n\t> \n\t> This does not work as I'd expected it: I can't successfully say:\n\t> \n\t>    git-filter-branch master\n\t> \n\t> It tells me:\n\t> \n\t>    Which ref do you want to rewrite?\n\n\tI tried that, and happily got the same.  The explanation: more \n\tthan one ref matched \"/master\".  My pattern was extremely borked.\n\n\tThanks.\n\n git-filter-branch.sh     |    2 +-\n t/t7003-filter-branch.sh |    5 +++++\n 2 files changed, 6 insertions(+), 1 deletions(-)\n\ndiff --git a/git-filter-branch.sh b/git-filter-branch.sh\nindex 0ff3475..019a302 100755\n--- a/git-filter-branch.sh\n+++ b/git-filter-branch.sh\n@@ -193,7 +193,7 @@ do\n \t;;\n \t*)\n \t\tref=\"$(git for-each-ref --format='%(refname)' |\n-\t\t\tgrep /\"$ref\")\"\n+\t\t\tgrep \"refs/\\(tags\\|heads\\)/$ref$\")\"\n \tesac\n \n \tgit check-ref-format \"$ref\" && echo \"$ref\"\ndiff --git a/t/t7003-filter-branch.sh b/t/t7003-filter-branch.sh\nindex bc6e2dd..c9a820d 100755\n--- a/t/t7003-filter-branch.sh\n+++ b/t/t7003-filter-branch.sh\n@@ -159,4 +159,9 @@ test_expect_success 'barf on invalid name' '\n \t! git filter-branch -f HEAD^\n '\n \n+test_expect_success 'only dwim refs/heads/$ref or refs/tags/$ref' '\n+\tgit update-ref refs/remotes/origin/master HEAD &&\n+\tgit filter-branch -f master\n+'\n+\n test_done\n-- \n1.5.3.rc2.32.g35c5b-dirty\n"},{"id":"48435","messageId":"46A5DCBC.E585A69D@eudaptics.com","threadId":"9179","inReplyTo":"Pine.LNX.4.64.0707241134330.14781@racer.site","subject":"Re: [PATCH] filter-branch: when dwim'ing a ref, only allow heads andtags","fromName":"Johannes Sixt","fromEmail":"j.sixt@eudaptics.com","sentAt":"2007-07-24T11:04:28Z","receivedAt":"2007-07-24T11:04:28Z","isPatch":true,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Johannes Schindelin wrote:\n> -                       grep /\"$ref\")\"\n> +                       grep \"refs/\\(tags\\|heads\\)/$ref$\")\"\n\nThanks, but I don't think that this is a portable grep pattern:\n\n$ echo \"abc\" | grep '\\(a\\|x\\)'\n$ echo \"abc\" | egrep '(a|x)'\nabc\n\nBut then, this is on some AIX 4.3. How about:\n\n   fgrep -e \"refs/heads/$ref\" -e \"refs/tags/$ref\"\nor\n   grep -e \"^refs/heads/$ref\" -e \"^refs/tags/$ref\"\n\n-- Hannes\n"},{"id":"48436","messageId":"Pine.LNX.4.64.0707241205480.14781@racer.site","threadId":"9179","inReplyTo":"46A5C615.24C24F0F@eudaptics.com","subject":"[PATCH] filter-branch: rewrite only refs which were not excluded by the options","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2007-07-24T11:06:21Z","receivedAt":"2007-07-24T11:06:21Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"\nThe rev-list options can exclude some -- or all -- refs:\n\n\tgit filter-branch <some-filter> master ^master\n\nWithout this patch, these refs are assumed to be deleted, or worse, they\nare rewritten to some bogus merge bases.\n\nSo really exclude excluded refs from being rewritten.  This also allows\nyou to safely call\n\n\tgit filter-branch <some-filter> --all <rev-list options>\n\nto rewrite _all_ branches and tags.\n\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n\tOn Tue, 24 Jul 2007, Johannes Sixt wrote:\n\n\t> Johannes Schindelin wrote:\n\t> \n\t> > +# NEEDSWORK: we should sort the unmapped refs topologically first\n\t> > +while read ref\n\t> > +do\n\t> > +       sha1=$(git rev-parse \"$ref\"^0)\n\t> > +       test -f \"$workdir\"/../map/$sha1 && continue\n\t> > +       # Assign the boundarie(s) in the set of rewritten commits\n\t> > +       # as the replacement commit(s).\n\t> > +       # (This would look a bit nicer if --not --stdin worked.)\n\t> > +       for p in $((cd \"$workdir\"/../map; ls | sed \"s/^/^/\") |\n\t> > +               git rev-list $ref --boundary --stdin |\n\t> > +               sed -n \"s/^-//p\")\n\t> > +       do\n\t> > +               map $p >> \"$workdir\"/../map/$sha1\n\t> > +       done\n\t> > +done < \"$tempdir\"/heads\n\t> \n\t> This logic seems to be borked, and I don't grok it. I was trying this:\n\t> \n\t>    git-filter-branch -- --since=2007.01.10 \\\n\t> \t\trefs/heads/topic refs/heads/master\n\n\tActually, the error lay somewhere else.  If excluded, topic should \n\tnot have been a rewrite candidate.\n\n\tThere might be something else looming here: what to do with\n\n\t\tgit filter-branch --subdir-filter subdir/ topic master \\\n\t\t\t^$(git merge-base topic master)\n\n\twhen topic has no changes to the subdirectory, but master has?\n\n\tI guess the safest would be to 'test -f \"$workdir\"/../map/$p', and \n\tif at least one is not there, leave 'topic' as is.  If at least \n\tone is there, however, we want to warn the user that this is not \n\tpossible.  (Something like: this was an unchanged ancestor: $p1, \n\tbut that was a changed one: $p2.  Make up your mind what you \n\twant.)\n\n git-filter-branch.sh     |    9 ++++++++-\n t/t7003-filter-branch.sh |    9 +++++++++\n 2 files changed, 17 insertions(+), 1 deletions(-)\n\ndiff --git a/git-filter-branch.sh b/git-filter-branch.sh\nindex 019a302..49b0f00 100755\n--- a/git-filter-branch.sh\n+++ b/git-filter-branch.sh\n@@ -181,6 +181,7 @@ export GIT_DIR GIT_WORK_TREE=.\n \n # These refs should be updated if their heads were rewritten\n \n+negatives=\"$(git rev-parse --revs-only \"$@\" | grep \"^\\^\")\"\n git rev-parse --revs-only --symbolic \"$@\" |\n while read ref\n do\n@@ -196,7 +197,13 @@ do\n \t\t\tgrep \"refs/\\(tags\\|heads\\)/$ref$\")\"\n \tesac\n \n-\tgit check-ref-format \"$ref\" && echo \"$ref\"\n+\t# make sure we have a valid ref\n+\tgit check-ref-format \"$ref\" || continue\n+\n+\t# if the ref has been excluded by the other options, skip it\n+\ttest -z \"$(git rev-list -1 \"$ref\" $negatives)\" && continue\n+\n+\techo \"$ref\"\n done > \"$tempdir\"/heads\n \n test -s \"$tempdir\"/heads ||\ndiff --git a/t/t7003-filter-branch.sh b/t/t7003-filter-branch.sh\nindex c9a820d..667eda7 100755\n--- a/t/t7003-filter-branch.sh\n+++ b/t/t7003-filter-branch.sh\n@@ -164,4 +164,13 @@ test_expect_success 'only dwim refs/heads/$ref or refs/tags/$ref' '\n \tgit filter-branch -f master\n '\n \n+test_expect_success 'do not update uninteresting refs' '\n+\tbranch=$(git rev-parse branch) &&\n+\tmaster=$(git rev-parse master) &&\n+\tgit filter-branch -f --env-filter \"GIT_AUTHOR_EMAIL=xy@probl.em\" \\\n+\t\tmaster ^removed-author branch &&\n+\ttest $branch = $(git rev-parse branch) &&\n+\ttest $master != $(git rev-parse master)\n+'\n+\n test_done\n-- \n1.5.3.rc2.32.g35c5b-dirty\n"},{"id":"48442","messageId":"Pine.LNX.4.64.0707241218270.14781@racer.site","threadId":"9179","inReplyTo":"46A5DCBC.E585A69D@eudaptics.com","subject":"Re: [PATCH] filter-branch: when dwim'ing a ref, only allow heads andtags","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2007-07-24T11:20:52Z","receivedAt":"2007-07-24T11:20:52Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Tue, 24 Jul 2007, Johannes Sixt wrote:\n\n> Johannes Schindelin wrote:\n> > -                       grep /\"$ref\")\"\n> > +                       grep \"refs/\\(tags\\|heads\\)/$ref$\")\"\n> \n> Thanks, but I don't think that this is a portable grep pattern:\n> \n> $ echo \"abc\" | grep '\\(a\\|x\\)'\n> $ echo \"abc\" | egrep '(a|x)'\n> abc\n> \n> But then, this is on some AIX 4.3. How about:\n> \n>    fgrep -e \"refs/heads/$ref\" -e \"refs/tags/$ref\"\n> or\n>    grep -e \"^refs/heads/$ref\" -e \"^refs/tags/$ref\"\n\nAh yes, I remember that Junio said some time ago that \"\\|\" is not \nportable.\n\nBut to be portable, let's stay with grep, and not use some fancy stuff \nlike egrep or fgrep.\n\nCiao,\nDscho\n"},{"id":"48443","messageId":"46A5E136.D413D3B7@eudaptics.com","threadId":"9179","inReplyTo":"Pine.LNX.4.64.0707241205480.14781@racer.site","subject":"Re: [PATCH] filter-branch: rewrite only refs which were not excluded bythe options","fromName":"Johannes Sixt","fromEmail":"j.sixt@eudaptics.com","sentAt":"2007-07-24T11:23:34Z","receivedAt":"2007-07-24T11:23:34Z","isPatch":true,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Johannes Schindelin wrote:\n> So really exclude excluded refs from being rewritten.  This also allows\n> you to safely call\n> \n>         git filter-branch <some-filter> --all <rev-list options>\n> \n> to rewrite _all_ branches and tags.\n\nBTW, '--all' in the argument list of filter-branch works only if it is\npreceded by '--':\n\n\tgit filter-branch <some-filter> -- --all <rev-list options>\n\n> @@ -181,6 +181,7 @@ export GIT_DIR GIT_WORK_TREE=.\n> \n>  # These refs should be updated if their heads were rewritten\n> \n> +negatives=\"$(git rev-parse --revs-only \"$@\" | grep \"^\\^\")\"\n>  git rev-parse --revs-only --symbolic \"$@\" |\n>  while read ref\n>  do\n> @@ -196,7 +197,13 @@ do\n>                         grep \"refs/\\(tags\\|heads\\)/$ref$\")\"\n>         esac\n> \n> -       git check-ref-format \"$ref\" && echo \"$ref\"\n> +       # make sure we have a valid ref\n> +       git check-ref-format \"$ref\" || continue\n> +\n> +       # if the ref has been excluded by the other options, skip it\n> +       test -z \"$(git rev-list -1 \"$ref\" $negatives)\" && continue\n\nDoes this catch my use-case with --since? I think not, because:\n\n$ git rev-parse --revs-only --since=2007.01.01 master topic\n--max-age=1167606000\n257061f3323dc0162f731d934f0870e919211fdf\n3405729b94a654df8afbb9a1e13a4cf49a1c351c\n\nThere are no negatives. Does it help to filter the non-positives?\n\nnegatives=$(git rev-parse --revs-only \"$@\" | egrep -v '^[0-9a-f]{40}$')\n\n(Except the the '{40}' part is not portable. Hmpf.)\n\n-- Hannes\n"},{"id":"48446","messageId":"Pine.LNX.4.64.0707241227140.14781@racer.site","threadId":"9179","inReplyTo":"Pine.LNX.4.64.0707241218270.14781@racer.site","subject":"[PATCH] filter-branch: when dwim'ing a ref, only allow heads and tags","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2007-07-24T11:27:59Z","receivedAt":"2007-07-24T11:27:59Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"\nPreviously, we matched all refs that had /$ref in them.  And tried to\nverify the result as a ref.  If more than one match was found, the result\nwas not a ref, though.\n\nSo only allow tags and heads to be dwim'ed.  If both a tag and a head with\nthat name exist, it will be ignored again.\n\nCaught by Johannes Sixt.\n\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n\n\tHeh.  I just realised that I managed to fsck up a one-line patch.  \n\tD'oh!  Thanks for fixing it, Hannes.\n\n git-filter-branch.sh     |    2 +-\n t/t7003-filter-branch.sh |    5 +++++\n 2 files changed, 6 insertions(+), 1 deletions(-)\n\ndiff --git a/git-filter-branch.sh b/git-filter-branch.sh\nindex 0ff3475..4fb3abe 100755\n--- a/git-filter-branch.sh\n+++ b/git-filter-branch.sh\n@@ -193,7 +193,7 @@ do\n \t;;\n \t*)\n \t\tref=\"$(git for-each-ref --format='%(refname)' |\n-\t\t\tgrep /\"$ref\")\"\n+\t\t\tgrep -e \"^refs/heads/$ref$\" -e \"^refs/tags/$ref$\")\"\n \tesac\n \n \tgit check-ref-format \"$ref\" && echo \"$ref\"\ndiff --git a/t/t7003-filter-branch.sh b/t/t7003-filter-branch.sh\nindex bc6e2dd..c9a820d 100755\n--- a/t/t7003-filter-branch.sh\n+++ b/t/t7003-filter-branch.sh\n@@ -159,4 +159,9 @@ test_expect_success 'barf on invalid name' '\n \t! git filter-branch -f HEAD^\n '\n \n+test_expect_success 'only dwim refs/heads/$ref or refs/tags/$ref' '\n+\tgit update-ref refs/remotes/origin/master HEAD &&\n+\tgit filter-branch -f master\n+'\n+\n test_done\n-- \n1.5.3.rc2.32.g35c5b-dirty\n"},{"id":"48447","messageId":"Pine.LNX.4.64.0707241229170.14781@racer.site","threadId":"9179","inReplyTo":"46A5E136.D413D3B7@eudaptics.com","subject":"Re: [PATCH] filter-branch: rewrite only refs which were not excluded bythe options","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2007-07-24T11:33:53Z","receivedAt":"2007-07-24T11:33:53Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Tue, 24 Jul 2007, Johannes Sixt wrote:\n\n> Johannes Schindelin wrote:\n> > So really exclude excluded refs from being rewritten.  This also allows\n> > you to safely call\n> > \n> >         git filter-branch <some-filter> --all <rev-list options>\n> > \n> > to rewrite _all_ branches and tags.\n> \n> BTW, '--all' in the argument list of filter-branch works only if it is\n> preceded by '--':\n> \n> \tgit filter-branch <some-filter> -- --all <rev-list options>\n\nHmm.  Maybe we should reconsider the logic.  I.e. instead of\n\n        *)\n                usage\n\n        *)\n                break\n\n> > @@ -181,6 +181,7 @@ export GIT_DIR GIT_WORK_TREE=.\n> > \n> >  # These refs should be updated if their heads were rewritten\n> > \n> > +negatives=\"$(git rev-parse --revs-only \"$@\" | grep \"^\\^\")\"\n> >  git rev-parse --revs-only --symbolic \"$@\" |\n> >  while read ref\n> >  do\n> > @@ -196,7 +197,13 @@ do\n> >                         grep \"refs/\\(tags\\|heads\\)/$ref$\")\"\n> >         esac\n> > \n> > -       git check-ref-format \"$ref\" && echo \"$ref\"\n> > +       # make sure we have a valid ref\n> > +       git check-ref-format \"$ref\" || continue\n> > +\n> > +       # if the ref has been excluded by the other options, skip it\n> > +       test -z \"$(git rev-list -1 \"$ref\" $negatives)\" && continue\n> \n> Does this catch my use-case with --since? I think not, because:\n> \n> $ git rev-parse --revs-only --since=2007.01.01 master topic\n> --max-age=1167606000\n> 257061f3323dc0162f731d934f0870e919211fdf\n> 3405729b94a654df8afbb9a1e13a4cf49a1c351c\n> \n> There are no negatives. Does it help to filter the non-positives?\n> \n> negatives=$(git rev-parse --revs-only \"$@\" | egrep -v '^[0-9a-f]{40}$')\n> \n> (Except the the '{40}' part is not portable. Hmpf.)\n\nTo keep the \"--since=...\" we have to lose the \"--revs-only\"...\nDarn.  I thought that \"--since=\" was expanded by rev-parse.  FWIW this \nmight work:\n\nnegatives=\"$(git rev-parse \"$@\" | while read line\n\tdo\n\t\tcase \"$line\" in\n\t\t$_x40) ;;\n\t\t*) echo \"$line\";;\n\t\tesac\n\tdone)\"\n\nCan you please test?  I am off for lunch.\n\nCiao,\nDscho\n"},{"id":"48459","messageId":"46A5FF69.F5D75C9E@eudaptics.com","threadId":"9179","inReplyTo":"Pine.LNX.4.64.0707241229170.14781@racer.site","subject":"Re: [PATCH] filter-branch: rewrite only refs which were not excludedbythe options","fromName":"Johannes Sixt","fromEmail":"j.sixt@eudaptics.com","sentAt":"2007-07-24T13:32:25Z","receivedAt":"2007-07-24T13:32:25Z","isPatch":true,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Johannes Schindelin wrote:\n> \n> Hi,\n> \n> On Tue, 24 Jul 2007, Johannes Sixt wrote:\n> \n> > Johannes Schindelin wrote:\n> > > So really exclude excluded refs from being rewritten.  This also allows\n> > > you to safely call\n> > >\n> > >         git filter-branch <some-filter> --all <rev-list options>\n> > >\n> > > to rewrite _all_ branches and tags.\n> >\n> > BTW, '--all' in the argument list of filter-branch works only if it is\n> > preceded by '--':\n> >\n> >       git filter-branch <some-filter> -- --all <rev-list options>\n> \n> Hmm.  Maybe we should reconsider the logic.  I.e. instead of\n> \n>         *)\n>                 usage\n> \n>         *)\n>                 break\n\nThat is not enough: This case block comes after a test that checks that\none additional argument is present, which would not be true anymore.\n\n> > > @@ -181,6 +181,7 @@ export GIT_DIR GIT_WORK_TREE=.\n> > >\n> > >  # These refs should be updated if their heads were rewritten\n> > >\n> > > +negatives=\"$(git rev-parse --revs-only \"$@\" | grep \"^\\^\")\"\n> > >  git rev-parse --revs-only --symbolic \"$@\" |\n> > >  while read ref\n> > >  do\n> > > @@ -196,7 +197,13 @@ do\n> > >                         grep \"refs/\\(tags\\|heads\\)/$ref$\")\"\n> > >         esac\n> > >\n> > > -       git check-ref-format \"$ref\" && echo \"$ref\"\n> > > +       # make sure we have a valid ref\n> > > +       git check-ref-format \"$ref\" || continue\n> > > +\n> > > +       # if the ref has been excluded by the other options, skip it\n> > > +       test -z \"$(git rev-list -1 \"$ref\" $negatives)\" && continue\n> >\n> > Does this catch my use-case with --since? I think not, because:\n> >\n> > $ git rev-parse --revs-only --since=2007.01.01 master topic\n> > --max-age=1167606000\n> > 257061f3323dc0162f731d934f0870e919211fdf\n> > 3405729b94a654df8afbb9a1e13a4cf49a1c351c\n> >\n> > There are no negatives. Does it help to filter the non-positives?\n> >\n> > negatives=$(git rev-parse --revs-only \"$@\" | egrep -v '^[0-9a-f]{40}$')\n> >\n> > (Except the the '{40}' part is not portable. Hmpf.)\n> \n> To keep the \"--since=...\" we have to lose the \"--revs-only\"...\n> Darn.  I thought that \"--since=\" was expanded by rev-parse.  FWIW this\n> might work:\n> \n> negatives=\"$(git rev-parse \"$@\" | while read line\n>         do\n>                 case \"$line\" in\n>                 $_x40) ;;\n>                 *) echo \"$line\";;\n>                 esac\n>         done)\"\n> \n> Can you please test?  I am off for lunch.\n\nThis worked:\n\nnegatives=`git rev-parse --revs-only \"$@\" | while read line\n\tdo\n\t\tcase \"$line\" in\n\t\t$_x40) ;;\n\t\t*) echo \"$line\";;\n\t\tesac\n\tdone`\n\ni.e. the closing parenthesis in the case arms together with the opening\n$( made for a syntax error. The --revs-only did not hurt in my tests,\nbut you may have other reasons to remove it.\n\nBut there's another problem. Consider this history:\n\n   ---X--o--M         <- master\n             \\\n          ...-o-...-o <- topic\n\nThen this (rather contrieved) command:\n\n   $ git-filter-branch -n $n master topic --not X\n\nIf $n is small enough so that M is never rewritten, then\n\n   git rev-list -1 \"$ref\" $negatives\n\nstill expands to non-empty even for 'master' (= M), which then\nincorrectly ends up in \"$tempdir\"/heads.\n\nI think the decision whether a positive ref should be rewritten should\nbe postponed until the rewrite has completed. Because then we know for\ncertain which revs were treated and can pick the matching refs. We only\nlose the check for the error \"Which ref do you want to rewrite?\"\n\n-- Hannes\n"},{"id":"48461","messageId":"46A5FFBB.2F3B12CF@eudaptics.com","threadId":"9179","inReplyTo":"Pine.LNX.4.64.0707241229170.14781@racer.site","subject":"Re: [PATCH] filter-branch: rewrite only refs which were not excludedbythe options","fromName":"Johannes Sixt","fromEmail":"j.sixt@eudaptics.com","sentAt":"2007-07-24T13:33:47Z","receivedAt":"2007-07-24T13:33:47Z","isPatch":true,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Johannes Schindelin wrote:\n> negatives=\"$(git rev-parse \"$@\" | while read line\n>         do\n>                 case \"$line\" in\n>                 $_x40) ;;\n>                 *) echo \"$line\";;\n>                 esac\n>         done)\"\n\nAh, and you must move the definition of _x40 up a couple of lines.\n\n-- Hannes\n"},{"id":"48463","messageId":"Pine.LNX.4.64.0707241435290.14781@racer.site","threadId":"9179","inReplyTo":"46A5FF69.F5D75C9E@eudaptics.com","subject":"Re: [PATCH] filter-branch: rewrite only refs which were not excludedbythe options","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2007-07-24T13:41:05Z","receivedAt":"2007-07-24T13:41:05Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Tue, 24 Jul 2007, Johannes Sixt wrote:\n\n> Johannes Schindelin wrote:\n> > \n> > On Tue, 24 Jul 2007, Johannes Sixt wrote:\n> > \n> > > BTW, '--all' in the argument list of filter-branch works only if it \n> > > is preceded by '--':\n> > >\n> > >       git filter-branch <some-filter> -- --all <rev-list options>\n> > \n> > Hmm.  Maybe we should reconsider the logic.  I.e. instead of\n> > \n> >         *)\n> >                 usage\n> > \n> >         *)\n> >                 break\n> \n> That is not enough: This case block comes after a test that checks that\n> one additional argument is present, which would not be true anymore.\n\nRight.\n\n> > > > @@ -181,6 +181,7 @@ export GIT_DIR GIT_WORK_TREE=.\n> > > >\n> > > >  # These refs should be updated if their heads were rewritten\n> > > >\n> > > > +negatives=\"$(git rev-parse --revs-only \"$@\" | grep \"^\\^\")\"\n> > > >  git rev-parse --revs-only --symbolic \"$@\" |\n> > > >  while read ref\n> > > >  do\n> > > > @@ -196,7 +197,13 @@ do\n> > > >                         grep \"refs/\\(tags\\|heads\\)/$ref$\")\"\n> > > >         esac\n> > > >\n> > > > -       git check-ref-format \"$ref\" && echo \"$ref\"\n> > > > +       # make sure we have a valid ref\n> > > > +       git check-ref-format \"$ref\" || continue\n> > > > +\n> > > > +       # if the ref has been excluded by the other options, skip it\n> > > > +       test -z \"$(git rev-list -1 \"$ref\" $negatives)\" && continue\n> > >\n> > > Does this catch my use-case with --since? I think not, because:\n> > >\n> > > $ git rev-parse --revs-only --since=2007.01.01 master topic\n> > > --max-age=1167606000\n> > > 257061f3323dc0162f731d934f0870e919211fdf\n> > > 3405729b94a654df8afbb9a1e13a4cf49a1c351c\n> > >\n> > > There are no negatives. Does it help to filter the non-positives?\n> > >\n> > > negatives=$(git rev-parse --revs-only \"$@\" | egrep -v '^[0-9a-f]{40}$')\n> > >\n> > > (Except the the '{40}' part is not portable. Hmpf.)\n> > \n> > To keep the \"--since=...\" we have to lose the \"--revs-only\"...\n> > Darn.  I thought that \"--since=\" was expanded by rev-parse.  FWIW this\n> > might work:\n> > \n> > negatives=\"$(git rev-parse \"$@\" | while read line\n> >         do\n> >                 case \"$line\" in\n> >                 $_x40) ;;\n> >                 *) echo \"$line\";;\n> >                 esac\n> >         done)\"\n> > \n> > Can you please test?  I am off for lunch.\n> \n> This worked:\n> \n> negatives=`git rev-parse --revs-only \"$@\" | while read line\n> \tdo\n> \t\tcase \"$line\" in\n> \t\t$_x40) ;;\n> \t\t*) echo \"$line\";;\n> \t\tesac\n> \tdone`\n>\n> i.e. the closing parenthesis in the case arms together with the opening\n> $( made for a syntax error. The --revs-only did not hurt in my tests,\n> but you may have other reasons to remove it.\n\nFunny.  AFAIR something similar worked here, all the time.  But I believe \nyou... you're on MinGW, right?\n\n> But there's another problem. Consider this history:\n> \n>    ---X--o--M         <- master\n>              \\\n>           ...-o-...-o <- topic\n> \n> Then this (rather contrieved) command:\n> \n>    $ git-filter-branch -n $n master topic --not X\n> \n> If $n is small enough so that M is never rewritten, then\n> \n>    git rev-list -1 \"$ref\" $negatives\n> \n> still expands to non-empty even for 'master' (= M), which then\n> incorrectly ends up in \"$tempdir\"/heads.\n\nAaargh!  Of course!  Since I have to add --topo-order at the end.  \nOtherwise it makes no sense.\n\n> I think the decision whether a positive ref should be rewritten should \n> be postponed until the rewrite has completed. Because then we know for \n> certain which revs were treated and can pick the matching refs. We only \n> lose the check for the error \"Which ref do you want to rewrite?\"\n\nNo, that is not enough:\n\n\tA - B - C\n\nB touches the subdirectory sub/.\n\n\tgit filter-branch C -- sub/\n\nwill not rewrite C.\n\nBesides, I really like the check for the error \"Which ref do you want to \nrewrite today?\" early, instead of working for a long time, only to say \n\"there was nothing to rewrite, you idiot, you should have chosen the \narguments more carefully\".\n\nCiao,\nDscho\n"},{"id":"48464","messageId":"Pine.LNX.4.64.0707241442040.14781@racer.site","threadId":"9179","inReplyTo":"46A5FF69.F5D75C9E@eudaptics.com","subject":"[REVISED PATCH] filter-branch: rewrite only unexcluded refs","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2007-07-24T13:42:49Z","receivedAt":"2007-07-24T13:42:49Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"\nThe rev-list options can exclude some -- or all -- refs:\n\n\tgit filter-branch <some-filter> master ^master\n\nWithout this patch, these refs are assumed to be deleted, or worse, they\nare rewritten to some bogus merge bases.\n\nSo really exclude excluded refs from being rewritten.  This also allows\nyou to safely call\n\n\tgit filter-branch <some-filter> --all <rev-list options>\n\nto rewrite _all_ branches and tags.\n\nThanks go to Johannes Sixt for help on the implementation and for testing.\n\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n git-filter-branch.sh     |   16 +++++++++++++++-\n t/t7003-filter-branch.sh |    9 +++++++++\n 2 files changed, 24 insertions(+), 1 deletions(-)\n\ndiff --git a/git-filter-branch.sh b/git-filter-branch.sh\nindex 4fb3abe..3fa2f63 100755\n--- a/git-filter-branch.sh\n+++ b/git-filter-branch.sh\n@@ -181,6 +181,14 @@ export GIT_DIR GIT_WORK_TREE=.\n \n # These refs should be updated if their heads were rewritten\n \n+negatives=\"`git rev-parse \"$@\" | while read line\n+\tdo\n+\t\tcase \"$line\" in\n+\t\t$_x40) ;;\n+\t\t*) echo \"$line\";;\n+\t\tesac\n+\tdone`\"\n+\n git rev-parse --revs-only --symbolic \"$@\" |\n while read ref\n do\n@@ -196,7 +204,13 @@ do\n \t\t\tgrep -e \"^refs/heads/$ref$\" -e \"^refs/tags/$ref$\")\"\n \tesac\n \n-\tgit check-ref-format \"$ref\" && echo \"$ref\"\n+\t# make sure we have a valid ref\n+\tgit check-ref-format \"$ref\" || continue\n+\n+\t# if the ref has been excluded by the other options, skip it\n+\ttest -z \"$(git rev-list -1 \"$ref\" $negatives --topo-order)\" && continue\n+\n+\techo \"$ref\"\n done > \"$tempdir\"/heads\n \n test -s \"$tempdir\"/heads ||\ndiff --git a/t/t7003-filter-branch.sh b/t/t7003-filter-branch.sh\nindex c9a820d..667eda7 100755\n--- a/t/t7003-filter-branch.sh\n+++ b/t/t7003-filter-branch.sh\n@@ -164,4 +164,13 @@ test_expect_success 'only dwim refs/heads/$ref or refs/tags/$ref' '\n \tgit filter-branch -f master\n '\n \n+test_expect_success 'do not update uninteresting refs' '\n+\tbranch=$(git rev-parse branch) &&\n+\tmaster=$(git rev-parse master) &&\n+\tgit filter-branch -f --env-filter \"GIT_AUTHOR_EMAIL=xy@probl.em\" \\\n+\t\tmaster ^removed-author branch &&\n+\ttest $branch = $(git rev-parse branch) &&\n+\ttest $master != $(git rev-parse master)\n+'\n+\n test_done\n-- \n1.5.3.rc2.32.g35c5b-dirty\n"},{"id":"48465","messageId":"Pine.LNX.4.64.0707241445470.14781@racer.site","threadId":"9179","inReplyTo":"46A5FFBB.2F3B12CF@eudaptics.com","subject":"Re: [PATCH] filter-branch: rewrite only refs which were not excludedbythe options","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2007-07-24T13:46:53Z","receivedAt":"2007-07-24T13:46:53Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Tue, 24 Jul 2007, Johannes Sixt wrote:\n\n> Johannes Schindelin wrote:\n> > negatives=\"$(git rev-parse \"$@\" | while read line\n> >         do\n> >                 case \"$line\" in\n> >                 $_x40) ;;\n> >                 *) echo \"$line\";;\n> >                 esac\n> >         done)\"\n> \n> Ah, and you must move the definition of _x40 up a couple of lines.\n\nD'oh.  Of course.\n\nWhen I have more tests, and thought about the problem I hinted at in \nanother mail, I'll send a cleaned up patch series.  Promised.  Rebase -i \nis good.\n\nCiao,\nDscho\n\n---\n\n git-filter-branch.sh |    5 +++--\n 1 files changed, 3 insertions(+), 2 deletions(-)\n\ndiff --git a/git-filter-branch.sh b/git-filter-branch.sh\nindex 3fa2f63..8107a6c 100755\n--- a/git-filter-branch.sh\n+++ b/git-filter-branch.sh\n@@ -11,6 +11,9 @@\n USAGE=\"git-filter-branch [-d TEMPDIR] [FILTERS] DESTBRANCH [REV-RANGE]\"\n . git-sh-setup\n \n+_x40='[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]'\n+_x40=\"$_x40$_x40$_x40$_x40$_x40$_x40$_x40$_x40\"\n+\n warn () {\n         echo \"$*\" >&2\n }\n@@ -322,8 +325,6 @@ done < \"$tempdir\"/heads\n \n # Finally update the refs\n \n-_x40='[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]'\n-_x40=\"$_x40$_x40$_x40$_x40$_x40$_x40$_x40$_x40\"\n count=0\n echo\n while read ref\n"},{"id":"48470","messageId":"46A607EB.BA31D7C5@eudaptics.com","threadId":"9179","inReplyTo":"Pine.LNX.4.64.0707241435290.14781@racer.site","subject":"Re: [PATCH] filter-branch: rewrite only refs which were not excludedbythe options","fromName":"Johannes Sixt","fromEmail":"j.sixt@eudaptics.com","sentAt":"2007-07-24T14:08:43Z","receivedAt":"2007-07-24T14:08:43Z","isPatch":true,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Johannes Schindelin wrote:\n> On Tue, 24 Jul 2007, Johannes Sixt wrote:\n> > This worked:\n> >\n> > negatives=`git rev-parse --revs-only \"$@\" | while read line\n> >       do\n> >               case \"$line\" in\n> >               $_x40) ;;\n> >               *) echo \"$line\";;\n> >               esac\n> >       done`\n> >\n> > i.e. the closing parenthesis in the case arms together with the opening\n> > $( made for a syntax error. The --revs-only did not hurt in my tests,\n> > but you may have other reasons to remove it.\n> \n> Funny.  AFAIR something similar worked here, all the time.  But I believe\n> you... you're on MinGW, right?\n\nNo. filter-branch is a shell script. I don't have time to waste ;)\nIt happens in bash 2.05b on Linux.\n\n> > But there's another problem. Consider this history:\n> >\n> >    ---X--o--M         <- master\n> >              \\\n> >           ...-o-...-o <- topic\n> >\n> > Then this (rather contrieved) command:\n> >\n> >    $ git-filter-branch -n $n master topic --not X\n> >\n> > If $n is small enough so that M is never rewritten, then\n> >\n> >    git rev-list -1 \"$ref\" $negatives\n> >\n> > still expands to non-empty even for 'master' (= M), which then\n> > incorrectly ends up in \"$tempdir\"/heads.\n> \n> Aaargh!  Of course!  Since I have to add --topo-order at the end.\n> Otherwise it makes no sense.\n\nNo, that was no my point: In my example above, if n=1, `git rev-list -1\n\"$ref\" $negatives` evaluates to\n\n    $ git rev-list -1 \"master\" -n 1 ^X\n\nwhich returns M, even though M is not going to be rewritten.\n--topo-order changes nothing. The problem is that the -n is a relative\nrestriction. --since is turned into --max-age, which is absolute,\ntherefore, the test works as expected with --since.\n\n> > I think the decision whether a positive ref should be rewritten should\n> > be postponed until the rewrite has completed. Because then we know for\n> > certain which revs were treated and can pick the matching refs. We only\n> > lose the check for the error \"Which ref do you want to rewrite?\"\n> \n> No, that is not enough:\n> \n>         A - B - C\n> \n> B touches the subdirectory sub/.\n> \n>         git filter-branch C -- sub/\n> \n> will not rewrite C.\n\nFair enough.\n\n-- Hannes\n"},{"id":"48472","messageId":"Pine.LNX.4.64.0707241518290.14781@racer.site","threadId":"9179","inReplyTo":"46A607EB.BA31D7C5@eudaptics.com","subject":"Re: [PATCH] filter-branch: rewrite only refs which were not excludedbythe options","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2007-07-24T14:21:00Z","receivedAt":"2007-07-24T14:21:00Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Tue, 24 Jul 2007, Johannes Sixt wrote:\n\n> Johannes Schindelin wrote:\n>\n> > On Tue, 24 Jul 2007, Johannes Sixt wrote:\n> >\n> > > But there's another problem. Consider this history:\n> > >\n> > >    ---X--o--M         <- master\n> > >              \\\n> > >           ...-o-...-o <- topic\n> > >\n> > > Then this (rather contrieved) command:\n> > >\n> > >    $ git-filter-branch -n $n master topic --not X\n> > >\n> > > If $n is small enough so that M is never rewritten, then\n> > >\n> > >    git rev-list -1 \"$ref\" $negatives\n> > >\n> > > still expands to non-empty even for 'master' (= M), which then \n> > > incorrectly ends up in \"$tempdir\"/heads.\n> > \n> > Aaargh!  Of course!  Since I have to add --topo-order at the end. \n> > Otherwise it makes no sense.\n> \n> No, that was no my point: In my example above, if n=1, `git rev-list -1\n> \"$ref\" $negatives` evaluates to\n> \n>     $ git rev-list -1 \"master\" -n 1 ^X\n> \n> which returns M, even though M is not going to be rewritten. \n> --topo-order changes nothing. The problem is that the -n is a relative \n> restriction. --since is turned into --max-age, which is absolute, \n> therefore, the test works as expected with --since.\n\nSo you think we have to say something like\n\n\tgit rev-list \"$ref\" $negatives | grep \"$ref\" > /dev/null || continue\n\n?\n\nI really should add a test case for that.\n\nCiao,\nDscho\n"},{"id":"48479","messageId":"46A614CE.597C7130@eudaptics.com","threadId":"9179","inReplyTo":"Pine.LNX.4.64.0707241518290.14781@racer.site","subject":"Re: [PATCH] filter-branch: rewrite only refs which were not excludedbythe options","fromName":"Johannes Sixt","fromEmail":"j.sixt@eudaptics.com","sentAt":"2007-07-24T15:03:42Z","receivedAt":"2007-07-24T15:03:42Z","isPatch":true,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Johannes Schindelin wrote:\n> \n> Hi,\n> \n> On Tue, 24 Jul 2007, Johannes Sixt wrote:\n> \n> > Johannes Schindelin wrote:\n> >\n> > > On Tue, 24 Jul 2007, Johannes Sixt wrote:\n> > >\n> > > > But there's another problem. Consider this history:\n> > > >\n> > > >    ---X--o--M         <- master\n> > > >              \\\n> > > >           ...-o-...-o <- topic\n> > > >\n> > > > Then this (rather contrieved) command:\n> > > >\n> > > >    $ git-filter-branch -n $n master topic --not X\n> > > >\n> > > > If $n is small enough so that M is never rewritten, then\n> > > >\n> > > >    git rev-list -1 \"$ref\" $negatives\n> > > >\n> > > > still expands to non-empty even for 'master' (= M), which then\n> > > > incorrectly ends up in \"$tempdir\"/heads.\n> > >\n> > > Aaargh!  Of course!  Since I have to add --topo-order at the end.\n> > > Otherwise it makes no sense.\n> >\n> > No, that was no my point: In my example above, if n=1, `git rev-list -1\n> > \"$ref\" $negatives` evaluates to\n> >\n> >     $ git rev-list -1 \"master\" -n 1 ^X\n> >\n> > which returns M, even though M is not going to be rewritten.\n> > --topo-order changes nothing. The problem is that the -n is a relative\n> > restriction. --since is turned into --max-age, which is absolute,\n> > therefore, the test works as expected with --since.\n> \n> So you think we have to say something like\n> \n>         git rev-list \"$ref\" $negatives | grep \"$ref\" > /dev/null || continue\n> \n> ?\n\nNo, doesn't help either.\n\nWe are talking about a case where there is more than one positive ref.\nWe need not consider the -- sub/ case - it makes things just even more\ncomplicated. There are two different rev ranges to be considered:\n\n  # (1) candidate range to be rewritten\n  $ git rev-list \"$@\"\n\n  # (2) test if positive ref is in candidate range\n  $ git rev-list $ref $negatives\n\nUsually (without -n) (2) is a subset of (1) because (1) has all positive\nrefs and (2) has only one. And the subset is empty iff the positive ref\nis not in the rewritten range.\n\nHowever, if \"$@\" (and, hence, $negatives) contains the -n limiter, this\nis no longer true. Example:\n\n (1)  is: \"rev-list -n 1 A B ^C\": we get either A or B, but not both;\n      lets say A.\n (2A) is: \"rev-list -n 1 A ^C\": we get A -- good\n (2B) is: \"rev-list -n 1 B ^C\": we get B -- ouch!\n\nFor each positive ref, A, B, we conduct test (2). For A, the test result\nis correct. But for B it is not. We expect it to tell us that B is not\nrewritten; but in fact it tells the opposite by returning something\ninstead of nothing.\n\n-- Hannes\n"},{"id":"48506","messageId":"Pine.LNX.4.64.0707242047400.14781@racer.site","threadId":"9179","inReplyTo":"46A614CE.597C7130@eudaptics.com","subject":"Re: [PATCH] filter-branch: rewrite only refs which were not excludedbythe options","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2007-07-24T19:52:08Z","receivedAt":"2007-07-24T19:52:08Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Tue, 24 Jul 2007, Johannes Sixt wrote:\n\n> Johannes Schindelin wrote:\n> \n> > On Tue, 24 Jul 2007, Johannes Sixt wrote:\n> > \n> > > Johannes Schindelin wrote:\n> > >\n> > > > On Tue, 24 Jul 2007, Johannes Sixt wrote:\n> > > >\n> > > > > But there's another problem. Consider this history:\n> > > > >\n> > > > >    ---X--o--M         <- master\n> > > > >              \\\n> > > > >           ...-o-...-o <- topic\n> > > > >\n> > > > > Then this (rather contrieved) command:\n> > > > >\n> > > > >    $ git-filter-branch -n $n master topic --not X\n> > > > >\n> > > > > If $n is small enough so that M is never rewritten, then\n> > > > >\n> > > > >    git rev-list -1 \"$ref\" $negatives\n> > > > >\n> > > > > still expands to non-empty even for 'master' (= M), which then\n> > > > > incorrectly ends up in \"$tempdir\"/heads.\n> > > >\n> > > > Aaargh!  Of course!  Since I have to add --topo-order at the end.\n> > > > Otherwise it makes no sense.\n> > >\n> > > No, that was no my point: In my example above, if n=1, `git rev-list -1\n> > > \"$ref\" $negatives` evaluates to\n> > >\n> > >     $ git rev-list -1 \"master\" -n 1 ^X\n> > >\n> > > which returns M, even though M is not going to be rewritten.\n> > > --topo-order changes nothing. The problem is that the -n is a relative\n> > > restriction. --since is turned into --max-age, which is absolute,\n> > > therefore, the test works as expected with --since.\n> > \n> > So you think we have to say something like\n> > \n> >         git rev-list \"$ref\" $negatives | grep \"$ref\" > /dev/null || continue\n> > \n> > ?\n> \n> No, doesn't help either.\n> \n> We are talking about a case where there is more than one positive ref.\n> We need not consider the -- sub/ case - it makes things just even more\n> complicated. There are two different rev ranges to be considered:\n> \n>   # (1) candidate range to be rewritten\n>   $ git rev-list \"$@\"\n> \n>   # (2) test if positive ref is in candidate range\n>   $ git rev-list $ref $negatives\n\nOkay, but with out any subdirs,\n\n\tgit rev-list \"$@\" | grep $(git rev-parse \"$ref\") > /dev/null || continue\n\nshould do exactly what we want.  But in that case, we could just use the \ngenerated list ../revs to grep for the positive refs.\n\nDarn, this _is_ getting complicated.\n\nCiao,\nDscho\n"}]}