# =?y?q?=5BGSOC=5D=20Discuss=3A=20Refactoring=20in=20order=20to=20reduce=20Git=E2=80=99s=20global=20state?=

6 messages from 2026-02-19 to 2026-03-04. Participants: Shreyansh Paliwal, Karthik Nayak.
Thread: https://gitlist.dev/t/65024

## Shreyansh Paliwal, 2026-02-19 18:02

Subject: =?y?q?=5BGSOC=5D=20Discuss=3A=20Refactoring=20in=20order=20to=20reduce=20Git=E2=80=99s=20global=20state?=
Message-ID: <20260219181154.66814-1-shreyanshpaliwalcmsmn@gmail.com>
URL: https://gitlist.dev/e/20260219181154.66814-1-shreyanshpaliwalcmsmn%40gmail.com

```
Hi everyone,

I have been around Git for some time and am interested in the “Refactoring
in order to reduce Git’s global state” project for GSoC 2026.

So far I have built Git from source, completed a microproject, and explored
some related areas in worktree and wt-status. I have also gone through the
blog posts by Ayush and Bello Olamide, which were very helpful in getting
to know about the ongoing/previous related to this. From what I gathered,

- In Outreachy, recent work has focused on moving core.attributesfile and
  core.sparseCheckout into local structs and also to handle the issue of
  lazy loading, but it is still a work in progress.

- In last year’s GSoC work, the focus included removing uses of
  the_repository and other globals across areas such as
  preload-index:(core_preload_index), builtin/prune:
  (repository_format_precious_objects), builtin/fmt-merge-msg:
  (merge_log_config).

Though I still have a few questions regarding the project for better clarity,

- Should the primary focus be on core library code rather than builtin?
  (ref. [1])

- Is it preferable to approach the project file-wise (eg. cleanup of one
  file making it completely free of the_repository) or variable-wise (eg.
  identify one global state from environment.c and eliminate across the
  codebase)?

- Are there any globals which are best not to be removed currently?

For example, in editor.c there are mainly two globals,

- editor_program, which appears to be only used within the file and is not
  dependant on repository. So would it be preferable to remove it from
  environment.c and localize it within editor.c, move it into struct
  repository_settings / repo_config_values, or keep it as is?

- the_repository, there is only one instance in the function
  git_sequence_editor() which is used in editor.c which can be modified to
  pass struct repository down the callers but is also used in
  builtin/var.c, where a local repository instance is not available. In
  that case, would it be feasible to pass the_repository or is there any
  other way?

I have also surveyed files that use #define USE_THE_REPOSITORY_VARIABLE to
roughly analyse the usage of globals, and I could make that much of the
library code is still dependant on the_repository, so could that be taken
on priority to reduce the usage of the_repository throughout the codebase.

Thanks,
Shreyansh

[1]- https://lore.kernel.org/git/7b5dd0c4-0ca0-458e-89db-621a70dac9ae@gmail.com/

```

## Shreyansh Paliwal, 2026-02-19 18:17

Subject: Re: [GSOC] Discuss: Refactoring in order to reduce global state
Message-ID: <20260219181736.71467-1-shreyanshpaliwalcmsmn@gmail.com>
URL: https://gitlist.dev/e/20260219181736.71467-1-shreyanshpaliwalcmsmn%40gmail.com
In-Reply-To: <20260219181154.66814-1-shreyanshpaliwalcmsmn@gmail.com>

```
I think there was an issue with git send-email that is why the subject
line seems malformed. Please ignore that.



```

## Shreyansh Paliwal, 2026-02-23 08:26

Subject: Re: [GSOC] Discuss: Refactoring in order to reduce global state
Message-ID: <20260223082616.1824407-1-shreyanshpaliwalcmsmn@gmail.com>
URL: https://gitlist.dev/e/20260223082616.1824407-1-shreyanshpaliwalcmsmn%40gmail.com
In-Reply-To: <20260219181154.66814-1-shreyanshpaliwalcmsmn@gmail.com>

```
ping.

```

## Karthik Nayak, 2026-02-24 13:40

