Meanwhile, over in the default branch, Harry decides the white balls should be sorted before analysing them, because that’s how they are on the box.
lottery harry$ hg diff diff -r f282002d72ee src/pb.c --- a/src/pb.c Tue May 17 14:14:44 2011 -0500 +++ b/src/pb.c Tue May 17 14:26:36 2011 -0500 @@ -6,6 +6,25 @@ #define MAX_WHITE_BALL 59 #define MAX_POWER_BALL 39 +static int my_sort_func(const void* p1, const void* p2) +{ + int v1 = *((int *) p1); + int v2 = *((int *) p2); + + if (v1 < v2) + { + return -1; + } + else if (v1 > v2) + { + return 1; + } + else + { + return 0; + } +} + int calculate_result(int white_balls[5], int power_ball) { for (int i=0; i<5; i++) @@ -27,6 +46,8 @@ return -1; } + qsort(white_balls, 5, sizeof(int), my_sort_func); + return 0; }
And he commits the change.
lottery harry$ hg commit -m "sort the white balls"
But now he’s curious about what Sally has been doing. She said he wasn’t allowed to commit to her branch but she didn’t say anything about looking at it.
lottery harry$ hg log changeset: 18:3e1b620bb7ad tag: tip parent: 16:f282002d72ee user: Harry <harry@futilisoft.com> date: Tue May 17 14:27:37 2011 -0500 summary: sort the white balls changeset: 17:836e4df60a27 branch: no_boys_allowed user: Sally <sally@futilisoft.com> date: Tue May 17 14:24:14 2011 -0500 summary: add -favorite and cleanup some other stuff
Interesting. She added the “favorite” feature. Harry decides he wants that. So he asks Mercurial to merge stuff from Sally’s branch into the default branch.
lottery harry$ hg merge -r 836e4df60a27 merging src/pb.c 0 files updated, 1 files merged, 0 files removed, 0 files unresolved (branch merge, don't forget to commit)
Brilliant! Harry examines pb.c
and discovers that it was merged correctly.
Sally’s “favorite” changes are there and his qsort
changes are as well. So he
compiles the code, runs a quick test, and commits the merge.
lottery harry$ make gcc -std=c99 -Wall -Wextra -Werror pb.c -o pb lottery harry$ ./pb -favorite 5 3 33 22 7 31 0 percent chance of winning lottery harry$ hg commit -m "merge changes from sally" lottery harry$ hg push pushing to http://server.futilisoft.com:8000/ searching for changes remote: adding changesets remote: adding manifests remote: adding file changes remote: added 2 changesets with 2 changes to 1 files