简体   繁体   中英

Hg: Update on a line-by-line level?

I have a bug that is present in one changeset but not its parent. Is there some functionality in mercurial where I can "update" in smaller increments, to see where the problem starts?

For example, if the diff is a change in functions A, B, and C, I would run the test suite after making each of those changes, to try to diagnose the problem.

The answer is: it depends how much manual labor you are willing to put in.

What you can do is roll up your sleeves and use the attic extension in interactive mode. If you are using TortoiseHg, you already have it, just run hgtk shelve and it lets you move changes around one diff hunk at a time. (a hunk being a set of contiguous line diffs)

There are plenty of other diff patching tools that will give you single-hunk resolution. Let me know if you need more details.

And just for fun, let's talk about how an automated solution like bisect is not possible, since it doesn't always make sense that half a changeset should still compile. Even worse, what if they do compile, but have logic errors? Here's a simple worst case scenario...

void main(){
    Foo *x = malloc(128);
    frobFoo(&x);
-   free(x);   //line 4 removed in changeset
}

void frobFoo(Foo ** x){
+   free(*x);  //line 8 added in changeset
}

You can use hg diff -r firstrev -r secondrev and filter the output to only the bits concerning those functions, then step through the patches one by one.

Or you could use the bisect extension, designed for this purpose - although it will give you all changes made to your codebase, not just those concerning a particular function. You could ameliorate this by extraction only the revs changing your function and then doing a bisection search of those revisions only.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM