Compare
53d330c360227e66298e0f4dba2ce6b6a3a36c37..48fc56621cbea18dd0f23a87af90b7a930d1e1d2
Merge branch 'ps/odb-generic-corrupt-objects' into en/midx-missing-pack-fallback
* ps/odb-generic-corrupt-objects: odb: handle `OBJECT_INFO_DIE_IF_CORRUPT` generically odb/source: allow `read_object_info()` to bubble up error messages odb/source: let callers discern missing and corrupt objects odb/source: introduce error status when reading objects odb/source-packed: flag known-bad objects as corrupt and not missing
Junio C Hamano <gitster@pobox.com> · 2026-08-25 20:49 UTC
36 files changed,
+387
−1304
- Documentation/RelNotes/2.56.0.adoc
- Documentation/config/branch.adoc
- Documentation/git-branch.adoc
- Documentation/git-interpret-trailers.adoc
- builtin/branch.c
- builtin/pack-objects.c
- loose.c
- loose.h
- midx.c
- midx.h
- odb.c
- odb.h
- odb/source-files.c
- odb/source-files.h
- odb/source-inmemory.c
- odb/source-inmemory.h
- odb/source-loose.c
- odb/source-loose.h
- odb/source-packed.c
- odb/source-packed.h
- odb/source.c
- odb/source.h
- packfile.c
- packfile.h
- ref-filter.c
- ref-filter.h
- repository.c
- setup.c
- setup.h
- t/helper/test-read-midx.c
- t/t1016-compatObjectFormat.sh
- t/t1060-object-corruption.sh
- t/t2406-worktree-repair.sh
- t/t3200-branch.sh
- t/unit-tests/u-odb-inmemory.c
- worktree.c
modified Documentation/RelNotes/2.56.0.adoc
| @@ -101,10 +101,6 @@ UI, Workflows & Features | |||
| 101 | 101 | automatically run 'git bisect reset' to jump back to the original | |
| 102 | 102 | state or to the found culprit. | |
| 103 | 103 | ||
| 104 | - | * The 'git branch' command has been taught the '--delete-merged' option | |
| 105 | - | to remove local branches that are already merged into their tracked | |
| 106 | - | remote-tracking branches. | |
| 107 | - | ||
| 108 | 104 | ||
| 109 | 105 | Performance, Internal Implementation, Development Support etc. | |
| 110 | 106 | -------------------------------------------------------------- | |
| @@ -375,12 +371,6 @@ Performance, Internal Implementation, Development Support etc. | |||
| 375 | 371 | Calls to write(3p) in send_sideband() and cat_blob() have been | |
| 376 | 372 | refactored to use writev(3p) wrappers to reduce syscall overhead. | |
| 377 | 373 | ||
| 378 | - | * The creation of the on-disk data structures for the object database | |
| 379 | - | has been made pluggable, allowing future backends to customize their | |
| 380 | - | setup. As part of this, the initialization of the object database | |
| 381 | - | has been deferred, and the loading of the loose-object map has been | |
| 382 | - | detangled from repository initialization. | |
| 383 | - | ||
| 384 | 374 | ||
| 385 | 375 | Fixes since v2.55 | |
| 386 | 376 | ----------------- | |
| @@ -606,9 +596,3 @@ Fixes since v2.55 | |||
| 606 | 596 | * Documentation for 'git replay' has been updated to refer to its | |
| 607 | 597 | configuration variables. | |
| 608 | 598 | (merge 48c0549f5c kh/doc-replay-config later to maint). | |
| 609 | - | ||
| 610 | - | * Documentation for 'git interpret-trailers' has been updated to explain | |
| 611 | - | the format of trailer keys (alphanumeric characters and hyphens), | |
| 612 | - | replace outdated terminology, define key terms upfront, and document | |
| 613 | - | how comment lines in the input are treated. | |
| 614 | - | (merge 4515c86fd9 kh/doc-trailers later to maint). | |
modified Documentation/config/branch.adoc
| @@ -103,10 +103,3 @@ for details). | |||
| 103 | 103 | `git branch --edit-description`. Branch description is | |
| 104 | 104 | automatically added to the `format-patch` cover letter or | |
| 105 | 105 | `request-pull` summary. | |
| 106 | - | ||
| 107 | - | `branch.<name>.deleteMerged`:: | |
| 108 | - | If set to `false`, branch _<name>_ is exempt from | |
| 109 | - | `git branch --delete-merged`. Useful for a topic branch you | |
| 110 | - | intend to develop further after an initial round has been | |
| 111 | - | merged upstream. Defaults to true. Explicit deletion via | |
| 112 | - | `git branch -d` is unaffected. | |
modified Documentation/git-branch.adoc
| @@ -13,7 +13,6 @@ git branch [--color[=<when>] | --no-color] [--show-current] | |||
| 13 | 13 | [--column[=<options>] | --no-column] [--sort=<key>] | |
| 14 | 14 | [--merged [<commit>]] [--no-merged [<commit>]] | |
| 15 | 15 | [--contains [<commit>]] [--no-contains [<commit>]] | |
| 16 | - | [(--forked <branch>)...] | |
| 17 | 16 | [--points-at <object>] [--format=<format>] | |
| 18 | 17 | [(-r|--remotes) | (-a|--all)] | |
| 19 | 18 | [--list] [<pattern>...] | |
| @@ -25,7 +24,6 @@ git branch (-m|-M) [<old-branch>] <new-branch> | |||
| 25 | 24 | git branch (-c|-C) [<old-branch>] <new-branch> | |
| 26 | 25 | git branch (-d|-D) [-r] <branch-name>... | |
| 27 | 26 | git branch --edit-description [<branch-name>] | |
| 28 | - | git branch [--dry-run] (--delete-merged <pattern>)... [<branch-pattern>...] | |
| 29 | 27 | ||
| 30 | 28 | DESCRIPTION | |
| 31 | 29 | ----------- | |
| @@ -53,8 +51,7 @@ merged into the named commit (i.e. the branches whose tip commits are | |||
| 53 | 51 | reachable from the named commit) will be listed. With `--no-merged` only | |
| 54 | 52 | branches not merged into the named commit will be listed. If the _<commit>_ | |
| 55 | 53 | argument is missing it defaults to `HEAD` (i.e. the tip of the current | |
| 56 | - | branch). With `--forked`, only branches whose configured upstream matches | |
| 57 | - | the given branch or pattern will be listed. | |
| 54 | + | branch). | |
| 58 | 55 | ||
| 59 | 56 | The command's second form creates a new branch head named _<branch-name>_ | |
| 60 | 57 | which points to the current `HEAD`, or _<start-point>_ if given. As a | |
| @@ -202,45 +199,6 @@ This option is only applicable in non-verbose mode. | |||
| 202 | 199 | Print the name of the current branch. In detached `HEAD` state, | |
| 203 | 200 | nothing is printed. | |
| 204 | 201 | ||
| 205 | - | `--delete-merged <pattern>`:: | |
| 206 | - | Delete local branches whose configured upstream matches | |
| 207 | - | _<pattern>_, but only when their tip is reachable from that | |
| 208 | - | upstream. In other words, the work on the branch has already | |
| 209 | - | landed on the upstream it tracks, so the local copy is no longer | |
| 210 | - | needed. _<pattern>_ may name a ref, a remote (using the branch its | |
| 211 | - | `HEAD` points at), or a shell-style glob. The option can be | |
| 212 | - | repeated to widen the upstream match. | |
| 213 | - | Optional _<branch-pattern>_ arguments limit which local branches | |
| 214 | - | are considered, e.g. `git branch --delete-merged 'origin/*' | |
| 215 | - | 'topic-*'`. | |
| 216 | - | + | |
| 217 | - | A branch is not deleted when: | |
| 218 | - | + | |
| 219 | - | -- | |
| 220 | - | * its configured upstream ref no longer exists, | |
| 221 | - | * it is checked out in any worktree, | |
| 222 | - | * pushing it to the remote configured by | |
| 223 | - | `branch.<name>.remote` would update its upstream, so it cannot be | |
| 224 | - | distinguished from a branch that just looks fully merged right | |
| 225 | - | after a pull; this is determined by the remote's configured push and | |
| 226 | - | fetch refspecs, | |
| 227 | - | * it is the local upstream of a branch that is not being deleted, or | |
| 228 | - | * `branch.<name>.deleteMerged` is set to `false`. | |
| 229 | - | -- | |
| 230 | - | + | |
| 231 | - | When such a local upstream branch has its own upstream deleted by the | |
| 232 | - | same operation, its upstream configuration is cleared. | |
| 233 | - | + | |
| 234 | - | A branch whose work has not yet been merged into its upstream is | |
| 235 | - | silently skipped. Delete it with `git branch -D` if you want to | |
| 236 | - | remove it anyway. | |
| 237 | - | ||
| 238 | - | `--dry-run`:: | |
| 239 | - | With `--delete-merged`, print which branches would be | |
| 240 | - | deleted and exit without touching any ref. Useful for | |
| 241 | - | sanity-checking a wide pattern like `'origin/*'` before | |
| 242 | - | committing to the deletion. | |
| 243 | - | ||
| 244 | 202 | `-v`:: | |
| 245 | 203 | `-vv`:: | |
| 246 | 204 | `--verbose`:: | |
| @@ -353,14 +311,6 @@ superproject's "origin/main", but tracks the submodule's "origin/main". | |||
| 353 | 311 | Only list branches whose tips are not reachable from | |
| 354 | 312 | _<commit>_ (`HEAD` if not specified). Implies `--list`. | |
| 355 | 313 | ||
| 356 | - | `--forked <branch>`:: | |
| 357 | - | Only list branches whose configured upstream matches | |
| 358 | - | _<branch>_. The argument can be a ref (e.g. `origin/main`, | |
| 359 | - | `master`), a remote name like `origin` for the branch its | |
| 360 | - | `origin/HEAD` points at, or a shell-style glob (e.g. | |
| 361 | - | `'origin/*'`). The option can be repeated to widen the | |
| 362 | - | filter. Implies `--list`. | |
| 363 | - | ||
| 364 | 314 | `--points-at <object>`:: | |
| 365 | 315 | Only list branches of _<object>_. | |
| 366 | 316 | ||
modified Documentation/git-interpret-trailers.adoc
| @@ -3,7 +3,7 @@ git-interpret-trailers(1) | |||
| 3 | 3 | ||
| 4 | 4 | NAME | |
| 5 | 5 | ---- | |
| 6 | - | git-interpret-trailers - Add or parse metadata in commit messages | |
| 6 | + | git-interpret-trailers - Add or parse structured information in commit messages | |
| 7 | 7 | ||
| 8 | 8 | SYNOPSIS | |
| 9 | 9 | -------- | |
| @@ -14,15 +14,9 @@ git interpret-trailers [--in-place] [--trim-empty] | |||
| 14 | 14 | ||
| 15 | 15 | DESCRIPTION | |
| 16 | 16 | ----------- | |
| 17 | - | Add or parse trailer metadata at the end of the otherwise | |
| 18 | - | free-form part of a commit message, or any other kind of text. | |
| 19 | - | ||
| 20 | - | A _trailer_ in its simplest form is a key-value pair with a colon as a | |
| 21 | - | separator. The _key_ consists of ASCII alphanumeric characters and | |
| 22 | - | hyphens (`-`). A _trailer block_ consists of one or more trailers. The | |
| 23 | - | trailer block needs to be preceded by a blank line, where a _blank line_ | |
| 24 | - | is either an empty or a whitespace-only line. For example, in the | |
| 25 | - | following commit message | |
| 17 | + | Add or parse _trailer_ lines that look similar to RFC 822 e-mail | |
| 18 | + | headers, at the end of the otherwise free-form part of a commit | |
| 19 | + | message. For example, in the following commit message | |
| 26 | 20 | ||
| 27 | 21 | ------------------------------------------------ | |
| 28 | 22 | subject | |
| @@ -60,18 +54,10 @@ are applied to each input and the way any existing trailer in | |||
| 60 | 54 | the input is changed. They also make it possible to | |
| 61 | 55 | automatically add some trailers. | |
| 62 | 56 | ||
| 63 | - | Let's consider new trailers added with `--trailer`. | |
| 64 | - | By default, the new trailer will appear at the end of the trailer block. | |
| 65 | - | Also by default, this new trailer will only be added | |
| 66 | - | if the last trailer is different to it. | |
| 67 | - | A trailer block will be created with only that trailer if a trailer | |
| 68 | - | block does not already exist. Recall that a trailer block needs to be | |
| 69 | - | preceded by a blank line, so a blank line will be inserted before the | |
| 70 | - | new trailer block in that case. | |
| 71 | - | ||
| 72 | - | This is how the new trailer is added: a `<key>=<value>` or | |
| 73 | - | `<key>:<value>` argument given using `--trailer` will be appended after | |
| 74 | - | the existing trailers. The _<key>_ and _<value>_ parts will be trimmed | |
| 57 | + | By default, a `<key>=<value>` or `<key>:<value>` argument given | |
| 58 | + | using `--trailer` will be appended after the existing trailers only if | |
| 59 | + | the last trailer has a different (_<key>_, _<value>_) pair (or if there | |
| 60 | + | is no existing trailer). The _<key>_ and _<value>_ parts will be trimmed | |
| 75 | 61 | to remove starting and trailing whitespace, and the resulting trimmed | |
| 76 | 62 | _<key>_ and _<value>_ will appear in the output like this: | |
| 77 | 63 | ||
| @@ -82,16 +68,6 @@ key: value | |||
| 82 | 68 | This means that the trimmed _<key>_ and _<value>_ will be separated by | |
| 83 | 69 | "`:`{nbsp}" (one colon followed by one space). | |
| 84 | 70 | ||
| 85 | - | Existing trailers are extracted from the input by looking for the | |
| 86 | - | trailer block. A trailer block is a group of one or more lines that (i) | |
| 87 | - | is all trailers, or (ii) contains at least one Git-generated or | |
| 88 | - | user-configured trailer and consists of at | |
| 89 | - | least 25% trailers. | |
| 90 | - | The trailer block is by definition at the end of the commit message. | |
| 91 | - | The message in turn is either (i) at the end of the input, or (ii) the | |
| 92 | - | last non-whitespace lines before a line that starts with `---` (followed | |
| 93 | - | by a space or the end of the line). | |
| 94 | - | ||
| 95 | 71 | For convenience, a _<key-alias>_ can be configured to make using `--trailer` | |
| 96 | 72 | shorter to type on the command line. This can be configured using the | |
| 97 | 73 | `trailer.<key-alias>.key` configuration variable. The _<key-alias>_ must be a prefix | |
| @@ -105,6 +81,20 @@ trailer.sign.key "Signed-off-by: " | |||
| 105 | 81 | in your configuration, you only need to specify `--trailer="sign: foo"` | |
| 106 | 82 | on the command line instead of `--trailer="Signed-off-by: foo"`. | |
| 107 | 83 | ||
| 84 | + | By default the new trailer will appear at the end of all the existing | |
| 85 | + | trailers. If there is no existing trailer, the new trailer will appear | |
| 86 | + | at the end of the input. A blank line will be added before the new | |
| 87 | + | trailer if there isn't one already. | |
| 88 | + | ||
| 89 | + | Existing trailers are extracted from the input by looking for | |
| 90 | + | a group of one or more lines that (i) is all trailers, or (ii) contains at | |
| 91 | + | least one Git-generated or user-configured trailer and consists of at | |
| 92 | + | least 25% trailers. | |
| 93 | + | The group must be preceded by one or more empty (or whitespace-only) lines. | |
| 94 | + | The group must either be at the end of the input or be the last | |
| 95 | + | non-whitespace lines before a line that starts with `---` (followed by a | |
| 96 | + | space or the end of the line). | |
| 97 | + | ||
| 108 | 98 | When reading trailers, there can be no whitespace before or inside the | |
| 109 | 99 | _<key>_, but any number of regular space and tab characters are allowed | |
| 110 | 100 | between the _<key>_ and the separator. There can be whitespaces before, | |
| @@ -117,15 +107,8 @@ key: This is a very long value, with spaces and | |||
| 117 | 107 | newlines in it. | |
| 118 | 108 | ------------------------------------------------ | |
| 119 | 109 | ||
| 120 | - | OTHER RULES | |
| 121 | - | ----------- | |
| 122 | - | ||
| 123 | - | What was covered in the previous section are the rules that are relevant | |
| 124 | - | for regular use. The following points are included for completeness. | |
| 125 | - | ||
| 126 | - | This command ignores comment lines (see `core.commentString` in | |
| 127 | - | linkgit:git-config[1]). This is for use with the `prepare-commit-msg` | |
| 128 | - | and `commit-msg` hooks. | |
| 110 | + | Note that trailers do not follow (nor are they intended to follow) many of the | |
| 111 | + | rules for RFC 822 headers. For example they do not follow the encoding rule. | |
| 129 | 112 | ||
| 130 | 113 | OPTIONS | |
| 131 | 114 | ------- | |
| @@ -419,29 +402,6 @@ mv "\$1.new" "\$1" | |||
| 419 | 402 | $ chmod +x .git/hooks/commit-msg | |
| 420 | 403 | ------------ | |
| 421 | 404 | ||
| 422 | - | * Here we try to use three different trailer keys. But it fails because | |
| 423 | - | two of them are not recognized as trailer keys. | |
| 424 | - | + | |
| 425 | - | ---- | |
| 426 | - | $ cat msg.txt | |
| 427 | - | subject | |
| 428 | - | ||
| 429 | - | Skapad-på: some-branch | |
| 430 | - | Hash-in-v6.11: 45c12d3269fe48f22834320c782ffe86c3560f2c | |
| 431 | - | Reviewed-by: Alice <alice@example.com> | |
| 432 | - | $ git interpret-trailers --only-trailers <msg.txt | |
| 433 | - | $ | |
| 434 | - | ---- | |
| 435 | - | + | |
| 436 | - | Recall that a trailer key has to consist of only ASCII alphanumeric | |
| 437 | - | characters and hyphens, and this does not hold for the two first | |
| 438 | - | supposed trailer keys. And now none are recognized as trailers because | |
| 439 | - | the candidate trailer block has at least one non-trailer line, even | |
| 440 | - | though `Reviewed-by` is a valid trailer key. Recall that a trailer block | |
| 441 | - | has to either (i) be all trailers, or (ii) consist of at least one | |
| 442 | - | Git-generated or user-configured trailer (and some other conditions). | |
| 443 | - | And (ii) is not satisfied since we have not configured any trailer keys. | |
| 444 | - | ||
| 445 | 405 | SEE ALSO | |
| 446 | 406 | -------- | |
| 447 | 407 | linkgit:git-commit[1], linkgit:git-format-patch[1], linkgit:git-config[1] | |
modified builtin/branch.c
| @@ -21,7 +21,6 @@ | |||
| 21 | 21 | #include "branch.h" | |
| 22 | 22 | #include "path.h" | |
| 23 | 23 | #include "string-list.h" | |
| 24 | - | #include "strmap.h" | |
| 25 | 24 | #include "column.h" | |
| 26 | 25 | #include "utf8.h" | |
| 27 | 26 | #include "ref-filter.h" | |
| @@ -31,7 +30,7 @@ | |||
| 31 | 30 | #include "commit-reach.h" | |
| 32 | 31 | ||
| 33 | 32 | static const char * const builtin_branch_usage[] = { | |
| 34 | - | N_("git branch [<options>] [-r | -a] [--merged] [--no-merged] [(--forked <branch>)...]"), | |
| 33 | + | N_("git branch [<options>] [-r | -a] [--merged] [--no-merged]"), | |
| 35 | 34 | N_("git branch [<options>] [-f] [--recurse-submodules] <branch-name> [<start-point>]"), | |
| 36 | 35 | N_("git branch [<options>] [-l] [<pattern>...]"), | |
| 37 | 36 | N_("git branch [<options>] [-r] (-d | -D) <branch-name>..."), | |
| @@ -39,8 +38,6 @@ static const char * const builtin_branch_usage[] = { | |||
| 39 | 38 | N_("git branch [<options>] (-c | -C) [<old-branch>] <new-branch>"), | |
| 40 | 39 | N_("git branch [<options>] [-r | -a] [--points-at]"), | |
| 41 | 40 | N_("git branch [<options>] [-r | -a] [--format]"), | |
| 42 | - | N_("git branch [<options>] (--delete-merged <pattern>)... " | |
| 43 | - | "[<branch-pattern>...]"), | |
| 44 | 41 | NULL | |
| 45 | 42 | }; | |
| 46 | 43 | ||
| @@ -171,13 +168,10 @@ static int branch_merged(int kind, const char *name, | |||
| 171 | 168 | * upstream, if any, otherwise with HEAD", we should just | |
| 172 | 169 | * return the result of the repo_in_merge_bases() above without | |
| 173 | 170 | * any of the following code, but during the transition period, | |
| 174 | - | * a gentle reminder is in order. Callers that opt out of the | |
| 175 | - | * HEAD fallback by passing head_rev=NULL are not interested in | |
| 176 | - | * the reminder either: they have already established that the | |
| 177 | - | * branch has an upstream, so HEAD is irrelevant to the decision. | |
| 171 | + | * a gentle reminder is in order. | |
| 178 | 172 | */ | |
| 179 | - | if (head_rev && head_rev != reference_rev) { | |
| 180 | - | int expect = repo_in_merge_bases(the_repository, rev, head_rev); | |
| 173 | + | if (head_rev != reference_rev) { | |
| 174 | + | int expect = head_rev ? repo_in_merge_bases(the_repository, rev, head_rev) : 0; | |
| 181 | 175 | if (expect < 0) | |
| 182 | 176 | exit(128); | |
| 183 | 177 | if (expect == merged) | |
| @@ -195,32 +189,20 @@ static int branch_merged(int kind, const char *name, | |||
| 195 | 189 | return merged; | |
| 196 | 190 | } | |
| 197 | 191 | ||
| 198 | - | enum delete_branch_flags { | |
| 199 | - | DELETE_BRANCH_FORCE = (1 << 0), | |
| 200 | - | DELETE_BRANCH_QUIET = (1 << 1), | |
| 201 | - | DELETE_BRANCH_SKIP_UNMERGED = (1 << 2), | |
| 202 | - | DELETE_BRANCH_NO_HEAD_FALLBACK = (1 << 3), | |
| 203 | - | DELETE_BRANCH_DRY_RUN = (1 << 4), | |
| 204 | - | }; | |
| 205 | - | ||
| 206 | 192 | static int check_branch_commit(const char *branchname, const char *refname, | |
| 207 | 193 | const struct object_id *oid, struct commit *head_rev, | |
| 208 | - | int kinds, unsigned int flags) | |
| 194 | + | int kinds, int force) | |
| 209 | 195 | { | |
| 210 | 196 | struct commit *rev = lookup_commit_reference(the_repository, oid); | |
| 211 | - | if (!(flags & DELETE_BRANCH_FORCE) && !rev) { | |
| 197 | + | if (!force && !rev) { | |
| 212 | 198 | error(_("couldn't look up commit object for '%s'"), refname); | |
| 213 | 199 | return -1; | |
| 214 | 200 | } | |
| 215 | - | if (!(flags & DELETE_BRANCH_FORCE) && | |
| 216 | - | !branch_merged(kinds, branchname, rev, head_rev)) { | |
| 217 | - | if (!(flags & DELETE_BRANCH_SKIP_UNMERGED)) { | |
| 218 | - | error(_("the branch '%s' is not fully merged"), | |
| 219 | - | branchname); | |
| 220 | - | advise_if_enabled(ADVICE_FORCE_DELETE_BRANCH, | |
| 221 | - | _("If you are sure you want to delete it, " | |
| 222 | - | "run 'git branch -D %s'"), branchname); | |
| 223 | - | } | |
| 201 | + | if (!force && !branch_merged(kinds, branchname, rev, head_rev)) { | |
| 202 | + | error(_("the branch '%s' is not fully merged"), branchname); | |
| 203 | + | advise_if_enabled(ADVICE_FORCE_DELETE_BRANCH, | |
| 204 | + | _("If you are sure you want to delete it, " | |
| 205 | + | "run 'git branch -D %s'"), branchname); | |
| 224 | 206 | return -1; | |
| 225 | 207 | } | |
| 226 | 208 | return 0; | |
| @@ -235,8 +217,8 @@ static void delete_branch_config(const char *branchname) | |||
| 235 | 217 | strbuf_release(&buf); | |
| 236 | 218 | } | |
| 237 | 219 | ||
| 238 | - | static int delete_branches(int argc, const char **argv, int kinds, | |
| 239 | - | unsigned int flags) | |
| 220 | + | static int delete_branches(int argc, const char **argv, int force, int kinds, | |
| 221 | + | int quiet) | |
| 240 | 222 | { | |
| 241 | 223 | struct commit *head_rev = NULL; | |
| 242 | 224 | struct object_id oid; | |
| @@ -259,7 +241,7 @@ static int delete_branches(int argc, const char **argv, int kinds, | |||
| 259 | 241 | remote_branch = 1; | |
| 260 | 242 | allowed_interpret = INTERPRET_BRANCH_REMOTE; | |
| 261 | 243 | ||
| 262 | - | flags |= DELETE_BRANCH_FORCE; | |
| 244 | + | force = 1; | |
| 263 | 245 | break; | |
| 264 | 246 | case FILTER_REFS_BRANCHES: | |
| 265 | 247 | fmt = "refs/heads/%s"; | |
| @@ -270,13 +252,12 @@ static int delete_branches(int argc, const char **argv, int kinds, | |||
| 270 | 252 | } | |
| 271 | 253 | branch_name_pos = strcspn(fmt, "%"); | |
| 272 | 254 | ||
| 273 | - | if (!(flags & DELETE_BRANCH_FORCE) && | |
| 274 | - | !(flags & DELETE_BRANCH_NO_HEAD_FALLBACK)) | |
| 255 | + | if (!force) | |
| 275 | 256 | head_rev = lookup_commit_reference(the_repository, &head_oid); | |
| 276 | 257 | ||
| 277 | 258 | for (i = 0; i < argc; i++, strbuf_reset(&bname)) { | |
| 278 | 259 | char *target = NULL; | |
| 279 | - | int ref_flags = 0; | |
| 260 | + | int flags = 0; | |
| 280 | 261 | ||
| 281 | 262 | copy_branchname(the_repository, &bname, | |
| 282 | 263 | argv[i], allowed_interpret); | |
| @@ -306,7 +287,7 @@ static int delete_branches(int argc, const char **argv, int kinds, | |||
| 306 | 287 | RESOLVE_REF_READING | |
| 307 | 288 | | RESOLVE_REF_NO_RECURSE | |
| 308 | 289 | | RESOLVE_REF_ALLOW_BAD_NAME, | |
| 309 | - | &oid, &ref_flags); | |
| 290 | + | &oid, &flags); | |
| 310 | 291 | if (!target) { | |
| 311 | 292 | if (remote_branch) { | |
| 312 | 293 | error(_("remote-tracking branch '%s' not found"), bname.buf); | |
| @@ -318,7 +299,7 @@ static int delete_branches(int argc, const char **argv, int kinds, | |||
| 318 | 299 | | RESOLVE_REF_NO_RECURSE | |
| 319 | 300 | | RESOLVE_REF_ALLOW_BAD_NAME, | |
| 320 | 301 | &oid, | |
| 321 | - | &ref_flags); | |
| 302 | + | &flags); | |
| 322 | 303 | FREE_AND_NULL(virtual_name); | |
| 323 | 304 | ||
| 324 | 305 | if (virtual_target) | |
| @@ -333,39 +314,31 @@ static int delete_branches(int argc, const char **argv, int kinds, | |||
| 333 | 314 | continue; | |
| 334 | 315 | } | |
| 335 | 316 | ||
| 336 | - | if (!(ref_flags & (REF_ISSYMREF|REF_ISBROKEN)) && | |
| 317 | + | if (!(flags & (REF_ISSYMREF|REF_ISBROKEN)) && | |
| 337 | 318 | check_branch_commit(bname.buf, name, &oid, head_rev, kinds, | |
| 338 | - | flags)) { | |
| 339 | - | if (!(flags & DELETE_BRANCH_SKIP_UNMERGED)) | |
| 340 | - | ret = 1; | |
| 319 | + | force)) { | |
| 320 | + | ret = 1; | |
| 341 | 321 | goto next; | |
| 342 | 322 | } | |
| 343 | 323 | ||
| 344 | 324 | item = string_list_append(&refs_to_delete, name); | |
| 345 | - | item->util = xstrdup((ref_flags & REF_ISBROKEN) ? "broken" | |
| 346 | - | : (ref_flags & REF_ISSYMREF) ? target | |
| 325 | + | item->util = xstrdup((flags & REF_ISBROKEN) ? "broken" | |
| 326 | + | : (flags & REF_ISSYMREF) ? target | |
| 347 | 327 | : repo_find_unique_abbrev(the_repository, &oid, DEFAULT_ABBREV)); | |
| 348 | 328 | ||
| 349 | 329 | next: | |
| 350 | 330 | free(target); | |
| 351 | 331 | } | |
| 352 | 332 | ||
| 353 | - | if (!(flags & DELETE_BRANCH_DRY_RUN) && | |
| 354 | - | refs_delete_refs(get_main_ref_store(the_repository), NULL, &refs_to_delete, REF_NO_DEREF)) | |
| 333 | + | if (refs_delete_refs(get_main_ref_store(the_repository), NULL, &refs_to_delete, REF_NO_DEREF)) | |
| 355 | 334 | ret = 1; | |
| 356 | 335 | ||
| 357 | 336 | for_each_string_list_item(item, &refs_to_delete) { | |
| 358 | 337 | char *describe_ref = item->util; | |
| 359 | 338 | char *name = item->string; | |
| 360 | - | if (flags & DELETE_BRANCH_DRY_RUN) { | |
| 361 | - | if (!(flags & DELETE_BRANCH_QUIET)) | |
| 362 | - | printf(remote_branch | |
| 363 | - | ? _("Would delete remote-tracking branch %s (was %s).\n") | |
| 364 | - | : _("Would delete branch %s (was %s).\n"), | |
| 365 | - | name + branch_name_pos, describe_ref); | |
| 366 | - | } else if (!refs_ref_exists(get_main_ref_store(the_repository), name)) { | |
| 339 | + | if (!refs_ref_exists(get_main_ref_store(the_repository), name)) { | |
| 367 | 340 | char *refname = name + branch_name_pos; | |
| 368 | - | if (!(flags & DELETE_BRANCH_QUIET)) | |
| 341 | + | if (!quiet) | |
| 369 | 342 | printf(remote_branch | |
| 370 | 343 | ? _("Deleted remote-tracking branch %s (was %s).\n") | |
| 371 | 344 | : _("Deleted branch %s (was %s).\n"), | |
| @@ -708,208 +681,6 @@ static void copy_or_rename_branch(const char *oldname, const char *newname, int | |||
| 708 | 681 | free_worktrees(worktrees); | |
| 709 | 682 | } | |
| 710 | 683 | ||
| 711 | - | static int parse_opt_forked(const struct option *opt, const char *arg, int unset) | |
| 712 | - | { | |
| 713 | - | struct ref_filter *filter = opt->value; | |
| 714 | - | ||
| 715 | - | BUG_ON_OPT_NEG(unset); | |
| 716 | - | if (ref_filter_forked_add(filter, arg) < 0) | |
| 717 | - | die(_("'%s' is not a valid branch or pattern"), arg); | |
| 718 | - | return 0; | |
| 719 | - | } | |
| 720 | - | ||
| 721 | - | struct stacked_branch_data { | |
| 722 | - | struct strset *deletable_branch_names; | |
| 723 | - | struct strset *protected_branch_names; | |
| 724 | - | }; | |
| 725 | - | ||
| 726 | - | static int collect_stacked_branch_base(const struct reference *ref, | |
| 727 | - | void *cb_data) | |
| 728 | - | { | |
| 729 | - | struct stacked_branch_data *data = cb_data; | |
| 730 | - | const char *branch_name; | |
| 731 | - | struct branch *branch; | |
| 732 | - | const char *upstream_refname; | |
| 733 | - | const char *upstream_branch_name; | |
| 734 | - | ||
| 735 | - | if (!skip_prefix(ref->name, "refs/heads/", &branch_name)) | |
| 736 | - | BUG("expected local branch ref, got '%s'", ref->name); | |
| 737 | - | if (strset_contains(data->deletable_branch_names, branch_name)) | |
| 738 | - | return 0; | |
| 739 | - | ||
| 740 | - | branch = branch_get(branch_name); | |
| 741 | - | upstream_refname = branch_get_upstream(branch, NULL); | |
| 742 | - | if (!upstream_refname || | |
| 743 | - | !skip_prefix(upstream_refname, "refs/heads/", | |
| 744 | - | &upstream_branch_name) || | |
| 745 | - | !strset_contains(data->deletable_branch_names, | |
| 746 | - | upstream_branch_name)) | |
| 747 | - | return 0; | |
| 748 | - | ||
| 749 | - | strset_add(data->protected_branch_names, upstream_branch_name); | |
| 750 | - | return 0; | |
| 751 | - | } | |
| 752 | - | ||
| 753 | - | static void protect_stacked_branch_bases(struct ref_store *refs, | |
| 754 | - | struct strset *deletable_branch_names, | |
| 755 | - | struct strset *protected_branch_names) | |
| 756 | - | { | |
| 757 | - | struct stacked_branch_data data = { | |
| 758 | - | .deletable_branch_names = deletable_branch_names, | |
| 759 | - | .protected_branch_names = protected_branch_names, | |
| 760 | - | }; | |
| 761 | - | struct refs_for_each_ref_options opts = { | |
| 762 | - | .prefix = "refs/heads/", | |
| 763 | - | }; | |
| 764 | - | struct hashmap_iter iter; | |
| 765 | - | struct strmap_entry *entry; | |
| 766 | - | ||
| 767 | - | refs_for_each_ref_ext(refs, collect_stacked_branch_base, &data, &opts); | |
| 768 | - | ||
| 769 | - | strset_for_each_entry(protected_branch_names, &iter, entry) | |
| 770 | - | strset_remove(deletable_branch_names, entry->key); | |
| 771 | - | } | |
| 772 | - | ||
| 773 | - | static void clear_deleted_upstreams(struct strset *protected_branch_names, | |
| 774 | - | struct strset *deletable_branch_names) | |
| 775 | - | { | |
| 776 | - | struct strbuf key = STRBUF_INIT; | |
| 777 | - | struct hashmap_iter iter; | |
| 778 | - | struct strmap_entry *entry; | |
| 779 | - | ||
| 780 | - | strset_for_each_entry(protected_branch_names, &iter, entry) { | |
| 781 | - | struct branch *branch = branch_get(entry->key); | |
| 782 | - | const char *upstream_refname = branch_get_upstream(branch, NULL); | |
| 783 | - | const char *upstream_branch_name; | |
| 784 | - | ||
| 785 | - | if (!upstream_refname || | |
| 786 | - | !skip_prefix(upstream_refname, "refs/heads/", | |
| 787 | - | &upstream_branch_name) || | |
| 788 | - | !strset_contains(deletable_branch_names, | |
| 789 | - | upstream_branch_name)) | |
| 790 | - | continue; | |
| 791 | - | ||
| 792 | - | strbuf_addf(&key, "branch.%s.merge", branch->name); | |
| 793 | - | repo_config_set_gently(the_repository, key.buf, NULL); | |
| 794 | - | strbuf_reset(&key); | |
| 795 | - | strbuf_addf(&key, "branch.%s.remote", branch->name); | |
| 796 | - | repo_config_set_gently(the_repository, key.buf, NULL); | |
| 797 | - | strbuf_reset(&key); | |
| 798 | - | } | |
| 799 | - | ||
| 800 | - | strbuf_release(&key); | |
| 801 | - | } | |
| 802 | - | ||
| 803 | - | static int branch_pushes_to_upstream(struct branch *branch, | |
| 804 | - | const char *upstream) | |
| 805 | - | { | |
| 806 | - | struct remote *remote = remote_get(remote_for_branch(branch, NULL)); | |
| 807 | - | char *push_refname = NULL; | |
| 808 | - | char *tracking = NULL; | |
| 809 | - | int ret = 0; | |
| 810 | - | ||
| 811 | - | if (!remote) | |
| 812 | - | return 0; | |
| 813 | - | if (remote->push.nr) | |
| 814 | - | push_refname = apply_refspecs(&remote->push, branch->refname); | |
| 815 | - | else | |
| 816 | - | push_refname = xstrdup(branch->refname); | |
| 817 | - | if (push_refname) | |
| 818 | - | tracking = apply_refspecs(&remote->fetch, push_refname); | |
| 819 | - | if (tracking && !strcmp(tracking, upstream)) | |
| 820 | - | ret = 1; | |
| 821 | - | ||
| 822 | - | free(push_refname); | |
| 823 | - | free(tracking); | |
| 824 | - | return ret; | |
| 825 | - | } | |
| 826 | - | ||
| 827 | - | static int delete_merged_branches(const struct strvec *upstreams, | |
| 828 | - | const char **argv, unsigned int flags) | |
| 829 | - | { | |
| 830 | - | struct ref_store *refs = get_main_ref_store(the_repository); | |
| 831 | - | struct ref_filter filter = REF_FILTER_INIT; | |
| 832 | - | struct ref_array candidates = { 0 }; | |
| 833 | - | struct strset deletable_branch_names = STRSET_INIT; | |
| 834 | - | struct strset protected_branch_names = STRSET_INIT; | |
| 835 | - | struct strvec branches_to_delete = STRVEC_INIT; | |
| 836 | - | struct strbuf key = STRBUF_INIT; | |
| 837 | - | struct hashmap_iter iter; | |
| 838 | - | struct strmap_entry *entry; | |
| 839 | - | int ret = 0; | |
| 840 | - | ||
| 841 | - | for (size_t i = 0; i < upstreams->nr; i++) | |
| 842 | - | if (ref_filter_forked_add(&filter, upstreams->v[i]) < 0) | |
| 843 | - | die(_("'%s' is not a valid branch or pattern"), | |
| 844 | - | upstreams->v[i]); | |
| 845 | - | ||
| 846 | - | filter.kind = FILTER_REFS_BRANCHES; | |
| 847 | - | filter.name_patterns = argv; | |
| 848 | - | filter_refs(&candidates, &filter, filter.kind); | |
| 849 | - | ||
| 850 | - | for (int i = 0; i < candidates.nr; i++) { | |
| 851 | - | const char *branch_refname = candidates.items[i]->refname; | |
| 852 | - | const char *branch_name; | |
| 853 | - | struct branch *branch; | |
| 854 | - | const char *upstream_refname; | |
| 855 | - | int opt_out; | |
| 856 | - | ||
| 857 | - | if (!skip_prefix(branch_refname, "refs/heads/", &branch_name)) | |
| 858 | - | BUG("filter returned non-branch ref '%s'", branch_refname); | |
| 859 | - | if (branch_checked_out(branch_refname)) | |
| 860 | - | continue; | |
| 861 | - | ||
| 862 | - | branch = branch_get(branch_name); | |
| 863 | - | upstream_refname = branch_get_upstream(branch, NULL); | |
| 864 | - | if (!upstream_refname || !refs_ref_exists(refs, upstream_refname)) | |
| 865 | - | continue; | |
| 866 | - | if (branch_pushes_to_upstream(branch, upstream_refname)) | |
| 867 | - | continue; | |
| 868 | - | if (check_branch_commit(branch_name, branch_name, | |
| 869 | - | &candidates.items[i]->objectname, NULL, | |
| 870 | - | FILTER_REFS_BRANCHES, DELETE_BRANCH_SKIP_UNMERGED)) | |
| 871 | - | continue; | |
| 872 | - | ||
| 873 | - | strbuf_reset(&key); | |
| 874 | - | strbuf_addf(&key, "branch.%s.deletemerged", branch_name); | |
| 875 | - | if (!repo_config_get_bool(the_repository, key.buf, &opt_out) && | |
| 876 | - | !opt_out) { | |
| 877 | - | if (!(flags & DELETE_BRANCH_QUIET)) | |
| 878 | - | fprintf(stderr, | |
| 879 | - | _("Skipping '%s' (branch.%s.deleteMerged is false)\n"), | |
| 880 | - | branch_name, branch_name); | |
| 881 | - | continue; | |
| 882 | - | } | |
| 883 | - | ||
| 884 | - | strset_add(&deletable_branch_names, branch_name); | |
| 885 | - | } | |
| 886 | - | ||
| 887 | - | protect_stacked_branch_bases(refs, &deletable_branch_names, | |
| 888 | - | &protected_branch_names); | |
| 889 | - | ||
| 890 | - | strset_for_each_entry(&deletable_branch_names, &iter, entry) | |
| 891 | - | strvec_push(&branches_to_delete, entry->key); | |
| 892 | - | ||
| 893 | - | if (branches_to_delete.nr) | |
| 894 | - | ret = delete_branches(branches_to_delete.nr, branches_to_delete.v, | |
| 895 | - | FILTER_REFS_BRANCHES, | |
| 896 | - | DELETE_BRANCH_SKIP_UNMERGED | | |
| 897 | - | DELETE_BRANCH_NO_HEAD_FALLBACK | | |
| 898 | - | flags); | |
| 899 | - | ||
| 900 | - | if (!ret && !(flags & DELETE_BRANCH_DRY_RUN)) | |
| 901 | - | clear_deleted_upstreams(&protected_branch_names, | |
| 902 | - | &deletable_branch_names); | |
| 903 | - | ||
| 904 | - | strbuf_release(&key); | |
| 905 | - | strvec_clear(&branches_to_delete); | |
| 906 | - | strset_clear(&protected_branch_names); | |
| 907 | - | strset_clear(&deletable_branch_names); | |
| 908 | - | ref_array_clear(&candidates); | |
| 909 | - | ref_filter_clear(&filter); | |
| 910 | - | return ret; | |
| 911 | - | } | |
| 912 | - | ||
| 913 | 684 | static GIT_PATH_FUNC(edit_description, "EDIT_DESCRIPTION") | |
| 914 | 685 | ||
| 915 | 686 | static int edit_branch_description(const char *branch_name) | |
| @@ -974,8 +745,6 @@ int cmd_branch(int argc, | |||
| 974 | 745 | /* possible actions */ | |
| 975 | 746 | int delete = 0, rename = 0, copy = 0, list = 0, | |
| 976 | 747 | unset_upstream = 0, show_current = 0, edit_description = 0; | |
| 977 | - | struct strvec delete_merged = STRVEC_INIT; | |
| 978 | - | int dry_run = 0; | |
| 979 | 748 | const char *new_upstream = NULL; | |
| 980 | 749 | int noncreate_actions = 0; | |
| 981 | 750 | /* possible options */ | |
| @@ -1029,17 +798,9 @@ int cmd_branch(int argc, | |||
| 1029 | 798 | OPT_BOOL(0, "create-reflog", &reflog, N_("create the branch's reflog")), | |
| 1030 | 799 | OPT_BOOL(0, "edit-description", &edit_description, | |
| 1031 | 800 | N_("edit the description for the branch")), | |
| 1032 | - | OPT_CALLBACK_F(0, "delete-merged", &delete_merged, N_("pattern"), | |
| 1033 | - | N_("delete merged branches whose upstream matches <pattern> (repeatable)"), | |
| 1034 | - | PARSE_OPT_NONEG, parse_opt_strvec), | |
| 1035 | - | OPT_BOOL(0, "dry-run", &dry_run, | |
| 1036 | - | N_("with --delete-merged, only print which branches would be deleted")), | |
| 1037 | 801 | OPT__FORCE(&force, N_("force creation, move/rename, deletion"), PARSE_OPT_NOCOMPLETE), | |
| 1038 | 802 | OPT_MERGED(&filter, N_("print only branches that are merged")), | |
| 1039 | 803 | OPT_NO_MERGED(&filter, N_("print only branches that are not merged")), | |
| 1040 | - | OPT_CALLBACK_F(0, "forked", &filter, N_("branch"), | |
| 1041 | - | N_("print only branches whose upstream matches <branch> (repeatable)"), | |
| 1042 | - | PARSE_OPT_NONEG, parse_opt_forked), | |
| 1043 | 804 | OPT_COLUMN(0, "column", &colopts, N_("list branches in columns")), | |
| 1044 | 805 | OPT_REF_SORT(&sorting_options), | |
| 1045 | 806 | OPT_CALLBACK(0, "points-at", &filter.points_at, N_("object"), | |
| @@ -1081,24 +842,19 @@ int cmd_branch(int argc, | |||
| 1081 | 842 | 0); | |
| 1082 | 843 | ||
| 1083 | 844 | if (!delete && !rename && !copy && !edit_description && !new_upstream && | |
| 1084 | - | !show_current && !unset_upstream && !delete_merged.nr && | |
| 1085 | - | argc == 0) | |
| 845 | + | !show_current && !unset_upstream && argc == 0) | |
| 1086 | 846 | list = 1; | |
| 1087 | 847 | ||
| 1088 | 848 | if (filter.with_commit || filter.no_commit || | |
| 1089 | - | filter.reachable_from || filter.unreachable_from || | |
| 1090 | - | filter.points_at.nr || filter.forked.nr) | |
| 849 | + | filter.reachable_from || filter.unreachable_from || filter.points_at.nr) | |
| 1091 | 850 | list = 1; | |
| 1092 | 851 | ||
| 1093 | 852 | noncreate_actions = !!delete + !!rename + !!copy + !!new_upstream + | |
| 1094 | 853 | !!show_current + !!list + !!edit_description + | |
| 1095 | - | !!unset_upstream + !!delete_merged.nr; | |
| 854 | + | !!unset_upstream; | |
| 1096 | 855 | if (noncreate_actions > 1) | |
| 1097 | 856 | usage_with_options(builtin_branch_usage, options); | |
| 1098 | 857 | ||
| 1099 | - | if (dry_run && !delete_merged.nr) | |
| 1100 | - | die(_("--dry-run requires --delete-merged")); | |
| 1101 | - | ||
| 1102 | 858 | if (recurse_submodules_explicit) { | |
| 1103 | 859 | if (!submodule_propagate_branches) | |
| 1104 | 860 | die(_("branch with --recurse-submodules can only be used if submodule.propagateBranches is enabled")); | |
| @@ -1133,14 +889,7 @@ int cmd_branch(int argc, | |||
| 1133 | 889 | if (delete) { | |
| 1134 | 890 | if (!argc) | |
| 1135 | 891 | die(_("branch name required")); | |
| 1136 | - | ret = delete_branches(argc, argv, filter.kind, | |
| 1137 | - | (delete > 1 ? DELETE_BRANCH_FORCE : 0) | | |
| 1138 | - | (quiet ? DELETE_BRANCH_QUIET : 0)); | |
| 1139 | - | goto out; | |
| 1140 | - | } else if (delete_merged.nr) { | |
| 1141 | - | ret = delete_merged_branches(&delete_merged, argv, | |
| 1142 | - | (quiet ? DELETE_BRANCH_QUIET : 0) | | |
| 1143 | - | (dry_run ? DELETE_BRANCH_DRY_RUN : 0)); | |
| 892 | + | ret = delete_branches(argc, argv, delete > 1, filter.kind, quiet); | |
| 1144 | 893 | goto out; | |
| 1145 | 894 | } else if (show_current) { | |
| 1146 | 895 | print_current_branch_name(); | |
| @@ -1313,7 +1062,6 @@ int cmd_branch(int argc, | |||
| 1313 | 1062 | ret = 0; | |
| 1314 | 1063 | ||
| 1315 | 1064 | out: | |
| 1316 | - | strvec_clear(&delete_merged); | |
| 1317 | 1065 | string_list_clear(&sorting_options, 0); | |
| 1318 | 1066 | return ret; | |
| 1319 | 1067 | } | |
modified builtin/pack-objects.c
| @@ -1759,7 +1759,7 @@ static int want_object_in_pack_mtime(const struct object_id *oid, | |||
| 1759 | 1759 | struct odb_source *source = the_repository->objects->sources->next; | |
| 1760 | 1760 | for (; source; source = source->next) { | |
| 1761 | 1761 | struct odb_source_files *files = odb_source_files_downcast(source); | |
| 1762 | - | if (!odb_source_read_object_info(&files->loose->base, oid, NULL, 0)) | |
| 1762 | + | if (!odb_source_read_object_info(&files->loose->base, oid, NULL, 0, NULL)) | |
| 1763 | 1763 | return 0; | |
| 1764 | 1764 | } | |
| 1765 | 1765 | } | |
| @@ -1786,7 +1786,7 @@ static int want_object_in_pack_mtime(const struct object_id *oid, | |||
| 1786 | 1786 | struct multi_pack_index *m = get_multi_pack_index(files->packed); | |
| 1787 | 1787 | struct pack_entry e; | |
| 1788 | 1788 | ||
| 1789 | - | if (m && fill_midx_entry(m, oid, &e)) { | |
| 1789 | + | if (m && fill_midx_entry(m, oid, &e, NULL)) { | |
| 1790 | 1790 | want = want_object_in_pack_one(e.p, oid, exclude, found_pack, found_offset, found_mtime); | |
| 1791 | 1791 | if (want != -1) | |
| 1792 | 1792 | return want; | |
| @@ -4171,7 +4171,7 @@ static void add_cruft_object_entry(const struct object_id *oid, enum object_type | |||
| 4171 | 4171 | ||
| 4172 | 4172 | for (; !found && source; source = source->next) { | |
| 4173 | 4173 | struct odb_source_files *files = odb_source_files_downcast(source); | |
| 4174 | - | if (!odb_source_read_object_info(&files->loose->base, oid, NULL, 0)) | |
| 4174 | + | if (!odb_source_read_object_info(&files->loose->base, oid, NULL, 0, NULL)) | |
| 4175 | 4175 | found = 1; | |
| 4176 | 4176 | } | |
| 4177 | 4177 | ||
| @@ -4637,7 +4637,7 @@ static int force_object_loose(struct odb_source *source, | |||
| 4637 | 4637 | ||
| 4638 | 4638 | for (struct odb_source *s = source->odb->sources; s; s = s->next) { | |
| 4639 | 4639 | struct odb_source_files *files = odb_source_files_downcast(s); | |
| 4640 | - | if (!odb_source_read_object_info(&files->loose->base, oid, NULL, 0)) | |
| 4640 | + | if (!odb_source_read_object_info(&files->loose->base, oid, NULL, 0, NULL)) | |
| 4641 | 4641 | return 0; | |
| 4642 | 4642 | } | |
| 4643 | 4643 | ||
modified loose.c
| @@ -61,17 +61,12 @@ static int insert_loose_map(struct odb_source_loose *loose, | |||
| 61 | 61 | return inserted; | |
| 62 | 62 | } | |
| 63 | 63 | ||
| 64 | - | int loose_object_map_load(struct odb_source_loose *loose) | |
| 64 | + | static int load_one_loose_object_map(struct repository *repo, struct odb_source_loose *loose) | |
| 65 | 65 | { | |
| 66 | - | struct repository *repo = loose->base.odb->repo; | |
| 67 | - | struct strbuf buf = STRBUF_INIT; | |
| 68 | - | char *path; | |
| 66 | + | struct strbuf buf = STRBUF_INIT, path = STRBUF_INIT; | |
| 69 | 67 | FILE *fp; | |
| 70 | 68 | int ret = -1; | |
| 71 | 69 | ||
| 72 | - | if (!should_use_loose_object_map(repo)) | |
| 73 | - | return 0; | |
| 74 | - | ||
| 75 | 70 | if (!loose->map) | |
| 76 | 71 | loose_object_map_init(&loose->map); | |
| 77 | 72 | if (!loose->cache) { | |
| @@ -83,10 +78,10 @@ int loose_object_map_load(struct odb_source_loose *loose) | |||
| 83 | 78 | insert_loose_map(loose, repo->hash_algo->empty_blob, repo->compat_hash_algo->empty_blob); | |
| 84 | 79 | insert_loose_map(loose, repo->hash_algo->null_oid, repo->compat_hash_algo->null_oid); | |
| 85 | 80 | ||
| 86 | - | path = xstrfmt("%s/loose-object-idx", loose->base.path); | |
| 87 | - | fp = fopen(path, "rb"); | |
| 81 | + | repo_common_path_replace(repo, &path, "objects/loose-object-idx"); | |
| 82 | + | fp = fopen(path.buf, "rb"); | |
| 88 | 83 | if (!fp) { | |
| 89 | - | free(path); | |
| 84 | + | strbuf_release(&path); | |
| 90 | 85 | return 0; | |
| 91 | 86 | } | |
| 92 | 87 | ||
| @@ -107,7 +102,7 @@ int loose_object_map_load(struct odb_source_loose *loose) | |||
| 107 | 102 | err: | |
| 108 | 103 | fclose(fp); | |
| 109 | 104 | strbuf_release(&buf); | |
| 110 | - | free(path); | |
| 105 | + | strbuf_release(&path); | |
| 111 | 106 | return ret; | |
| 112 | 107 | } | |
| 113 | 108 | ||
| @@ -115,13 +110,17 @@ int repo_read_loose_object_map(struct repository *repo) | |||
| 115 | 110 | { | |
| 116 | 111 | struct odb_source *source; | |
| 117 | 112 | ||
| 113 | + | if (!should_use_loose_object_map(repo)) | |
| 114 | + | return 0; | |
| 115 | + | ||
| 118 | 116 | odb_prepare_alternates(repo->objects); | |
| 117 | + | ||
| 119 | 118 | for (source = repo->objects->sources; source; source = source->next) { | |
| 120 | 119 | struct odb_source_files *files = odb_source_files_downcast(source); | |
| 121 | - | if (loose_object_map_load(files->loose) < 0) | |
| 120 | + | if (load_one_loose_object_map(repo, files->loose) < 0) { | |
| 122 | 121 | return -1; | |
| 122 | + | } | |
| 123 | 123 | } | |
| 124 | - | ||
| 125 | 124 | return 0; | |
| 126 | 125 | } | |
| 127 | 126 | ||
modified loose.h
| @@ -13,7 +13,6 @@ struct loose_object_map { | |||
| 13 | 13 | ||
| 14 | 14 | void loose_object_map_init(struct loose_object_map **map); | |
| 15 | 15 | void loose_object_map_clear(struct loose_object_map **map); | |
| 16 | - | int loose_object_map_load(struct odb_source_loose *loose); | |
| 17 | 16 | int repo_loose_object_map_oid(struct repository *repo, | |
| 18 | 17 | const struct object_id *src, | |
| 19 | 18 | const struct git_hash_algo *dest_algo, | |
modified midx.c
| @@ -591,7 +591,8 @@ uint32_t nth_midxed_pack_int_id(struct multi_pack_index *m, uint32_t pos) | |||
| 591 | 591 | ||
| 592 | 592 | int fill_midx_entry(struct multi_pack_index *m, | |
| 593 | 593 | const struct object_id *oid, | |
| 594 | - | struct pack_entry *e) | |
| 594 | + | struct pack_entry *e, | |
| 595 | + | struct packed_git **bad_pack) | |
| 595 | 596 | { | |
| 596 | 597 | uint32_t pos; | |
| 597 | 598 | uint32_t pack_int_id; | |
| @@ -618,8 +619,11 @@ int fill_midx_entry(struct multi_pack_index *m, | |||
| 618 | 619 | return 0; | |
| 619 | 620 | ||
| 620 | 621 | if (oidset_size(&p->bad_objects) && | |
| 621 | - | oidset_contains(&p->bad_objects, oid)) | |
| 622 | + | oidset_contains(&p->bad_objects, oid)) { | |
| 623 | + | if (bad_pack && !*bad_pack) | |
| 624 | + | *bad_pack = p; | |
| 622 | 625 | return 0; | |
| 626 | + | } | |
| 623 | 627 | ||
| 624 | 628 | e->offset = nth_midxed_offset(m, pos); | |
| 625 | 629 | e->p = p; | |
| @@ -1028,7 +1032,7 @@ int verify_midx_file(struct odb_source_packed *source, unsigned flags) | |||
| 1028 | 1032 | ||
| 1029 | 1033 | nth_midxed_object_oid(&oid, m, pairs[i].pos); | |
| 1030 | 1034 | ||
| 1031 | - | if (!fill_midx_entry(m, &oid, &e)) { | |
| 1035 | + | if (!fill_midx_entry(m, &oid, &e, NULL)) { | |
| 1032 | 1036 | midx_report(_("failed to load pack entry for oid[%d] = %s"), | |
| 1033 | 1037 | pairs[i].pos, oid_to_hex(&oid)); | |
| 1034 | 1038 | continue; | |
modified midx.h
| @@ -117,7 +117,8 @@ uint32_t nth_midxed_pack_int_id(struct multi_pack_index *m, uint32_t pos); | |||
| 117 | 117 | struct object_id *nth_midxed_object_oid(struct object_id *oid, | |
| 118 | 118 | struct multi_pack_index *m, | |
| 119 | 119 | uint32_t n); | |
| 120 | - | int fill_midx_entry(struct multi_pack_index *m, const struct object_id *oid, struct pack_entry *e); | |
| 120 | + | int fill_midx_entry(struct multi_pack_index *m, const struct object_id *oid, | |
| 121 | + | struct pack_entry *e, struct packed_git **bad_pack); | |
| 121 | 122 | int midx_contains_pack(struct multi_pack_index *m, | |
| 122 | 123 | const char *idx_or_pack_name); | |
| 123 | 124 | int midx_layer_contains_pack(struct multi_pack_index *m, | |
modified odb.c
| @@ -15,7 +15,6 @@ | |||
| 15 | 15 | #include "object-name.h" | |
| 16 | 16 | #include "odb.h" | |
| 17 | 17 | #include "odb/source-inmemory.h" | |
| 18 | - | #include "packfile.h" | |
| 19 | 18 | #include "path.h" | |
| 20 | 19 | #include "promisor-remote.h" | |
| 21 | 20 | #include "quote.h" | |
| @@ -547,12 +546,15 @@ static int register_all_submodule_sources(struct object_database *odb) | |||
| 547 | 546 | return ret; | |
| 548 | 547 | } | |
| 549 | 548 | ||
| 550 | - | static int do_oid_object_info_extended(struct object_database *odb, | |
| 551 | - | const struct object_id *oid, | |
| 552 | - | struct object_info *oi, unsigned flags) | |
| 549 | + | static enum odb_read_status do_oid_object_info_extended(struct object_database *odb, | |
| 550 | + | const struct object_id *oid, | |
| 551 | + | struct object_info *oi, unsigned flags) | |
| 553 | 552 | { | |
| 553 | + | struct strbuf corrupt_err = STRBUF_INIT; | |
| 554 | 554 | const struct object_id *real = oid; | |
| 555 | + | enum odb_read_status ret; | |
| 555 | 556 | int already_retried = 0; | |
| 557 | + | bool corrupt = false; | |
| 556 | 558 | ||
| 557 | 559 | if (flags & OBJECT_INFO_LOOKUP_REPLACE) | |
| 558 | 560 | real = lookup_replace_object(odb->repo, oid); | |
| @@ -560,7 +562,7 @@ static int do_oid_object_info_extended(struct object_database *odb, | |||
| 560 | 562 | if (is_null_oid(real)) | |
| 561 | 563 | return -1; | |
| 562 | 564 | ||
| 563 | - | if (!odb_source_read_object_info(odb->inmemory_objects, oid, oi, flags)) | |
| 565 | + | if (!odb_source_read_object_info(odb->inmemory_objects, oid, oi, flags, NULL)) | |
| 564 | 566 | return 0; | |
| 565 | 567 | ||
| 566 | 568 | odb_prepare_alternates(odb); | |
| @@ -568,9 +570,14 @@ static int do_oid_object_info_extended(struct object_database *odb, | |||
| 568 | 570 | while (1) { | |
| 569 | 571 | struct odb_source *source; | |
| 570 | 572 | ||
| 571 | - | for (source = odb->sources; source; source = source->next) | |
| 572 | - | if (!odb_source_read_object_info(source, real, oi, flags)) | |
| 573 | - | return 0; | |
| 573 | + | for (source = odb->sources; source; source = source->next) { | |
| 574 | + | ret = odb_source_read_object_info(source, real, oi, flags, | |
| 575 | + | corrupt_err.len ? NULL : &corrupt_err); | |
| 576 | + | if (!ret) | |
| 577 | + | goto out; | |
| 578 | + | if (ret != ODB_READ_NOT_FOUND) | |
| 579 | + | corrupt = true; | |
| 580 | + | } | |
| 574 | 581 | ||
| 575 | 582 | /* | |
| 576 | 583 | * When the object hasn't been found we try a second read and | |
| @@ -578,10 +585,15 @@ static int do_oid_object_info_extended(struct object_database *odb, | |||
| 578 | 585 | * caches or reload on-disk state. | |
| 579 | 586 | */ | |
| 580 | 587 | if (!(flags & OBJECT_INFO_QUICK)) { | |
| 581 | - | for (source = odb->sources; source; source = source->next) | |
| 582 | - | if (!odb_source_read_object_info(source, real, oi, | |
| 583 | - | flags | OBJECT_INFO_SECOND_READ)) | |
| 584 | - | return 0; | |
| 588 | + | for (source = odb->sources; source; source = source->next) { | |
| 589 | + | ret = odb_source_read_object_info(source, real, oi, | |
| 590 | + | flags | OBJECT_INFO_SECOND_READ, | |
| 591 | + | corrupt_err.len ? NULL : &corrupt_err); | |
| 592 | + | if (!ret) | |
| 593 | + | goto out; | |
| 594 | + | if (ret != ODB_READ_NOT_FOUND) | |
| 595 | + | corrupt = true; | |
| 596 | + | } | |
| 585 | 597 | } | |
| 586 | 598 | ||
| 587 | 599 | /* | |
| @@ -604,16 +616,23 @@ static int do_oid_object_info_extended(struct object_database *odb, | |||
| 604 | 616 | } | |
| 605 | 617 | ||
| 606 | 618 | if (flags & OBJECT_INFO_DIE_IF_CORRUPT) { | |
| 607 | - | const struct packed_git *p; | |
| 608 | 619 | if ((flags & OBJECT_INFO_LOOKUP_REPLACE) && !oideq(real, oid)) | |
| 609 | 620 | die(_("replacement %s not found for %s"), | |
| 610 | 621 | oid_to_hex(real), oid_to_hex(oid)); | |
| 611 | - | if ((p = has_packed_and_bad(odb->repo, real))) | |
| 612 | - | die(_("packed object %s (stored in %s) is corrupt"), | |
| 613 | - | oid_to_hex(real), p->pack_name); | |
| 622 | + | if (corrupt) { | |
| 623 | + | if (corrupt_err.len) | |
| 624 | + | die("%s", corrupt_err.buf); | |
| 625 | + | die(_("object %s is corrupt"), oid_to_hex(real)); | |
| 626 | + | } | |
| 614 | 627 | } | |
| 615 | - | return -1; | |
| 628 | + | ||
| 629 | + | ret = corrupt ? ODB_READ_ERROR : ODB_READ_NOT_FOUND; | |
| 630 | + | goto out; | |
| 616 | 631 | } | |
| 632 | + | ||
| 633 | + | out: | |
| 634 | + | strbuf_release(&corrupt_err); | |
| 635 | + | return ret; | |
| 617 | 636 | } | |
| 618 | 637 | ||
| 619 | 638 | static int oid_object_info_convert(struct repository *r, | |
| @@ -696,12 +715,12 @@ static int oid_object_info_convert(struct repository *r, | |||
| 696 | 715 | return ret; | |
| 697 | 716 | } | |
| 698 | 717 | ||
| 699 | - | int odb_read_object_info_extended(struct object_database *odb, | |
| 700 | - | const struct object_id *oid, | |
| 701 | - | struct object_info *oi, | |
| 702 | - | enum object_info_flags flags) | |
| 718 | + | enum odb_read_status odb_read_object_info_extended(struct object_database *odb, | |
| 719 | + | const struct object_id *oid, | |
| 720 | + | struct object_info *oi, | |
| 721 | + | enum object_info_flags flags) | |
| 703 | 722 | { | |
| 704 | - | int ret; | |
| 723 | + | enum odb_read_status ret; | |
| 705 | 724 | ||
| 706 | 725 | if (oid->algo && (hash_algo_by_ptr(odb->repo->hash_algo) != oid->algo)) | |
| 707 | 726 | return oid_object_info_convert(odb->repo, oid, oi, flags); | |
| @@ -1047,29 +1066,26 @@ bool odb_optimize_required(struct object_database *odb, | |||
| 1047 | 1066 | } | |
| 1048 | 1067 | ||
| 1049 | 1068 | struct object_database *odb_new(struct repository *repo, | |
| 1050 | - | enum odb_new_flags flags) | |
| 1069 | + | const char *primary_source, | |
| 1070 | + | const char *secondary_sources) | |
| 1051 | 1071 | { | |
| 1052 | - | char *primary_source = NULL, *secondary_sources = NULL; | |
| 1053 | - | struct object_database *o; | |
| 1072 | + | struct object_database *o = xmalloc(sizeof(*o)); | |
| 1073 | + | char *to_free = NULL; | |
| 1054 | 1074 | ||
| 1055 | - | CALLOC_ARRAY(o, 1); | |
| 1075 | + | memset(o, 0, sizeof(*o)); | |
| 1056 | 1076 | o->repo = repo; | |
| 1057 | 1077 | pthread_mutex_init(&o->replace_mutex, NULL); | |
| 1058 | 1078 | string_list_init_dup(&o->submodule_source_paths); | |
| 1059 | 1079 | ||
| 1060 | - | if (flags & ODB_NEW_HONOR_ENV) { | |
| 1061 | - | primary_source = xstrdup_or_null(getenv(DB_ENVIRONMENT)); | |
| 1062 | - | secondary_sources = xstrdup_or_null(getenv(ALTERNATE_DB_ENVIRONMENT)); | |
| 1063 | - | } | |
| 1064 | 1080 | if (!primary_source) | |
| 1065 | - | primary_source = xstrfmt("%s/objects", repo->commondir); | |
| 1066 | - | ||
| 1081 | + | primary_source = to_free = xstrfmt("%s/objects", repo->commondir); | |
| 1067 | 1082 | o->sources = odb_source_new(o, primary_source, true); | |
| 1068 | 1083 | o->sources_tail = &o->sources->next; | |
| 1069 | - | o->alternate_db = secondary_sources; | |
| 1084 | + | o->alternate_db = xstrdup_or_null(secondary_sources); | |
| 1070 | 1085 | o->inmemory_objects = &odb_source_inmemory_new(o)->base; | |
| 1071 | 1086 | ||
| 1072 | - | free(primary_source); | |
| 1087 | + | free(to_free); | |
| 1088 | + | ||
| 1073 | 1089 | return o; | |
| 1074 | 1090 | } | |
| 1075 | 1091 | ||
modified odb.h
| @@ -100,20 +100,6 @@ struct object_database { | |||
| 100 | 100 | struct string_list submodule_source_paths; | |
| 101 | 101 | }; | |
| 102 | 102 | ||
| 103 | - | enum odb_new_flags { | |
| 104 | - | /* | |
| 105 | - | * Honor environment variables when constructing the object database | |
| 106 | - | * sources. This makes us respect the following environment variables: | |
| 107 | - | * | |
| 108 | - | * - GIT_OBJECT_DIRECTORY to override the primary object directory. | |
| 109 | - | * | |
| 110 | - | * - GIT_ALTERNATE_OBJECT_DIRECTORIES to override alternates. | |
| 111 | - | * | |
| 112 | - | * Environment variables may be backend-specific. | |
| 113 | - | */ | |
| 114 | - | ODB_NEW_HONOR_ENV = (1 << 0), | |
| 115 | - | }; | |
| 116 | - | ||
| 117 | 103 | /* | |
| 118 | 104 | * Create a new object database for the given repository. | |
| 119 | 105 | * | |
| @@ -126,7 +112,8 @@ enum odb_new_flags { | |||
| 126 | 112 | * Returns the newly created object database. | |
| 127 | 113 | */ | |
| 128 | 114 | struct object_database *odb_new(struct repository *repo, | |
| 129 | - | enum odb_new_flags flags); | |
| 115 | + | const char *primary_source, | |
| 116 | + | const char *alternate_sources); | |
| 130 | 117 | ||
| 131 | 118 | /* Free the object database and release all resources. */ | |
| 132 | 119 | void odb_free(struct object_database *o); | |
| @@ -448,14 +435,23 @@ enum object_info_flags { | |||
| 448 | 435 | OBJECT_INFO_FOR_PREFETCH = (OBJECT_INFO_SKIP_FETCH_OBJECT | OBJECT_INFO_QUICK), | |
| 449 | 436 | }; | |
| 450 | 437 | ||
| 438 | + | enum odb_read_status { | |
| 439 | + | /* The read was successful. */ | |
| 440 | + | ODB_READ_OK = 0, | |
| 441 | + | /* The read resulted in a generic error. */ | |
| 442 | + | ODB_READ_ERROR = -1, | |
| 443 | + | /* The object could not be found. */ | |
| 444 | + | ODB_READ_NOT_FOUND = -2, | |
| 445 | + | }; | |
| 446 | + | ||
| 451 | 447 | /* | |
| 452 | 448 | * Read object info from the object database and populate the `object_info` | |
| 453 | 449 | * structure. Returns 0 on success, a negative error code otherwise. | |
| 454 | 450 | */ | |
| 455 | - | int odb_read_object_info_extended(struct object_database *odb, | |
| 456 | - | const struct object_id *oid, | |
| 457 | - | struct object_info *oi, | |
| 458 | - | enum object_info_flags flags); | |
| 451 | + | enum odb_read_status odb_read_object_info_extended(struct object_database *odb, | |
| 452 | + | const struct object_id *oid, | |
| 453 | + | struct object_info *oi, | |
| 454 | + | enum object_info_flags flags); | |
| 459 | 455 | ||
| 460 | 456 | /* | |
| 461 | 457 | * Read a subset of object info for the given object ID. Returns an `enum | |
modified odb/source-files.c
| @@ -51,23 +51,6 @@ static void odb_source_files_close(struct odb_source *source) | |||
| 51 | 51 | odb_source_close(&files->packed->base); | |
| 52 | 52 | } | |
| 53 | 53 | ||
| 54 | - | static int odb_source_files_create_on_disk(struct odb_source *source) | |
| 55 | - | { | |
| 56 | - | struct strbuf path = STRBUF_INIT; | |
| 57 | - | ||
| 58 | - | safe_create_dir(source->odb->repo, source->path, 1); | |
| 59 | - | ||
| 60 | - | strbuf_addf(&path, "%s/pack", source->path); | |
| 61 | - | safe_create_dir(source->odb->repo, path.buf, 1); | |
| 62 | - | ||
| 63 | - | strbuf_reset(&path); | |
| 64 | - | strbuf_addf(&path, "%s/info", source->path); | |
| 65 | - | safe_create_dir(source->odb->repo, path.buf, 1); | |
| 66 | - | ||
| 67 | - | strbuf_release(&path); | |
| 68 | - | return 0; | |
| 69 | - | } | |
| 70 | - | ||
| 71 | 54 | static void odb_source_files_prepare(struct odb_source *source, | |
| 72 | 55 | enum odb_prepare_flags flags) | |
| 73 | 56 | { | |
| @@ -76,18 +59,35 @@ static void odb_source_files_prepare(struct odb_source *source, | |||
| 76 | 59 | odb_source_prepare(&files->packed->base, flags); | |
| 77 | 60 | } | |
| 78 | 61 | ||
| 79 | - | static int odb_source_files_read_object_info(struct odb_source *source, | |
| 80 | - | const struct object_id *oid, | |
| 81 | - | struct object_info *oi, | |
| 82 | - | enum object_info_flags flags) | |
| 62 | + | static enum odb_read_status odb_source_files_read_object_info(struct odb_source *source, | |
| 63 | + | const struct object_id *oid, | |
| 64 | + | struct object_info *oi, | |
| 65 | + | enum object_info_flags flags, | |
| 66 | + | struct strbuf *errmsg) | |
| 83 | 67 | { | |
| 84 | 68 | struct odb_source_files *files = odb_source_files_downcast(source); | |
| 69 | + | enum odb_read_status ret_packed, ret_loose; | |
| 85 | 70 | ||
| 86 | - | if (!odb_source_read_object_info(&files->packed->base, oid, oi, flags) || | |
| 87 | - | !odb_source_read_object_info(&files->loose->base, oid, oi, flags)) | |
| 71 | + | ret_packed = odb_source_read_object_info(&files->packed->base, oid, oi, | |
| 72 | + | flags, errmsg); | |
| 73 | + | if (!ret_packed) | |
| 88 | 74 | return 0; | |
| 89 | 75 | ||
| 90 | - | return -1; | |
| 76 | + | ret_loose = odb_source_read_object_info(&files->loose->base, oid, oi, flags, | |
| 77 | + | ret_packed == ODB_READ_NOT_FOUND ? errmsg : NULL); | |
| 78 | + | if (!ret_loose) | |
| 79 | + | return 0; | |
| 80 | + | ||
| 81 | + | /* | |
| 82 | + | * Reading the packed object may have failed even though the object | |
| 83 | + | * exists, for example because it is corrupt. Report this failure to | |
| 84 | + | * the caller in case neither of the sources was able to read the | |
| 85 | + | * object, and prefer the error of the packed source in case both | |
| 86 | + | * reads have failed. | |
| 87 | + | */ | |
| 88 | + | if (ret_packed != ODB_READ_NOT_FOUND) | |
| 89 | + | return ret_packed; | |
| 90 | + | return ret_loose; | |
| 91 | 91 | } | |
| 92 | 92 | ||
| 93 | 93 | static int odb_source_files_read_object_stream(struct odb_read_stream **out, | |
| @@ -759,7 +759,6 @@ struct odb_source_files *odb_source_files_new(struct object_database *odb, | |||
| 759 | 759 | ||
| 760 | 760 | files->base.free = odb_source_files_free; | |
| 761 | 761 | files->base.close = odb_source_files_close; | |
| 762 | - | files->base.create_on_disk = odb_source_files_create_on_disk; | |
| 763 | 762 | files->base.prepare = odb_source_files_prepare; | |
| 764 | 763 | files->base.read_object_info = odb_source_files_read_object_info; | |
| 765 | 764 | files->base.read_object_stream = odb_source_files_read_object_stream; | |
modified odb/source-files.h
| @@ -43,9 +43,7 @@ bool odb_source_files_optimize_required(struct odb_source *source, | |||
| 43 | 43 | static inline struct odb_source_files *odb_source_files_downcast(struct odb_source *source) | |
| 44 | 44 | { | |
| 45 | 45 | if (source->type != ODB_SOURCE_FILES) | |
| 46 | - | BUG("trying to downcast source of type '%s' to '%s'", | |
| 47 | - | odb_source_type_to_name(source->type), | |
| 48 | - | odb_source_type_to_name(ODB_SOURCE_FILES)); | |
| 46 | + | BUG("trying to downcast source of type '%d' to files", source->type); | |
| 49 | 47 | return container_of(source, struct odb_source_files, base); | |
| 50 | 48 | } | |
| 51 | 49 | ||
modified odb/source-inmemory.c
| @@ -56,17 +56,18 @@ static void populate_object_info(struct odb_source_inmemory *source, | |||
| 56 | 56 | oi->source_infop->source = &source->base; | |
| 57 | 57 | } | |
| 58 | 58 | ||
| 59 | - | static int odb_source_inmemory_read_object_info(struct odb_source *source, | |
| 60 | - | const struct object_id *oid, | |
| 61 | - | struct object_info *oi, | |
| 62 | - | enum object_info_flags flags UNUSED) | |
| 59 | + | static enum odb_read_status odb_source_inmemory_read_object_info(struct odb_source *source, | |
| 60 | + | const struct object_id *oid, | |
| 61 | + | struct object_info *oi, | |
| 62 | + | enum object_info_flags flags UNUSED, | |
| 63 | + | struct strbuf *errmsg UNUSED) | |
| 63 | 64 | { | |
| 64 | 65 | struct odb_source_inmemory *inmemory = odb_source_inmemory_downcast(source); | |
| 65 | 66 | const struct inmemory_object *object; | |
| 66 | 67 | ||
| 67 | 68 | object = find_cached_object(inmemory, oid); | |
| 68 | 69 | if (!object) | |
| 69 | - | return -1; | |
| 70 | + | return ODB_READ_NOT_FOUND; | |
| 70 | 71 | ||
| 71 | 72 | populate_object_info(inmemory, oi, object); | |
| 72 | 73 | return 0; | |
modified odb/source-inmemory.h
| @@ -26,9 +26,7 @@ struct odb_source_inmemory *odb_source_inmemory_new(struct object_database *odb) | |||
| 26 | 26 | static inline struct odb_source_inmemory *odb_source_inmemory_downcast(struct odb_source *source) | |
| 27 | 27 | { | |
| 28 | 28 | if (source->type != ODB_SOURCE_INMEMORY) | |
| 29 | - | BUG("trying to downcast source of type '%s' to '%s'", | |
| 30 | - | odb_source_type_to_name(source->type), | |
| 31 | - | odb_source_type_to_name(ODB_SOURCE_INMEMORY)); | |
| 29 | + | BUG("trying to downcast source of type '%d' to in-memory", source->type); | |
| 32 | 30 | return container_of(source, struct odb_source_inmemory, base); | |
| 33 | 31 | } | |
| 34 | 32 | ||
modified odb/source-loose.c
| @@ -67,7 +67,8 @@ static int read_object_info_from_path(struct odb_source_loose *loose, | |||
| 67 | 67 | const char *path, | |
| 68 | 68 | const struct object_id *oid, | |
| 69 | 69 | struct object_info *oi, | |
| 70 | - | enum object_info_flags flags) | |
| 70 | + | enum object_info_flags flags, | |
| 71 | + | struct strbuf *errmsg) | |
| 71 | 72 | { | |
| 72 | 73 | int ret; | |
| 73 | 74 | int fd; | |
| @@ -91,11 +92,16 @@ static int read_object_info_from_path(struct odb_source_loose *loose, | |||
| 91 | 92 | struct stat st; | |
| 92 | 93 | ||
| 93 | 94 | if ((!oi || (!oi->disk_sizep && !oi->mtimep)) && (flags & OBJECT_INFO_QUICK)) { | |
| 94 | - | ret = quick_has_loose(loose, oid) ? 0 : -1; | |
| 95 | + | ret = quick_has_loose(loose, oid) ? 0 : ODB_READ_NOT_FOUND; | |
| 95 | 96 | goto out; | |
| 96 | 97 | } | |
| 97 | 98 | ||
| 98 | 99 | if (lstat(path, &st) < 0) { | |
| 100 | + | if (errno == ENOENT) { | |
| 101 | + | ret = ODB_READ_NOT_FOUND; | |
| 102 | + | goto out; | |
| 103 | + | } | |
| 104 | + | ||
| 99 | 105 | ret = -1; | |
| 100 | 106 | goto out; | |
| 101 | 107 | } | |
| @@ -113,9 +119,12 @@ static int read_object_info_from_path(struct odb_source_loose *loose, | |||
| 113 | 119 | ||
| 114 | 120 | fd = git_open(path); | |
| 115 | 121 | if (fd < 0) { | |
| 116 | - | if (errno != ENOENT) | |
| 117 | - | error_errno(_("unable to open loose object %s"), oid_to_hex(oid)); | |
| 118 | - | ret = -1; | |
| 122 | + | if (errno == ENOENT) { | |
| 123 | + | ret = ODB_READ_NOT_FOUND; | |
| 124 | + | goto out; | |
| 125 | + | } | |
| 126 | + | ||
| 127 | + | ret = error_errno(_("unable to open loose object %s"), oid_to_hex(oid)); | |
| 119 | 128 | goto out; | |
| 120 | 129 | } | |
| 121 | 130 | ||
| @@ -155,7 +164,7 @@ static int read_object_info_from_path(struct odb_source_loose *loose, | |||
| 155 | 164 | ||
| 156 | 165 | if (parse_loose_header(hdr, oi) < 0) { | |
| 157 | 166 | ret = error(_("unable to parse %s header"), oid_to_hex(oid)); | |
| 158 | - | goto corrupt; | |
| 167 | + | goto out; | |
| 159 | 168 | } | |
| 160 | 169 | ||
| 161 | 170 | if (*oi->typep < 0) | |
| @@ -165,7 +174,7 @@ static int read_object_info_from_path(struct odb_source_loose *loose, | |||
| 165 | 174 | *oi->contentp = unpack_loose_rest(&stream, hdr, *oi->sizep, oid); | |
| 166 | 175 | if (!*oi->contentp) { | |
| 167 | 176 | ret = -1; | |
| 168 | - | goto corrupt; | |
| 177 | + | goto out; | |
| 169 | 178 | } | |
| 170 | 179 | } | |
| 171 | 180 | ||
| @@ -173,21 +182,19 @@ static int read_object_info_from_path(struct odb_source_loose *loose, | |||
| 173 | 182 | case ULHR_BAD: | |
| 174 | 183 | ret = error(_("unable to unpack %s header"), | |
| 175 | 184 | oid_to_hex(oid)); | |
| 176 | - | goto corrupt; | |
| 185 | + | goto out; | |
| 177 | 186 | case ULHR_TOO_LONG: | |
| 178 | 187 | ret = error(_("header for %s too long, exceeds %d bytes"), | |
| 179 | 188 | oid_to_hex(oid), MAX_HEADER_LEN); | |
| 180 | - | goto corrupt; | |
| 189 | + | goto out; | |
| 181 | 190 | } | |
| 182 | 191 | ||
| 183 | 192 | ret = 0; | |
| 184 | 193 | ||
| 185 | - | corrupt: | |
| 186 | - | if (ret && (flags & OBJECT_INFO_DIE_IF_CORRUPT)) | |
| 187 | - | die(_("loose object %s (stored in %s) is corrupt"), | |
| 188 | - | oid_to_hex(oid), path); | |
| 189 | - | ||
| 190 | 194 | out: | |
| 195 | + | if (ret && ret != ODB_READ_NOT_FOUND && errmsg) | |
| 196 | + | strbuf_addf(errmsg, _("loose object %s (stored in %s) is corrupt"), | |
| 197 | + | oid_to_hex(oid), path); | |
| 191 | 198 | if (stream_to_end) | |
| 192 | 199 | git_inflate_end(stream_to_end); | |
| 193 | 200 | if (map) | |
| @@ -206,10 +213,11 @@ out: | |||
| 206 | 213 | return ret; | |
| 207 | 214 | } | |
| 208 | 215 | ||
| 209 | - | static int odb_source_loose_read_object_info(struct odb_source *source, | |
| 210 | - | const struct object_id *oid, | |
| 211 | - | struct object_info *oi, | |
| 212 | - | enum object_info_flags flags) | |
| 216 | + | static enum odb_read_status odb_source_loose_read_object_info(struct odb_source *source, | |
| 217 | + | const struct object_id *oid, | |
| 218 | + | struct object_info *oi, | |
| 219 | + | enum object_info_flags flags, | |
| 220 | + | struct strbuf *errmsg) | |
| 213 | 221 | { | |
| 214 | 222 | struct odb_source_loose *loose = odb_source_loose_downcast(source); | |
| 215 | 223 | static struct strbuf buf = STRBUF_INIT; | |
| @@ -221,10 +229,10 @@ static int odb_source_loose_read_object_info(struct odb_source *source, | |||
| 221 | 229 | * second time. | |
| 222 | 230 | */ | |
| 223 | 231 | if (flags & OBJECT_INFO_SECOND_READ) | |
| 224 | - | return -1; | |
| 232 | + | return ODB_READ_NOT_FOUND; | |
| 225 | 233 | ||
| 226 | 234 | odb_loose_path(loose, &buf, oid); | |
| 227 | - | return read_object_info_from_path(loose, buf.buf, oid, oi, flags); | |
| 235 | + | return read_object_info_from_path(loose, buf.buf, oid, oi, flags, errmsg); | |
| 228 | 236 | } | |
| 229 | 237 | ||
| 230 | 238 | /* | |
| @@ -421,7 +429,7 @@ static int for_each_object_wrapper_cb(const struct object_id *oid, | |||
| 421 | 429 | if (data->request) { | |
| 422 | 430 | struct object_info oi = *data->request; | |
| 423 | 431 | ||
| 424 | - | if (read_object_info_from_path(data->loose, path, oid, &oi, 0) < 0) | |
| 432 | + | if (read_object_info_from_path(data->loose, path, oid, &oi, 0, NULL) < 0) | |
| 425 | 433 | return -1; | |
| 426 | 434 | ||
| 427 | 435 | return data->cb(oid, &oi, data->cb_data); | |
| @@ -439,7 +447,7 @@ static int for_each_prefixed_object_wrapper_cb(const struct object_id *oid, | |||
| 439 | 447 | struct object_info oi = *data->request; | |
| 440 | 448 | ||
| 441 | 449 | if (odb_source_read_object_info(&data->loose->base, | |
| 442 | - | oid, &oi, 0) < 0) | |
| 450 | + | oid, &oi, 0, NULL) < 0) | |
| 443 | 451 | return -1; | |
| 444 | 452 | ||
| 445 | 453 | return data->cb(oid, &oi, data->cb_data); | |
| @@ -1055,7 +1063,5 @@ struct odb_source_loose *odb_source_loose_new(struct object_database *odb, | |||
| 1055 | 1063 | if (!is_absolute_path(loose->base.path)) | |
| 1056 | 1064 | chdir_notify_register(NULL, odb_source_loose_reparent, loose); | |
| 1057 | 1065 | ||
| 1058 | - | loose_object_map_load(loose); | |
| 1059 | - | ||
| 1060 | 1066 | return loose; | |
| 1061 | 1067 | } | |
modified odb/source-loose.h
| @@ -41,9 +41,7 @@ struct odb_source_loose *odb_source_loose_new(struct object_database *odb, | |||
| 41 | 41 | static inline struct odb_source_loose *odb_source_loose_downcast(struct odb_source *source) | |
| 42 | 42 | { | |
| 43 | 43 | if (source->type != ODB_SOURCE_LOOSE) | |
| 44 | - | BUG("trying to downcast source of type '%s' to '%s'", | |
| 45 | - | odb_source_type_to_name(source->type), | |
| 46 | - | odb_source_type_to_name(ODB_SOURCE_LOOSE)); | |
| 44 | + | BUG("trying to downcast source of type '%d' to loose", source->type); | |
| 47 | 45 | return container_of(source, struct odb_source_loose, base); | |
| 48 | 46 | } | |
| 49 | 47 | ||
modified odb/source-packed.c
| @@ -2,7 +2,9 @@ | |||
| 2 | 2 | #include "abspath.h" | |
| 3 | 3 | #include "chdir-notify.h" | |
| 4 | 4 | #include "dir.h" | |
| 5 | + | #include "gettext.h" | |
| 5 | 6 | #include "git-zlib.h" | |
| 7 | + | #include "hex.h" | |
| 6 | 8 | #include "list-objects-filter-options.h" | |
| 7 | 9 | #include "mergesort.h" | |
| 8 | 10 | #include "midx.h" | |
| @@ -10,21 +12,23 @@ | |||
| 10 | 12 | #include "odb/streaming.h" | |
| 11 | 13 | #include "packfile.h" | |
| 12 | 14 | #include "pack-bitmap.h" | |
| 15 | + | #include "strbuf.h" | |
| 13 | 16 | ||
| 14 | 17 | static int find_pack_entry(struct odb_source_packed *store, | |
| 15 | 18 | const struct object_id *oid, | |
| 16 | - | struct pack_entry *e) | |
| 19 | + | struct pack_entry *e, | |
| 20 | + | struct packed_git **bad_pack) | |
| 17 | 21 | { | |
| 18 | 22 | struct packfile_list_entry *l; | |
| 19 | 23 | ||
| 20 | 24 | odb_source_prepare(&store->base, 0); | |
| 21 | - | if (store->midx && fill_midx_entry(store->midx, oid, e)) | |
| 25 | + | if (store->midx && fill_midx_entry(store->midx, oid, e, bad_pack)) | |
| 22 | 26 | return 1; | |
| 23 | 27 | ||
| 24 | 28 | for (l = store->packs.head; l; l = l->next) { | |
| 25 | 29 | struct packed_git *p = l->pack; | |
| 26 | 30 | ||
| 27 | - | if (!p->multi_pack_index && packfile_fill_entry(p, oid, e)) { | |
| 31 | + | if (!p->multi_pack_index && packfile_fill_entry(p, oid, e, bad_pack)) { | |
| 28 | 32 | if (!store->skip_mru_updates) | |
| 29 | 33 | packfile_list_prepend(&store->packs, p); | |
| 30 | 34 | return 1; | |
| @@ -34,12 +38,14 @@ static int find_pack_entry(struct odb_source_packed *store, | |||
| 34 | 38 | return 0; | |
| 35 | 39 | } | |
| 36 | 40 | ||
| 37 | - | static int odb_source_packed_read_object_info(struct odb_source *source, | |
| 38 | - | const struct object_id *oid, | |
| 39 | - | struct object_info *oi, | |
| 40 | - | enum object_info_flags flags) | |
| 41 | + | static enum odb_read_status odb_source_packed_read_object_info(struct odb_source *source, | |
| 42 | + | const struct object_id *oid, | |
| 43 | + | struct object_info *oi, | |
| 44 | + | enum object_info_flags flags, | |
| 45 | + | struct strbuf *errmsg) | |
| 41 | 46 | { | |
| 42 | 47 | struct odb_source_packed *packed = odb_source_packed_downcast(source); | |
| 48 | + | struct packed_git *bad_pack = NULL; | |
| 43 | 49 | struct pack_entry e; | |
| 44 | 50 | int ret; | |
| 45 | 51 | ||
| @@ -51,23 +57,45 @@ static int odb_source_packed_read_object_info(struct odb_source *source, | |||
| 51 | 57 | if (flags & OBJECT_INFO_SECOND_READ) | |
| 52 | 58 | odb_source_prepare(source, ODB_PREPARE_FLUSH_CACHES); | |
| 53 | 59 | ||
| 54 | - | if (!find_pack_entry(packed, oid, &e)) | |
| 55 | - | return 1; | |
| 60 | + | if (!find_pack_entry(packed, oid, &e, &bad_pack)) { | |
| 61 | + | /* | |
| 62 | + | * The lookup may have failed because the object is known to be | |
| 63 | + | * corrupt in one of the packfiles. Report the object as | |
| 64 | + | * corrupt instead of missing in that case. | |
| 65 | + | */ | |
| 66 | + | if (bad_pack) { | |
| 67 | + | ret = -1; | |
| 68 | + | goto out; | |
| 69 | + | } | |
| 70 | + | ||
| 71 | + | ret = ODB_READ_NOT_FOUND; | |
| 72 | + | goto out; | |
| 73 | + | } | |
| 56 | 74 | ||
| 57 | 75 | /* | |
| 58 | 76 | * We know that the caller doesn't actually need the | |
| 59 | 77 | * information below, so return early. | |
| 60 | 78 | */ | |
| 61 | - | if (!oi) | |
| 62 | - | return 0; | |
| 79 | + | if (!oi) { | |
| 80 | + | ret = 0; | |
| 81 | + | goto out; | |
| 82 | + | } | |
| 63 | 83 | ||
| 64 | 84 | ret = packed_object_info(packed, e.p, e.offset, oi); | |
| 65 | 85 | if (ret < 0) { | |
| 86 | + | bad_pack = e.p; | |
| 66 | 87 | mark_bad_packed_object(e.p, oid); | |
| 67 | - | return -1; | |
| 88 | + | goto out; | |
| 68 | 89 | } | |
| 69 | 90 | ||
| 70 | - | return 0; | |
| 91 | + | ret = 0; | |
| 92 | + | ||
| 93 | + | out: | |
| 94 | + | if (ret < 0 && bad_pack && errmsg) | |
| 95 | + | strbuf_addf(errmsg, _("packed object %s (stored in %s) is corrupt"), | |
| 96 | + | oid_to_hex(oid), bad_pack->pack_name); | |
| 97 | + | ||
| 98 | + | return ret; | |
| 71 | 99 | } | |
| 72 | 100 | ||
| 73 | 101 | static int odb_source_packed_read_object_stream(struct odb_read_stream **out, | |
| @@ -77,7 +105,7 @@ static int odb_source_packed_read_object_stream(struct odb_read_stream **out, | |||
| 77 | 105 | struct odb_source_packed *packed = odb_source_packed_downcast(source); | |
| 78 | 106 | struct pack_entry e; | |
| 79 | 107 | ||
| 80 | - | if (!find_pack_entry(packed, oid, &e)) | |
| 108 | + | if (!find_pack_entry(packed, oid, &e, NULL)) | |
| 81 | 109 | return -1; | |
| 82 | 110 | ||
| 83 | 111 | return packfile_read_object_stream(out, oid, e.p, e.offset); | |
| @@ -583,7 +611,7 @@ static int odb_source_packed_freshen_object(struct odb_source *source, | |||
| 583 | 611 | timesp = × | |
| 584 | 612 | } | |
| 585 | 613 | ||
| 586 | - | if (!find_pack_entry(packed, oid, &e)) | |
| 614 | + | if (!find_pack_entry(packed, oid, &e, NULL)) | |
| 587 | 615 | return 0; | |
| 588 | 616 | if (e.p->is_cruft) | |
| 589 | 617 | return 0; | |
modified odb/source-packed.h
| @@ -78,9 +78,7 @@ struct odb_source_packed *odb_source_packed_new(struct object_database *odb, | |||
| 78 | 78 | static inline struct odb_source_packed *odb_source_packed_downcast(struct odb_source *source) | |
| 79 | 79 | { | |
| 80 | 80 | if (source->type != ODB_SOURCE_PACKED) | |
| 81 | - | BUG("trying to downcast source of type '%s' to '%s'", | |
| 82 | - | odb_source_type_to_name(source->type), | |
| 83 | - | odb_source_type_to_name(ODB_SOURCE_PACKED)); | |
| 81 | + | BUG("trying to downcast source of type '%d' to packed", source->type); | |
| 84 | 82 | return container_of(source, struct odb_source_packed, base); | |
| 85 | 83 | } | |
| 86 | 84 | ||
modified odb/source.c
| @@ -4,25 +4,6 @@ | |||
| 4 | 4 | #include "odb/source.h" | |
| 5 | 5 | #include "packfile.h" | |
| 6 | 6 | ||
| 7 | - | static const char * const odb_source_names_by_type[] = { | |
| 8 | - | [ODB_SOURCE_UNKNOWN] = "unknown", | |
| 9 | - | [ODB_SOURCE_FILES] = "files", | |
| 10 | - | [ODB_SOURCE_LOOSE] = "loose", | |
| 11 | - | [ODB_SOURCE_PACKED] = "packed", | |
| 12 | - | [ODB_SOURCE_INMEMORY] = "in-memory", | |
| 13 | - | }; | |
| 14 | - | ||
| 15 | - | const char *odb_source_type_to_name(enum odb_source_type type) | |
| 16 | - | { | |
| 17 | - | const char *name; | |
| 18 | - | if (type < 0 || type >= ARRAY_SIZE(odb_source_names_by_type)) | |
| 19 | - | type = ODB_SOURCE_UNKNOWN; | |
| 20 | - | name = odb_source_names_by_type[type]; | |
| 21 | - | if (!name) | |
| 22 | - | BUG("name missing in `odb_source_names_by_type` for '%d'", type); | |
| 23 | - | return name; | |
| 24 | - | } | |
| 25 | - | ||
| 26 | 7 | struct odb_source *odb_source_new(struct object_database *odb, | |
| 27 | 8 | const char *path, | |
| 28 | 9 | bool local) | |
modified odb/source.h
| @@ -25,14 +25,9 @@ enum odb_source_type { | |||
| 25 | 25 | ODB_SOURCE_INMEMORY, | |
| 26 | 26 | }; | |
| 27 | 27 | ||
| 28 | - | /* | |
| 29 | - | * Convert between the enum and its name. Returns the equivalent of "unknown" | |
| 30 | - | * for unknown types. | |
| 31 | - | */ | |
| 32 | - | const char *odb_source_type_to_name(enum odb_source_type type); | |
| 33 | - | ||
| 34 | 28 | struct object_id; | |
| 35 | 29 | struct odb_read_stream; | |
| 30 | + | struct strbuf; | |
| 36 | 31 | struct strvec; | |
| 37 | 32 | ||
| 38 | 33 | /* | |
| @@ -89,18 +84,6 @@ struct odb_source { | |||
| 89 | 84 | */ | |
| 90 | 85 | void (*close)(struct odb_source *source); | |
| 91 | 86 | ||
| 92 | - | /* | |
| 93 | - | * This callback is expected to create on-disk data structures that are | |
| 94 | - | * required for this source to operate. | |
| 95 | - | * | |
| 96 | - | * The callback is expected to return 0 on success, a negative error | |
| 97 | - | * code otherwise. | |
| 98 | - | * | |
| 99 | - | * This callback may be NULL in case the source does not need any | |
| 100 | - | * on-disk setup. | |
| 101 | - | */ | |
| 102 | - | int (*create_on_disk)(struct odb_source *source); | |
| 103 | - | ||
| 104 | 87 | /* | |
| 105 | 88 | * This callback is expected to prepare the source so that it becomes | |
| 106 | 89 | * ready for use. It optionally clears underlying caches of the object | |
| @@ -128,13 +111,17 @@ struct odb_source { | |||
| 128 | 111 | * second read in case they know that the first read would have | |
| 129 | 112 | * already surfaced the object without reloading any on-disk state. | |
| 130 | 113 | * | |
| 131 | - | * The callback is expected to return a negative error code in case | |
| 132 | - | * reading the object has failed, 0 otherwise. | |
| 114 | + | * The callback is expected to return an `enum odb_read_status`. Please | |
| 115 | + | * refer to the individual values that can be returned. In case reading | |
| 116 | + | * the object has failed with a generic error and `errmsg` is non-NULL, | |
| 117 | + | * the callback is expected to populate it with a human-readable | |
| 118 | + | * message that describes the failure. | |
| 133 | 119 | */ | |
| 134 | - | int (*read_object_info)(struct odb_source *source, | |
| 135 | - | const struct object_id *oid, | |
| 136 | - | struct object_info *oi, | |
| 137 | - | enum object_info_flags flags); | |
| 120 | + | enum odb_read_status (*read_object_info)(struct odb_source *source, | |
| 121 | + | const struct object_id *oid, | |
| 122 | + | struct object_info *oi, | |
| 123 | + | enum object_info_flags flags, | |
| 124 | + | struct strbuf *errmsg); | |
| 138 | 125 | ||
| 139 | 126 | /* | |
| 140 | 127 | * This callback is expected to create a new read stream that can be | |
| @@ -345,17 +332,6 @@ static inline void odb_source_close(struct odb_source *source) | |||
| 345 | 332 | source->close(source); | |
| 346 | 333 | } | |
| 347 | 334 | ||
| 348 | - | /* | |
| 349 | - | * Create on-disk data structures that are required for this source to operate | |
| 350 | - | * correctly. Returns 0 on success, a negative error code otherwise. | |
| 351 | - | */ | |
| 352 | - | static inline int odb_source_create_on_disk(struct odb_source *source) | |
| 353 | - | { | |
| 354 | - | if (!source->create_on_disk) | |
| 355 | - | return 0; | |
| 356 | - | return source->create_on_disk(source); | |
| 357 | - | } | |
| 358 | - | ||
| 359 | 335 | /* | |
| 360 | 336 | * Prepare the object database source and clear any caches. Depending on the | |
| 361 | 337 | * backend used this may have the effect that concurrently-written objects | |
| @@ -369,14 +345,19 @@ static inline void odb_source_prepare(struct odb_source *source, | |||
| 369 | 345 | ||
| 370 | 346 | /* | |
| 371 | 347 | * Read an object from the object database source identified by its object ID. | |
| 372 | - | * Returns 0 on success, a negative error code otherwise. | |
| 348 | + | * Please refer to `enum odb_read_status` for the individual error codes. | |
| 349 | + | * | |
| 350 | + | * In case reading the object has failed with a generic error and `errmsg` is | |
| 351 | + | * non-NULL it will be populated with a human-readable message that describes | |
| 352 | + | * the failure. | |
| 373 | 353 | */ | |
| 374 | - | static inline int odb_source_read_object_info(struct odb_source *source, | |
| 375 | - | const struct object_id *oid, | |
| 376 | - | struct object_info *oi, | |
| 377 | - | enum object_info_flags flags) | |
| 354 | + | static inline enum odb_read_status odb_source_read_object_info(struct odb_source *source, | |
| 355 | + | const struct object_id *oid, | |
| 356 | + | struct object_info *oi, | |
| 357 | + | enum object_info_flags flags, | |
| 358 | + | struct strbuf *errmsg) | |
| 378 | 359 | { | |
| 379 | - | return source->read_object_info(source, oid, oi, flags); | |
| 360 | + | return source->read_object_info(source, oid, oi, flags, errmsg); | |
| 380 | 361 | } | |
| 381 | 362 | ||
| 382 | 363 | /* | |
modified packfile.c
| @@ -985,23 +985,6 @@ void mark_bad_packed_object(struct packed_git *p, const struct object_id *oid) | |||
| 985 | 985 | oidset_insert(&p->bad_objects, oid); | |
| 986 | 986 | } | |
| 987 | 987 | ||
| 988 | - | const struct packed_git *has_packed_and_bad(struct repository *r, | |
| 989 | - | const struct object_id *oid) | |
| 990 | - | { | |
| 991 | - | struct odb_source *source; | |
| 992 | - | ||
| 993 | - | for (source = r->objects->sources; source; source = source->next) { | |
| 994 | - | struct odb_source_files *files = odb_source_files_downcast(source); | |
| 995 | - | struct packfile_list_entry *e; | |
| 996 | - | ||
| 997 | - | for (e = files->packed->packs.head; e; e = e->next) | |
| 998 | - | if (oidset_contains(&e->pack->bad_objects, oid)) | |
| 999 | - | return e->pack; | |
| 1000 | - | } | |
| 1001 | - | ||
| 1002 | - | return NULL; | |
| 1003 | - | } | |
| 1004 | - | ||
| 1005 | 988 | off_t get_delta_base(struct packed_git *p, | |
| 1006 | 989 | struct pack_window **w_curs, | |
| 1007 | 990 | off_t *curpos, | |
| @@ -1859,13 +1842,17 @@ int is_pack_valid(struct packed_git *p) | |||
| 1859 | 1842 | ||
| 1860 | 1843 | int packfile_fill_entry(struct packed_git *p, | |
| 1861 | 1844 | const struct object_id *oid, | |
| 1862 | - | struct pack_entry *e) | |
| 1845 | + | struct pack_entry *e, | |
| 1846 | + | struct packed_git **bad_pack) | |
| 1863 | 1847 | { | |
| 1864 | 1848 | off_t offset; | |
| 1865 | 1849 | ||
| 1866 | 1850 | if (oidset_size(&p->bad_objects) && | |
| 1867 | - | oidset_contains(&p->bad_objects, oid)) | |
| 1851 | + | oidset_contains(&p->bad_objects, oid)) { | |
| 1852 | + | if (bad_pack && !*bad_pack) | |
| 1853 | + | *bad_pack = p; | |
| 1868 | 1854 | return 0; | |
| 1855 | + | } | |
| 1869 | 1856 | ||
| 1870 | 1857 | offset = find_pack_entry_one(oid, p); | |
| 1871 | 1858 | if (!offset) | |
| @@ -1941,7 +1928,7 @@ int has_object_pack(struct repository *r, const struct object_id *oid) | |||
| 1941 | 1928 | odb_prepare_alternates(r->objects); | |
| 1942 | 1929 | for (source = r->objects->sources; source; source = source->next) { | |
| 1943 | 1930 | struct odb_source_files *files = odb_source_files_downcast(source); | |
| 1944 | - | if (!odb_source_read_object_info(&files->packed->base, oid, NULL, 0)) | |
| 1931 | + | if (!odb_source_read_object_info(&files->packed->base, oid, NULL, 0, NULL)) | |
| 1945 | 1932 | return 1; | |
| 1946 | 1933 | } | |
| 1947 | 1934 | ||
| @@ -1962,7 +1949,7 @@ int has_object_kept_pack(struct repository *r, const struct object_id *oid, | |||
| 1962 | 1949 | ||
| 1963 | 1950 | for (; *cache; cache++) { | |
| 1964 | 1951 | struct packed_git *p = *cache; | |
| 1965 | - | if (packfile_fill_entry(p, oid, &e)) | |
| 1952 | + | if (packfile_fill_entry(p, oid, &e, NULL)) | |
| 1966 | 1953 | return 1; | |
| 1967 | 1954 | } | |
| 1968 | 1955 | } | |
modified packfile.h
| @@ -294,7 +294,8 @@ off_t find_pack_entry_one(const struct object_id *oid, struct packed_git *); | |||
| 294 | 294 | ||
| 295 | 295 | int packfile_fill_entry(struct packed_git *p, | |
| 296 | 296 | const struct object_id *oid, | |
| 297 | - | struct pack_entry *e); | |
| 297 | + | struct pack_entry *e, | |
| 298 | + | struct packed_git **bad_pack); | |
| 298 | 299 | ||
| 299 | 300 | int is_pack_valid(struct packed_git *); | |
| 300 | 301 | void *unpack_entry(struct repository *r, struct packed_git *, off_t, | |
| @@ -328,7 +329,6 @@ int packed_object_info_with_index_pos(struct odb_source_packed *source, | |||
| 328 | 329 | uint32_t *maybe_index_pos, struct object_info *oi); | |
| 329 | 330 | ||
| 330 | 331 | void mark_bad_packed_object(struct packed_git *, const struct object_id *); | |
| 331 | - | const struct packed_git *has_packed_and_bad(struct repository *, const struct object_id *); | |
| 332 | 332 | ||
| 333 | 333 | int has_object_pack(struct repository *r, const struct object_id *oid); | |
| 334 | 334 | int has_object_kept_pack(struct repository *r, const struct object_id *oid, | |
modified ref-filter.c
| @@ -2744,72 +2744,6 @@ static int filter_exclude_match(struct ref_filter *filter, const char *refname) | |||
| 2744 | 2744 | return match_pattern(filter->exclude.v, refname, filter->ignore_case); | |
| 2745 | 2745 | } | |
| 2746 | 2746 | ||
| 2747 | - | static const char *short_upstream_name(const char *full_ref) | |
| 2748 | - | { | |
| 2749 | - | const char *short_name = full_ref; | |
| 2750 | - | ||
| 2751 | - | if (!skip_prefix(short_name, "refs/heads/", &short_name)) | |
| 2752 | - | skip_prefix(short_name, "refs/remotes/", &short_name); | |
| 2753 | - | return short_name; | |
| 2754 | - | } | |
| 2755 | - | ||
| 2756 | - | /* | |
| 2757 | - | * Match the configured upstream of a branch against the registered | |
| 2758 | - | * --forked patterns. Exact patterns are compared against the full | |
| 2759 | - | * upstream refname so they are unambiguous; glob patterns are matched | |
| 2760 | - | * against the abbreviated upstream so that a glob such as origin/... | |
| 2761 | - | * works as typed. | |
| 2762 | - | */ | |
| 2763 | - | static int filter_forked_match(struct ref_filter *filter, const char *refname) | |
| 2764 | - | { | |
| 2765 | - | const char *short_name; | |
| 2766 | - | struct branch *branch; | |
| 2767 | - | const char *upstream; | |
| 2768 | - | ||
| 2769 | - | if (!skip_prefix(refname, "refs/heads/", &short_name)) | |
| 2770 | - | return 0; | |
| 2771 | - | branch = branch_get(short_name); | |
| 2772 | - | if (!branch) | |
| 2773 | - | return 0; | |
| 2774 | - | upstream = branch_get_upstream(branch, NULL); | |
| 2775 | - | if (!upstream) | |
| 2776 | - | return 0; | |
| 2777 | - | ||
| 2778 | - | for (size_t i = 0; i < filter->forked.nr; i++) { | |
| 2779 | - | const char *pattern = filter->forked.v[i]; | |
| 2780 | - | if (has_glob_specials(pattern)) { | |
| 2781 | - | if (!wildmatch(pattern, short_upstream_name(upstream), | |
| 2782 | - | WM_PATHNAME)) | |
| 2783 | - | return 1; | |
| 2784 | - | } else if (!strcmp(pattern, upstream)) { | |
| 2785 | - | return 1; | |
| 2786 | - | } | |
| 2787 | - | } | |
| 2788 | - | return 0; | |
| 2789 | - | } | |
| 2790 | - | ||
| 2791 | - | int ref_filter_forked_add(struct ref_filter *filter, const char *arg) | |
| 2792 | - | { | |
| 2793 | - | struct object_id oid; | |
| 2794 | - | char *full_ref = NULL; | |
| 2795 | - | ||
| 2796 | - | if (has_glob_specials(arg)) { | |
| 2797 | - | strvec_push(&filter->forked, arg); | |
| 2798 | - | return 0; | |
| 2799 | - | } | |
| 2800 | - | ||
| 2801 | - | if (repo_dwim_ref(the_repository, arg, strlen(arg), &oid, | |
| 2802 | - | &full_ref, 0) == 1 && | |
| 2803 | - | (starts_with(full_ref, "refs/heads/") || | |
| 2804 | - | starts_with(full_ref, "refs/remotes/"))) { | |
| 2805 | - | strvec_push(&filter->forked, full_ref); | |
| 2806 | - | free(full_ref); | |
| 2807 | - | return 0; | |
| 2808 | - | } | |
| 2809 | - | free(full_ref); | |
| 2810 | - | return -1; | |
| 2811 | - | } | |
| 2812 | - | ||
| 2813 | 2747 | /* | |
| 2814 | 2748 | * We need to seek to the reference right after a given marker but excluding any | |
| 2815 | 2749 | * matching references. So we seek to the lexicographically next reference. | |
| @@ -3045,9 +2979,6 @@ static struct ref_array_item *apply_ref_filter(const struct reference *ref, | |||
| 3045 | 2979 | if (filter->points_at.nr && !match_points_at(&filter->points_at, ref->oid, ref->name)) | |
| 3046 | 2980 | return NULL; | |
| 3047 | 2981 | ||
| 3048 | - | if (filter->forked.nr && !filter_forked_match(filter, ref->name)) | |
| 3049 | - | return NULL; | |
| 3050 | - | ||
| 3051 | 2982 | /* | |
| 3052 | 2983 | * A merge filter is applied on refs pointing to commits. Hence | |
| 3053 | 2984 | * obtain the commit using the 'oid' available and discard all | |
| @@ -3833,7 +3764,6 @@ void ref_filter_init(struct ref_filter *filter) | |||
| 3833 | 3764 | void ref_filter_clear(struct ref_filter *filter) | |
| 3834 | 3765 | { | |
| 3835 | 3766 | strvec_clear(&filter->exclude); | |
| 3836 | - | strvec_clear(&filter->forked); | |
| 3837 | 3767 | oid_array_clear(&filter->points_at); | |
| 3838 | 3768 | commit_list_free(filter->with_commit); | |
| 3839 | 3769 | commit_list_free(filter->no_commit); | |
modified ref-filter.h
| @@ -67,7 +67,6 @@ struct ref_filter { | |||
| 67 | 67 | const char **name_patterns; | |
| 68 | 68 | const char *start_after; | |
| 69 | 69 | struct strvec exclude; | |
| 70 | - | struct strvec forked; | |
| 71 | 70 | struct oid_array points_at; | |
| 72 | 71 | struct commit_list *with_commit; | |
| 73 | 72 | struct commit_list *no_commit; | |
| @@ -111,7 +110,6 @@ struct ref_format { | |||
| 111 | 110 | #define REF_FILTER_INIT { \ | |
| 112 | 111 | .points_at = OID_ARRAY_INIT, \ | |
| 113 | 112 | .exclude = STRVEC_INIT, \ | |
| 114 | - | .forked = STRVEC_INIT, \ | |
| 115 | 113 | } | |
| 116 | 114 | #define REF_FORMAT_INIT { \ | |
| 117 | 115 | .use_color = GIT_COLOR_UNKNOWN, \ | |
| @@ -174,14 +172,6 @@ void ref_sorting_release(struct ref_sorting *); | |||
| 174 | 172 | struct ref_sorting *ref_sorting_options(struct string_list *); | |
| 175 | 173 | /* Function to parse --merged and --no-merged options */ | |
| 176 | 174 | int parse_opt_merge_filter(const struct option *opt, const char *arg, int unset); | |
| 177 | - | /* | |
| 178 | - | * Register a --forked <branch> pattern on the filter. The argument is | |
| 179 | - | * either a ref, which is resolved to its full refname, or a shell-style | |
| 180 | - | * glob. Branches are kept only when their configured upstream matches | |
| 181 | - | * one of the registered patterns. Returns -1 if the argument is not a | |
| 182 | - | * valid ref or pattern. | |
| 183 | - | */ | |
| 184 | - | int ref_filter_forked_add(struct ref_filter *filter, const char *arg); | |
| 185 | 175 | /* Get the current HEAD's description */ | |
| 186 | 176 | char *get_head_description(void); | |
| 187 | 177 | /* Set up translated strings in the output. */ | |
modified repository.c
| @@ -201,6 +201,8 @@ void repo_set_compat_hash_algo(struct repository *repo MAYBE_UNUSED, uint32_t al | |||
| 201 | 201 | if (hash_algo_by_ptr(repo->hash_algo) == algo) | |
| 202 | 202 | BUG("hash_algo and compat_hash_algo match"); | |
| 203 | 203 | repo->compat_hash_algo = algo ? &hash_algos[algo] : NULL; | |
| 204 | + | if (repo->compat_hash_algo) | |
| 205 | + | repo_read_loose_object_map(repo); | |
| 204 | 206 | #else | |
| 205 | 207 | if (algo) | |
| 206 | 208 | die(_("compatibility hash algorithm support requires Rust")); | |
| @@ -294,7 +296,6 @@ int repo_init(struct repository *repo, | |||
| 294 | 296 | warning("%s", err.buf); | |
| 295 | 297 | goto error; | |
| 296 | 298 | } | |
| 297 | - | repo->objects = odb_new(repo, 0); | |
| 298 | 299 | ||
| 299 | 300 | if (worktree) | |
| 300 | 301 | repo_set_worktree(repo, worktree); | |
modified setup.c
| @@ -962,54 +962,16 @@ void read_gitfile_error_die(int error_code, const char *path) | |||
| 962 | 962 | * cases). | |
| 963 | 963 | */ | |
| 964 | 964 | const char *read_gitfile_gently(const char *path, int *return_error_code) | |
| 965 | - | { | |
| 966 | - | int error_code = 0; | |
| 967 | - | const char *slash; | |
| 968 | - | struct strbuf contents = STRBUF_INIT; | |
| 969 | - | static struct strbuf realpath = STRBUF_INIT; | |
| 970 | - | ||
| 971 | - | error_code = read_gitfile_raw(&contents, path); | |
| 972 | - | if (error_code) | |
| 973 | - | goto cleanup_return; | |
| 974 | - | ||
| 975 | - | if (!is_absolute_path(contents.buf) && (slash = strrchr(path, '/'))) { | |
| 976 | - | size_t pathlen = slash+1 - path; | |
| 977 | - | char *dir = xstrfmt("%.*s%s", (int)pathlen, path, contents.buf); | |
| 978 | - | strbuf_reset(&contents); | |
| 979 | - | strbuf_addstr(&contents, dir); | |
| 980 | - | free(dir); | |
| 981 | - | } | |
| 982 | - | if (!is_git_directory(contents.buf)) { | |
| 983 | - | error_code = READ_GITFILE_ERR_NOT_A_REPO; | |
| 984 | - | goto cleanup_return; | |
| 985 | - | } | |
| 986 | - | ||
| 987 | - | strbuf_realpath(&realpath, contents.buf, 1); | |
| 988 | - | ||
| 989 | - | cleanup_return: | |
| 990 | - | if (return_error_code) | |
| 991 | - | *return_error_code = error_code; | |
| 992 | - | else if (error_code) | |
| 993 | - | read_gitfile_error_die(error_code, path); | |
| 994 | - | ||
| 995 | - | strbuf_release(&contents); | |
| 996 | - | return error_code ? NULL : realpath.buf; | |
| 997 | - | } | |
| 998 | - | ||
| 999 | - | /* | |
| 1000 | - | * Read the path following "gitdir: " from the .git file into strbuf. | |
| 1001 | - | * | |
| 1002 | - | * Unlike read_gitfile_gently(), this function does not resolve a | |
| 1003 | - | * relative path or validate it using is_git_directory(). | |
| 1004 | - | */ | |
| 1005 | - | int read_gitfile_raw(struct strbuf *contents, const char *path) | |
| 1006 | 965 | { | |
| 1007 | 966 | const int max_file_size = 1 << 20; /* 1MB */ | |
| 1008 | 967 | int error_code = 0; | |
| 1009 | 968 | char *buf = NULL; | |
| 969 | + | char *dir = NULL; | |
| 970 | + | const char *slash; | |
| 1010 | 971 | struct stat st; | |
| 1011 | 972 | int fd; | |
| 1012 | 973 | ssize_t len; | |
| 974 | + | static struct strbuf realpath = STRBUF_INIT; | |
| 1013 | 975 | ||
| 1014 | 976 | if (stat(path, &st)) { | |
| 1015 | 977 | if (errno == ENOENT || errno == ENOTDIR) | |
| @@ -1052,11 +1014,32 @@ int read_gitfile_raw(struct strbuf *contents, const char *path) | |||
| 1052 | 1014 | error_code = READ_GITFILE_ERR_NO_PATH; | |
| 1053 | 1015 | goto cleanup_return; | |
| 1054 | 1016 | } | |
| 1055 | - | strbuf_add(contents, buf+8, len-8); | |
| 1017 | + | buf[len] = '\0'; | |
| 1018 | + | dir = buf + 8; | |
| 1019 | + | ||
| 1020 | + | if (!is_absolute_path(dir) && (slash = strrchr(path, '/'))) { | |
| 1021 | + | size_t pathlen = slash+1 - path; | |
| 1022 | + | dir = xstrfmt("%.*s%.*s", (int)pathlen, path, | |
| 1023 | + | (int)(len - 8), buf + 8); | |
| 1024 | + | free(buf); | |
| 1025 | + | buf = dir; | |
| 1026 | + | } | |
| 1027 | + | if (!is_git_directory(dir)) { | |
| 1028 | + | error_code = READ_GITFILE_ERR_NOT_A_REPO; | |
| 1029 | + | goto cleanup_return; | |
| 1030 | + | } | |
| 1031 | + | ||
| 1032 | + | strbuf_realpath(&realpath, dir, 1); | |
| 1033 | + | path = realpath.buf; | |
| 1056 | 1034 | ||
| 1057 | 1035 | cleanup_return: | |
| 1036 | + | if (return_error_code) | |
| 1037 | + | *return_error_code = error_code; | |
| 1038 | + | else if (error_code) | |
| 1039 | + | read_gitfile_error_die(error_code, path); | |
| 1040 | + | ||
| 1058 | 1041 | free(buf); | |
| 1059 | - | return error_code; | |
| 1042 | + | return error_code ? NULL : path; | |
| 1060 | 1043 | } | |
| 1061 | 1044 | ||
| 1062 | 1045 | static void apply_gitdir_and_environment(struct repository *repo, const char *path) | |
| @@ -1782,6 +1765,8 @@ int apply_repository_format(struct repository *repo, | |||
| 1782 | 1765 | enum apply_repository_format_flags flags, | |
| 1783 | 1766 | struct strbuf *err) | |
| 1784 | 1767 | { | |
| 1768 | + | char *object_directory = NULL, *alternate_object_directories = NULL; | |
| 1769 | + | ||
| 1785 | 1770 | if (verify_repository_format(format, err) < 0) | |
| 1786 | 1771 | return -1; | |
| 1787 | 1772 | ||
| @@ -1794,6 +1779,8 @@ int apply_repository_format(struct repository *repo, | |||
| 1794 | 1779 | if (flags & APPLY_REPOSITORY_FORMAT_HONOR_ENV) { | |
| 1795 | 1780 | const char *shallow_file; | |
| 1796 | 1781 | ||
| 1782 | + | object_directory = xstrdup_or_null(getenv(DB_ENVIRONMENT)); | |
| 1783 | + | alternate_object_directories = xstrdup_or_null(getenv(ALTERNATE_DB_ENVIRONMENT)); | |
| 1797 | 1784 | shallow_file = getenv(GIT_SHALLOW_FILE_ENVIRONMENT); | |
| 1798 | 1785 | if (shallow_file) | |
| 1799 | 1786 | set_alternate_shallow_file(repo, shallow_file); | |
| @@ -1801,6 +1788,8 @@ int apply_repository_format(struct repository *repo, | |||
| 1801 | 1788 | ||
| 1802 | 1789 | repo->bare_cfg = format->is_bare; | |
| 1803 | 1790 | repo_set_hash_algo(repo, format->hash_algo); | |
| 1791 | + | repo->objects = odb_new(repo, object_directory, | |
| 1792 | + | alternate_object_directories); | |
| 1804 | 1793 | repo_set_compat_hash_algo(repo, format->compat_hash_algo); | |
| 1805 | 1794 | repo_set_ref_storage_format(repo, | |
| 1806 | 1795 | format->ref_storage_format, | |
| @@ -1816,6 +1805,8 @@ int apply_repository_format(struct repository *repo, | |||
| 1816 | 1805 | repo->repository_format_precious_objects = | |
| 1817 | 1806 | format->precious_objects; | |
| 1818 | 1807 | ||
| 1808 | + | free(alternate_object_directories); | |
| 1809 | + | free(object_directory); | |
| 1819 | 1810 | return 0; | |
| 1820 | 1811 | } | |
| 1821 | 1812 | ||
| @@ -1899,7 +1890,6 @@ const char *enter_repo(struct repository *repo, const char *path, unsigned flags | |||
| 1899 | 1890 | read_and_verify_repository_format(&fmt, ".", NULL); | |
| 1900 | 1891 | if (apply_repository_format(repo, &fmt, APPLY_REPOSITORY_FORMAT_HONOR_ENV, &err) < 0) | |
| 1901 | 1892 | die("%s", err.buf); | |
| 1902 | - | repo->objects = odb_new(repo, ODB_NEW_HONOR_ENV); | |
| 1903 | 1893 | startup_info->have_repository = 1; | |
| 1904 | 1894 | ||
| 1905 | 1895 | clear_repository_format(&fmt); | |
| @@ -2102,7 +2092,6 @@ const char *setup_git_directory_gently(struct repository *repo, int *nongit_ok) | |||
| 2102 | 2092 | if (apply_repository_format(repo, &discovery.format, | |
| 2103 | 2093 | APPLY_REPOSITORY_FORMAT_HONOR_ENV, &err) < 0) | |
| 2104 | 2094 | die("%s", err.buf); | |
| 2105 | - | repo->objects = odb_new(repo, ODB_NEW_HONOR_ENV); | |
| 2106 | 2095 | ||
| 2107 | 2096 | clear_repository_format(&discovery.format); | |
| 2108 | 2097 | strbuf_release(&err); | |
| @@ -2664,29 +2653,25 @@ static int create_default_files(struct repository *repo, | |||
| 2664 | 2653 | return reinit; | |
| 2665 | 2654 | } | |
| 2666 | 2655 | ||
| 2667 | - | static void create_object_database(struct repository *repo) | |
| 2656 | + | static void create_object_directory(struct repository *repo) | |
| 2668 | 2657 | { | |
| 2669 | - | /* | |
| 2670 | - | * Create the "objects" directory in the common directory. This is done | |
| 2671 | - | * so that the repository can be discovered regardless of the backend | |
| 2672 | - | * used. | |
| 2673 | - | * | |
| 2674 | - | * Note that we only do this in case the object directory wasn't | |
| 2675 | - | * overwritten via an environment variable. If it _is_ being overridden | |
| 2676 | - | * then we skip this step, as the repository won't be discoverable | |
| 2677 | - | * anyway without the environment variable. | |
| 2678 | - | */ | |
| 2679 | - | if (!getenv(DB_ENVIRONMENT)) { | |
| 2680 | - | struct strbuf objects_dir = STRBUF_INIT; | |
| 2681 | - | repo_common_path_append(repo, &objects_dir, "objects"); | |
| 2682 | - | safe_create_dir(repo, objects_dir.buf, 1); | |
| 2683 | - | strbuf_release(&objects_dir); | |
| 2684 | - | } | |
| 2658 | + | struct strbuf path = STRBUF_INIT; | |
| 2659 | + | size_t baselen; | |
| 2660 | + | ||
| 2661 | + | strbuf_addstr(&path, repo_get_object_directory(repo)); | |
| 2662 | + | baselen = path.len; | |
| 2685 | 2663 | ||
| 2686 | - | repo->objects = odb_new(repo, ODB_NEW_HONOR_ENV); | |
| 2664 | + | safe_create_dir(repo, path.buf, 1); | |
| 2687 | 2665 | ||
| 2688 | - | if (odb_source_create_on_disk(repo->objects->sources) < 0) | |
| 2689 | - | die(_("failed creating object database")); | |
| 2666 | + | strbuf_setlen(&path, baselen); | |
| 2667 | + | strbuf_addstr(&path, "/pack"); | |
| 2668 | + | safe_create_dir(repo, path.buf, 1); | |
| 2669 | + | ||
| 2670 | + | strbuf_setlen(&path, baselen); | |
| 2671 | + | strbuf_addstr(&path, "/info"); | |
| 2672 | + | safe_create_dir(repo, path.buf, 1); | |
| 2673 | + | ||
| 2674 | + | strbuf_release(&path); | |
| 2690 | 2675 | } | |
| 2691 | 2676 | ||
| 2692 | 2677 | static void separate_git_dir(struct repository *repo, | |
| @@ -2884,6 +2869,7 @@ int init_db(struct repository *repo, | |||
| 2884 | 2869 | repository_format_configure(&repo_fmt, hash, ref_storage_format); | |
| 2885 | 2870 | if (apply_repository_format(repo, &repo_fmt, APPLY_REPOSITORY_FORMAT_HONOR_ENV, &err) < 0) | |
| 2886 | 2871 | die("%s", err.buf); | |
| 2872 | + | startup_info->have_repository = 1; | |
| 2887 | 2873 | ||
| 2888 | 2874 | /* | |
| 2889 | 2875 | * Ensure `core.hidedotfiles` is processed. This must happen after we | |
| @@ -2899,9 +2885,7 @@ int init_db(struct repository *repo, | |||
| 2899 | 2885 | ||
| 2900 | 2886 | if (!(flags & INIT_DB_SKIP_REFDB)) | |
| 2901 | 2887 | create_reference_database(repo, initial_branch, flags & INIT_DB_QUIET); | |
| 2902 | - | create_object_database(repo); | |
| 2903 | - | ||
| 2904 | - | startup_info->have_repository = 1; | |
| 2888 | + | create_object_directory(repo); | |
| 2905 | 2889 | ||
| 2906 | 2890 | if (repo_settings_get_shared_repository(repo)) { | |
| 2907 | 2891 | char buf[10]; | |
modified setup.h
| @@ -40,7 +40,6 @@ int is_nonbare_repository_dir(struct strbuf *path); | |||
| 40 | 40 | #define READ_GITFILE_ERR_IS_A_DIR 10 | |
| 41 | 41 | void read_gitfile_error_die(int error_code, const char *path); | |
| 42 | 42 | const char *read_gitfile_gently(const char *path, int *return_error_code); | |
| 43 | - | int read_gitfile_raw(struct strbuf *contents, const char *path); | |
| 44 | 43 | #define read_gitfile(path) read_gitfile_gently((path), NULL) | |
| 45 | 44 | const char *resolve_gitdir_gently(const char *suspect, int *return_error_code); | |
| 46 | 45 | #define resolve_gitdir(path) resolve_gitdir_gently((path), NULL) | |
| @@ -246,8 +245,8 @@ enum apply_repository_format_flags { | |||
| 246 | 245 | ||
| 247 | 246 | /* | |
| 248 | 247 | * Apply the given repository format to the repo. This initializes extensions | |
| 249 | - | * required for normal operation. Returns 0 on success, a negative error code | |
| 250 | - | * when the format is not valid as determined by | |
| 248 | + | * and basic data structures required for normal operation. Returns 0 on | |
| 249 | + | * success, a negative error code when the format is not valid as determined by | |
| 251 | 250 | * `verify_repository_format()`. | |
| 252 | 251 | */ | |
| 253 | 252 | int apply_repository_format(struct repository *repo, | |
modified t/helper/test-read-midx.c
| @@ -82,7 +82,7 @@ static int read_midx_file(const char *object_dir, const char *checksum, | |||
| 82 | 82 | for (i = 0; i < m->num_objects; i++) { | |
| 83 | 83 | nth_midxed_object_oid(&oid, m, | |
| 84 | 84 | i + m->num_objects_in_base); | |
| 85 | - | fill_midx_entry(m, &oid, &e); | |
| 85 | + | fill_midx_entry(m, &oid, &e, NULL); | |
| 86 | 86 | ||
| 87 | 87 | printf("%s %"PRIu64"\t%s\n", | |
| 88 | 88 | oid_to_hex(&oid), e.offset, e.p->pack_name); | |
modified t/t1016-compatObjectFormat.sh
| @@ -187,24 +187,6 @@ do | |||
| 187 | 187 | eval signedtag3_${hash}_oid=$(git hash-object -t tag -w ../${hash}_signedtag3) && | |
| 188 | 188 | eval signedtag4_${hash}_oid=$(git hash-object -t tag -w ../${hash}_signedtag4) | |
| 189 | 189 | ' | |
| 190 | - | ||
| 191 | - | test_expect_success 'rev-parse maps oid of object borrowed from alternate' ' | |
| 192 | - | for repo in alt borrow | |
| 193 | - | do | |
| 194 | - | test_when_finished "rm -rf $repo" && | |
| 195 | - | git init --object-format=$hash $repo && | |
| 196 | - | git -C $repo config set core.repositoryformatversion 1 && | |
| 197 | - | git -C $repo config set extensions.compatObjectFormat $(compat_hash $hash) || exit 1 | |
| 198 | - | done && | |
| 199 | - | ||
| 200 | - | git -C alt commit --allow-empty --message A && | |
| 201 | - | echo "$(pwd)/alt/.git/objects" >borrow/.git/objects/info/alternates && | |
| 202 | - | ||
| 203 | - | oid=$(git -C alt rev-parse HEAD) && | |
| 204 | - | git -C alt rev-parse --output-object-format=$(compat_hash $hash) "$oid" >expect && | |
| 205 | - | git -C borrow rev-parse --output-object-format=$(compat_hash $hash) "$oid" >actual && | |
| 206 | - | test_cmp expect actual | |
| 207 | - | ' | |
| 208 | 190 | done | |
| 209 | 191 | cd "$base" | |
| 210 | 192 | ||
modified t/t1060-object-corruption.sh
| @@ -145,4 +145,22 @@ test_expect_success 'partial clone of corrupted repository' ' | |||
| 145 | 145 | test_must_fail git -C corrupt-partial checkout --force | |
| 146 | 146 | ' | |
| 147 | 147 | ||
| 148 | + | test_expect_success 'corrupted loose commit can be read from alternate' ' | |
| 149 | + | git init repo-a && | |
| 150 | + | tree=$(git -C repo-a write-tree) && | |
| 151 | + | commit=$(git -C repo-a commit-tree $tree </dev/null) && | |
| 152 | + | ||
| 153 | + | cp -r repo-a repo-b && | |
| 154 | + | ( | |
| 155 | + | cd repo-b && | |
| 156 | + | echo ../../../repo-a/.git/objects >.git/objects/info/alternates && | |
| 157 | + | corrupt_byte "$commit" 1 | |
| 158 | + | ) && | |
| 159 | + | ||
| 160 | + | git -C repo-a cat-file -p "$commit" >expect && | |
| 161 | + | git -C repo-b cat-file -p "$commit" >actual 2>err && | |
| 162 | + | test_cmp expect actual && | |
| 163 | + | test_grep "inflate: data stream error" err | |
| 164 | + | ' | |
| 165 | + | ||
| 148 | 166 | test_done | |
modified t/t2406-worktree-repair.sh
| @@ -228,60 +228,30 @@ test_expect_success 'repair worktree with relative path with missing gitfile' ' | |||
| 228 | 228 | test_cmp expect wt/.git | |
| 229 | 229 | ' | |
| 230 | 230 | ||
| 231 | - | test_expect_success 'repair absolute to relative from side worktree' ' | |
| 232 | - | test_when_finished "rm -rf main side" && | |
| 231 | + | test_expect_success 'repair absolute worktree to use relative paths' ' | |
| 232 | + | test_when_finished "rm -rf main side sidemoved" && | |
| 233 | 233 | test_create_repo main && | |
| 234 | 234 | test_commit -C main init && | |
| 235 | 235 | git -C main worktree add --detach ../side && | |
| 236 | - | echo "../../../../side/.git" >expect-gitdir && | |
| 236 | + | echo "../../../../sidemoved/.git" >expect-gitdir && | |
| 237 | 237 | echo "gitdir: ../main/.git/worktrees/side" >expect-gitfile && | |
| 238 | - | git -C main worktree repair --relative-paths ../side 2>main/err && | |
| 239 | - | test_grep "gitdir absolute/relative path mismatch" main/err && | |
| 238 | + | mv side sidemoved && | |
| 239 | + | git -C main worktree repair --relative-paths ../sidemoved && | |
| 240 | 240 | test_cmp expect-gitdir main/.git/worktrees/side/gitdir && | |
| 241 | - | test_cmp expect-gitfile side/.git | |
| 241 | + | test_cmp expect-gitfile sidemoved/.git | |
| 242 | 242 | ' | |
| 243 | 243 | ||
| 244 | - | test_expect_success 'repair relative to absolute from side worktree' ' | |
| 245 | - | test_when_finished "rm -rf main side" && | |
| 244 | + | test_expect_success 'repair relative worktree to use absolute paths' ' | |
| 245 | + | test_when_finished "rm -rf main side sidemoved" && | |
| 246 | 246 | test_create_repo main && | |
| 247 | 247 | test_commit -C main init && | |
| 248 | 248 | git -C main worktree add --relative-paths --detach ../side && | |
| 249 | - | echo "$(pwd)/side/.git" >expect-gitdir && | |
| 250 | - | echo "gitdir: $(pwd)/main/.git/worktrees/side" >expect-gitfile && | |
| 251 | - | git -C main worktree repair ../side 2>main/err && | |
| 252 | - | test_grep "gitdir absolute/relative path mismatch" main/err && | |
| 253 | - | test_cmp expect-gitdir main/.git/worktrees/side/gitdir && | |
| 254 | - | test_cmp expect-gitfile side/.git | |
| 255 | - | ' | |
| 256 | - | ||
| 257 | - | test_expect_success 'repair absolute to relative from main worktree' ' | |
| 258 | - | test_when_finished "rm -rf main side" && | |
| 259 | - | test_create_repo main && | |
| 260 | - | git -C main config worktree.useRelativePaths false && | |
| 261 | - | test_commit -C main init && | |
| 262 | - | git -C main worktree add --detach ../side && | |
| 263 | - | echo "../../../../side/.git" >expect-gitdir && | |
| 264 | - | echo "gitdir: ../main/.git/worktrees/side" >expect-gitfile && | |
| 265 | - | git -C main config worktree.useRelativePaths true && | |
| 266 | - | git -C main worktree repair 2>main/err && | |
| 267 | - | test_grep ".git file absolute/relative path mismatch" main/err && | |
| 268 | - | test_cmp expect-gitdir main/.git/worktrees/side/gitdir && | |
| 269 | - | test_cmp expect-gitfile side/.git | |
| 270 | - | ' | |
| 271 | - | ||
| 272 | - | test_expect_success 'repair relative to absolute from main worktree' ' | |
| 273 | - | test_when_finished "rm -rf main side" && | |
| 274 | - | test_create_repo main && | |
| 275 | - | git -C main config worktree.useRelativePaths true && | |
| 276 | - | test_commit -C main init && | |
| 277 | - | git -C main worktree add --detach ../side && | |
| 278 | - | echo "$(pwd)/side/.git" >expect-gitdir && | |
| 249 | + | echo "$(pwd)/sidemoved/.git" >expect-gitdir && | |
| 279 | 250 | echo "gitdir: $(pwd)/main/.git/worktrees/side" >expect-gitfile && | |
| 280 | - | git -C main config worktree.useRelativePaths false && | |
| 281 | - | git -C main worktree repair 2>main/err && | |
| 282 | - | test_grep ".git file absolute/relative path mismatch" main/err && | |
| 251 | + | mv side sidemoved && | |
| 252 | + | git -C main worktree repair ../sidemoved && | |
| 283 | 253 | test_cmp expect-gitdir main/.git/worktrees/side/gitdir && | |
| 284 | - | test_cmp expect-gitfile side/.git | |
| 254 | + | test_cmp expect-gitfile sidemoved/.git | |
| 285 | 255 | ' | |
| 286 | 256 | ||
| 287 | 257 | test_done | |
modified t/t3200-branch.sh
| @@ -1757,425 +1757,4 @@ test_expect_success 'errors if given a bad branch name' ' | |||
| 1757 | 1757 | test_cmp expect actual | |
| 1758 | 1758 | ' | |
| 1759 | 1759 | ||
| 1760 | - | test_expect_success '--forked: setup' ' | |
| 1761 | - | test_create_repo forked-upstream && | |
| 1762 | - | ( | |
| 1763 | - | cd forked-upstream && | |
| 1764 | - | test_commit base && | |
| 1765 | - | git branch one base && | |
| 1766 | - | git branch two base | |
| 1767 | - | ) && | |
| 1768 | - | ||
| 1769 | - | test_create_repo forked-other && | |
| 1770 | - | ( | |
| 1771 | - | cd forked-other && | |
| 1772 | - | test_commit other-base && | |
| 1773 | - | git branch foreign other-base | |
| 1774 | - | ) && | |
| 1775 | - | ||
| 1776 | - | git clone forked-upstream forked && | |
| 1777 | - | ( | |
| 1778 | - | cd forked && | |
| 1779 | - | git remote add -f other ../forked-other && | |
| 1780 | - | git branch local-base && | |
| 1781 | - | git branch --track local-one origin/one && | |
| 1782 | - | git branch --track local-two origin/two && | |
| 1783 | - | git branch --track local-foreign other/foreign && | |
| 1784 | - | git branch --track local-onbase local-base && | |
| 1785 | - | ||
| 1786 | - | git checkout local-one && | |
| 1787 | - | test_commit --no-tag local-one-work local-one.t && | |
| 1788 | - | git checkout local-foreign && | |
| 1789 | - | test_commit --no-tag local-foreign-work local-foreign.t | |
| 1790 | - | ) | |
| 1791 | - | ' | |
| 1792 | - | ||
| 1793 | - | test_expect_success '--forked <upstream-tracking-branch> filters by upstream' ' | |
| 1794 | - | git -C forked branch --forked origin/one \ | |
| 1795 | - | --format="%(refname:short)" >actual && | |
| 1796 | - | echo local-one >expect && | |
| 1797 | - | test_cmp expect actual | |
| 1798 | - | ' | |
| 1799 | - | ||
| 1800 | - | test_expect_success '--forked <glob> filters by wildmatch' ' | |
| 1801 | - | git -C forked branch --forked "origin/*" \ | |
| 1802 | - | --format="%(refname:short)" >actual && | |
| 1803 | - | cat >expect <<-\EOF && | |
| 1804 | - | local-one | |
| 1805 | - | local-two | |
| 1806 | - | main | |
| 1807 | - | EOF | |
| 1808 | - | test_cmp expect actual | |
| 1809 | - | ' | |
| 1810 | - | ||
| 1811 | - | test_expect_success '--forked <local-branch> matches branches with local upstream' ' | |
| 1812 | - | git -C forked branch --forked local-base \ | |
| 1813 | - | --format="%(refname:short)" >actual && | |
| 1814 | - | echo local-onbase >expect && | |
| 1815 | - | test_cmp expect actual | |
| 1816 | - | ' | |
| 1817 | - | ||
| 1818 | - | test_expect_success '--forked can be repeated to widen the filter' ' | |
| 1819 | - | git -C forked branch --forked origin/one \ | |
| 1820 | - | --forked other/foreign \ | |
| 1821 | - | --format="%(refname:short)" >actual && | |
| 1822 | - | cat >expect <<-\EOF && | |
| 1823 | - | local-foreign | |
| 1824 | - | local-one | |
| 1825 | - | EOF | |
| 1826 | - | test_cmp expect actual | |
| 1827 | - | ' | |
| 1828 | - | ||
| 1829 | - | test_expect_success '--forked combines literal and glob arguments' ' | |
| 1830 | - | git -C forked branch --forked local-base \ | |
| 1831 | - | --forked "other/*" \ | |
| 1832 | - | --format="%(refname:short)" >actual && | |
| 1833 | - | cat >expect <<-\EOF && | |
| 1834 | - | local-foreign | |
| 1835 | - | local-onbase | |
| 1836 | - | EOF | |
| 1837 | - | test_cmp expect actual | |
| 1838 | - | ' | |
| 1839 | - | ||
| 1840 | - | test_expect_success '--forked "*/*" covers every remote-tracking upstream' ' | |
| 1841 | - | git -C forked branch --forked "*/*" \ | |
| 1842 | - | --format="%(refname:short)" >actual && | |
| 1843 | - | cat >expect <<-\EOF && | |
| 1844 | - | local-foreign | |
| 1845 | - | local-one | |
| 1846 | - | local-two | |
| 1847 | - | main | |
| 1848 | - | EOF | |
| 1849 | - | test_cmp expect actual | |
| 1850 | - | ' | |
| 1851 | - | ||
| 1852 | - | test_expect_success '--forked composes with --no-merged' ' | |
| 1853 | - | git -C forked branch --forked "origin/*" \ | |
| 1854 | - | --no-merged origin/one \ | |
| 1855 | - | --format="%(refname:short)" >actual && | |
| 1856 | - | echo local-one >expect && | |
| 1857 | - | test_cmp expect actual | |
| 1858 | - | ' | |
| 1859 | - | ||
| 1860 | - | test_expect_success '--forked <remote> uses the branch <remote>/HEAD points at' ' | |
| 1861 | - | git -C forked branch --forked origin \ | |
| 1862 | - | --format="%(refname:short)" >actual && | |
| 1863 | - | echo main >expect && | |
| 1864 | - | test_cmp expect actual | |
| 1865 | - | ' | |
| 1866 | - | ||
| 1867 | - | test_expect_success '--forked narrows a <pattern> argument' ' | |
| 1868 | - | git -C forked branch --forked "origin/*" "local-*" \ | |
| 1869 | - | --format="%(refname:short)" >actual && | |
| 1870 | - | cat >expect <<-\EOF && | |
| 1871 | - | local-one | |
| 1872 | - | local-two | |
| 1873 | - | EOF | |
| 1874 | - | test_cmp expect actual | |
| 1875 | - | ' | |
| 1876 | - | ||
| 1877 | - | test_expect_success '--forked rejects unknown branch/pattern' ' | |
| 1878 | - | test_must_fail git -C forked branch --forked nope 2>err && | |
| 1879 | - | test_grep "not a valid branch or pattern" err | |
| 1880 | - | ' | |
| 1881 | - | ||
| 1882 | - | test_expect_success '--forked requires a value' ' | |
| 1883 | - | test_must_fail git -C forked branch --forked 2>err && | |
| 1884 | - | test_grep "requires a value" err | |
| 1885 | - | ' | |
| 1886 | - | ||
| 1887 | - | test_expect_success '--delete-merged: setup' ' | |
| 1888 | - | git init -b main upstream && | |
| 1889 | - | ( | |
| 1890 | - | cd upstream && | |
| 1891 | - | test_commit base && | |
| 1892 | - | git checkout -b next && | |
| 1893 | - | test_commit next-work && | |
| 1894 | - | git checkout main | |
| 1895 | - | ) && | |
| 1896 | - | git init -b main other && | |
| 1897 | - | test_commit -C other other-base && | |
| 1898 | - | git init -b main fork | |
| 1899 | - | ' | |
| 1900 | - | ||
| 1901 | - | setup_repo_for_delete_merged () { | |
| 1902 | - | rm -rf repo && | |
| 1903 | - | git clone upstream repo && | |
| 1904 | - | ( | |
| 1905 | - | cd repo && | |
| 1906 | - | git remote add fork ../fork && | |
| 1907 | - | git remote add other ../other && | |
| 1908 | - | git config push.default current && | |
| 1909 | - | git fetch other | |
| 1910 | - | ) | |
| 1911 | - | } | |
| 1912 | - | ||
| 1913 | - | create_merged_branch () { | |
| 1914 | - | ( | |
| 1915 | - | cd repo && | |
| 1916 | - | git checkout -b "$1" --track origin/next && | |
| 1917 | - | git commit --allow-empty -m "$1 work" && | |
| 1918 | - | git push origin "$1:next" | |
| 1919 | - | ) | |
| 1920 | - | } | |
| 1921 | - | ||
| 1922 | - | check_branches () { | |
| 1923 | - | git for-each-ref --format="%(refname:short)" refs/heads/ >actual && | |
| 1924 | - | cat >expect && | |
| 1925 | - | test_cmp expect actual | |
| 1926 | - | } | |
| 1927 | - | ||
| 1928 | - | test_expect_success '--delete-merged keeps cloned main without explicit push configuration' ' | |
| 1929 | - | setup_repo_for_delete_merged && | |
| 1930 | - | ( | |
| 1931 | - | cd repo && | |
| 1932 | - | test_cmp_config origin branch.main.remote && | |
| 1933 | - | test_cmp_config refs/heads/main branch.main.merge && | |
| 1934 | - | git checkout --detach && | |
| 1935 | - | ||
| 1936 | - | git branch --delete-merged */* && | |
| 1937 | - | ||
| 1938 | - | check_branches <<-\EOF | |
| 1939 | - | main | |
| 1940 | - | EOF | |
| 1941 | - | ) | |
| 1942 | - | ' | |
| 1943 | - | ||
| 1944 | - | test_expect_success '--delete-merged deletes only selected merged branches' ' | |
| 1945 | - | setup_repo_for_delete_merged && | |
| 1946 | - | create_merged_branch also-merged && | |
| 1947 | - | create_merged_branch merged && | |
| 1948 | - | ( | |
| 1949 | - | cd repo && | |
| 1950 | - | git checkout -b unmerged --track origin/next && | |
| 1951 | - | git commit --allow-empty -m "unmerged work" && | |
| 1952 | - | git checkout -b tracks-other --track other/main && | |
| 1953 | - | sha=$(git rev-parse --short merged) && | |
| 1954 | - | ||
| 1955 | - | git branch --dry-run --delete-merged origin/next merged \ | |
| 1956 | - | >actual 2>&1 && | |
| 1957 | - | echo "Would delete branch merged (was $sha)." >expect && | |
| 1958 | - | test_cmp expect actual && | |
| 1959 | - | git rev-parse --verify refs/heads/merged && | |
| 1960 | - | ||
| 1961 | - | check_branches <<-\EOF && | |
| 1962 | - | also-merged | |
| 1963 | - | main | |
| 1964 | - | merged | |
| 1965 | - | tracks-other | |
| 1966 | - | unmerged | |
| 1967 | - | EOF | |
| 1968 | - | ||
| 1969 | - | git branch --delete-merged origin/next merged >actual 2>&1 && | |
| 1970 | - | echo "Deleted branch merged (was $sha)." >expect && | |
| 1971 | - | test_cmp expect actual && | |
| 1972 | - | ||
| 1973 | - | check_branches <<-\EOF | |
| 1974 | - | also-merged | |
| 1975 | - | main | |
| 1976 | - | tracks-other | |
| 1977 | - | unmerged | |
| 1978 | - | EOF | |
| 1979 | - | ) | |
| 1980 | - | ' | |
| 1981 | - | ||
| 1982 | - | test_expect_success '--delete-merged keeps main despite a different default push remote' ' | |
| 1983 | - | setup_repo_for_delete_merged && | |
| 1984 | - | create_merged_branch on-next && | |
| 1985 | - | create_merged_branch checked-out && | |
| 1986 | - | create_merged_branch upstream-gone && | |
| 1987 | - | ( | |
| 1988 | - | cd repo && | |
| 1989 | - | git config remote.pushDefault fork && | |
| 1990 | - | git checkout -b local-to-delete --track main && | |
| 1991 | - | git config branch.upstream-gone.merge refs/heads/topic && | |
| 1992 | - | git checkout -b tracks-other --track other/main && | |
| 1993 | - | git checkout checked-out && | |
| 1994 | - | ||
| 1995 | - | git branch --delete-merged origin/* --delete-merged main && | |
| 1996 | - | ||
| 1997 | - | check_branches <<-\EOF | |
| 1998 | - | checked-out | |
| 1999 | - | main | |
| 2000 | - | tracks-other | |
| 2001 | - | upstream-gone | |
| 2002 | - | EOF | |
| 2003 | - | ) | |
| 2004 | - | ' | |
| 2005 | - | ||
| 2006 | - | test_expect_success '--delete-merged maps push refspecs to upstreams' ' | |
| 2007 | - | setup_repo_for_delete_merged && | |
| 2008 | - | ( | |
| 2009 | - | cd repo && | |
| 2010 | - | git checkout -b topic && | |
| 2011 | - | git config remote.origin.push \ | |
| 2012 | - | "refs/heads/topic:refs/heads/published" && | |
| 2013 | - | git push origin && | |
| 2014 | - | git branch --set-upstream-to=origin/published topic && | |
| 2015 | - | git checkout -b other-topic --track origin/published && | |
| 2016 | - | git checkout --detach && | |
| 2017 | - | ||
| 2018 | - | git branch --delete-merged origin/published && | |
| 2019 | - | ||
| 2020 | - | check_branches <<-\EOF | |
| 2021 | - | main | |
| 2022 | - | topic | |
| 2023 | - | EOF | |
| 2024 | - | ) | |
| 2025 | - | ' | |
| 2026 | - | ||
| 2027 | - | test_expect_success '--delete-merged keeps the upstream of a surviving branch' ' | |
| 2028 | - | setup_repo_for_delete_merged && | |
| 2029 | - | create_merged_branch feature && | |
| 2030 | - | ( | |
| 2031 | - | cd repo && | |
| 2032 | - | git checkout -b topic --track feature && | |
| 2033 | - | git commit --allow-empty -m "topic work" && | |
| 2034 | - | ||
| 2035 | - | git branch --dry-run --delete-merged origin/next >out && | |
| 2036 | - | test_grep ! "feature" out && | |
| 2037 | - | ||
| 2038 | - | git branch --delete-merged origin/next 2>err && | |
| 2039 | - | test_must_be_empty err && | |
| 2040 | - | ||
| 2041 | - | check_branches <<-\EOF && | |
| 2042 | - | feature | |
| 2043 | - | main | |
| 2044 | - | topic | |
| 2045 | - | EOF | |
| 2046 | - | ||
| 2047 | - | pattern="branch\\.(feature|topic)\\.(merge|remote)" && | |
| 2048 | - | git config --local --get-regexp "$pattern" >actual && | |
| 2049 | - | cat >expect <<-\EOF && | |
| 2050 | - | branch.feature.remote origin | |
| 2051 | - | branch.feature.merge refs/heads/next | |
| 2052 | - | branch.topic.remote . | |
| 2053 | - | branch.topic.merge refs/heads/feature | |
| 2054 | - | EOF | |
| 2055 | - | test_cmp expect actual | |
| 2056 | - | ) | |
| 2057 | - | ' | |
| 2058 | - | ||
| 2059 | - | test_expect_success '--delete-merged clears the deleted upstream of a protected branch' ' | |
| 2060 | - | setup_repo_for_delete_merged && | |
| 2061 | - | ( | |
| 2062 | - | cd repo && | |
| 2063 | - | git branch --track lower origin/next && | |
| 2064 | - | git branch --track mid lower && | |
| 2065 | - | git checkout -b tip --track mid && | |
| 2066 | - | git commit --allow-empty -m "tip work" && | |
| 2067 | - | sha=$(git rev-parse --short lower) && | |
| 2068 | - | ||
| 2069 | - | git branch --dry-run --delete-merged origin/next \ | |
| 2070 | - | --delete-merged lower >actual 2>&1 && | |
| 2071 | - | echo "Would delete branch lower (was $sha)." >expect && | |
| 2072 | - | test_cmp expect actual && | |
| 2073 | - | ||
| 2074 | - | pattern="branch\\.(lower|mid|tip)\\.(merge|remote)" && | |
| 2075 | - | git config --local --get-regexp "$pattern" >actual && | |
| 2076 | - | cat >expect <<-\EOF && | |
| 2077 | - | branch.lower.remote origin | |
| 2078 | - | branch.lower.merge refs/heads/next | |
| 2079 | - | branch.mid.remote . | |
| 2080 | - | branch.mid.merge refs/heads/lower | |
| 2081 | - | branch.tip.remote . | |
| 2082 | - | branch.tip.merge refs/heads/mid | |
| 2083 | - | EOF | |
| 2084 | - | test_cmp expect actual && | |
| 2085 | - | ||
| 2086 | - | git branch --delete-merged origin/next \ | |
| 2087 | - | --delete-merged lower >actual 2>&1 && | |
| 2088 | - | echo "Deleted branch lower (was $sha)." >expect && | |
| 2089 | - | test_cmp expect actual && | |
| 2090 | - | ||
| 2091 | - | check_branches <<-\EOF && | |
| 2092 | - | main | |
| 2093 | - | mid | |
| 2094 | - | tip | |
| 2095 | - | EOF | |
| 2096 | - | ||
| 2097 | - | pattern="branch\\.(mid|tip)\\.(merge|remote)" && | |
| 2098 | - | git config --local --get-regexp "$pattern" >actual && | |
| 2099 | - | cat >expect <<-\EOF && | |
| 2100 | - | branch.tip.remote . | |
| 2101 | - | branch.tip.merge refs/heads/mid | |
| 2102 | - | EOF | |
| 2103 | - | test_cmp expect actual | |
| 2104 | - | ) | |
| 2105 | - | ' | |
| 2106 | - | ||
| 2107 | - | test_expect_success '--delete-merged result is independent of stacked branch names' ' | |
| 2108 | - | setup_repo_for_delete_merged && | |
| 2109 | - | ( | |
| 2110 | - | cd repo && | |
| 2111 | - | git branch --track c-lower origin/next && | |
| 2112 | - | git branch --track b-mid c-lower && | |
| 2113 | - | git checkout -b a-tip --track b-mid && | |
| 2114 | - | git commit --allow-empty -m "tip work" && | |
| 2115 | - | ||
| 2116 | - | git branch --delete-merged origin/next --delete-merged "c-*" && | |
| 2117 | - | ||
| 2118 | - | check_branches <<-\EOF && | |
| 2119 | - | a-tip | |
| 2120 | - | b-mid | |
| 2121 | - | main | |
| 2122 | - | EOF | |
| 2123 | - | ||
| 2124 | - | git branch --delete-merged origin/next \ | |
| 2125 | - | --delete-merged "c-*" >actual 2>&1 && | |
| 2126 | - | test_must_be_empty actual && | |
| 2127 | - | ||
| 2128 | - | check_branches <<-\EOF | |
| 2129 | - | a-tip | |
| 2130 | - | b-mid | |
| 2131 | - | main | |
| 2132 | - | EOF | |
| 2133 | - | ) | |
| 2134 | - | ' | |
| 2135 | - | ||
| 2136 | - | test_expect_success '--delete-merged requires a value' ' | |
| 2137 | - | test_must_fail git -C forked branch --delete-merged 2>err && | |
| 2138 | - | test_grep "requires a value" err | |
| 2139 | - | ' | |
| 2140 | - | ||
| 2141 | - | test_expect_success '--delete-merged honours branch.<name>.deleteMerged=false' ' | |
| 2142 | - | setup_repo_for_delete_merged && | |
| 2143 | - | create_merged_branch deleted && | |
| 2144 | - | create_merged_branch kept && | |
| 2145 | - | ( | |
| 2146 | - | cd repo && | |
| 2147 | - | git config branch.kept.deleteMerged false && | |
| 2148 | - | git checkout --detach && | |
| 2149 | - | ||
| 2150 | - | git branch --delete-merged origin/next 2>err && | |
| 2151 | - | ||
| 2152 | - | test_grep "Skipping .kept." err && | |
| 2153 | - | check_branches <<-\EOF | |
| 2154 | - | kept | |
| 2155 | - | main | |
| 2156 | - | EOF | |
| 2157 | - | ) | |
| 2158 | - | ' | |
| 2159 | - | ||
| 2160 | - | test_expect_success "branch -d still deletes a deleteMerged=false branch" ' | |
| 2161 | - | setup_repo_for_delete_merged && | |
| 2162 | - | create_merged_branch kept && | |
| 2163 | - | ( | |
| 2164 | - | cd repo && | |
| 2165 | - | git config branch.kept.deleteMerged false && | |
| 2166 | - | git checkout --detach && | |
| 2167 | - | ||
| 2168 | - | git branch -d kept && | |
| 2169 | - | ||
| 2170 | - | check_branches <<-\EOF | |
| 2171 | - | main | |
| 2172 | - | EOF | |
| 2173 | - | ) | |
| 2174 | - | ' | |
| 2175 | - | ||
| 2176 | - | test_expect_success '--dry-run without --delete-merged is rejected' ' | |
| 2177 | - | test_must_fail git -C forked branch --dry-run 2>err && | |
| 2178 | - | test_grep "requires --delete-merged" err | |
| 2179 | - | ' | |
| 2180 | - | ||
| 2181 | 1760 | test_done | |
modified t/unit-tests/u-odb-inmemory.c
| @@ -29,7 +29,7 @@ static void cl_assert_object_info(struct odb_source_inmemory *source, | |||
| 29 | 29 | .contentp = &actual_content, | |
| 30 | 30 | }; | |
| 31 | 31 | ||
| 32 | - | cl_must_pass(odb_source_read_object_info(&source->base, oid, &oi, 0)); | |
| 32 | + | cl_must_pass(odb_source_read_object_info(&source->base, oid, &oi, 0, NULL)); | |
| 33 | 33 | cl_assert_equal_u(actual_size, strlen(expected_content)); | |
| 34 | 34 | cl_assert_equal_u(actual_type, expected_type); | |
| 35 | 35 | cl_assert_equal_s((char *) actual_content, expected_content); | |
| @@ -50,7 +50,7 @@ static void cl_assert_write_object(struct odb_source_inmemory *source, | |||
| 50 | 50 | ||
| 51 | 51 | void test_odb_inmemory__initialize(void) | |
| 52 | 52 | { | |
| 53 | - | odb = odb_new(&repo, 0); | |
| 53 | + | odb = odb_new(&repo, "", ""); | |
| 54 | 54 | } | |
| 55 | 55 | ||
| 56 | 56 | void test_odb_inmemory__cleanup(void) | |
| @@ -72,7 +72,8 @@ void test_odb_inmemory__read_missing_object(void) | |||
| 72 | 72 | const char *end; | |
| 73 | 73 | ||
| 74 | 74 | cl_must_pass(parse_oid_hex_algop(RANDOM_OID, &oid, &end, repo.hash_algo)); | |
| 75 | - | cl_must_fail(odb_source_read_object_info(&source->base, &oid, NULL, 0)); | |
| 75 | + | cl_assert_equal_i(odb_source_read_object_info(&source->base, &oid, NULL, 0, NULL), | |
| 76 | + | ODB_READ_NOT_FOUND); | |
| 76 | 77 | ||
| 77 | 78 | odb_source_free(&source->base); | |
| 78 | 79 | } | |
modified worktree.c
| @@ -649,8 +649,7 @@ static void repair_gitfile(struct worktree *wt, | |||
| 649 | 649 | struct strbuf gitdir = STRBUF_INIT; | |
| 650 | 650 | struct strbuf repo = STRBUF_INIT; | |
| 651 | 651 | struct strbuf backlink = STRBUF_INIT; | |
| 652 | - | struct strbuf contents = STRBUF_INIT; | |
| 653 | - | const char *dotgit_contents = NULL; | |
| 652 | + | char *dotgit_contents = NULL; | |
| 654 | 653 | const char *repair = NULL; | |
| 655 | 654 | char *path = NULL; | |
| 656 | 655 | int err; | |
| @@ -668,9 +667,7 @@ static void repair_gitfile(struct worktree *wt, | |||
| 668 | 667 | strbuf_realpath(&repo, path, 1); | |
| 669 | 668 | strbuf_addf(&dotgit, "%s/.git", wt->path); | |
| 670 | 669 | strbuf_addf(&gitdir, "%s/gitdir", repo.buf); | |
| 671 | - | err = read_gitfile_raw(&contents, dotgit.buf); | |
| 672 | - | if (!err) | |
| 673 | - | dotgit_contents = contents.buf; | |
| 670 | + | dotgit_contents = xstrdup_or_null(read_gitfile_gently(dotgit.buf, &err)); | |
| 674 | 671 | ||
| 675 | 672 | if (dotgit_contents) { | |
| 676 | 673 | if (is_absolute_path(dotgit_contents)) { | |
| @@ -684,7 +681,7 @@ static void repair_gitfile(struct worktree *wt, | |||
| 684 | 681 | if (err == READ_GITFILE_ERR_NOT_A_FILE || | |
| 685 | 682 | err == READ_GITFILE_ERR_IS_A_DIR) | |
| 686 | 683 | fn(1, wt->path, _(".git is not a file"), cb_data); | |
| 687 | - | else if (err || !is_git_directory(backlink.buf)) | |
| 684 | + | else if (err) | |
| 688 | 685 | repair = _(".git file broken"); | |
| 689 | 686 | else if (fspathcmp(backlink.buf, repo.buf)) | |
| 690 | 687 | repair = _(".git file incorrect"); | |
| @@ -698,12 +695,12 @@ static void repair_gitfile(struct worktree *wt, | |||
| 698 | 695 | } | |
| 699 | 696 | ||
| 700 | 697 | done: | |
| 698 | + | free(dotgit_contents); | |
| 701 | 699 | free(path); | |
| 702 | 700 | strbuf_release(&repo); | |
| 703 | 701 | strbuf_release(&dotgit); | |
| 704 | 702 | strbuf_release(&gitdir); | |
| 705 | 703 | strbuf_release(&backlink); | |
| 706 | - | strbuf_release(&contents); | |
| 707 | 704 | } | |
| 708 | 705 | ||
| 709 | 706 | static void repair_noop(int iserr UNUSED, | |
| @@ -860,7 +857,14 @@ void repair_worktree_at_path(struct repository *repo, | |||
| 860 | 857 | strbuf_realpath_forgiving(&inferred_backlink, inferred_backlink.buf, 0); | |
| 861 | 858 | dotgit_contents = xstrdup_or_null(read_gitfile_gently(dotgit.buf, &err)); | |
| 862 | 859 | if (dotgit_contents) { | |
| 863 | - | strbuf_addstr(&backlink, dotgit_contents); | |
| 860 | + | if (is_absolute_path(dotgit_contents)) { | |
| 861 | + | strbuf_addstr(&backlink, dotgit_contents); | |
| 862 | + | } else { | |
| 863 | + | strbuf_addbuf(&backlink, &dotgit); | |
| 864 | + | strbuf_strip_suffix(&backlink, ".git"); | |
| 865 | + | strbuf_addstr(&backlink, dotgit_contents); | |
| 866 | + | strbuf_realpath_forgiving(&backlink, backlink.buf, 0); | |
| 867 | + | } | |
| 864 | 868 | } else if (err == READ_GITFILE_ERR_NOT_A_FILE || | |
| 865 | 869 | err == READ_GITFILE_ERR_IS_A_DIR) { | |
| 866 | 870 | fn(1, dotgit.buf, _("unable to locate repository; .git is not a file"), cb_data); | |