-
Notifications
You must be signed in to change notification settings - Fork 141
Replace more instances of the_index
and the_repository
#379
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I don't have a lot of experience working in C but can I claim this? |
Excellent, "good first issue" is meant for exactly this case.
Sure, why don't you start I could even imagine that one file would also be too much, as there might be multiple affected functions, and you could start with extending just one function's signature so that the index (or the repository) parameter is passed in. To make this build, you will of course need to adjust all callers (Personally, I would use |
Sure. Thanks a lot. |
Hello Dscho! Could you explain this part in just a bit more detail please? Would be of great help! I am working on submodules as well and there are some things I wanna clear out! :) E: From what I have understood so far is that with the introduction of submodules, a concept of repo inside a repo has come into being. This would mean that a global
And this serves the purpose of simplifying the variable name right?
Could you explain this please? So, if there were a hypothetical world without submodules, then there wouldn't have been any immediate need to make this switch right? Thanks, |
Well, those instances wouldn't be local variables forever, but rather function parameters. Have you followed the link I provided as an example? |
I did just now. I see they are function parameters just like you said.
In this case, we would not have really needed to do this right? |
There are many advantages to using sort of an object-oriented design in this area. Having the option to support submodules in-process (including transparently recursive diffs) is only one of them. |
Hey, I'm planning to work on this, but I cannot find more references to |
https://github.com/git/git/search?q=the_repository&type=code shows at least one match outside of I think that you could find these locations via |
Hey, @dscho, I'm trying to replace |
Sure. Did you define |
Yes, I'll link a PR today for review. 😄 I guess passing |
The tests are implemented in shell. Unless you're referring to test helpers, where it is totally okay to use |
@dscho , please have a look at the PR and suggest necessary changes. :) |
Once upon a time, Git was intended to be just like all the other simplistic Unix utilities, a set of commands to be cobbled together by shell scripts. In those times, it was (deemed) okay to cut corners, using global variables all over the place, and leaving it to
exit()
to "clean up" allocated memory.In the meantime, Git has matured a lot, and most of its code is in proper C, and quite some of that code has been prepared for more versatile use already, e.g. for in-process submodule handling, by avoiding global variables.
Two of those global variables are
the_index
andthe_repository
. The former represents "the" Git index (AKA staging area) while the latter represents the.git
directory.Ideally, we would have no code in
libgit.a
(i.e. the internal API functions) that accessthe_index
orthe_repository
directly. Rather, they should be passed through as function parameters, much like object-oriented languages implicitly pass athis
orself
parameter.The convention is to give the repository parameter the short-and-sweet name
r
, and the index parameter the pretty intuitive nameindex
. A good example to follow is this commit: 90d3405Note that it is not necessary to pass through both the index and the repository, at least not in general, as
the_repository->index
is a thing. Only in rare circumstances will a function want to work specifically on a temporary, or potentially temporary, index. Meaning: when adding astruct the_repository *r
parameter to a function's signature that already has astruct index_state *index
, the latter parameter can be removed.The text was updated successfully, but these errors were encountered: