git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Konstantin Khomoutov <kostix@bswap.ru>
To: Aman <amanmatreja@gmail.com>
Cc: "Konstantin Khomoutov" <kostix@bswap.ru>,
	"Git List" <git@vger.kernel.org>,
	"Kerry, Richard" <richard.kerry@atos.net>,
	"Philip Oakley" <philipoakley@iee.email>,
	"git-vger@eldondev.com" <git-vger@eldondev.com>,
	"Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
Subject: Re: About GIT Internals
Date: Mon, 6 Jun 2022 14:52:15 +0300	[thread overview]
Message-ID: <20220606115215.mxzney54vf6vkzlp@carbon> (raw)
In-Reply-To: <CACMKQb3gYwdyfRSLWO4FWb6+Kxrk-WURpLayrgFsszCKMhWONw@mail.gmail.com>

On Sat, Jun 04, 2022 at 08:54:10PM +0530, Aman wrote:

[...]
> > If you do also understand the latter - that is, understanding that Git is an
> > assortment of CLI tools combined into two layers called "plumbing" and
> > "porcelain", - then you should have no difficulty starting to read the code:
> > basically locate the source code of the entry point Git binary (which is,
> > well, "git", or "git.exe" on Windows) and start reading it.

(I have reversed the order of your questions below so that my comments follow
logically one after another.)

> What do you mean by the "entry point" of the git binary?

Well, porcelain Git commands (those supposed to be used by users to carry out
their day-to-day tasks) are all implemented as subcommands of a single
executable image file called "git" on all supported platforms (except Windows,
where it's called "git.exe"): for instance, you run "git init" to initialize a
repository, and your OS looks up the executable image file named "git"
somewhere in the list of directories containing such files (it's usually
contained in the environment variable named "PATH"), executes it and passes it
a single command-line argument - "init". The rest of the commands works the
same way. Therefore, that binary named "git" is an entry point of the Git
software package: the execution of most Git commands starts there (not *all*
Git commands, but let's not touch this yet).

> How do I do that?

Well, basically that's out of the scope of this list, but let's try...

Git is a complex software package mostly written in C (and POSIX shell).
As many F/OSS projects written in C, it has a top-level Makefile which is a
file supposed to be processed by GNU Make; this file contains a set of rules
for generating files from other files (compiling C source code into object
files and linking those into libraries and executable image files is exactly
this - generating files from other files). So usually you start from reading
the Makefile to find where the binary file of interest is generated, and from
which source files.

The problem is that Git's Makefile is *complex.*
So let's save you some headache and cut straight to the point: of the top
interest to you are the two files: git.c and common-main.c. The former is
exactly what implements that top-level entry point program, "git", while the
latter implements the function called "main" which is an entry point to any
program written in C which is supposed to be runnable standalone (as opposed
to becoming a library); the object file generated when compiling common-main.c
is linked to every other compiled code implementing Git commands, its main()
calls cmd_main() which is supposed to be implemented in the code of those
commands.

The rest is basically just usual C stuff - source files and header files.
If you're not familiar with these basics, then, I'm afraid, Git may be not the
best project to dive into.

In any case, I find the idea proposed by Junio elsewhere in this thread to be
very smart: it should be quite enlightening to read the "early" Git code to
make yourself accustomed to its overal architecture before moving on to its
present - much more complicated - implementation which nevertheless still
maintains the same architecture.


  reply	other threads:[~2022-06-06 13:00 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-25 16:10 About GIT Internals Aman
2022-05-25 16:49 ` Emily Shaffer
2022-05-25 21:14 ` Erik Cervin Edin
2022-05-25 23:34 ` git-vger
2022-05-26  8:47   ` Philip Oakley
     [not found]     ` <CACMKQb3exv13sYN5uEP_AG-JYu1rmVj4HDxjdw8_Y-+maJPwGg@mail.gmail.com>
2022-05-27 14:40       ` Philip Oakley
     [not found]         ` <C4B1A93D-800F-4C49-93D5-86FE58B1DDCA@hxcore.ol>
2022-05-27 15:14           ` Philip Oakley
2022-05-30  9:49         ` Kerry, Richard
2022-05-30 11:53           ` Konstantin Khomoutov
2022-05-30 13:50             ` Ævar Arnfjörð Bjarmason
2022-06-03 12:18               ` Aman
2022-06-03 15:23                 ` Konstantin Khomoutov
2022-06-04 15:24                   ` Aman
2022-06-06 11:52                     ` Konstantin Khomoutov [this message]
2022-06-03 15:25                 ` Emily Shaffer
2022-06-03 17:15                   ` Junio C Hamano
2022-05-26 12:45 ` Konstantin Khomoutov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220606115215.mxzney54vf6vkzlp@carbon \
    --to=kostix@bswap.ru \
    --cc=amanmatreja@gmail.com \
    --cc=avarab@gmail.com \
    --cc=git-vger@eldondev.com \
    --cc=git@vger.kernel.org \
    --cc=philipoakley@iee.email \
    --cc=richard.kerry@atos.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).