Subject: Re: [GSOC] Discuss: Refactoring in order to reduce Git’s global state
Message-ID: <CAOLa=ZSxkgGbWjYCu4DP269LtOdtn7Tcbz+DJH1ASyrGVXvb2A@mail.gmail.com>
URL: https://gitlist.dev/e/CAOLa%3DZSxkgGbWjYCu4DP269LtOdtn7Tcbz%2BDJH1ASyrGVXvb2A%40mail.gmail.com
In-Reply-To: <20260219181154.66814-1-shreyanshpaliwalcmsmn@gmail.com>

```
Shreyansh Paliwal <shreyanshpaliwalcmsmn@gmail.com> writes:

> Hi everyone,
>
> I have been around Git for some time and am interested in the “Refactoring
> in order to reduce Git’s global state” project for GSoC 2026.
>
> So far I have built Git from source, completed a microproject, and explored
> some related areas in worktree and wt-status. I have also gone through the
> blog posts by Ayush and Bello Olamide, which were very helpful in getting
> to know about the ongoing/previous related to this. From what I gathered,
>
> - In Outreachy, recent work has focused on moving core.attributesfile and
>   core.sparseCheckout into local structs and also to handle the issue of
>   lazy loading, but it is still a work in progress.
>
> - In last year’s GSoC work, the focus included removing uses of
>   the_repository and other globals across areas such as
>   preload-index:(core_preload_index), builtin/prune:
>   (repository_format_precious_objects), builtin/fmt-merge-msg:
>   (merge_log_config).
>
> Though I still have a few questions regarding the project for better clarity,
>
> - Should the primary focus be on core library code rather than builtin?
>   (ref. [1])
>

Phillip does make a good point, replacing global variable usage in the
library code is indeed more useful.

However cleanup of some of the global config variables, could involve
touching the builtin code.

> - Is it preferable to approach the project file-wise (eg. cleanup of one
>   file making it completely free of the_repository) or variable-wise (eg.
>   identify one global state from environment.c and eliminate across the
>   codebase)?
>

Depends, some variables (e.g. the_repository) are spread more broadly so
trying to go variable wise might not make much sense for them.

> - Are there any globals which are best not to be removed currently?
>
> For example, in editor.c there are mainly two globals,
>
> - editor_program, which appears to be only used within the file and is not
>   dependant on repository. So would it be preferable to remove it from
>   environment.c and localize it within editor.c, move it into struct
>   repository_settings / repo_config_values, or keep it as is?
>

Makes sense to localize it within editor.c. What's more important is to
understand that currently `editor_program` is setup inside
`git_default_core_config()`. What would the new flow look like?
Also with a global variable, its parsed once and available till
execution ends. Will that still be the case?

> - the_repository, there is only one instance in the function
>   git_sequence_editor() which is used in editor.c which can be modified to
>   pass struct repository down the callers but is also used in
>   builtin/var.c, where a local repository instance is not available. In
>   that case, would it be feasible to pass the_repository or is there any
>   other way?
>

Yes, that's how I would tackle it. Moving dependency to upper layers is
a valid way to go about this, we do want to avoid this scenario if the
upper layer is already cleared of such variables and has access to an
alternative. In your case 'builtin/var.c' already uses 'the_repository',
so this should be acceptable.

> I have also surveyed files that use #define USE_THE_REPOSITORY_VARIABLE to
> roughly analyse the usage of globals, and I could make that much of the
> library code is still dependant on the_repository, so could that be taken
> on priority to reduce the usage of the_repository throughout the codebase.
>
> Thanks,
> Shreyansh
>
> [1]- https://lore.kernel.org/git/7b5dd0c4-0ca0-458e-89db-621a70dac9ae@gmail.com/

```

## Shreyansh Paliwal, 2026-02-24 16:15

Subject: Re: [GSOC] Discuss: Refactoring in order to reduce Git’s global state
Message-ID: <20260224161932.33080-1-shreyanshpaliwalcmsmn@gmail.com>
URL: https://gitlist.dev/e/20260224161932.33080-1-shreyanshpaliwalcmsmn%40gmail.com
In-Reply-To: <CAOLa=ZSxkgGbWjYCu4DP269LtOdtn7Tcbz+DJH1ASyrGVXvb2A@mail.gmail.com>

