GIT refactoring hints (copy, then modify) (was: Re: [PATCH] Do not use un-initialised variables in audit_logging)

Andrew Bartlett abartlet at
Mon Jun 25 19:12:44 UTC 2018

On Tue, 2018-06-26 at 06:57 +1200, Gary Lockyer wrote:
> Look good to me RB+.
> Note to self write unit tests before refactoring code :-)

Actually, there is a more important lessson.

When moving code around, try really hard to:
 - copy code
 - fix code

In particular, try really hard to trigger the git 'copy of' detection
in gitk et al.

If you are creating a whole new file from another file, consider making
a copy of the whole file, then cutting out the rest of the functions as
a second step, if that allows you to get diff with just -, not changes.

Even if you can't do that, if you can show that the lines added and
removed are identical, it still helps.

Then make the changes you feel you need for the re-factor, because
these will be much easier to review, and you will be able to justify
(or find you can't justify) the changes one at a time then.

Nobody teaches this, but in my experience it can really help.


Andrew Bartlett

Andrew Bartlett             
Authentication Developer, Samba Team
Samba Developer, Catalyst IT

More information about the samba-technical mailing list