{"thread":{"id":"51712","subject":"Bug Report: notes disassociated after history edits","startedAt":"2019-08-22T20:54:34Z","lastAt":"2019-08-23T16:58:13Z","messageCount":3,"participants":["Christopher Sean Morrison","Jeff King","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"380976","messageId":"01F35983-BC98-4518-8ED3-C0E1AFC7507A@mac.com","threadId":"51712","inReplyTo":null,"subject":"Bug Report: notes disassociated after history edits","fromName":"Christopher Sean Morrison","fromEmail":"brlcad@mac.com","sentAt":"2019-08-22T20:44:37Z","receivedAt":"2019-08-22T20:54:34Z","isPatch":false,"sender":{"key":"brlcad@mac.com","avatar":null},"body":"Hi,\n\nWe’re migrating a very large old repository to Git (the oldest in continuous development!) and using the notes feature to preserve Svn data like revision IDs and branch information.  We’ve run into what seems like an incomplete feature or bug in that notes get orphaned/disassociated if an old commit is changed (e.g., edit a committer's e-mail or the commit message).\n\nThe changed commit and all children commits get sha updates, but the notes remain associated with the original sha.  This can be particularly catastrophic, for example, if an early commit is changed as all notes become orphaned.\n\nI presume this is a bug but perhaps we may be doing something wrong?  Is there a better way to preserve old Svn information that will work with filter-branch?\n\nWe want to be able to look up commits by the old Svn commit ID because they are pervasively referenced in commit messages, issue trackers, mailing lists, etc.  We also simply don’t want to lose the data on philosophical grounds as we have a detailed continuous development history that goes back 30+ years.  Thank you in advance for any assistance or insights.\n\nCheers!\nSean\n\n"},{"id":"380996","messageId":"20190823055932.GA10806@sigill.intra.peff.net","threadId":"51712","inReplyTo":"01F35983-BC98-4518-8ED3-C0E1AFC7507A@mac.com","subject":"Re: Bug Report: notes disassociated after history edits","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2019-08-23T05:59:33Z","receivedAt":"2019-08-23T05:59:35Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Thu, Aug 22, 2019 at 04:44:37PM -0400, Christopher Sean Morrison wrote:\n\n> We’re migrating a very large old repository to Git (the oldest in\n> continuous development!) and using the notes feature to preserve Svn\n> data like revision IDs and branch information.  We’ve run into what\n> seems like an incomplete feature or bug in that notes get\n> orphaned/disassociated if an old commit is changed (e.g., edit a\n> committer's e-mail or the commit message).\n> \n> The changed commit and all children commits get sha updates, but the\n> notes remain associated with the original sha.  This can be\n> particularly catastrophic, for example, if an early commit is changed\n> as all notes become orphaned.\n> \n> I presume this is a bug but perhaps we may be doing something wrong?\n> Is there a better way to preserve old Svn information that will work\n> with filter-branch?\n\nWhether the old notes apply to the rewritten commit depends on what is\nin the notes. Commands like rebase and \"commit --amend\" that rewrite\nhistory have some options to carry notes across rewrites. See\n\"notes.rewrite*\" in \"git help config\".\n\nI don't think that filter-branch ever learned about rewriting notes.\nHere's an old thread asking the same thing:\n\n  https://public-inbox.org/git/hbf.20110317iwua@bombur.uio.no/\n\nAnd it even mentions an even more ancient patch:\n\n  https://public-inbox.org/git/0ad4b8c1a5377d697513cd8e49f64419cd8deef4.1266164150.git.trast@student.ethz.ch/\n\nThe consensus seems to be that filter-branch should actually have a\nnotes filter, but nobody ever implemented it.\n\nIn the meantime, I think you could accomplish the same thing with a\n--commit-filter. This seems to work for me:\n\n  # fake repo with some notes\n  git init repo\n  cd repo\n  for i in 1 2 3; do\n\techo $i >orig-$i\n\tgit add orig-$i\n\tgit commit -m $i\n\tgit notes add -m \"note $i\"\n  done\n\n  # introduce a silly tree change that will modify the commit ids,\n  # and map the notes, too\n  git filter-branch \\\n\t  --tree-filter 'rename s/orig-/new-/ *' \\\n\t  --commit-filter '\n\t\tcommit=$(git commit-tree \"$@\")\n\t\tgit notes copy $GIT_COMMIT $commit\n\t\techo $commit\n\t  '\n\n  # this should have the new-* files, but still have notes\n  git log --raw\n\nI think you could also use \"--state-branch\", and then pass its mapping\ninto a single \"notes copy\" invocation, which would be much more\nefficient. E.g.:\n\n  git filter-branch \\\n    --tree-filter 'rename s/orig-/new-/ *' \\\n    --state-branch refs/mapped-state\n  git cat-file blob refs/mapped-state:filter.map |\n    tr ':' ' ' |\n    git notes copy --stdin\n\nHope that helps.\n\n-Peff\n"},{"id":"381019","messageId":"xmqq5zmnn7j3.fsf@gitster-ct.c.googlers.com","threadId":"51712","inReplyTo":"20190823055932.GA10806@sigill.intra.peff.net","subject":"Re: Bug Report: notes disassociated after history edits","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2019-08-23T16:58:08Z","receivedAt":"2019-08-23T16:58:13Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jeff King <peff@peff.net> writes:\n\n> ...\n> \t  --commit-filter '\n> \t\tcommit=$(git commit-tree \"$@\")\n> \t\tgit notes copy $GIT_COMMIT $commit\n> \t\techo $commit\n> \t  '\n\nThanks.  I was writing the same \"git notes copy $this $that\" based\nresponse, but TIL we had --stdin to feed the input in bulk ;-)\n"}]}