aboutsummaryrefslogtreecommitdiffstats
path: root/diff.c (unfollow)
AgeCommit message (Collapse)AuthorFilesLines
2025-09-30xdiff: delete redundant array xdfile_t.haEzekiel Newren3-21/+16
When 0 <= i < xdfile_t.nreff the following is true: xdfile_t.ha[i] == xdfile_t.recs[xdfile_t.rindex[i]] This makes the code about 5% slower. The fields rindex and ha are specific to the classic diff (myers and minimal). I plan on creating a struct for classic diff, but there's a lot of cleanup that needs to be done before that can happen and leaving ha in would make those cleanups harder to follow. A subsequent commit will delete the chastore cha from xdfile_t. That later commit will investigate deleting ha and cha independently and together. Signed-off-by: Ezekiel Newren <ezekielnewren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2025-09-30xdiff: delete struct diffdata_tEzekiel Newren2-33/+10
Every field in this struct is an alias for a certain field in xdfile_t. diffdata_t.nrec -> xdfile_t.nreff diffdata_t.ha -> xdfile_t.ha diffdata_t.rindex -> xdfile_t.rindex diffdata_t.rchg -> xdfile_t.rchg I think this struct existed before xdfile_t, and was kept for backward compatibility reasons. I think xdiffi should have been refactored to use the new (xdfile_t) struct, but was easier to alias it instead. The local variables rchg* and rindex* don't shorten the lines by much, nor do they really need to be there to make the code more readable. Delete them. Signed-off-by: Ezekiel Newren <ezekielnewren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2025-09-30xdiff: delete local variables that alias fields in xrecord_tEzekiel Newren1-16/+13
Use the type xrecord_t as the local variable for the functions in the file xdiff/xemit.c. Most places directly reference the fields inside of this struct, doing that here makes it more consistent with the rest of the code. Signed-off-by: Ezekiel Newren <ezekielnewren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2025-09-30xdiff: delete superfluous function xdl_get_rec() in xemitEzekiel Newren1-16/+7
When xrecord_t was a linked list, and recs didn't exist, I assume this function walked the list until it found the right record. Accessing a contiguous array is so trivial that this function is now superfluous. Delete it. Signed-off-by: Ezekiel Newren <ezekielnewren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2025-09-29gitk: add proc run_themeloaderMark Levedahl1-1/+21
gitk currently accepts a single themeloader file via the config file, and will source this with errors reported to the console. This is fine for simple configuration, but will not support interactive theme exploration from the gui. In particular, a themeloader file must be sourced only once as the themes defined cannot be re-defined. Also, errors must be handled rather than just aborting while printing to the console. So, add a proc to handle the above, supporting expansion of the gui config pages. Signed-off-by: Mark Levedahl <mlevedahl@gmail.com>
2025-09-29gitk: eliminate unused ui color variablesMark Levedahl1-10/+6
gitk has a number of variables used in setting up colors for the classic (non-themed) widget set. These variables are unused with ttk, so let's eliminate them. But, leave the variables in the config file for now - those can be eliminated after this change is merged. Signed-off-by: Mark Levedahl <mlevedahl@gmail.com>
2025-09-29gitk: eliminate Interface color option from guiMark Levedahl1-5/+0
gitk offers to change the ui color on the colors prefs page, but the variable set has no effect because gitk is using themes. Let's eliminate the "Interface" color selection option from that page. Signed-off-by: Mark Levedahl <mlevedahl@gmail.com>
2025-09-29gitk: use text labels for next/prev search buttonsMark Levedahl1-25/+2
gitk allows searching for commits with various criteria, and provides up/down search buttons to facilitate this search. These buttons are labelled with bitmaps, and those bitmaps are not always recolored correctly for the ui scheme as the theme colors are not known. Let's just use text labels on these, allowing the styles to handle any coloring needed. Use utf codepoints for the arrows, presuming that these code points are available in the selected font. Signed-off-by: Mark Levedahl <mlevedahl@gmail.com>
2025-09-29gitk: use text labels for commit ID buttonsMark Levedahl1-25/+4
gitk maintains a stack of commit ids visited, and allows navigating these using a pair of buttons shown with arrows using bitmaps. An attempt is made to recolor these bitmaps to handle different color schemes, but this is unreliable across multiple themes as the required colors are not universally known. Let's just use text labels for these buttons, allowing the themes to recolor the text along with everything else. Use utf code points for the text, presuming that these arrow glyphs are available in the selected font. Signed-off-by: Mark Levedahl <mlevedahl@gmail.com>
2025-09-29gitk: do not invoke tk_setPaletteMark Levedahl1-16/+0
gitk uses themed widgets with a user selected theme, but also invokes tk_setPalette to configure colors for the non-themed widgets including the menubar. However, themes in general are expected to configure those colors already. The builtin themes (default, alt, clam, classic on unix/X11) all have compatible colors, and need no such reconfiguration, and (most, if not all) available themes set the options database for this purpose as well. Furthermore, gitk in the past avoided invoking tk_setPalette on Windows to avoid some issues. So, let's stop calling tk_setPalette everywhere, and just rely upon the selected theme (possibly user installed) to have set all needed colors. Note: if a user installs more than one theme using $themeloader, the last one installed will have defined the colors to be used. Those colors will probably be incorrect for any other set, including Tk's builtin set. Signed-off-by: Mark Levedahl <mlevedahl@gmail.com>
2025-09-29gitk: use config variables to define and load a themeMark Levedahl1-1/+15
gitk uses themed tk, but has no capability to alter the theme defined by Tk. While there are documented ways to install other themes, and to make one the default, these methods are obscure at best. Instead, let's offer two config variables: - theme this is the name of the theme to use, and must be available. - themeloader - this is the full pathname of a tcl script that will load one or more themes into the Tk namespace. By default, theme is set to the theme active when Tk is started, and themeloader = {}. These variables must be defined to something else to have any user visible effect. Signed-off-by: Mark Levedahl <mlevedahl@gmail.com>
2025-09-29doc: patch-id: fix accidental literal blocksKristoffer Haugsbakk1-20/+23
All the final paragraphs on these three options are rendered as literal blocks. The intent was surely to keep each of them wed to their respective description list items. But the attempt at maintaining the indentation level of the block causes each them to be interpreted as a code block, since code blocks can be represented using indentation. We need to use list continuation (+) in order to keep them wed to their blocks. There is also an unordered list which sandwiches two paragraphs on an option. We don’t need to do anything about that since it attaches to the description list item without list continuation (i.e. it is already correct). But for consistency let’s use list continuation and an open block on it. Signed-off-by: Kristoffer Haugsbakk <code@khaugsbakk.name> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2025-09-29The thirteenth batcnJunio C Hamano1-0/+42
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2025-09-28t7500: make each piece more independentJunio C Hamano1-8/+8
These tests prepare the working tree & index state to have something to be committed, and try a sequence of "test_must_fail git commit". If an earlier one did not fail by a bug, a later one will fail for a wrong reason (namely, "nothing to commit"). Give them "--allow-empty" to make sure that they would work even when there is nothing to commit by accident. Signed-off-by: Junio C Hamano <gitster@pobox.com> Signed-off-by: Taylor Blau <me@ttaylorr.com> Signed-off-by: D. Ben Knoble <ben.knoble+github@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2025-09-28clang-format: exclude control macros from SpaceBeforeParensJustin Tobler1-1/+1
The formatter currently suggests adding a space between a control macro and parentheses. In the Git project, this is not typically expected. Set `SpaceBeforeParens` to `ControlStatementsExceptControlMacros` accordingly. Helped-by: Karthik Nayak <karthik.188@gmail.com> Signed-off-by: Justin Tobler <jltobler@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2025-09-27doc: change the markup of paragraphs following a nested list itemJean-Noël Avila2-14/+15
Asciidoctor and asciidoc.py have different behaviors when a paragraph follows a nested list item. Asciidoctor has a bug[1] that makes it keep a plus sign (+) used to attached paragraphs at the beginning of the paragraph. This commit uses workarounds to avoid this problem by using second level definition lists and open blocks. [1]:https://github.com/asciidoctor/asciidoctor/issues/4704 Signed-off-by: Jean-Noël Avila <jn.avila@free.fr> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2025-09-26xdiff: delete unnecessary fields from xrecord_t and xdfile_tEzekiel Newren2-16/+2
xrecord_t.next, xdfile_t.hbits, xdfile_t.rhash are initialized, but never used for anything by the code. Remove them. Best-viewed-with: --color-words Signed-off-by: Ezekiel Newren <ezekielnewren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2025-09-26xdiff: delete local variables and initialize/free xdfile_t directlyEzekiel Newren1-48/+30
These local variables are essentially a hand-rolled additional implementation of xdl_free_ctx() inlined into xdl_prepare_ctx(). Modify the code to use the existing xdl_free_ctx() function so there aren't two ways to free such variables. Signed-off-by: Ezekiel Newren <ezekielnewren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2025-09-26xdiff: delete static forward declarations in xprepareEzekiel Newren1-66/+50
Move xdl_prepare_env() later in the file to avoid the need for static forward declarations. Best-viewed-with: --color-moved Signed-off-by: Ezekiel Newren <ezekielnewren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2025-09-26http-push: avoid new compile errorJohannes Schindelin1-1/+2
With the recent update in Git for Windows/ARM64 as of https://github.com/git-for-windows/git-sdk-arm64/commit/21b288e16358 cURL was updated from v8.15.0 to v8.16.0, and the LLVM-based builds (but strangely not the GCC-based builds) continuously greet me thusly: http-push.c:211:2: error: call to '_curl_easy_setopt_err_long' declared with 'warning' attribute: curl_easy_setopt expects a long argument [-Werror,-Wattribute-warning] CC builtin/apply.o 211 | curl_easy_setopt(curl, CURLOPT_INFILESIZE, buffer->buf.len); | ^ C:/a/git-sdk-arm64/git-sdk-arm64/minimal-sdk/clangarm64/include/curl/typecheck-gcc.h:50:15: note: expanded from macro 'curl_easy_setopt' 50 | _curl_easy_setopt_err_long(); \ | ^ 1 error generated. make: *** [Makefile:2877: http-push.o] Error 1 The easiest way to shut up that compile error (which is legitimate, seeing as the `CURLOPT_INFILESIZE` options expects a `long` parameter, but `buffer->buf.len` refers to the `size_t` attribute of a `strbuf`) would be to simply cast the parameter to a `long`. However, there is a much better solution: To use the `CURLOPT_INFILESIZE_LARGE` option instead, which was added in cURL v7.11.0 (see https://curl.se/ch/7.11.0.html) and which Git _already_ uses in `curl_append_msgs_to_imap()`. This fix was the motivation for renaming `xcurl_off_t()` to `cast_size_t_to_curl_off_t()` and making it available more broadly, which is the reason why it is used here, too. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2025-09-26imap-send: be more careful when casting to `curl_off_t`Johannes Schindelin1-1/+1
When casting a `size_t` to `curl_off_t`, there is a currently uncommon chance that the value can be cut off (`curl_off_t` is expected to be a signed 64-bit data type). Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2025-09-26http: offer to cast `size_t` to `curl_off_t` safelyJohannes Schindelin2-11/+13
This commit moves the `xcurl_off_t()` function, which validates that a given value fits within the `curl_off_t` data type and then casts it, to a more central place so that it can be used outside of `remote-curl.c`, too. At the same time, this function is renamed to conform better with the naming convention of the helper functions that safely cast from one data type to another which has been well established in `git-compat-util.h`. With this move, `gettext.h` must be `#include`d in `http.h` to allow the error message to remain translatable. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2025-09-25gitk: make sha1but a ttk::buttonMark Levedahl1-4/+3
gitk's 'Commit ID' button uses a classic widget, not a themed one, leading to inconsistent style. Commit 51a7e8b654 (d93f1713b0 ("gitk: Use themed tk widgets", 2009-04-17) that added themed widgets did not touch this particular widget, but does not say why. Regardless, let's use a themed button to be consistent with the rest of the interface. Signed-off-by: Mark Levedahl <mlevedahl@gmail.com>
2025-09-25diff --no-index: fix logic for paths ending in '/'Jacob Keller2-28/+51
If one of the two provided paths for git diff --no-index ends in a '/', a failure similar to the following occurs: $ git diff --no-index -- /tmp/ /tmp/ ':!' fatal: `pos + len' is too far after the end of the buffer This occurs because of an incorrect calculation of the skip lengths in diff_no_index(). The code wants to calculate the length of the string, but add one in case the string doesn't end with a slash. The method it uses is incorrect, as it always checks the trailing NUL character of the string. This will never be a '/', so we always add one. In the event that we *do* have a trailing slash, this will create an off-by-one length error later when using the skip value. The most straightforward fix would be to correct the skip1 and skip2 lengths by using ends_with(). However, Johannes made a good point that the existing logic is wasting a lot of computation. We generate the match string by copying the path in and then skipping almost all of it immediately with a potentially expensive memmove() from the strbuf_remove() call. We also re-initialize the match stringbuf each time we call read_directory_contents. The read_directory_contents really wants a path that is rooted at the start of the directory scan. We're currently building this by taking the full path and stripping out the start portion. Instead, replace this logic by building up the portion of the match as we go. Start by initializing two strbuf in diff_no_index containing the empty string. Pass these into queue_diff, which in turn passes the appropriate left or right side into read_directory_contents. As before, we build up the matches by appending elements to the match path and then clearing them using strbuf_setlen. In the recursive portion of the queue_diff algorithm, we build up new match paths the same way that we build up new buffer paths, by appending the elements and then clearing them with strbuf_setlen after each iteration. This is cheaper as it avoids repeated allocations, and is a bit simpler to track what is going on. Add a couple of test cases that pass in paths already ending in '/', to ensure the tests cover this regression. Reported-by: Johannes Schindelin <Johannes.Schindelin@gmx.de> Closes: https://lore.kernel.org/git/c75ec5f9-407a-6555-d4fb-bb629d54ec61@gmx.de/ Signed-off-by: Jacob Keller <jacob.e.keller@intel.com> [jc: small leakfixes at the end of diff_no_index()] Signed-off-by: Junio C Hamano <gitster@pobox.com>
2025-09-25format-patch: handle range-diff on notes correctly for single patchesKristoffer Haugsbakk2-2/+17
(The two next paragraphs are taken from the previous commit.) git-format-patch(1) supports Git notes by showing them beneath the patch/commit message, similar to git-log(1). The command also supports showing those same notes ref names in the range diff output. Note *the same* ref names; any Git notes options or configuration variables need to be handed off to the range-diff machinery. This works correctly in the case when the range diff is on the cover letter. But it does not work correctly when the output is a single patch with an embedded range diff. Concretely, git-format-patch(1) needs to pass `--[no-]notes` options on to the range-diff subprocess in `range-diff.c`. Range diffs for single- commit series are handled in `log-tree.c`. But `log-tree.c` had no access to any `log_arg` variable before we added it to `rev_info` in the previous commit. Use that new struct member to fix this inconsistency. Signed-off-by: Kristoffer Haugsbakk <code@khaugsbakk.name> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2025-09-25revision: add rdiff_log_arg to rev_infoKristoffer Haugsbakk2-4/+5
git-format-patch(1) supports Git notes by showing them beneath the patch/commit message, similar to git-log(1). The command also supports showing those same notes ref names in the range diff output. Note *the same* ref names; any Git notes options or configuration variables need to be handed off to the range-diff machinery. This works correctly in the case when the range diff is on the cover letter. But it does not work correctly when the output is a single patch with an embedded range diff. Concretely, git-format-patch(1) needs to pass `--[no-]notes` options on to the range-diff subprocess in `range-diff.c`. This is handled in `builtin/log.c` by the local variable `log_arg` in the case of mul- tiple commits, but not in the single commit case where there is no cover letter and the range diff is embedded in the patch output; the range diff is then made in `log-tree.c`, whither `log_arg` has not been propagated. This means that the range-diff subprocess reverts to its default behavior, which is to act like git-log(1) w.r.t. notes. We need to fix this. But first lay the groundwork by converting `log_arg` to a struct member; next we can simply use that member in `log-tree.c` without having to thread it from `builtin/log.c`. No functional changes. Helped-by: Junio C Hamano <gitster@pobox.com> Signed-off-by: Kristoffer Haugsbakk <code@khaugsbakk.name> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2025-09-25range-diff: rename other_arg to log_argKristoffer Haugsbakk4-18/+18
Rename `other_arg` to `log_arg` in `range_diff_options` and related places. “Other argument” comes from bd361918 (range-diff: pass through --notes to `git log`, 2019-11-20) which introduced Git notes handling to git-range-diff(1) by passing that option on to git-log(1). And that kind of name might be fine in a local context. However, it was initially spread among multiple files, and is now[1] part of the `range_diff_options` struct. It is, prima facie, difficult to guess what “other” means, especially when just looking at the struct. But with a little reading we find out that it is used for `--[no-]notes` and `--diff-merges`, which are both passed on to git-log(1). We should just rename it to reflect this role; `log_arg` suggests, along with the `strvec` type, that it is used to pass extra arguments to git-log(1). † 1: since f1ce6c19 (range-diff: combine all options in a single data structure, 2021-02-05) Suggested-by: Junio C Hamano <gitster@pobox.com> Signed-off-by: Kristoffer Haugsbakk <code@khaugsbakk.name> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2025-09-25add-patch: update hunk splitability after editingPhillip Wood2-1/+32
If, when the user edits a hunk, they change deletion lines into context lines or vice versa, then the number of hunks that the edited hunk can be split into may differ from the unedited hunk. This means that so we should recalculate `hunk->splittable_into` after the hunk has been edited. In practice users are unlikely to hit this bug as it is doubtful that a user who has edited a hunk will split it afterwards. Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2025-09-25add -p: mark split hunks as undecidedPhillip Wood2-1/+12
When a hunk is split, each of the new hunks inherits whether it is selected or not from the original hunk. If a selected hunk is split all of the new hunks are marked as "selected" and the user is only prompted with the first of the split hunks. The user is not asked whether or not they wish to select the rest of the new hunks. This means that if they wish to deselect any of the new hunks apart from the first one they have to navigate back to the hunk they want to deselect before they can deselect it. This is unfortunate as the user is presumably splitting the original hunk because they only want to select some sub-set of it. Instead mark all the new hunks as "undecided" so that the user is prompted whether they wish to select each one in turn. In the case where the user only wants to change the selection of the first of the split hunks they will now have to do more work re-selecting the remaining split hunks. However, changing the selection of any of the other newly created hunks is now much simpler as the user no-longer has to navigate back to them in order to change their selected state. Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2025-09-25gitk: use themed spinboxesMark Levedahl1-7/+7
gitk uses classic (non-themed) spinboxes rather than the ttk variants. Commit d93f1713b0 ("gitk: Use themed tk widgets", 2009-04-17) that added ttk makes no mention of why ttk:spinboxes were omitted, but this leads to an inconsistent interface. Let's use the ttk version. Signed-off-by: Mark Levedahl <mlevedahl@gmail.com>
2025-09-24doc: git-push: rewrite refspec specificationJulia Evans1-47/+58
From user feedback, there was a request for examples, as well as a comment that one person found "If git push [<repository>] without any <refspec> argument is set to update some ref at the destination with <src> with remote.<repository>.push configuration variable..." impossible to understand. To make the section easier to navigate, create a list of every possible refspec form, with examples for each form as well as 2 forms which were previously missing (patterns and negative refspecs). Made a few changes to use more familiar language, but ultimately refspecs are a pretty advanced feature so I've mostly left the terminology alone. Signed-off-by: Julia Evans <julia@jvns.ca> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2025-09-24doc: git-push: create PUSH RULES sectionJulia Evans1-49/+45
Right now the rules for when a `git push` is allowed are buried at the bottom of the description of `<refspec>`. Put them in their own section so that we can reference them from `--force` and give some context for why they exist. Having the "PUSH RULES" section also lets us be a little bit more specific with the rule in `--force`: we can just focus on the rule for pushing for a branch (which is likely the one that's most relevant) and leave the details about what happens when you push to a tag or a ref that isn't a branch to the later section. Signed-off-by: Julia Evans <julia@jvns.ca> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2025-09-24packfile: refactor `get_packed_git_mru()` to work on packfile storePatrick Steinhardt3-7/+10
The `get_packed_git_mru()` function prepares the packfile store and then returns its packfiles in most-recently-used order. Refactor it to accept a packfile store instead of a repository to clarify its scope. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2025-09-24packfile: refactor `get_all_packs()` to work on packfile storePatrick Steinhardt18-42/+76
The `get_all_packs()` function prepares the packfile store and then returns its packfiles. Refactor it to accept a packfile store instead of a repository to clarify its scope. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2025-09-24packfile: refactor `get_packed_git()` to work on packfile storePatrick Steinhardt5-8/+13
The `get_packed_git()` function prepares the packfile store and then returns its packfiles. Refactor it to accept a packfile store instead of a repository to clarify its scope. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2025-09-24packfile: move `get_multi_pack_index()` into "midx.c"Patrick Steinhardt4-8/+17
The `get_multi_pack_index()` function is declared and implemented in the packfile subsystem, even though it really belongs into the multi-pack index subsystem. The reason for this is likely that it needs to call `packfile_store_prepare()`, which is not exposed by the packfile system. In a subsequent commit we're about to add another caller outside of the packfile system though, so we'll have to expose the function anyway. Do so now already and move `get_multi_pack_index()` into the MIDX subsystem. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2025-09-24packfile: introduce function to load and add packfilesPatrick Steinhardt5-41/+48
We have a recurring pattern where we essentially perform an upsert of a packfile in case it isn't yet known by the packfile store. The logic to do so is non-trivial as we have to reconstruct the packfile's key, check the map of packfiles, then create the new packfile and finally add it to the store. Introduce a new function that does this dance for us. Refactor callsites to use it. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2025-09-24packfile: refactor `install_packed_git()` to work on packfile storePatrick Steinhardt7-12/+18
The `install_packed_git()` functions adds a packfile to a specific object store. Refactor it to accept a packfile store instead of a repository to clarify its scope. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2025-09-24packfile: split up responsibilities of `reprepare_packed_git()`Patrick Steinhardt13-35/+55
In `reprepare_packed_git()` we perform a couple of operations: - We reload alternate object directories. - We clear the loose object cache. - We reprepare packfiles. While the logic is hosted in "packfile.c", it clearly reaches into other subsystems that aren't related to packfiles. Split up the responsibility and introduce `odb_reprepare()` which now becomes responsible for repreparing the whole object database. The existing `reprepare_packed_git()` function is refactored accordingly and only cares about reloading the packfile store now. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2025-09-24packfile: refactor `prepare_packed_git()` to work on packfile storePatrick Steinhardt1-23/+18
The `prepare_packed_git()` function and its friends are responsible for loading packfiles as well as the multi-pack index for a given object database. Refactor these functions to accept a packfile store instead of a repository to clarify their scope. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2025-09-24packfile: reorder functions to avoid function declarationPatrick Steinhardt1-34/+33
Reorder functions so that we can avoid a forward declaration of `prepare_packed_git()`. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2025-09-24odb: move kept cache into `struct packfile_store`Patrick Steinhardt3-17/+23
The object database tracks a cache of "kept" packfiles, which is used by git-pack-objects(1) to handle cruft objects. With the introduction of the `struct packfile_store` we have a better place to host this cache though. Move the cache accordingly. This moves the last bit of packfile-related state from the object database into the packfile store. Adapt the comment for the `packfiles` pointer in `struct object_database` to reflect this. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2025-09-24odb: move MRU list of packfiles into `struct packfile_store`Patrick Steinhardt5-12/+10
The object database tracks the list of packfiles in most-recently-used order, which is mostly used to favor reading from packfiles that contain most of the objects that we're currently accessing. With the introduction of the `struct packfile_store` we have a better place to host this list though. Move the list accordingly. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2025-09-24odb: move packfile map into `struct packfile_store`Patrick Steinhardt5-26/+26
The object database tracks a map of packfiles by their respective paths, which is used to figure out whether a given packfile has already been loaded. With the introduction of the `struct packfile_store` we have a better place to host this list though. Move the map accordingly. `pack_map_entry_cmp()` isn't used anywhere but in "packfile.c" anymore after this change, so we convert it to a static function, as well. Note that we also drop the `inline` hint: the function is used as a callback function exclusively, and callbacks cannot be inlined. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2025-09-24odb: move initialization bit into `struct packfile_store`Patrick Steinhardt3-9/+9
The object database knows to skip re-initializing the list of packfiles in case it's already been initialized. Whether or not that is the case is tracked via a separate `initialized` bit that is stored in the object database. With the introduction of the `struct packfile_store` we have a better place to host this bit though. Move it accordingly. While at it, convert the field into a boolean now that we're allowed to use them in our code base. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2025-09-24odb: move list of packfiles into `struct packfile_store`Patrick Steinhardt4-29/+41
The object database tracks the list of packfiles it currently knows about. With the introduction of the `struct packfile_store` we have a better place to host this list though. Move the list accordingly. Extract the logic from `odb_clear()` that knows to close all such packfiles and move it into the new subsystem, as well. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2025-09-24packfile: introduce a new `struct packfile_store`Patrick Steinhardt4-1/+34
Information about an object database's packfiles is currently distributed across two different structures: - `struct packed_git` contains the `next` pointer as well as the `mru_head`, both of which serve to store the list of packfiles. - `struct object_database` contains several fields that relate to the packfiles. So we don't really have a central data structure that tracks our packfiles, and consequently responsibilities aren't always clear cut. A consequence for the upcoming pluggable object databases is that this makes it very hard to move management of packfiles from the object database level down into the object database source. Introduce a new `struct packfile_store` which is about to become the single source of truth for managing packfiles. Right now this data structure doesn't yet contain anything, but in subsequent patches we will move all data structures that relate to packfiles and that are currently contained in `struct object_database` into this new home. Note that this is only a first step: most importantly, we won't (yet) move the `struct packed_git::next` pointer around. This will happen in a subsequent patch series though so that `struct packed_git` will really only host information about the specific packfile it represents. Further note that the new structure still sits at the wrong level at the end of this patch series: as mentioned, it should eventually sit at the level of the object database source, not at the object database level. But introducing the packfile store now already makes it way easier to eventually push down the now-selfcontained data structure by one level. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2025-09-23The twelfth batchJunio C Hamano1-0/+13
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2025-09-22revision: retain argv NULL invariant in setup_revisions()Jeff King1-0/+6
In an argc/argv pair, the entry for argv[argc] is generally NULL. You can iterate by counting up to argc, or by looking for the NULL entry in argv. When we pass such a pair to setup_revisions(), it shrinks argc to account for the options we consumed and returns the result to the caller. But it doesn't touch the entries after the reduced argc. So argv[argc] will be left pointing at some arbitrary entry rather than NULL. This isn't the source of any known bugs, since all callers are aware of the limitation and act accordingly. But it's a possible gotcha that may be easy to miss. Let's set the new argv[argc] to NULL, taking care to free it if the caller asked us to do so. It is tempting to do likewise for all of the entries afterwards, too, as some of them may also need to be freed (e.g., if coming from a strvec). But doing so isn't entirely trivial, as we munge argc in the function (e.g., when we find "--" and move all of the entries after it into the prune_data list). It would be possible with some light refactoring, but it's probably not worth it. Nobody should ever look at them (they are beyond the revised argc and past the NULL argv entry) outside of strvec cleanup, and setup_revisions_from_strvec() already handles this case. There's one other interesting gotcha: many callers which do not want to provide arguments just pass 0/NULL for argc/argv. We need to check for this case before assigning the final NULL. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2025-09-22treewide: pass strvecs around for setup_revisions_from_strvec()Jeff King7-18/+18
The previous commit converted callers of setup_revisions() with a strvec to use the safer and easier _from_strvec() variant. Let's now convert spots that don't directly have a strvec, but receive an argc/argv pair that eventually comes from one. We'll instead pass the strvec down to the point where we call setup_revisions(). That makes these functions slightly less flexible if they were to grow other callers that don't use strvecs, but this rigidity is buying us some safety. It is only safe to pass the free_removed_argv_elements option to setup_revisions() if we know the elements of argv/argc are allocated on the heap. That isn't communicated in the type system when we are passed the bare elements. But if we get a strvec, we know that the elements are allocated strings. And at any rate, each of these modified functions has only a single caller (that has a strvec), so the loss of flexibility is unlikely to ever matter. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>