Week 10 (update)
Hello,
In the last blog post I talked mentioned about some bugs and you may wonder what were this bugs. Since I fixed them and (as a result) I can talk about them, here are some notes:
- You may have used in some shell scripts
$@
or$*
. For one, I remember that at some point I read about the difference between these two special parameters. In practice, I did use both of them unconsciously, without being aware which one would be better. At first glance, they might seem same. Here you can learn more about both of them. In my case, I was using$@
instead of$*
when callinggit stash--helper create
. Here is an example to make it more clear:
#/bin/sh
echo "echoing all params"
echo 'Using "$@":' "$@"
echo 'Using "$*":' "$*"
echo
echo "echoing each param"
echo 'Using "$@":'
for i in "$@"; do
echo $i;
done
echo
echo 'Using "$*":'
for i in "$*"; do
echo $i;
done
Running:
./test.sh this is a test
will produce the output:
echoing all params
Using "$@": this is a test
Using "$*": this is a test
echoing each param
Using "$@":
this
is
a
test
Using "$*":
this is a test
-
I had some troubles with calling some functions. In the debugging process, I found out that I called
setup_revisions()
the wrong way. This function parses arguments starting with position 1, not 0. Thankfully, this did not take too much time to find & fix. One easy solution for this is to push a dummy argument at the beginning of an argument array (or to giveparse_options()
PARSE_OPT_KEEP_ARGV0 as flag; in my case the first method was better sincecreate_stash()
will be called bypush_stash()
at some point) -
One other problem was that I was spawning a child process, but forgot to add the
GIT_INDEX_FILE=...
value to environment variable array. -
There were other tiny bugs stemming from not knowing very well the API. For example, at some point I needed to get only the title of a commit message. What I did was to get the whole commit message (including the ‘metadata’ such as author, date). To solve this, I looked through other C commands (such as
git log
) and found aboutpretty_print_commit()
. From that moment, it was easy to fix it. -
And… the last note, but probably the most important one. I think that I was a little bit too confident when I started to convert
git stash create
. You may wonder why. Well, I tried to convert each command by directly calling the API, which, in theory, would be a great way. In reality, though, there might appear regressions. This was my case… What did I learn? Although it might be a tedious way to convert a command from shell to C, there is always the possibility of spawning child processes instead of directly calling the API. Of course, this is really inefficient; but by doing so, the debugging takes less time. Once the whole command is ported to C, the development can continue (and should) by converting each child process into direct API calls (if possible). This way, the command can be tested if it still works as intended after each child process converted.
P.S: I will submit a new iteration of the patches I talked about in the last post sooner since I do not expect to get any more reviews. I will also submit the ones regarding “GET_OID_GENTLY” with the RFC tag.
Thanks!