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 telly.
lottery harry$ git diff diff --git a/src/pb.c b/src/pb.c index 9f3ce49..45c5730 100644 --- a/src/pb.c +++ b/src/pb.c @@ -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; } lottery harry$ git commit -a -m "sort the white balls" [master eabf466] sort the white balls 1 files changed, 20 insertions(+), 0 deletions(-)
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$ git fetch remote: Counting objects: 11, done. remote: Compressing objects: 100% (6/6), done. remote: Total 8 (delta 2), reused 0 (delta 0) Unpacking objects: 100% (8/8), done. From http://server.futilisoft.com:8000/lottery * [new branch] no_boys_allowed -> origin/no_boys_allowed lottery harry$ git log ..origin/no_boys_allowed commit 02f97979589ee827dfa3f4cfb662eb246b48d919 Author: Sally <sally@futilisoft.com> Date: Sat Jun 11 17:55:35 2011 +0200 add -favorite and cleanup some other stuff
Interesting. She added the “favorite” feature. Harry decides he wants that. So he asks Git to merge stuff from Sally’s branch into the default branch.
lottery harry$ git merge origin/no_boys_allowed Auto-merging src/pb.c Merge made by recursive. src/pb.c | 61 +++++++++++++++++++++++++++++++++++++++++++------------------ 1 files changed, 43 insertions(+), 18 deletions(-)
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$ git push Counting objects: 14, done. Compressing objects: 100% (6/6), done. Writing objects: 100% (8/8), 1.06 KiB, done. Total 8 (delta 2), reused 0 (delta 0) Unpacking objects: 100% (8/8), done. To http://server.futilisoft.com:8000/lottery 4c75c49..df43333 master -> master