git blame -M problem

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,
    I am now digging into blame/log code recent days. And I find that
'git blame -M' act not as what express in the document. In the docs:

-M|<num>|
Detect moving lines in the file as well. When a commit moves a block
of lines in a file (e.g. the original file has A and then B, and the
commit changes it to B and then A), the traditional blame algorithm
typically blames the lines that were moved up (i.e. B) to the parent
and assigns blame to the lines that were moved down (i.e. A) to the
child commit. With this option, both groups of lines are blamed on the
parent.

<num> is optional but it is the lower bound on the number of
alphanumeric characters that git must detect as moving within a file
for it to associate those lines with the parent commit.

It said, -M will blame the moved code to its author before movement.
But from the code, I find, the function 'find_move_in_parent' is
really try to find some same code with the current suspected lines in
the current blamed file instead of searching code movement. So, if you
have a file like:
-------------------
byang@byang-laptop:~/git/test$ cat n
one
two
three
one
two
three
--------------------
Note that, the last three lines is copied from the first three ones.

byang@byang-laptop:~/git/test$ git blame n
41f445bd (Bo Yang 2010-03-25 22:01:26 +0800 1) one
41f445bd (Bo Yang 2010-03-25 22:01:26 +0800 2) two
41f445bd (Bo Yang 2010-03-25 22:01:26 +0800 3) three
b2b6ac51 (Bo Yang 2010-03-25 22:01:38 +0800 4) one
b2b6ac51 (Bo Yang 2010-03-25 22:01:38 +0800 5) two
b2b6ac51 (Bo Yang 2010-03-25 22:01:38 +0800 6) three

byang@byang-laptop:~/git/test$ git blame -M1 n
41f445bd (Bo Yang 2010-03-25 22:01:26 +0800 1) one
41f445bd (Bo Yang 2010-03-25 22:01:26 +0800 2) two
41f445bd (Bo Yang 2010-03-25 22:01:26 +0800 3) three
41f445bd (Bo Yang 2010-03-25 22:01:26 +0800 4) one
41f445bd (Bo Yang 2010-03-25 22:01:26 +0800 5) two
41f445bd (Bo Yang 2010-03-25 22:01:26 +0800 6) three

And blame -C

byang@byang-laptop:~/git/test$ git blame -C1 n
41f445bd (Bo Yang 2010-03-25 22:01:26 +0800 1) one
41f445bd (Bo Yang 2010-03-25 22:01:26 +0800 2) two
41f445bd (Bo Yang 2010-03-25 22:01:26 +0800 3) three
b2b6ac51 (Bo Yang 2010-03-25 22:01:38 +0800 4) one
b2b6ac51 (Bo Yang 2010-03-25 22:01:38 +0800 5) two
b2b6ac51 (Bo Yang 2010-03-25 22:01:38 +0800 6) three

byang@byang-laptop:~/git/test$ git blame -C1 -C1 n
41f445bd (Bo Yang 2010-03-25 22:01:26 +0800 1) one
41f445bd (Bo Yang 2010-03-25 22:01:26 +0800 2) two
41f445bd (Bo Yang 2010-03-25 22:01:26 +0800 3) three
b2b6ac51 (Bo Yang 2010-03-25 22:01:38 +0800 4) one
b2b6ac51 (Bo Yang 2010-03-25 22:01:38 +0800 5) two
b2b6ac51 (Bo Yang 2010-03-25 22:01:38 +0800 6) three

byang@byang-laptop:~/git/test$ git blame -C1 -C1 -C1 n
41f445bd (Bo Yang 2010-03-25 22:01:26 +0800 1) one
41f445bd (Bo Yang 2010-03-25 22:01:26 +0800 2) two
41f445bd (Bo Yang 2010-03-25 22:01:26 +0800 3) three
b2b6ac51 (Bo Yang 2010-03-25 22:01:38 +0800 4) one
b2b6ac51 (Bo Yang 2010-03-25 22:01:38 +0800 5) two
b2b6ac51 (Bo Yang 2010-03-25 22:01:38 +0800 6) three

So, I think indeed, -M deals with the code move/copy inside same file
and -C deal with code copy between files. I am wondering is this
behavior desired? If so, should the documents to be changed to make it
more clear?

Thanks!

Regards!
Bo
-- 
My blog: http://blog.morebits.org
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]