refactoring edit history of source code

17
Refactoring Edit History of Source Code ‡ Ritsumeikan University, Japan Shinpei Hayashi Takayuki Omori Teruyoshi Zenmyo Katsuhisa Maruyama Motoshi Saeki † Tokyo Institute of Technology, Japan

Upload: shinpei-hayashi

Post on 13-Jul-2015

2.598 views

Category:

Technology


2 download

TRANSCRIPT

Refactoring Edit History���of Source Code

‡ Ritsumeikan University, Japan

Shinpei Hayashi† ���

Takayuki Omori‡ ���

Teruyoshi Zenmyo† ���

Katsuhisa Maruyama‡ ���

Motoshi Saeki†

† Tokyo Institute of Technology, Japan

2

Background

l  Edit histories are used for various ways – Committing edits into SCM repository – Undo/redo past edit operations – Understanding histories by replaying them���

[Hattori '10][Omori '11]

à Well-structured history enhances��� these activities

The recorded raw history: ... actually well-structured?

Example

3

private  int  foo()  {          int  state  =  ...;                    ...          state  =  bar(state,  false);                    ...                                                            }    private  int  bar(int  state,  boolean  f)  {          ...

private  int  transit()  {          int  state  =  ...;          log.trace(”state  =  ”  +  state);          ...          state  =  nextState(state  +  1,  true);          log.trace(”state  =  ”  +  state);          ...                                                            }    private  int  nextState(int  state,  boolean  f)  {          ...

Rename bar  to nextState

Rename foo to transit

Adding log.trace (1)

Adding log.trace  (2)

Bug-fix (1) false to true

Bug-fix (3) state to state  +  1

Several problems –  Tangled changes according to multiple tasks

–  2nd code refactoring w/o tool causes individual changes –  Loggings are hard to undo

4

Edit History Refactoring

l Definition – Restructuring of an edit history for improving the

usability and/or understandability of the history without changing its overall effect

Source code Source code

Code refactoring Refactor

Edit history Edit history

History refactoring Refactor

5

Edit History Refactoring

l  Changes are reordered by the associated tasks for ��� easily committing them separately

l  Code refactorings and loggings: merged into a single��� change for easily handling them –  Make the loggings latest for easily undoing them

Rename bar  to nextState

Rename foo to transit

Adding log.trace (1)

Adding log.trace  (2)

Bug-fix (1) false to true

Bug-fix (3) state to state  +  1

Refactor!

6

Changes

l Change := (sequence of chunks, group) – A sequence of keystrokes on IDE generates���

a change including a single chunk

– A code refactoring w/ tool generates a large change including multiple chunks

Edit history

removal Edit history

transit foo ���transit foo ���

transit

foo ���transit

foo ���transit

foo ���transit

foo

addition replace replace

multiple���replaces

Primitive Refactorings

7

Split Change

Swap Changes

Cancel Changes

Merge Changes

l  Transformation procedures and pre/post-conditions���are defined

8

Large Refactorings

l  Bubble sorting based on a group order –  Applying Swap Changes multiple times

Swap

Merge

Swap

Swap

Merge Merge

Reorder Changes

9

Large Refactorings

l  Localizing a large change –  e.g., file-level formatting à method level formatting

Revert

Split (by methods)

Merge

Some edits Formatting

Reconfigure Changes

Historef: A supporting tool

10

Historef: A supporting tool

11

Performed changes

Historef: A supporting tool

12

Groups / Switching UI

Historef: A supporting tool

13

History refactoring commands

14

Application 1: Task Level Commit

l Commit the changes to SCM repository separately for each task – Reorder the changes based on groups – Merge the reordered changes, and commit them to SCM

Merge Merge Merge

Commit

Reorder

15

Application 2: Selective Undo

l Undoing the focused change from history – Swap to make the focused changes latest – Merge them, and undo the latest change

Merge

Undo

Conclusion

4!

Edit History Refactoring!

! Definition!– Restructuring of an edit history for improving the

usability and/or understandability of the history without changing its overall effect!

Source code! Source code!

Code refactoring!Refactor!

Edit history! Edit history!

History refactoring!Refactor!

Primitive Refactorings!

7!

Split Change!

Swap Changes!

Cancel Changes!

Merge Changes!

!  Transformation procedures and pre/post-conditions"are defined!

Example!

3!

private(int(foo()({(((((int(state(=(...;((((((((((...(((((state(=(bar(state,(false);((((((((((...((((((((((((((((((((((((((((((}((private(int(bar(int(state,(boolean(f)({(((((...!

private(int(transit()({(((((int(state(=(...;(((((log.trace(”state(=(”(+(state);(((((...(((((state(=(nextState(state(+(1,(true);(((((log.trace(”state(=(”(+(state);(((((...((((((((((((((((((((((((((((((}((private(int(nextState(int(state,(boolean(f)({(((((...!

Rename bar(to nextState!

Rename foo to transit!

Adding log.trace (1)!

Adding log.trace((2)!

Bug-fix (1) false to true!

Bug-fix (3) state to state(+(1!

Several problems!–  Tangled changes according to multiple tasks!

–  2nd code refactoring w/o tool causes individual changes!–  Loggings are hard to undo!

14!

Application 1: Task Level Commit!

! Commit the changes to SCM repository separately for each task!– Reorder the changes based on groups!– Merge the reordered changes, and commit them to SCM!

Merge! Merge! Merge!

Commit!

Reorder!

Credit

l Photo by Elsie esq. – Chronology | Flickr –  http://www.flickr.com/photos/elsie/4607687530/

17