threads / discuss / 24071

Porcelain support for daggy-fixes?

Subject: Porcelain support for daggy-fixes?

## tl;dr

3 messages between Jun 10, 2010 and Jun 11, 2010.

replies: 2people: 2as markdown or json

Mikko Rantalainen· Jun 10, 2010, 13:55 UTC · lore
Introduction: http://monotone.ca/wiki/DaggyFixes/
I understand that this can already be done with git. The method is
1) store the current HEAD somewhere
2) figure out the proper parent for the bug fix
3) checkout the parent
4) implement the fix
5) commit the fix
6) checkout HEAD
7) merge with the commit from step 5

Is there some way to do this more automatically? The way I think this should be done:

1) fix a bug that you just found (let's imagine for a second that you
just happened to know how to fix the bug without knowing the history of bug)
2) git commit (the bugfix is now the tip of the HEAD)
3) git daggy-fix
And you're done.
Here the magical "daggy-fix" would do the following:

"Remove" the change HEAD^..HEAD from the current branch, try to recursively apply the patch to ancestors of HEAD and locate oldest parent that the patch can be automatically applied to without a conflict. Let's call this parent BUG (best guess for the original commit that introduced the bug). Commit the patch as a new child of BUG and then merge with HEAD^ (from the moment daggy-fix was executed). Checkout the new HEAD to replace the original HEAD.

In short, replace the current tip of the current branch with the merge of last commit rebased as the bugfix for historical commit and HEAD^.

Logical syntax for this command could be
git daggy-fix fix-commit-id bug-commit-id

where fix-commit-id is the commit that should be relocated and re-merged bug-commit-id is the commit that introduced the bug (no need for automatic detection of the parent)

both commit id's are optional.
Does this sound reasonable or is there already some better way?
-- 
Mikko
Pascal Obry· Jun 10, 2010, 14:21 UTC · re: Mikko Rantalainen · lore

Re: Porcelain support for daggy-fixes?

Mikko,
Show 9 quoted lines
> I understand that this can already be done with git. The method is
>
> 1) store the current HEAD somewhere
> 2) figure out the proper parent for the bug fix
> 3) checkout the parent
> 4) implement the fix
> 5) commit the fix
> 6) checkout HEAD
> 7) merge with the commit from step 5
I would probably create a topic/fix branch:
1) figure out the proper parent for the bug fix
2) create the fix branch and move to it
    $ git co -b fix-feature-whatever parent
3) implement the fix
4) commit the fix
5) checkout HEAD
6) merge with the commit from step 4
And also merge on release branch if needed.
Pascal.
-- 
--|------------------------------------------------------
--| Pascal Obry                           Team-Ada Member
--| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE
--|------------------------------------------------------
--|              http://www.obry.net
--| "The best way to travel is by means of imagination"
--|
--| gpg --keyserver wwwkeys.pgp.net --recv-key C1082595
Mikko Rantalainen· Jun 11, 2010, 11:25 UTC · re: Pascal Obry · lore

Re: Porcelain support for daggy-fixes?

Pascal Obry wrote:
Show 11 quoted lines
> I would probably create a topic/fix branch:
> 
> 1) figure out the proper parent for the bug fix
> 2) create the fix branch and move to it
>     $ git co -b fix-feature-whatever parent
> 3) implement the fix
> 4) commit the fix
> 5) checkout HEAD
> 6) merge with the commit from step 4
> 
> And also merge on release branch if needed.

OK. I agree with this. The only problem is step 1 above (plus the other repeated steps if this is done every time you find a bug).

I'm still wondering if it would be possible to figure the correct parent automatically. How about the following:

Given: minimal patch to fix a bug committed to tip of the master.
Target: find proper parent for daggy-fix for the given bugfix (and then
later rewrite history to put the fix as daggy-fix and merge with the master)
Idea:

Compare the list of removed lines from latest commit (the bugfix) with the output of the same lines from git blame --cc (immediately before the bugfix). Proper parent for the bug fix is the commit that is newest for any removed line from the parent of the bugfix in the tip of the master (HEAD^).

Does it sound sensible to assume that the proper parent for the bug fix is the newest commit that has modified any line that is removed or replaced by the bug fix?

Why do I even think about this? I believe that daggy-fix style would be beneficial for many software projects but for small fixes it requires many little steps to implement and extra work to figure out the correct parent. Small bugs are often easy to fix at the tip of the master so the fixes usually end up there. It would be awesome if git were smart enough to move the fix to the correct location (daggy-fix) and do automatic merge, once told that the last commit was really a bugfix. If this ends up working well enough, then it should be a flag for commit (--bugfix) which does the commit to proper parent and then does another merge commit with the current branch. Then the other branches (or forks) could merge the fix more easily (daggy-fixes should merge without conflicts if done correctly).

-- 
Mikko

← back to recent threads