2

Background

As part work to abstract a few classes to one interface, I've had to changes a file which makes use of one of these old classes to now point it to the interface fields.

The file previously would have looked something like this (simplified for example).

public class Foo{

    public string RetrieveValue(MyModel model)
    {
        return model.Area.Street.Flat;
    }

    public string RetrieveOtherValue(MyModel model)
    {
        return model.Area.Shop;
    }

}

But would now look like this.

public class Foo{

    public string RetrieveValue(MyModel model)
    {
        return model.Base_Area.Base_Street.Base_Flat;
    }

    public string RetrieveOtherValue(MyModel model)
    {
        return model.Base_Area.Base_Shop;
    }

}

Question

Can I check easily that the only change here was the inclusion of Base_ in various places?

It's easy to see on this scale with a diff tool, but the file big enough that I don't trust just eyeballing it. My source control in use is git but I'm happy to use other tools if necessary.

Ideally I'd like to ignore all sorts of whitespace, too.

Geesh_SO
  • 2,156
  • 5
  • 31
  • 58

2 Answers2

2

I think the following should get close:

git diff --word-diff-regex=. > changes.txt
grep -oP '\+[^\+]+\+' changes.txt | tr -d '\+' | sort -u

In the first line, you make a diff which you write to a file.
The second line extracts the changes on character basis and removes the "+". In the end it is sorted and unique values are kept. I applied the above code to your example and got the following result:

Base_

This even works with more files or files which were changed in other folders. You still get the answer right away - but in case, analysis takes more time.

Christoph
  • 6,841
  • 4
  • 37
  • 89
1

How about this?

diff <(git show HEAD~1:/path/to/file) <(sed 's/Base_//' /path/to/file)

Change to HEAD~0 If you have not commited the file yet.

balki
  • 26,394
  • 30
  • 105
  • 151