```
> Shreyansh Paliwal <shreyanshpaliwalcmsmn@gmail.com> writes:
>
> > Hi everyone,
> >
> > I have been around Git for some time and am interested in the “Refactoring
> > in order to reduce Git’s global state” project for GSoC 2026.
> >
> > So far I have built Git from source, completed a microproject, and explored
> > some related areas in worktree and wt-status. I have also gone through the
> > blog posts by Ayush and Bello Olamide, which were very helpful in getting
> > to know about the ongoing/previous related to this. From what I gathered,
> >
> > - In Outreachy, recent work has focused on moving core.attributesfile and
> >   core.sparseCheckout into local structs and also to handle the issue of
> >   lazy loading, but it is still a work in progress.
> >
> > - In last year’s GSoC work, the focus included removing uses of
> >   the_repository and other globals across areas such as
> >   preload-index:(core_preload_index), builtin/prune:
> >   (repository_format_precious_objects), builtin/fmt-merge-msg:
> >   (merge_log_config).
> >
> > Though I still have a few questions regarding the project for better clarity,
> >
> > - Should the primary focus be on core library code rather than builtin?
> >   (ref. [1])
> >
>
> Phillip does make a good point, replacing global variable usage in the
> library code is indeed more useful.
>
> However cleanup of some of the global config variables, could involve
> touching the builtin code.

Right, Got it.

> > - Is it preferable to approach the project file-wise (eg. cleanup of one
> >   file making it completely free of the_repository) or variable-wise (eg.
> >   identify one global state from environment.c and eliminate across the
> >   codebase)?
> >
>
> Depends, some variables (e.g. the_repository) are spread more broadly so
> trying to go variable wise might not make much sense for them.
>
> > - Are there any globals which are best not to be removed currently?
> >
> > For example, in editor.c there are mainly two globals,
> >
> > - editor_program, which appears to be only used within the file and is not
> >   dependant on repository. So would it be preferable to remove it from
> >   environment.c and localize it within editor.c, move it into struct
> >   repository_settings / repo_config_values, or keep it as is?
> >
>
> Makes sense to localize it within editor.c. What's more important is to
> understand that currently `editor_program` is setup inside
> `git_default_core_config()`. What would the new flow look like?
> Also with a global variable, its parsed once and available till
> execution ends. Will that still be the case?

Hmm. I will see how we can localize editor_program while keeping the parsing
and availability like the global. I think Junio also pointed out something
related to lazy loading of global variables in some recent discussion, I will
look into that as well and will follow-up by an rfc patch on this, maybe that
will clear more things out.

> > - the_repository, there is only one instance in the function
> >   git_sequence_editor() which is used in editor.c which can be modified to
> >   pass struct repository down the callers but is also used in
> >   builtin/var.c, where a local repository instance is not available. In
> >   that case, would it be feasible to pass the_repository or is there any
> >   other way?
> >
>
> Yes, that's how I would tackle it. Moving dependency to upper layers is
> a valid way to go about this, we do want to avoid this scenario if the
> upper layer is already cleared of such variables and has access to an
> alternative. In your case 'builtin/var.c' already uses 'the_repository',
> so this should be acceptable.

Understood. That makes sense.

Thanks for the guidance,
Shreyansh

```

## Shreyansh Paliwal, 2026-03-04 14:57

Subject: Re: [GSOC] Discuss: Refactoring in order to reduce Git’s global state
Message-ID: <20260304145823.189440-1-shreyanshpaliwalcmsmn@gmail.com>
URL: https://gitlist.dev/e/20260304145823.189440-1-shreyanshpaliwalcmsmn%40gmail.com
In-Reply-To: <20260224161932.33080-1-shreyanshpaliwalcmsmn@gmail.com>

```
Hi Karthik,

Following up on this, I recently sent a patch on `editor_program` [1],
but the discussion hasn’t reached a clear conclusion yet. I would really
appreciate your thoughts and feedback on it including what you think
would be the most appropriate way forward.

Thanks,
Shreyansh

[1]- https://lore.kernel.org/git/20260301105228.1738388-1-shreyanshpaliwalcmsmn@gmail.com/

```
