Subject: Re: Can't find the revelant commit with git-log

From: René Scharfe <[email-masked]>
Date: Tue, 25 Jan 2011 17:12:00 +0100

Am 25.01.2011 10:01, schrieb Francis Moreau:
> Hello,
> 
> I'm trying to find out a commit which removed a function inside a file.
> 
> The project is the Linux kernel, and I'm trying to look for changes
> which happened between v2.6.27 and v2.6.28. The changes happened in the
> following file: drivers/pci/intel-iommu.c where a function has been
> removed:
> 
>    $ git --version
>    git version 1.7.4.rc3
> 
>    $ cd ~/linux-2.6/drivers/pci/
>    $ git grep blacklist v2.6.27 -- drivers/pci/intel-iommu.c
>    $
> 
> No ouput... hmm, I know it's in... oh maybe the path is incorrect
> 
>    $ git git grep blacklist v2.6.27 -- intel-iommu.c
>    v2.6.27:intel-iommu.c:static int blacklist_iommu(const struct dmi_system_id *id)
>    v2.6.27:intel-iommu.c:          .callback = blacklist_iommu,
> 
> ah, so Git failed previously without any comments on the wrong
> path... maybe it should ?

Good idea.

> So at that point I know that in the revision v2.6.27, there's a function
> called "blacklist_iommu" in drivers/pci/intel-iommu.c
> 
> Now take a look if it's still there in v2.6.28:
> 
>    $ git git grep blacklist v2.6.28 -- intel-iommu.c
>    $
> 
> This time nothing is printed but I know that the command is correct.
> 
> So now I'm interested in looking for the commit which removed this
> function. Fo this I'm trying to use git-log(1):
> 
>    $ git log --full-history --follow -S'static int blacklist_iommu(const struct dmi_system_id *id)' v2.6.27..v2.6.28 -- intel-iommu.c
>    $ echo $?
>    0
> 
> I tried different options but it fails.
> 
> Also I found that passing the exact string to '-S' is annoying, are
> there any way to just pass a part of the string such as
> "-Sblacklist_iommu" ?

This (-Sblacklist_iommu) works for me.

> Sorry if I miss the revelant git-log's option, but there're so many...

Try -m (show full diff for merge commits), as the change you're looking
for seems to have been introduced by a merge, not a regular commit.

	$ opts="--stat -Sblacklist_iommu -m --oneline"
	$ revs="v2.6.27..v2.6.28"

	$ git log $opts $revs -- drivers/pci/intel-iommu.c

This returns nothing.  Hmm.  Let's try this instead:

	$ git log $opts $revs -- drivers/pci/
	057316c (from 3e2dab9) Merge branch 'linus' into test
	 drivers/pci/intel-iommu.c |  307 ++++++++++++++++++++------------------------
	 1 files changed, 140 insertions(+), 167 deletions(-)
	6b2ada8 (from 3b7ecb5) Merge branches 'core/softlockup', 'core/softirq', 'core/resources', 'core/printk' and 'core/misc' into core-v28-for-linus
	 drivers/pci/intel-iommu.c |  187 ++++++--------------------------------------
	 1 files changed, 26 insertions(+), 161 deletions(-)
	d847059 (from 725c258) Merge branch 'x86/apic' into x86-v28-for-linus-phase4-B
	 drivers/pci/intel-iommu.c |  185 ++++++---------------------------------------
	 1 files changed, 25 insertions(+), 160 deletions(-)
	725c258 (from 129d6ab) Merge branches 'core/iommu', 'x86/amd-iommu' and 'x86/iommu' into x86-v28-for-linus-phase3-B
	 drivers/pci/intel-iommu.c |   25 ++++++++++++++++++++++++-
	 1 files changed, 24 insertions(+), 1 deletions(-)
	6e03f99 (from 9821626) Merge branch 'linus' into x86/iommu
	 drivers/pci/intel-iommu.c |   23 +++++++++++++++++++++++
	 1 files changed, 23 insertions(+), 0 deletions(-)

Strange, why did we need to remove the last path component to get these
results which say that exactly the file we previously specified was changed?

Also interesting, and matching the above results in that we see the need for
the -m flag confirmed:

	$ for merge in 057316c 6b2ada8 d847059 725c258 6e03f99
	do
		a=$(git show $merge | grep -c blacklist_iommu)
		b=$(git show -m $merge | grep -c blacklist_iommu)
		echo $merge $a $b
	done
	057316c 0 2
	6b2ada8 0 2
	d847059 0 2
	725c258 0 2
	6e03f99 0 2

IAW: the combined diff for the five found merges doesn't show any changes to
a line containing the string "blacklist_iommu", but the full diffs do.

Let's check for the presence of the string in the merge results and their
parents:

	$ for merge in 057316c 6b2ada8 d847059 725c258 6e03f99
	  do
		for rev in $(git show $merge | grep ^Merge:)
		do
			t=parent
			case $rev in
			Merge:)
				echo
				rev=$merge
				t=merge
				;;
			esac
			if git grep -q blacklist_iommu $rev -- drivers/pci/
			then
				echo "$t $rev: found"
			else
				echo "$t $rev: not found"
			fi
		done
	done

	merge 057316c: not found
	parent 3e2dab9: found
	parent 2515ddc: not found
	
	merge 6b2ada8: not found
	parent 278429c: not found
	parent 3b7ecb5: found
	parent 77af7e3: not found
	parent 1516071: not found
	parent 1fa63a8: not found
	parent 8546232: not found
	
	merge d847059: not found
	parent 725c258: found
	parent 11494547: not found
	
	merge 725c258: found
	parent 3dd392a: found
	parent 72d3105: found
	parent 129d6ab: not found
	parent 1e19b16: found
	
	merge 6e03f99: found
	parent 9821626: not found
	parent 6bfb09a: found

Hmm, seems like the function is gone since d847059.  Does all of this help
you in any way?

René