2

I organized code incorrectly in a game I'm developing, and intend to move the state update code from GameView class into the Level class. I would like to record this cut-and-paste in some way. I use Mercurial for versioning. Is this possible with Mercurial? Does any other VCS provide this feature?


Reading a bit more and watching Linus' talk about git at Google, as well as reviewing answers and comments, I understand that this is a feature of git's blame command and works by doing heuristics.

I could get this functionality by using hg-git, exporting the Mercurial changesets, and then just using the git blame -M -C command. Is there an easier way that does not involve git?

If it is not, I'll accept an existing answer that mentions git and describes using its functionality best.

Ivan Vučica
  • 9,529
  • 9
  • 60
  • 111

5 Answers5

2

git does this automatically. See How does Git track history during a refactoring?

Community
  • 1
  • 1
clee
  • 10,943
  • 6
  • 36
  • 28
  • 1
    That is regarding renames, not the more difficult case of having a function move between files. – Paul Nathan Feb 11 '11 at 17:34
  • 1
    “On a second note, tracking renames is really just a special case of tracking how content moves in the tree. In some cases, you may instead be interested in querying when a function was added or moved to a different file.” – clee Feb 11 '11 at 17:45
  • Yes, but tracking whole file moves seems a lot easier to stomach performance-wise, since only file hashes need to be compared. – lubomir.brindza Feb 11 '11 at 19:31
  • And yet git is renowned for having great performance! Crazy. :) – clee Feb 11 '11 at 20:29
  • Heh, I didn't mean to imply that git is slow or anything like that, @clee - – lubomir.brindza Feb 13 '11 at 16:55
1

If the level class doesn't already exist you can do it with:

hg copy GameView.ext Level.ext

and then delete from GameView whatever you've moving to Level, and modify Level to reflect the correct name and exclude everything that's staying in GameView.

If Level already existed I don't think there's any good way to do it unless you're willing to extract that code out into its own class that could start out as a copy of GameView and be included (via #include, or composition, or extension) in Level.

Ry4an Brase
  • 78,112
  • 7
  • 148
  • 169
1

I don't think that Mercurial tracks file renames/moves explicitly, at least it's not a part of a changeset (although it can guess where a particular file came from based on it's content).

That being said, I'm afraid that I'm not aware of any VCS that tracks movement of code between files, just addition to the target and subtraction from the source.

lubomir.brindza
  • 256
  • 4
  • 11
  • 1
    http://stackoverflow.com/questions/4908336/can-git-really-track-the-movement-of-a-single-function-from-1-file-to-another-if – clee Feb 11 '11 at 17:48
  • @clee: I stand corrected, I guess. Following up on the article, do you think `hg annotate` is a valid substitution for `git blame` (when taking the mentioned functionality into accord)? – lubomir.brindza Feb 13 '11 at 08:31
1

Mercurial supports file rename detection as follows:

hg addremove -s 100

The -s means "similarity" and the 100 means 100%. It will look for files whose name has changed but their content remains identical.

I quite often use this command with a 85 or 90% similarity figure. And in combination with the -n switch which allows a dry run (i.e. do nothing but report), it can be very powerful.

Detection of actual moved code is not really possible I don't think.

nbevans
  • 7,739
  • 3
  • 27
  • 32
0

What I do for this sort of situation is isolate the changes from my other development, then commit the movement in a single commit with a note, "moved function munge() between files.

To my knowledge, no VCS tracks the movement of data. Renames are trackable with git and Clearcase.

Paul Nathan
  • 39,638
  • 28
  • 112
  • 212