In the Subversion example, this is the place where Sally asks for a lock. But Git doesn’t support lock. |
Harry updates his repository instance.
lottery harry$ git pull remote: Counting objects: 3, done. remote: Compressing objects: 100% (2/2), done. Unpacking objects: 100% (2/2), done. remote: Total 2 (delta 0), reused 0 (delta 0) From http://server.futilisoft.com:8000/lottery 3e04765..3cdcf54 master -> origin/master Updating 3e04765..3cdcf54 Fast-forward 443 files changed, 0 insertions(+), 45673 deletions(-) delete mode 100644 libvmime-0.9.1/ delete mode 100644 libvmime-0.9.1/AUTHORS delete mode 100644 libvmime-0.9.1/COPYING delete mode 100644 libvmime-0.9.1/ChangeLog delete mode 100644 libvmime-0.9.1/HACKING delete mode 100644 libvmime-0.9.1/INSTALL delete mode 100644 libvmime-0.9.1/Makefile.am ... lottery harry$ ls -l total 8 -rw-r--r-- 1 harry staff 66 May 17 11:47 Makefile drwxr-xr-x 3 harry staff 102 May 17 13:58 src
Sod it! That Sally must be barmy! She’s deleted all his email code!
Harry decides to indent[26] pb.c
.
lottery harry$ indent src/pb.c lottery harry$ git status -s M src/pb.c ? pb.c.BAK
Harry whinges for a while, calms down and reverts the changes.
lottery harry$ git checkout src/pb.c lottery harry$ git status -s ?? pb.c.BAK lottery harry$ rm pb.c.BAK lottery harry$ git status -s lottery harry$ git status # On branch master nothing to commit (working directory clean)
Git doesn’t exactly have a revert command. Or rather, it does, but git revert does something else, not what I call revert. To revert the contents of a file, Harry uses git checkout filename. |
Sally has
decided to eliminate uses of atoi()
, which is deprecated.
lottery sally$ git diff diff --git a/src/pb.c b/src/pb.c index 9f3ce49..cd378f5 100644 --- a/src/pb.c +++ b/src/pb.c @@ -43,7 +43,14 @@ int white_balls[5]; for (int i=0; i<5; i++) { - white_balls[i] = atoi(argv[1+i]); + char* endptr = NULL; + long val = strtol(argv[1+i], &endptr, 10); + if (*endptr) + { + fprintf(stderr, "Invalid arguments\n"); + return -1; + } + white_balls[i] = (int) val; } int result = calculate_result(white_balls, power_ball); lottery sally$ make gcc -std=c99 -Wall -Wextra -Werror pb.c -o pb lottery sally$ ./pb 1 2 3 4 5 6 0 percent chance of winning lottery sally$ ./pb 1 2 3e 4 5 6 Invalid arguments
And she commits her changes, easy as slipping in the mud.
lottery sally$ git commit -a -m "use strtol. atoi is deprecated." [master 4c75c49] use strtol. atoi is deprecated. 1 files changed, 8 insertions(+), 1 deletions(-) lottery sally$ git push Counting objects: 7, done. Compressing objects: 100% (3/3), done. Writing objects: 100% (4/4), 463 bytes, done. Total 4 (delta 1), reused 0 (delta 0) Unpacking objects: 100% (4/4), done. To http://server.futilisoft.com:8000/lottery 3cdcf54..4c75c49 master -> master