GSoC Week 7

Taking decisions

This week was an even more deeper dive into git submodule's code. I am almost done with the module_summary frontend function. My set-branch port will move to next on git/git hopefully!

I learned even more about shell scripting and the shell code of summary. This time, I will present my thoughts here on what I have learned. There may seem to be a bit less information here because of the relatively early write-up of the blog because I finally leave for my home this Friday! <3

Anyway, moving on to the important stuff

Current Progress

As of now, the module_summary() (the frontend function for the summary subcommand) is almost done with. I have successfully ported it from shell taking some inspiration from Prathamesh’s patch as well. Prathamesh’s patch had 6 functions namely module_summary(), compute_summary_module_list(), submodule_summary_callback(), prepare_submodule_summary(), print_submodule_summary() and finally verify_submodule_object_name(). The port I am planning to do will aim to have 3 functions namely module_summary(), summary_submodule_cb() and summary_submodule() drawing on the pattern of already ported subcommands such as sync, init, deinit, etc.

This week I had to make a decision on the way my work will progress, facing two choices: (A) To either copy Prathamesh’s code as-is and then modify it later as per current coding guidelines and pattern of porting. (B) To take inspiration from Prathamesh’s code and simultaneously make amends to it. After discussion with my mentors Christian and Kaartic, I decided to go with (A) for the ease of review offered by it. So, I will copy the code by Prathamesh and make some minor amends (more on that below) and then make the major changes. I will type the code line-by-line so that I get an good understanding of it and Prathamesh’s mindset at that time as well.

The function submodule_summary_callback() made by Prathamesh is almost identical to the for_each_listed_submodule() already existing now (my speculation is that this function mustn’t be existing back then; on running a git blame -L 439 445 builtin/submodule--helper.c shows that the function was created by Prathamesh in October i.e., way after the aforementioned patch). Hence, there is no need to copy/use that function in my code, therefore its existence will be eliminated.

One major thing I have learnt this week is the actual working of summary. Though I did make the required amends regarding this in the previous blog, I thought that this cannot be stressed enough so here it is: git submodule summary takes in the revision of the superproject not the submodule, therefore justifying all the code and the working going on.

git submodule

The main command at the heart of summary is git diff-index, a plumbing command used to compare trees or indexes. This is the command which will help us in finding a diff of the submodules (if any exist). We use the it in the manner

git $diff_cmd  $cached --ignore-submodules=dirty --raw $head -- "$@"

where $diff-cmd will hold the value diff-index and the ignore-submodules=dirty option will ignore any changes made to the working tree of the submodules and only consider the commits. The $head denotes the existing revision passed down in summary (if any, else defaulting to HEAD). The $@ denotes the path(s) of the submodule(s) in question, this is because all other arguments were shifted in lines such as test $# = 0 || shift leaving us to only the submodule path. One thing to note is that we can pass multiple paths to summary and we will get a summary for each of the submodules corresponding to their paths.

Shell scripting

I have learned some nuances related to shell scripting as well:

  • $? denotes the exit code of a command.
  • $@ contains the arguments passed to a command in a list form.
  • $* contains arguments passed to a command concatenated into a single string rather than a list like above.
  • $# gives the number of arguments passed to a command.
  • && executes the command following it only if the one preceding it succeeds.
  • || executes the command following it only if the one preceding it fails.

Next Steps

My job now is to use Prathamesh’s work on summary and better it. This week I will build his code and start making amends to it, in particular amends regarding compute_summary_module_list(). I will have to adjust it as per currently available functions and coding guidelines.

Home does feel good after such a long time!

Over and out,
Shourya Shukla

Comments

Popular posts from this blog

The Final Report

GSoC Week 15