{"thread":{"id":"28717","subject":"How to verify that lines were only moved, not edited?","startedAt":"2011-10-19T14:34:20Z","lastAt":"2011-10-20T06:25:09Z","messageCount":5,"participants":["Johannes Sixt","Jeff King","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"177995","messageId":"4E9EDFEC.3040009@viscovery.net","threadId":"28717","inReplyTo":null,"subject":"How to verify that lines were only moved, not edited?","fromName":"Johannes Sixt","fromEmail":"j.sixt@viscovery.net","sentAt":"2011-10-19T14:34:20Z","receivedAt":"2011-10-19T14:34:20Z","isPatch":false,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"I thought there was a way to use git-blame to find out whether a change\nonly shuffled lines, but otherwise did not modify them. I tried \"git blame\n-M -- the/file\", but it does not work as expected, neither with a toy file\nnor with a 5000+ lines file (with 55 lines moved).\n\ngit init\necho A > foo\necho B >> foo\ngit add foo\ngit commit -m initial\necho B > foo\necho A >> foo\ngit commit -a -m swapped\n\nThe results are:\n$ git blame -M -s -- foo\n^e3abca2 1) B\n6189cb46 2) A\n\nI would have expected:\n^e3abca2 1) B\n^e3abca2 2) A\n\nOh, look! This produces the expected result:\n$ git blame -M1 -s -- foo\n\nwhile this produces the same as with just -M:\n$ git blame -M2 -s -- foo\n\nBut neither helps with my 5000+ lines file. Does it mean that the lines\nwere changed? But I'm sure they were just moved! Please help!\n\n-- Hannes\n"},{"id":"178000","messageId":"20111019163354.GB3157@sigill.intra.peff.net","threadId":"28717","inReplyTo":"4E9EDFEC.3040009@viscovery.net","subject":"Re: How to verify that lines were only moved, not edited?","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2011-10-19T16:33:54Z","receivedAt":"2011-10-19T16:33:54Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Wed, Oct 19, 2011 at 04:34:20PM +0200, Johannes Sixt wrote:\n\n> I thought there was a way to use git-blame to find out whether a change\n> only shuffled lines, but otherwise did not modify them. I tried \"git blame\n> -M -- the/file\", but it does not work as expected, neither with a toy file\n> nor with a 5000+ lines file (with 55 lines moved).\n> \n> git init\n> echo A > foo\n> echo B >> foo\n> git add foo\n> git commit -m initial\n> echo B > foo\n> echo A >> foo\n> git commit -a -m swapped\n> \n> The results are:\n> $ git blame -M -s -- foo\n> ^e3abca2 1) B\n> 6189cb46 2) A\n> \n> I would have expected:\n> ^e3abca2 1) B\n> ^e3abca2 2) A\n> \n> Oh, look! This produces the expected result:\n> $ git blame -M1 -s -- foo\n\nRight. Your toy lines aren't long enough to be considered \"interesting\"\nby the default score. From git-blame(1):\n\n  -M[<num>]\n  [...]\n  <num> is optional but it is the lower bound on the number of\n  alphanumeric characters that git must detect as moving/copying within\n  a file for it to associate those lines with the parent commit. The\n  default value is 20.\n\nWhereas with a longer sample:\n\n  git init\n  seq 1 5000 >foo\n  git add foo\n  git commit -m initial\n  sed -i '/^2..$/d' foo\n  seq 200 299 >>foo\n  git commit -a -m 'move 200-299 to end'\n\nI get the expected result from \"git blame -M\" (i.e., everything\nattributed to the root commit).\n\n> But neither helps with my 5000+ lines file. Does it mean that the lines\n> were changed? But I'm sure they were just moved! Please help!\n\nWhat does the file look like? I think blame has some heuristics about\nlines which are uninteresting, and maybe you are triggering a corner\ncase there.\n\n-Peff\n"},{"id":"178001","messageId":"7vvcrkdi59.fsf@alter.siamese.dyndns.org","threadId":"28717","inReplyTo":"4E9EDFEC.3040009@viscovery.net","subject":"Re: How to verify that lines were only moved, not edited?","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2011-10-19T17:07:46Z","receivedAt":"2011-10-19T17:07:46Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Johannes Sixt <j.sixt@viscovery.net> writes:\n\n> I thought there was a way to use git-blame to find out whether a change\n> only shuffled lines, but otherwise did not modify them. I tried \"git blame\n> -M -- the/file\",...\n\nYou said \"a change\" and I somehow expected that such a blame would be done\nwith a revision range, e.g. \"git blame -M HEAD^..HEAD -- the/file\".\n\nIf the two endpoints you are comparing have other commits in between that\nmake changes then revert them in such a way that the end result cancels\nout, \"git diff A B -- the/file\" won't see such intermediate changes, but\nthey may interfere with \"git blame A..B -- the/file\", i.e. when A is not a\ndirect parent of B.\n\n> ... nor with a 5000+ lines file (with 55 lines moved).\n\n> ... while this produces the same as with just -M:\n> $ git blame -M2 -s -- foo\n\nYes, blame tries to omit matches that consists only of non words, so that\nyou won't see \"all those lines with a single \"}\" on them that close\ndefinitions for your 100 new functions were copied from the closing brace\nof one function you originally had in the file\" symptom, and -M<level>\ncontrols it.\n\n> But neither helps with my 5000+ lines file. Does it mean that the lines\n> were changed? But I'm sure they were just moved! Please help!\n\nWhen reviewing a \"supposedly move-only\" change, I typically just grab +/-\nblocks from the patch, remove the +/- prefix and run comparison between\nthem.\n"},{"id":"178071","messageId":"4E9FBDA7.3000904@viscovery.net","threadId":"28717","inReplyTo":"20111019163354.GB3157@sigill.intra.peff.net","subject":"Re: How to verify that lines were only moved, not edited?","fromName":"Johannes Sixt","fromEmail":"j.sixt@viscovery.net","sentAt":"2011-10-20T06:20:23Z","receivedAt":"2011-10-20T06:20:23Z","isPatch":false,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Am 10/19/2011 18:33, schrieb Jeff King:\n>   git init\n>   seq 1 5000 >foo\n>   git add foo\n>   git commit -m initial\n>   sed -i '/^2..$/d' foo\n>   seq 200 299 >>foo\n>   git commit -a -m 'move 200-299 to end'\n> \n> I get the expected result from \"git blame -M\" (i.e., everything\n> attributed to the root commit).\n\nI see. My example is more like this:\n\n for i in `seq 1 20`; do md5sum - <<< $i; done > foo\n git commit -a -m foo\n for i in `seq 1 20`; do md5sum - <<< $i; done | sort > foo\n git commit -a -m foo\\ sorted\n\ni.e., the sort order of a block of lines was changed \"in place\". Here,\nmost of the lines are attributed to the last commit. Am I expecting too\nmuch from git-blame to detect line motions in such a case?\n\n-- Hannes\n"},{"id":"178072","messageId":"4E9FBEC5.2000407@viscovery.net","threadId":"28717","inReplyTo":"7vvcrkdi59.fsf@alter.siamese.dyndns.org","subject":"Re: How to verify that lines were only moved, not edited?","fromName":"Johannes Sixt","fromEmail":"j.sixt@viscovery.net","sentAt":"2011-10-20T06:25:09Z","receivedAt":"2011-10-20T06:25:09Z","isPatch":false,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Am 10/19/2011 19:07, schrieb Junio C Hamano:\n> When reviewing a \"supposedly move-only\" change, I typically just grab +/-\n> blocks from the patch, remove the +/- prefix and run comparison between\n> them.\n\nThanks. As I explained to Jeff, I don't have a block-move, but the sort\norder of a block of lines was changed \"in place\". It seems I have to fall\nback to a similarly manual method as well (e.g., compare the\nwhole-file-sorted versions of the pre- and the post-image).\n\n-- Hannes\n"}]}