aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Documentation/CodingGuidelines11
-rw-r--r--Documentation/RelNotes/2.46.1.txt22
-rw-r--r--Documentation/RelNotes/2.47.0.txt60
-rw-r--r--Documentation/config/gc.txt3
-rw-r--r--Documentation/config/init.txt10
-rw-r--r--Documentation/config/maintenance.txt11
-rw-r--r--Documentation/git-diff-tree.txt2
-rw-r--r--Documentation/git-for-each-ref.txt42
-rw-r--r--Documentation/git-gc.txt5
-rw-r--r--Documentation/git-send-email.txt7
-rw-r--r--Documentation/git-svn.txt14
-rw-r--r--Documentation/gittutorial.txt2
-rw-r--r--Documentation/howto/maintain-git.txt4
-rw-r--r--Makefile6
-rw-r--r--add-patch.c3
-rw-r--r--builtin/am.c9
-rw-r--r--builtin/branch.c7
-rw-r--r--builtin/bugreport.c2
-rw-r--r--builtin/bundle.c5
-rw-r--r--builtin/checkout.c2
-rw-r--r--builtin/clone.c2
-rw-r--r--builtin/commit.c7
-rw-r--r--builtin/config.c16
-rw-r--r--builtin/count-objects.c2
-rw-r--r--builtin/diff.c6
-rw-r--r--builtin/fast-export.c19
-rw-r--r--builtin/fast-import.c12
-rw-r--r--builtin/fsck.c2
-rw-r--r--builtin/gc.c395
-rw-r--r--builtin/hook.c2
-rw-r--r--builtin/log.c14
-rw-r--r--builtin/merge.c2
-rw-r--r--builtin/notes.c11
-rw-r--r--builtin/pack-objects.c8
-rw-r--r--builtin/rebase.c3
-rw-r--r--builtin/receive-pack.c10
-rw-r--r--builtin/remote.c4
-rw-r--r--builtin/stash.c23
-rw-r--r--builtin/submodule--helper.c2
-rw-r--r--builtin/update-index.c4
-rw-r--r--builtin/update-ref.c8
-rw-r--r--builtin/worktree.c6
-rw-r--r--bulk-checkin.c2
-rw-r--r--bundle.c7
-rw-r--r--commit-reach.c126
-rw-r--r--commit-reach.h17
-rw-r--r--commit.c10
-rw-r--r--commit.h2
-rw-r--r--compat/fsmonitor/fsm-ipc-darwin.c2
-rw-r--r--compat/precompose_utf8.c1
-rw-r--r--config.c227
-rw-r--r--config.h285
-rw-r--r--connect.c2
-rw-r--r--contrib/completion/git-prompt.sh191
-rw-r--r--credential.c2
-rw-r--r--csum-file.c2
-rw-r--r--csum-file.h10
-rw-r--r--daemon.c8
-rw-r--r--diff-lib.c9
-rw-r--r--diff.c16
-rw-r--r--editor.c15
-rw-r--r--editor.h5
-rw-r--r--environment.c1
-rw-r--r--environment.h1
-rw-r--r--fsmonitor.c2
-rwxr-xr-xgit-send-email.perl21
-rwxr-xr-xgit-svn.perl51
-rw-r--r--git.c13
-rw-r--r--gpg-interface.c2
-rw-r--r--graph.c2
-rw-r--r--hook.c21
-rw-r--r--hook.h13
-rw-r--r--imap-send.c4
-rw-r--r--mailinfo.c2
-rw-r--r--merge-ll.c2
-rw-r--r--merge-ort.c3
-rw-r--r--midx-write.c10
-rw-r--r--object-file.c1
-rw-r--r--object-name.c1
-rw-r--r--oss-fuzz/dummy-cmd-main.c2
-rw-r--r--pack-bitmap-write.c40
-rw-r--r--pack-bitmap.h11
-rw-r--r--pager.c2
-rw-r--r--parallel-checkout.c2
-rw-r--r--path.c97
-rw-r--r--path.h170
-rw-r--r--perl/Git/SVN.pm2
-rw-r--r--protocol.c2
-rw-r--r--pseudo-merge.c21
-rw-r--r--pseudo-merge.h6
-rw-r--r--range-diff.c6
-rw-r--r--read-cache.c146
-rw-r--r--ref-filter.c82
-rw-r--r--ref-filter.h15
-rw-r--r--refs.c9
-rw-r--r--refs/files-backend.c8
-rw-r--r--refs/packed-backend.c6
-rw-r--r--refs/reftable-backend.c20
-rw-r--r--reftable/blocksource.c8
-rw-r--r--reftable/dump.c111
-rw-r--r--reftable/generic.c229
-rw-r--r--reftable/generic.h37
-rw-r--r--reftable/iter.c129
-rw-r--r--reftable/iter.h30
-rw-r--r--reftable/merged.c72
-rw-r--r--reftable/merged.h4
-rw-r--r--reftable/reader.c70
-rw-r--r--reftable/reader.h4
-rw-r--r--reftable/record.c154
-rw-r--r--reftable/record.h1
-rw-r--r--reftable/reftable-generic.h47
-rw-r--r--reftable/reftable-merged.h26
-rw-r--r--reftable/reftable-reader.h9
-rw-r--r--reftable/reftable-record.h8
-rw-r--r--reftable/reftable-stack.h3
-rw-r--r--reftable/reftable-tests.h4
-rw-r--r--reftable/stack.c94
-rw-r--r--reftable/stack_test.c35
-rw-r--r--reftable/test_framework.c2
-rw-r--r--reftable/writer.c2
-rw-r--r--remote.c2
-rw-r--r--rerere.c6
-rw-r--r--reset.c2
-rw-r--r--revision.c2
-rw-r--r--run-command.c12
-rw-r--r--scalar.c3
-rw-r--r--sequencer.c80
-rw-r--r--setup.c103
-rw-r--r--sideband.c2
-rw-r--r--submodule-config.c18
-rw-r--r--submodule.c2
-rw-r--r--t/helper/test-advise.c2
-rw-r--r--t/helper/test-config.c2
-rw-r--r--t/helper/test-example-tap.c2
-rw-r--r--t/helper/test-hashmap.c2
-rw-r--r--t/helper/test-mergesort.c2
-rw-r--r--t/helper/test-reach.c2
-rw-r--r--t/helper/test-reftable.c190
-rw-r--r--t/helper/test-tool.c1
-rw-r--r--t/helper/test-tool.h1
-rw-r--r--t/helper/test-urlmatch-normalization.c56
-rw-r--r--t/helper/test-userdiff.c2
-rwxr-xr-xt/perf/p1500-graph-walks.sh31
-rwxr-xr-xt/t0001-init.sh145
-rwxr-xr-xt/t0110-urlmatch-normalization.sh182
-rw-r--r--t/t0110/README9
-rw-r--r--t/t0110/url-11
-rw-r--r--t/t0110/url-101
-rw-r--r--t/t0110/url-111
-rw-r--r--t/t0110/url-21
-rw-r--r--t/t0110/url-31
-rw-r--r--t/t0110/url-41
-rw-r--r--t/t0110/url-51
-rw-r--r--t/t0110/url-61
-rw-r--r--t/t0110/url-71
-rw-r--r--t/t0110/url-81
-rw-r--r--t/t0110/url-91
-rwxr-xr-xt/t0210-trace2-normal.sh2
-rwxr-xr-xt/t1006-cat-file.sh1
-rwxr-xr-xt/t1050-large.sh1
-rwxr-xr-xt/t1450-fsck.sh1
-rwxr-xr-xt/t1601-index-bogus.sh2
-rwxr-xr-xt/t3310-notes-merge-manual-resolve.sh1
-rwxr-xr-xt/t3311-notes-merge-fanout.sh1
-rwxr-xr-xt/t3400-rebase.sh6
-rwxr-xr-xt/t3404-rebase-interactive.sh1
-rwxr-xr-xt/t3435-rebase-gpg-sign.sh1
-rwxr-xr-xt/t3507-cherry-pick-conflict.sh1
-rwxr-xr-xt/t3510-cherry-pick-sequence.sh1
-rwxr-xr-xt/t3705-add-sparse-checkout.sh1
-rwxr-xr-xt/t3903-stash.sh15
-rwxr-xr-xt/t4013-diff-various.sh1
-rwxr-xr-xt/t4014-format-patch.sh1
-rwxr-xr-xt/t4018-diff-funcname.sh1
-rwxr-xr-xt/t4030-diff-textconv.sh2
-rwxr-xr-xt/t4042-diff-textconv-caching.sh2
-rwxr-xr-xt/t4048-diff-combined-binary.sh1
-rwxr-xr-xt/t4064-diff-oidfind.sh2
-rwxr-xr-xt/t4065-diff-anchored.sh1
-rwxr-xr-xt/t4068-diff-symmetric-merge-base.sh1
-rwxr-xr-xt/t4069-remerge-diff.sh1
-rwxr-xr-xt/t4108-apply-threeway.sh1
-rwxr-xr-xt/t4129-apply-samemode.sh2
-rwxr-xr-xt/t4209-log-pickaxe.sh2
-rwxr-xr-xt/t5304-prune.sh1
-rwxr-xr-xt/t5333-pseudo-merge-bitmaps.sh56
-rwxr-xr-xt/t5616-partial-clone.sh6
-rwxr-xr-xt/t6020-bundle-misc.sh32
-rwxr-xr-xt/t6300-for-each-ref.sh9
-rwxr-xr-xt/t6421-merge-partial-clone.sh1
-rwxr-xr-xt/t6428-merge-conflicts-sparse.sh1
-rwxr-xr-xt/t6500-gc.sh45
-rwxr-xr-xt/t6600-test-reach.sh121
-rwxr-xr-xt/t7008-filter-branch-null-sha1.sh1
-rwxr-xr-xt/t7030-verify-tag.sh1
-rwxr-xr-xt/t7817-grep-sparse-checkout.sh1
-rwxr-xr-xt/t7900-maintenance.sh101
-rwxr-xr-xt/t9001-send-email.sh118
-rwxr-xr-xt/t9300-fast-import.sh1
-rwxr-xr-xt/t9304-fast-import-marks.sh2
-rwxr-xr-xt/t9351-fast-export-anonymize.sh1
-rw-r--r--t/unit-tests/t-ctype.c2
-rw-r--r--t/unit-tests/t-hash.c2
-rw-r--r--t/unit-tests/t-hashmap.c4
-rw-r--r--t/unit-tests/t-mem-pool.c2
-rw-r--r--t/unit-tests/t-prio-queue.c2
-rw-r--r--t/unit-tests/t-reftable-basics.c2
-rw-r--r--t/unit-tests/t-reftable-merged.c21
-rw-r--r--t/unit-tests/t-reftable-pq.c2
-rw-r--r--t/unit-tests/t-reftable-readwrite.c (renamed from reftable/readwrite_test.c)441
-rw-r--r--t/unit-tests/t-reftable-record.c2
-rw-r--r--t/unit-tests/t-reftable-tree.c2
-rw-r--r--t/unit-tests/t-strbuf.c2
-rw-r--r--t/unit-tests/t-strcmp-offset.c2
-rw-r--r--t/unit-tests/t-strvec.c2
-rw-r--r--t/unit-tests/t-trailer.c2
-rw-r--r--t/unit-tests/t-urlmatch-normalization.c271
-rw-r--r--trailer.c2
-rw-r--r--transport.c2
-rw-r--r--unpack-trees.c2
-rw-r--r--userdiff.c38
-rw-r--r--userdiff.h4
-rw-r--r--versioncmp.c2
-rw-r--r--worktree.c2
-rw-r--r--wt-status.c14
225 files changed, 3494 insertions, 2356 deletions
diff --git a/Documentation/CodingGuidelines b/Documentation/CodingGuidelines
index e4bd0abdcd..ccaea39752 100644
--- a/Documentation/CodingGuidelines
+++ b/Documentation/CodingGuidelines
@@ -303,7 +303,9 @@ For C programs:
v12.01, 2022-03-28).
- Variables have to be declared at the beginning of the block, before
- the first statement (i.e. -Wdeclaration-after-statement).
+ the first statement (i.e. -Wdeclaration-after-statement). It is
+ encouraged to have a blank line between the end of the declarations
+ and the first statement in the block.
- NULL pointers shall be written as NULL, not as 0.
@@ -323,6 +325,13 @@ For C programs:
while( condition )
func (bar+1);
+ - A binary operator (other than ",") and ternary conditional "?:"
+ have a space on each side of the operator to separate it from its
+ operands. E.g. "A + 1", not "A+1".
+
+ - A unary operator (other than "." and "->") have no space between it
+ and its operand. E.g. "(char *)ptr", not "(char *) ptr".
+
- Do not explicitly compare an integral value with constant 0 or '\0',
or a pointer value with constant NULL. For instance, to validate that
counted array <ptr, cnt> is initialized but has no elements, write:
diff --git a/Documentation/RelNotes/2.46.1.txt b/Documentation/RelNotes/2.46.1.txt
index 52afb3556a..3b4c44305f 100644
--- a/Documentation/RelNotes/2.46.1.txt
+++ b/Documentation/RelNotes/2.46.1.txt
@@ -34,4 +34,26 @@ Fixes since Git 2.46
* Perforce tests have been updated.
+ * The credential helper to talk to OSX keychain sometimes sent
+ garbage bytes after the username, which has been corrected.
+
+ * A recent update broke "git ls-remote" used outside a repository,
+ which has been corrected.
+
+ * "git config --value=foo --fixed-value section.key newvalue" barfed
+ when the existing value in the configuration file used the
+ valueless true syntax, which has been corrected.
+
+ * "git reflog expire" failed to honor annotated tags when computing
+ reachable commits.
+
+ * A flakey test and incorrect calls to strtoX() functions have been
+ fixed.
+
+ * Follow-up on 2.45.1 regression fix.
+
+ * "git rev-list ... | git diff-tree -p --remerge-diff --stdin" should
+ behave more or less like "git log -p --remerge-diff" but instead it
+ crashed, forgetting to prepare a temporary object store needed.
+
Also contains minor documentation updates and code clean-ups.
diff --git a/Documentation/RelNotes/2.47.0.txt b/Documentation/RelNotes/2.47.0.txt
index ba1a9cbc9e..0f796d6d4c 100644
--- a/Documentation/RelNotes/2.47.0.txt
+++ b/Documentation/RelNotes/2.47.0.txt
@@ -27,6 +27,25 @@ UI, Workflows & Features
* Support to specify ref backend for submodules has been enhanced.
+ * "git svn" has been taught about svn:global-ignores property
+ recent versions of Subversion has.
+
+ * The default object hash and ref backend format used to be settable
+ only with explicit command line option to "git init" and
+ environment variables, but now they can be configured in the user's
+ global and system wide configuration.
+
+ * "git send-email" learned "--translate-aliases" option that reads
+ addresses from the standard input and emits the result of applying
+ aliases on them to the standard output.
+
+ * 'git for-each-ref' learned a new "--format" atom to find the branch
+ that the history leading to a given commit "%(is-base:<commit>)" is
+ likely based on.
+
+ * The command line prompt support used to be littered with bash-isms,
+ which has been corrected to work with more shells.
+
Performance, Internal Implementation, Development Support etc.
--------------------------------------------------------------
@@ -73,6 +92,14 @@ Performance, Internal Implementation, Development Support etc.
* Incremental updates of multi-pack index files is getting worked on.
+ * Use of API functions that implicitly depend on the_repository
+ object in the config subsystem has been rewritten to pass a
+ repository object through the callchain.
+
+ * Drop unused parameters from functions.
+
+ * Mark unused parameters as UNUSED to squelch -Wunused warnings.
+
Fixes since v2.46
-----------------
@@ -106,11 +133,9 @@ Fixes since v2.46
* The credential helper to talk to OSX keychain sometimes sent
garbage bytes after the username, which has been corrected.
- (merge b201316835 jk/osxkeychain-username-is-nul-terminated later to maint).
* A recent update broke "git ls-remote" used outside a repository,
which has been corrected.
- (merge 9e89dcb66a ps/ls-remote-out-of-repo-fix later to maint).
* The patch parser in 'git apply' has been a bit more lenient against
unexpected mode bits, like 100664, recorded on extended header lines.
@@ -119,7 +144,6 @@ Fixes since v2.46
* "git config --value=foo --fixed-value section.key newvalue" barfed
when the existing value in the configuration file used the
valueless true syntax, which has been corrected.
- (merge 615d2de3b4 tb/config-fixed-value-with-valueless-true later to maint).
* The patch parser in "git patch-id" has been tightened to avoid
getting confused by lines that look like a patch header in the log
@@ -128,28 +152,34 @@ Fixes since v2.46
* "git reflog expire" failed to honor annotated tags when computing
reachable commits.
- (merge 5133ead528 jc/reflog-expire-lookup-commit-fix later to maint).
* A flakey test and incorrect calls to strtoX() functions have been
fixed.
- (merge ec60bb9fc4 kl/test-fixes later to maint).
* Follow-up on 2.45.1 regression fix.
- (merge ee0be850b0 jc/safe-directory later to maint).
* "git rev-list ... | git diff-tree -p --remerge-diff --stdin" should
behave more or less like "git log -p --remerge-diff" but instead it
crashed, forgetting to prepare a temporary object store needed.
- (merge a77554ea09 xx/diff-tree-remerge-diff-fix later to maint).
+
+ * "git bundle unbundle" outside a repository triggered a BUG()
+ unnecessarily, which has been corrected.
+ (merge 96a9a3e42e ps/bundle-outside-repo-fix later to maint).
+
+ * Maintenance tasks other than "gc" now properly go background when
+ "git maintenance" runs them.
+
+ * We created a useless pseudo-merge reachability bitmap that is about
+ 0 commits, and attempted to include commits that are not in packs,
+ which made no sense. These bugs have been corrected.
+ (merge a72dfab8b8 tb/pseudo-merge-bitmap-fixes later to maint).
+
+ * "git rebase -x --quiet" was not quiet, which was corrected.
* Other code cleanup, docfix, build fix, etc.
(merge bb0498b1bb jc/how-to-maintain-updates later to maint).
- (merge 7c7516b8db jc/jl-git-no-advice-fix later to maint).
- (merge c3d034df16 jc/leakfix-hashfile later to maint).
- (merge d98d9c77e5 jc/leakfix-mailmap later to maint).
- (merge c199707496 jr/ls-files-expand-literal-doc later to maint).
- (merge e2e373ba82 ss/packed-ref-store-leakfix later to maint).
- (merge 0c4d5aa22d rs/use-decimal-width later to maint).
- (merge 67be8c4de5 jc/document-use-of-local later to maint).
- (merge 098be29f5b rs/t-example-simplify later to maint).
(merge 0d66f601a9 jc/tests-no-useless-tee later to maint).
+ (merge 170cdfc5a4 jc/grammo-fixes later to maint).
+ (merge 983555a1f2 jc/how-to-maintain-updates later to maint).
+ (merge e3209bd4df ps/stash-keep-untrack-empty-fix later to maint).
+ (merge 44db6f75cc jc/coding-style-c-operator-with-spaces later to maint).
diff --git a/Documentation/config/gc.txt b/Documentation/config/gc.txt
index 664a3c2874..1d4f9470ea 100644
--- a/Documentation/config/gc.txt
+++ b/Documentation/config/gc.txt
@@ -40,7 +40,8 @@ use, it'll affect how the auto pack limit works.
gc.autoDetach::
Make `git gc --auto` return immediately and run in the background
- if the system supports it. Default is true.
+ if the system supports it. Default is true. This config variable acts
+ as a fallback in case `maintenance.autoDetach` is not set.
gc.bigPackThreshold::
If non-zero, all non-cruft packs larger than this limit are kept
diff --git a/Documentation/config/init.txt b/Documentation/config/init.txt
index af03acdbcb..e45b2a8121 100644
--- a/Documentation/config/init.txt
+++ b/Documentation/config/init.txt
@@ -8,3 +8,13 @@ endif::[]
`init.defaultBranch`::
Allows overriding the default branch name e.g. when initializing
a new repository.
+`init.defaultObjectFormat`::
+ Allows overriding the default object format for new repositories. See
+ `--object-format=` in linkgit:git-init[1]. Both the command line option
+ and the `GIT_DEFAULT_HASH` environment variable take precedence over
+ this config.
+`init.defaultRefFormat`::
+ Allows overriding the default ref storage format for new repositories.
+ See `--ref-format=` in linkgit:git-init[1]. Both the command line
+ option and the `GIT_DEFAULT_REF_FORMAT` environment variable take
+ precedence over this config.
diff --git a/Documentation/config/maintenance.txt b/Documentation/config/maintenance.txt
index 69a4f05153..72a9d6cf81 100644
--- a/Documentation/config/maintenance.txt
+++ b/Documentation/config/maintenance.txt
@@ -3,6 +3,17 @@ maintenance.auto::
`git maintenance run --auto` after doing their normal work. Defaults
to true.
+maintenance.autoDetach::
+ Many Git commands trigger automatic maintenance after they have
+ written data into the repository. This boolean config option
+ controls whether this automatic maintenance shall happen in the
+ foreground or whether the maintenance process shall detach and
+ continue to run in the background.
++
+If unset, the value of `gc.autoDetach` is used as a fallback. Defaults
+to true if both are unset, meaning that the maintenance process will
+detach.
+
maintenance.strategy::
This string config option provides a way to specify one of a few
recommended schedules for background maintenance. This only affects
diff --git a/Documentation/git-diff-tree.txt b/Documentation/git-diff-tree.txt
index 143318c411..09286a85eb 100644
--- a/Documentation/git-diff-tree.txt
+++ b/Documentation/git-diff-tree.txt
@@ -88,7 +88,7 @@ include::pretty-options.txt[]
--no-commit-id::
'git diff-tree' outputs a line with the commit ID when
- applicable. This flag suppressed the commit ID output.
+ applicable. This flag suppresses the commit ID output.
-c::
This flag changes the way a merge commit is displayed
diff --git a/Documentation/git-for-each-ref.txt b/Documentation/git-for-each-ref.txt
index c1dd12b93c..d3764401a2 100644
--- a/Documentation/git-for-each-ref.txt
+++ b/Documentation/git-for-each-ref.txt
@@ -264,6 +264,48 @@ ahead-behind:<committish>::
commits ahead and behind, respectively, when comparing the output
ref to the `<committish>` specified in the format.
+is-base:<committish>::
+ In at most one row, `(<committish>)` will appear to indicate the ref
+ that is most likely the ref used as a starting point for the branch
+ that produced `<committish>`. This choice is made using a heuristic:
+ choose the ref that minimizes the number of commits in the
+ first-parent history of `<committish>` and not in the first-parent
+ history of the ref.
++
+For example, consider the following figure of first-parent histories of
+several refs:
++
+----
+*--*--*--*--*--* refs/heads/A
+\
+ \
+ *--*--*--* refs/heads/B
+ \ \
+ \ \
+ * * refs/heads/C
+ \
+ \
+ *--* refs/heads/D
+----
++
+Here, if `A`, `B`, and `C` are the filtered references, and the format
+string is `%(refname):%(is-base:D)`, then the output would be
++
+----
+refs/heads/A:
+refs/heads/B:(D)
+refs/heads/C:
+----
++
+This is because the first-parent history of `D` has its earliest
+intersection with the first-parent histories of the filtered refs at a
+common first-parent ancestor of `B` and `C` and ties are broken by the
+earliest ref in the sorted order.
++
+Note that this token will not appear if the first-parent history of
+`<committish>` does not intersect the first-parent histories of the
+filtered refs.
+
describe[:options]::
A human-readable name, like linkgit:git-describe[1];
empty string for undescribable commits. The `describe` string may
diff --git a/Documentation/git-gc.txt b/Documentation/git-gc.txt
index b5561c458a..370e22faae 100644
--- a/Documentation/git-gc.txt
+++ b/Documentation/git-gc.txt
@@ -9,7 +9,7 @@ git-gc - Cleanup unnecessary files and optimize the local repository
SYNOPSIS
--------
[verse]
-'git gc' [--aggressive] [--auto] [--quiet] [--prune=<date> | --no-prune] [--force] [--keep-largest-pack]
+'git gc' [--aggressive] [--auto] [--[no-]detach] [--quiet] [--prune=<date> | --no-prune] [--force] [--keep-largest-pack]
DESCRIPTION
-----------
@@ -53,6 +53,9 @@ configuration options such as `gc.auto` and `gc.autoPackLimit`, all
other housekeeping tasks (e.g. rerere, working trees, reflog...) will
be performed as well.
+--[no-]detach::
+ Run in the background if the system supports it. This option overrides
+ the `gc.autoDetach` config.
--[no-]cruft::
When expiring unreachable objects, pack them separately into a
diff --git a/Documentation/git-send-email.txt b/Documentation/git-send-email.txt
index c5d664f451..2e6f1d63ae 100644
--- a/Documentation/git-send-email.txt
+++ b/Documentation/git-send-email.txt
@@ -12,6 +12,7 @@ SYNOPSIS
'git send-email' [<options>] (<file>|<directory>)...
'git send-email' [<options>] <format-patch-options>
'git send-email' --dump-aliases
+'git send-email' --translate-aliases
DESCRIPTION
@@ -475,6 +476,12 @@ Information
that this only includes the alias name and not its expanded email addresses.
See 'sendemail.aliasesFile' for more information about aliases.
+--translate-aliases::
+ Instead of the normal operation, read from standard input and
+ interpret each line as an email alias. Translate it according to the
+ configured alias file(s). Output each translated name and email
+ address to standard output, one per line. See 'sendemail.aliasFile'
+ for more information about aliases.
CONFIGURATION
-------------
diff --git a/Documentation/git-svn.txt b/Documentation/git-svn.txt
index 43c68c2ec4..bcf7d84a87 100644
--- a/Documentation/git-svn.txt
+++ b/Documentation/git-svn.txt
@@ -431,14 +431,14 @@ Any other arguments are passed directly to 'git log'
independently of 'git svn' functions.
'create-ignore'::
- Recursively finds the svn:ignore property on directories and
- creates matching .gitignore files. The resulting files are staged to
- be committed, but are not committed. Use -r/--revision to refer to a
- specific revision.
+ Recursively finds the svn:ignore and svn:global-ignores properties
+ on directories and creates matching .gitignore files. The resulting
+ files are staged to be committed, but are not committed. Use
+ -r/--revision to refer to a specific revision.
'show-ignore'::
- Recursively finds and lists the svn:ignore property on
- directories. The output is suitable for appending to
+ Recursively finds and lists the svn:ignore and svn:global-ignores
+ properties on directories. The output is suitable for appending to
the $GIT_DIR/info/exclude file.
'mkdirs'::
@@ -871,7 +871,7 @@ Tracking and contributing to the trunk of a Subversion-managed project
# Now commit your changes (that were committed previously using Git) to SVN,
# as well as automatically updating your working HEAD:
git svn dcommit
-# Append svn:ignore settings to the default Git exclude file:
+# Append svn:ignore and svn:global-ignores settings to the default Git exclude file:
git svn show-ignore >> .git/info/exclude
------------------------------------------------------------------------
diff --git a/Documentation/gittutorial.txt b/Documentation/gittutorial.txt
index 4759408788..f89ad30cf6 100644
--- a/Documentation/gittutorial.txt
+++ b/Documentation/gittutorial.txt
@@ -360,7 +360,7 @@ $ gitk HEAD...FETCH_HEAD
This means "show everything that is reachable from either one, but
exclude anything that is reachable from both of them".
-Please note that these range notation can be used with both `gitk`
+Please note that these range notations can be used with both `gitk`
and `git log`.
After inspecting what Bob did, if there is nothing urgent, Alice may
diff --git a/Documentation/howto/maintain-git.txt b/Documentation/howto/maintain-git.txt
index 41f54050f8..da31332f11 100644
--- a/Documentation/howto/maintain-git.txt
+++ b/Documentation/howto/maintain-git.txt
@@ -181,6 +181,10 @@ by doing the following:
$ git diff ORIG_HEAD.. ;# final review
$ make test ;# final review
+ If the tip of 'master' is updated, also generate the preformatted
+ documentation and push the out result to git-htmldocs and
+ git-manpages repositories.
+
- Handle the remaining patches:
- Anything unobvious that is applicable to 'master' (in other
diff --git a/Makefile b/Makefile
index 4c94bc718f..5b84e985dd 100644
--- a/Makefile
+++ b/Makefile
@@ -843,7 +843,6 @@ TEST_BUILTINS_OBJS += test-submodule.o
TEST_BUILTINS_OBJS += test-subprocess.o
TEST_BUILTINS_OBJS += test-trace2.o
TEST_BUILTINS_OBJS += test-truncate.o
-TEST_BUILTINS_OBJS += test-urlmatch-normalization.o
TEST_BUILTINS_OBJS += test-userdiff.o
TEST_BUILTINS_OBJS += test-wildmatch.o
TEST_BUILTINS_OBJS += test-windows-named-pipe.o
@@ -1344,12 +1343,14 @@ UNIT_TEST_PROGRAMS += t-reftable-basics
UNIT_TEST_PROGRAMS += t-reftable-block
UNIT_TEST_PROGRAMS += t-reftable-merged
UNIT_TEST_PROGRAMS += t-reftable-pq
+UNIT_TEST_PROGRAMS += t-reftable-readwrite
UNIT_TEST_PROGRAMS += t-reftable-record
UNIT_TEST_PROGRAMS += t-reftable-tree
UNIT_TEST_PROGRAMS += t-strbuf
UNIT_TEST_PROGRAMS += t-strcmp-offset
UNIT_TEST_PROGRAMS += t-strvec
UNIT_TEST_PROGRAMS += t-trailer
+UNIT_TEST_PROGRAMS += t-urlmatch-normalization
UNIT_TEST_PROGS = $(patsubst %,$(UNIT_TEST_BIN)/%$X,$(UNIT_TEST_PROGRAMS))
UNIT_TEST_OBJS = $(patsubst %,$(UNIT_TEST_DIR)/%.o,$(UNIT_TEST_PROGRAMS))
UNIT_TEST_OBJS += $(UNIT_TEST_DIR)/test-lib.o
@@ -2678,13 +2679,10 @@ REFTABLE_OBJS += reftable/merged.o
REFTABLE_OBJS += reftable/pq.o
REFTABLE_OBJS += reftable/reader.o
REFTABLE_OBJS += reftable/record.o
-REFTABLE_OBJS += reftable/generic.o
REFTABLE_OBJS += reftable/stack.o
REFTABLE_OBJS += reftable/tree.o
REFTABLE_OBJS += reftable/writer.o
-REFTABLE_TEST_OBJS += reftable/dump.o
-REFTABLE_TEST_OBJS += reftable/readwrite_test.o
REFTABLE_TEST_OBJS += reftable/stack_test.o
REFTABLE_TEST_OBJS += reftable/test_framework.o
diff --git a/add-patch.c b/add-patch.c
index 1cec4ab67b..557903310d 100644
--- a/add-patch.c
+++ b/add-patch.c
@@ -1142,7 +1142,8 @@ static int edit_hunk_manually(struct add_p_state *s, struct hunk *hunk)
"removed, then the edit is\n"
"aborted and the hunk is left unchanged.\n"));
- if (strbuf_edit_interactively(&s->buf, "addp-hunk-edit.diff", NULL) < 0)
+ if (strbuf_edit_interactively(the_repository, &s->buf,
+ "addp-hunk-edit.diff", NULL) < 0)
return -1;
/* strip out commented lines */
diff --git a/builtin/am.c b/builtin/am.c
index a12be088f7..d8875ad402 100644
--- a/builtin/am.c
+++ b/builtin/am.c
@@ -490,7 +490,8 @@ static int run_applypatch_msg_hook(struct am_state *state)
assert(state->msg);
if (!state->no_verify)
- ret = run_hooks_l("applypatch-msg", am_path(state, "final-commit"), NULL);
+ ret = run_hooks_l(the_repository, "applypatch-msg",
+ am_path(state, "final-commit"), NULL);
if (!ret) {
FREE_AND_NULL(state->msg);
@@ -512,7 +513,7 @@ static int run_post_rewrite_hook(const struct am_state *state)
strvec_push(&opt.args, "rebase");
opt.path_to_stdin = am_path(state, "rewritten");
- return run_hooks_opt("post-rewrite", &opt);
+ return run_hooks_opt(the_repository, "post-rewrite", &opt);
}
/**
@@ -1663,7 +1664,7 @@ static void do_commit(const struct am_state *state)
const char *reflog_msg, *author, *committer = NULL;
struct strbuf sb = STRBUF_INIT;
- if (!state->no_verify && run_hooks("pre-applypatch"))
+ if (!state->no_verify && run_hooks(the_repository, "pre-applypatch"))
exit(1);
if (write_index_as_tree(&tree, the_repository->index, get_index_file(), 0, NULL))
@@ -1716,7 +1717,7 @@ static void do_commit(const struct am_state *state)
fclose(fp);
}
- run_hooks("post-applypatch");
+ run_hooks(the_repository, "post-applypatch");
free_commit_list(parents);
strbuf_release(&sb);
diff --git a/builtin/branch.c b/builtin/branch.c
index 48cac74f97..3f870741bf 100644
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@ -210,7 +210,7 @@ static void delete_branch_config(const char *branchname)
{
struct strbuf buf = STRBUF_INIT;
strbuf_addf(&buf, "branch.%s", branchname);
- if (git_config_rename_section(buf.buf, NULL) < 0)
+ if (repo_config_rename_section(the_repository, buf.buf, NULL) < 0)
warning(_("update of config-file failed"));
strbuf_release(&buf);
}
@@ -659,9 +659,10 @@ static void copy_or_rename_branch(const char *oldname, const char *newname, int
strbuf_addf(&oldsection, "branch.%s", interpreted_oldname);
strbuf_addf(&newsection, "branch.%s", interpreted_newname);
- if (!copy && git_config_rename_section(oldsection.buf, newsection.buf) < 0)
+ if (!copy && repo_config_rename_section(the_repository, oldsection.buf, newsection.buf) < 0)
die(_("branch is renamed, but update of config-file failed"));
- if (copy && strcmp(interpreted_oldname, interpreted_newname) && git_config_copy_section(oldsection.buf, newsection.buf) < 0)
+ if (copy && strcmp(interpreted_oldname, interpreted_newname) &&
+ repo_config_copy_section(the_repository, oldsection.buf, newsection.buf) < 0)
die(_("branch is copied, but update of config-file failed"));
strbuf_release(&oldref);
strbuf_release(&newref);
diff --git a/builtin/bugreport.c b/builtin/bugreport.c
index b3cc77af53..bdfed3d8f1 100644
--- a/builtin/bugreport.c
+++ b/builtin/bugreport.c
@@ -58,7 +58,7 @@ static void get_populated_hooks(struct strbuf *hook_info, int nongit)
for (p = hook_name_list; *p; p++) {
const char *hook = *p;
- if (hook_exists(hook))
+ if (hook_exists(the_repository, hook))
strbuf_addf(hook_info, "%s\n", hook);
}
}
diff --git a/builtin/bundle.c b/builtin/bundle.c
index d5d41a8f67..86d0ed7049 100644
--- a/builtin/bundle.c
+++ b/builtin/bundle.c
@@ -207,12 +207,13 @@ static int cmd_bundle_unbundle(int argc, const char **argv, const char *prefix)
builtin_bundle_unbundle_usage, options, &bundle_file);
/* bundle internals use argv[1] as further parameters */
+ if (!startup_info->have_repository)
+ die(_("Need a repository to unbundle."));
+
if ((bundle_fd = open_bundle(bundle_file, &header, NULL)) < 0) {
ret = 1;
goto cleanup;
}
- if (!startup_info->have_repository)
- die(_("Need a repository to unbundle."));
if (progress)
strvec_pushl(&extra_index_pack_args, "-v", "--progress-title",
_("Unbundling objects"), NULL);
diff --git a/builtin/checkout.c b/builtin/checkout.c
index 2ff0896937..4cfe6fab50 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -125,7 +125,7 @@ static void branch_info_release(struct branch_info *info)
static int post_checkout_hook(struct commit *old_commit, struct commit *new_commit,
int changed)
{
- return run_hooks_l("post-checkout",
+ return run_hooks_l(the_repository, "post-checkout",
oid_to_hex(old_commit ? &old_commit->object.oid : null_oid()),
oid_to_hex(new_commit ? &new_commit->object.oid : null_oid()),
changed ? "1" : "0", NULL);
diff --git a/builtin/clone.c b/builtin/clone.c
index 75b15b5773..269b6e18a4 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -789,7 +789,7 @@ static int checkout(int submodule_progress, int filter_submodules,
if (write_locked_index(the_repository->index, &lock_file, COMMIT_LOCK))
die(_("unable to write new index file"));
- err |= run_hooks_l("post-checkout", oid_to_hex(null_oid()),
+ err |= run_hooks_l(the_repository, "post-checkout", oid_to_hex(null_oid()),
oid_to_hex(&oid), "1", NULL);
if (!err && (option_recurse_submodules.nr > 0)) {
diff --git a/builtin/commit.c b/builtin/commit.c
index 66427ba82d..b2033c4887 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -684,7 +684,9 @@ static void adjust_comment_line_char(const struct strbuf *sb)
const char *p;
if (!memchr(sb->buf, candidates[0], sb->len)) {
- comment_line_str = xstrfmt("%c", candidates[0]);
+ free(comment_line_str_to_free);
+ comment_line_str = comment_line_str_to_free =
+ xstrfmt("%c", candidates[0]);
return;
}
@@ -705,7 +707,8 @@ static void adjust_comment_line_char(const struct strbuf *sb)
if (!*p)
die(_("unable to select a comment character that is not used\n"
"in the current commit message"));
- comment_line_str = xstrfmt("%c", *p);
+ free(comment_line_str_to_free);
+ comment_line_str = comment_line_str_to_free = xstrfmt("%c", *p);
}
static void prepare_amend_commit(struct commit *commit, struct strbuf *sb,
diff --git a/builtin/config.c b/builtin/config.c
index 20a0b64090..e00d983596 100644
--- a/builtin/config.c
+++ b/builtin/config.c
@@ -1026,8 +1026,8 @@ static int cmd_config_rename_section(int argc, const char **argv, const char *pr
location_options_init(&location_opts, prefix);
check_write(&location_opts.source);
- ret = git_config_rename_section_in_file(location_opts.source.file,
- argv[0], argv[1]);
+ ret = repo_config_rename_section_in_file(the_repository, location_opts.source.file,
+ argv[0], argv[1]);
if (ret < 0)
goto out;
else if (!ret)
@@ -1055,8 +1055,8 @@ static int cmd_config_remove_section(int argc, const char **argv, const char *pr
location_options_init(&location_opts, prefix);
check_write(&location_opts.source);
- ret = git_config_rename_section_in_file(location_opts.source.file,
- argv[0], NULL);
+ ret = repo_config_rename_section_in_file(the_repository, location_opts.source.file,
+ argv[0], NULL);
if (ret < 0)
goto out;
else if (!ret)
@@ -1353,8 +1353,8 @@ static int cmd_config_actions(int argc, const char **argv, const char *prefix)
else if (actions == ACTION_RENAME_SECTION) {
check_write(&location_opts.source);
check_argc(argc, 2, 2);
- ret = git_config_rename_section_in_file(location_opts.source.file,
- argv[0], argv[1]);
+ ret = repo_config_rename_section_in_file(the_repository, location_opts.source.file,
+ argv[0], argv[1]);
if (ret < 0)
goto out;
else if (!ret)
@@ -1365,8 +1365,8 @@ static int cmd_config_actions(int argc, const char **argv, const char *prefix)
else if (actions == ACTION_REMOVE_SECTION) {
check_write(&location_opts.source);
check_argc(argc, 1, 1);
- ret = git_config_rename_section_in_file(location_opts.source.file,
- argv[0], NULL);
+ ret = repo_config_rename_section_in_file(the_repository, location_opts.source.file,
+ argv[0], NULL);
if (ret < 0)
goto out;
else if (!ret)
diff --git a/builtin/count-objects.c b/builtin/count-objects.c
index 2d4bb5e8d0..ec6098a149 100644
--- a/builtin/count-objects.c
+++ b/builtin/count-objects.c
@@ -113,7 +113,7 @@ int cmd_count_objects(int argc, const char **argv, const char *prefix)
usage_with_options(count_objects_usage, opts);
if (verbose) {
report_garbage = real_report_garbage;
- report_linked_checkout_garbage();
+ report_linked_checkout_garbage(the_repository);
}
for_each_loose_file_in_objdir(get_object_directory(),
diff --git a/builtin/diff.c b/builtin/diff.c
index 9b6cdabe15..6eac445579 100644
--- a/builtin/diff.c
+++ b/builtin/diff.c
@@ -388,6 +388,11 @@ static void symdiff_prepare(struct rev_info *rev, struct symdiff *sym)
sym->skip = map;
}
+static void symdiff_release(struct symdiff *sdiff)
+{
+ bitmap_free(sdiff->skip);
+}
+
int cmd_diff(int argc, const char **argv, const char *prefix)
{
int i;
@@ -619,6 +624,7 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
refresh_index_quietly();
release_revisions(&rev);
object_array_clear(&ent);
+ symdiff_release(&sdiff);
UNLEAK(blob);
return result;
}
diff --git a/builtin/fast-export.c b/builtin/fast-export.c
index 4b6e8c6832..f253b79322 100644
--- a/builtin/fast-export.c
+++ b/builtin/fast-export.c
@@ -42,8 +42,8 @@ static int full_tree;
static int reference_excluded_commits;
static int show_original_ids;
static int mark_tags;
-static struct string_list extra_refs = STRING_LIST_INIT_NODUP;
-static struct string_list tag_refs = STRING_LIST_INIT_NODUP;
+static struct string_list extra_refs = STRING_LIST_INIT_DUP;
+static struct string_list tag_refs = STRING_LIST_INIT_DUP;
static struct refspec refspecs = REFSPEC_INIT_FETCH;
static int anonymize;
static struct hashmap anonymized_seeds;
@@ -901,7 +901,7 @@ static void handle_tag(const char *name, struct tag *tag)
free(buf);
}
-static struct commit *get_commit(struct rev_cmdline_entry *e, char *full_name)
+static struct commit *get_commit(struct rev_cmdline_entry *e, const char *full_name)
{
switch (e->item->type) {
case OBJ_COMMIT:
@@ -932,14 +932,16 @@ static void get_tags_and_duplicates(struct rev_cmdline_info *info)
struct rev_cmdline_entry *e = info->rev + i;
struct object_id oid;
struct commit *commit;
- char *full_name;
+ char *full_name = NULL;
if (e->flags & UNINTERESTING)
continue;
if (repo_dwim_ref(the_repository, e->name, strlen(e->name),
- &oid, &full_name, 0) != 1)
+ &oid, &full_name, 0) != 1) {
+ free(full_name);
continue;
+ }
if (refspecs.nr) {
char *private;
@@ -955,6 +957,7 @@ static void get_tags_and_duplicates(struct rev_cmdline_info *info)
warning("%s: Unexpected object of type %s, skipping.",
e->name,
type_name(e->item->type));
+ free(full_name);
continue;
}
@@ -963,10 +966,12 @@ static void get_tags_and_duplicates(struct rev_cmdline_info *info)
break;
case OBJ_BLOB:
export_blob(&commit->object.oid);
+ free(full_name);
continue;
default: /* OBJ_TAG (nested tags) is already handled */
warning("Tag points to object of unexpected type %s, skipping.",
type_name(commit->object.type));
+ free(full_name);
continue;
}
@@ -979,6 +984,8 @@ static void get_tags_and_duplicates(struct rev_cmdline_info *info)
if (!*revision_sources_at(&revision_sources, commit))
*revision_sources_at(&revision_sources, commit) = full_name;
+ else
+ free(full_name);
}
string_list_sort(&extra_refs);
@@ -1278,9 +1285,11 @@ int cmd_fast_export(int argc, const char **argv, const char *prefix)
revs.diffopt.format_callback = show_filemodify;
revs.diffopt.format_callback_data = &paths_of_changed_objects;
revs.diffopt.flags.recursive = 1;
+
revs.diffopt.no_free = 1;
while ((commit = get_revision(&revs)))
handle_commit(commit, &revs, &paths_of_changed_objects);
+ revs.diffopt.no_free = 0;
handle_tags_and_duplicates(&extra_refs);
handle_tags_and_duplicates(&tag_refs);
diff --git a/builtin/fast-import.c b/builtin/fast-import.c
index d21c4053a7..2214c105f1 100644
--- a/builtin/fast-import.c
+++ b/builtin/fast-import.c
@@ -206,8 +206,8 @@ static unsigned int object_entry_alloc = 5000;
static struct object_entry_pool *blocks;
static struct hashmap object_table;
static struct mark_set *marks;
-static const char *export_marks_file;
-static const char *import_marks_file;
+static char *export_marks_file;
+static char *import_marks_file;
static int import_marks_file_from_stream;
static int import_marks_file_ignore_missing;
static int import_marks_file_done;
@@ -3274,6 +3274,7 @@ static void option_import_marks(const char *marks,
read_marks();
}
+ free(import_marks_file);
import_marks_file = make_fast_import_path(marks);
import_marks_file_from_stream = from_stream;
import_marks_file_ignore_missing = ignore_missing;
@@ -3316,6 +3317,7 @@ static void option_active_branches(const char *branches)
static void option_export_marks(const char *marks)
{
+ free(export_marks_file);
export_marks_file = make_fast_import_path(marks);
}
@@ -3357,6 +3359,8 @@ static void option_rewrite_submodules(const char *arg, struct string_list *list)
free(f);
string_list_insert(list, s)->util = ms;
+
+ free(s);
}
static int parse_one_option(const char *option)
@@ -3481,8 +3485,8 @@ static void git_pack_config(void)
if (!git_config_get_int("pack.indexversion", &indexversion_value)) {
pack_idx_opts.version = indexversion_value;
if (pack_idx_opts.version > 2)
- git_die_config("pack.indexversion",
- "bad pack.indexVersion=%"PRIu32, pack_idx_opts.version);
+ git_die_config(the_repository, "pack.indexversion",
+ "bad pack.indexVersion=%"PRIu32, pack_idx_opts.version);
}
if (!git_config_get_ulong("pack.packsizelimit", &packsizelimit_value))
max_packsize = packsizelimit_value;
diff --git a/builtin/fsck.c b/builtin/fsck.c
index ef014bbbcd..60f4e6fad9 100644
--- a/builtin/fsck.c
+++ b/builtin/fsck.c
@@ -1053,7 +1053,7 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
* and may get overwritten by other calls
* while we're examining the index.
*/
- path = xstrdup(worktree_git_path(wt, "index"));
+ path = xstrdup(worktree_git_path(the_repository, wt, "index"));
read_index_from(&istate, path, get_worktree_git_dir(wt));
fsck_index(&istate, path, wt->is_current);
discard_index(&istate);
diff --git a/builtin/gc.c b/builtin/gc.c
index 65be7c31b3..427faf1cfe 100644
--- a/builtin/gc.c
+++ b/builtin/gc.c
@@ -49,23 +49,7 @@ static const char * const builtin_gc_usage[] = {
NULL
};
-static int pack_refs = 1;
-static int prune_reflogs = 1;
-static int cruft_packs = 1;
-static unsigned long max_cruft_size;
-static int aggressive_depth = 50;
-static int aggressive_window = 250;
-static int gc_auto_threshold = 6700;
-static int gc_auto_pack_limit = 50;
-static int detach_auto = 1;
static timestamp_t gc_log_expire_time;
-static const char *gc_log_expire = "1.day.ago";
-static const char *prune_expire = "2.weeks.ago";
-static const char *prune_worktrees_expire = "3.months.ago";
-static char *repack_filter;
-static char *repack_filter_to;
-static unsigned long big_pack_threshold;
-static unsigned long max_delta_cache_size = DEFAULT_DELTA_CACHE_SIZE;
static struct strvec reflog = STRVEC_INIT;
static struct strvec repack = STRVEC_INIT;
@@ -125,13 +109,6 @@ static void process_log_file_at_exit(void)
process_log_file();
}
-static void process_log_file_on_signal(int signo)
-{
- process_log_file();
- sigchain_pop(signo);
- raise(signo);
-}
-
static int gc_config_is_timestamp_never(const char *var)
{
const char *value;
@@ -145,37 +122,100 @@ static int gc_config_is_timestamp_never(const char *var)
return 0;
}
-static void gc_config(void)
+struct gc_config {
+ int pack_refs;
+ int prune_reflogs;
+ int cruft_packs;
+ unsigned long max_cruft_size;
+ int aggressive_depth;
+ int aggressive_window;
+ int gc_auto_threshold;
+ int gc_auto_pack_limit;
+ int detach_auto;
+ char *gc_log_expire;
+ char *prune_expire;
+ char *prune_worktrees_expire;
+ char *repack_filter;
+ char *repack_filter_to;
+ unsigned long big_pack_threshold;
+ unsigned long max_delta_cache_size;
+};
+
+#define GC_CONFIG_INIT { \
+ .pack_refs = 1, \
+ .prune_reflogs = 1, \
+ .cruft_packs = 1, \
+ .aggressive_depth = 50, \
+ .aggressive_window = 250, \
+ .gc_auto_threshold = 6700, \
+ .gc_auto_pack_limit = 50, \
+ .detach_auto = 1, \
+ .gc_log_expire = xstrdup("1.day.ago"), \
+ .prune_expire = xstrdup("2.weeks.ago"), \
+ .prune_worktrees_expire = xstrdup("3.months.ago"), \
+ .max_delta_cache_size = DEFAULT_DELTA_CACHE_SIZE, \
+}
+
+static void gc_config_release(struct gc_config *cfg)
+{
+ free(cfg->gc_log_expire);
+ free(cfg->prune_expire);
+ free(cfg->prune_worktrees_expire);
+ free(cfg->repack_filter);
+ free(cfg->repack_filter_to);
+}
+
+static void gc_config(struct gc_config *cfg)
{
const char *value;
+ char *owned = NULL;
if (!git_config_get_value("gc.packrefs", &value)) {
if (value && !strcmp(value, "notbare"))
- pack_refs = -1;
+ cfg->pack_refs = -1;
else
- pack_refs = git_config_bool("gc.packrefs", value);
+ cfg->pack_refs = git_config_bool("gc.packrefs", value);
}
if (gc_config_is_timestamp_never("gc.reflogexpire") &&
gc_config_is_timestamp_never("gc.reflogexpireunreachable"))
- prune_reflogs = 0;
+ cfg->prune_reflogs = 0;
+
+ git_config_get_int("gc.aggressivewindow", &cfg->aggressive_window);
+ git_config_get_int("gc.aggressivedepth", &cfg->aggressive_depth);
+ git_config_get_int("gc.auto", &cfg->gc_auto_threshold);
+ git_config_get_int("gc.autopacklimit", &cfg->gc_auto_pack_limit);
+ git_config_get_bool("gc.autodetach", &cfg->detach_auto);
+ git_config_get_bool("gc.cruftpacks", &cfg->cruft_packs);
+ git_config_get_ulong("gc.maxcruftsize", &cfg->max_cruft_size);
+
+ if (!repo_config_get_expiry(the_repository, "gc.pruneexpire", &owned)) {
+ free(cfg->prune_expire);
+ cfg->prune_expire = owned;
+ }
- git_config_get_int("gc.aggressivewindow", &aggressive_window);
- git_config_get_int("gc.aggressivedepth", &aggressive_depth);
- git_config_get_int("gc.auto", &gc_auto_threshold);
- git_config_get_int("gc.autopacklimit", &gc_auto_pack_limit);
- git_config_get_bool("gc.autodetach", &detach_auto);
- git_config_get_bool("gc.cruftpacks", &cruft_packs);
- git_config_get_ulong("gc.maxcruftsize", &max_cruft_size);
- git_config_get_expiry("gc.pruneexpire", &prune_expire);
- git_config_get_expiry("gc.worktreepruneexpire", &prune_worktrees_expire);
- git_config_get_expiry("gc.logexpiry", &gc_log_expire);
+ if (!repo_config_get_expiry(the_repository, "gc.worktreepruneexpire", &owned)) {
+ free(cfg->prune_worktrees_expire);
+ cfg->prune_worktrees_expire = owned;
+ }
- git_config_get_ulong("gc.bigpackthreshold", &big_pack_threshold);
- git_config_get_ulong("pack.deltacachesize", &max_delta_cache_size);
+ if (!repo_config_get_expiry(the_repository, "gc.logexpiry", &owned)) {
+ free(cfg->gc_log_expire);
+ cfg->gc_log_expire = owned;
+ }
+
+ git_config_get_ulong("gc.bigpackthreshold", &cfg->big_pack_threshold);
+ git_config_get_ulong("pack.deltacachesize", &cfg->max_delta_cache_size);
+
+ if (!git_config_get_string("gc.repackfilter", &owned)) {
+ free(cfg->repack_filter);
+ cfg->repack_filter = owned;
+ }
- git_config_get_string("gc.repackfilter", &repack_filter);
- git_config_get_string("gc.repackfilterto", &repack_filter_to);
+ if (!git_config_get_string("gc.repackfilterto", &owned)) {
+ free(cfg->repack_filter_to);
+ cfg->repack_filter_to = owned;
+ }
git_config(git_default_config, NULL);
}
@@ -202,11 +242,15 @@ static enum schedule_priority parse_schedule(const char *value)
struct maintenance_run_opts {
int auto_flag;
+ int detach;
int quiet;
enum schedule_priority schedule;
};
+#define MAINTENANCE_RUN_OPTS_INIT { \
+ .detach = -1, \
+}
-static int pack_refs_condition(void)
+static int pack_refs_condition(UNUSED struct gc_config *cfg)
{
/*
* The auto-repacking logic for refs is handled by the ref backends and
@@ -216,7 +260,8 @@ static int pack_refs_condition(void)
return 1;
}
-static int maintenance_task_pack_refs(MAYBE_UNUSED struct maintenance_run_opts *opts)
+static int maintenance_task_pack_refs(MAYBE_UNUSED struct maintenance_run_opts *opts,
+ UNUSED struct gc_config *cfg)
{
struct child_process cmd = CHILD_PROCESS_INIT;
@@ -228,7 +273,7 @@ static int maintenance_task_pack_refs(MAYBE_UNUSED struct maintenance_run_opts *
return run_command(&cmd);
}
-static int too_many_loose_objects(void)
+static int too_many_loose_objects(struct gc_config *cfg)
{
/*
* Quickly check if a "gc" is needed, by estimating how
@@ -247,7 +292,7 @@ static int too_many_loose_objects(void)
if (!dir)
return 0;
- auto_threshold = DIV_ROUND_UP(gc_auto_threshold, 256);
+ auto_threshold = DIV_ROUND_UP(cfg->gc_auto_threshold, 256);
while ((ent = readdir(dir)) != NULL) {
if (strspn(ent->d_name, "0123456789abcdef") != hexsz_loose ||
ent->d_name[hexsz_loose] != '\0')
@@ -283,12 +328,12 @@ static struct packed_git *find_base_packs(struct string_list *packs,
return base;
}
-static int too_many_packs(void)
+static int too_many_packs(struct gc_config *cfg)
{
struct packed_git *p;
int cnt;
- if (gc_auto_pack_limit <= 0)
+ if (cfg->gc_auto_pack_limit <= 0)
return 0;
for (cnt = 0, p = get_all_packs(the_repository); p; p = p->next) {
@@ -302,7 +347,7 @@ static int too_many_packs(void)
*/
cnt++;
}
- return gc_auto_pack_limit < cnt;
+ return cfg->gc_auto_pack_limit < cnt;
}
static uint64_t total_ram(void)
@@ -336,7 +381,8 @@ static uint64_t total_ram(void)
return 0;
}
-static uint64_t estimate_repack_memory(struct packed_git *pack)
+static uint64_t estimate_repack_memory(struct gc_config *cfg,
+ struct packed_git *pack)
{
unsigned long nr_objects = repo_approximate_object_count(the_repository);
size_t os_cache, heap;
@@ -373,7 +419,7 @@ static uint64_t estimate_repack_memory(struct packed_git *pack)
*/
heap += delta_base_cache_limit;
/* and of course pack-objects has its own delta cache */
- heap += max_delta_cache_size;
+ heap += cfg->max_delta_cache_size;
return os_cache + heap;
}
@@ -384,30 +430,31 @@ static int keep_one_pack(struct string_list_item *item, void *data UNUSED)
return 0;
}
-static void add_repack_all_option(struct string_list *keep_pack)
+static void add_repack_all_option(struct gc_config *cfg,
+ struct string_list *keep_pack)
{
- if (prune_expire && !strcmp(prune_expire, "now"))
+ if (cfg->prune_expire && !strcmp(cfg->prune_expire, "now"))
strvec_push(&repack, "-a");
- else if (cruft_packs) {
+ else if (cfg->cruft_packs) {
strvec_push(&repack, "--cruft");
- if (prune_expire)
- strvec_pushf(&repack, "--cruft-expiration=%s", prune_expire);
- if (max_cruft_size)
+ if (cfg->prune_expire)
+ strvec_pushf(&repack, "--cruft-expiration=%s", cfg->prune_expire);
+ if (cfg->max_cruft_size)
strvec_pushf(&repack, "--max-cruft-size=%lu",
- max_cruft_size);
+ cfg->max_cruft_size);
} else {
strvec_push(&repack, "-A");
- if (prune_expire)
- strvec_pushf(&repack, "--unpack-unreachable=%s", prune_expire);
+ if (cfg->prune_expire)
+ strvec_pushf(&repack, "--unpack-unreachable=%s", cfg->prune_expire);
}
if (keep_pack)
for_each_string_list(keep_pack, keep_one_pack, NULL);
- if (repack_filter && *repack_filter)
- strvec_pushf(&repack, "--filter=%s", repack_filter);
- if (repack_filter_to && *repack_filter_to)
- strvec_pushf(&repack, "--filter-to=%s", repack_filter_to);
+ if (cfg->repack_filter && *cfg->repack_filter)
+ strvec_pushf(&repack, "--filter=%s", cfg->repack_filter);
+ if (cfg->repack_filter_to && *cfg->repack_filter_to)
+ strvec_pushf(&repack, "--filter-to=%s", cfg->repack_filter_to);
}
static void add_repack_incremental_option(void)
@@ -415,13 +462,13 @@ static void add_repack_incremental_option(void)
strvec_push(&repack, "--no-write-bitmap-index");
}
-static int need_to_gc(void)
+static int need_to_gc(struct gc_config *cfg)
{
/*
* Setting gc.auto to 0 or negative can disable the
* automatic gc.
*/
- if (gc_auto_threshold <= 0)
+ if (cfg->gc_auto_threshold <= 0)
return 0;
/*
@@ -430,13 +477,13 @@ static int need_to_gc(void)
* we run "repack -A -d -l". Otherwise we tell the caller
* there is no need.
*/
- if (too_many_packs()) {
+ if (too_many_packs(cfg)) {
struct string_list keep_pack = STRING_LIST_INIT_NODUP;
- if (big_pack_threshold) {
- find_base_packs(&keep_pack, big_pack_threshold);
- if (keep_pack.nr >= gc_auto_pack_limit) {
- big_pack_threshold = 0;
+ if (cfg->big_pack_threshold) {
+ find_base_packs(&keep_pack, cfg->big_pack_threshold);
+ if (keep_pack.nr >= cfg->gc_auto_pack_limit) {
+ cfg->big_pack_threshold = 0;
string_list_clear(&keep_pack, 0);
find_base_packs(&keep_pack, 0);
}
@@ -445,7 +492,7 @@ static int need_to_gc(void)
uint64_t mem_have, mem_want;
mem_have = total_ram();
- mem_want = estimate_repack_memory(p);
+ mem_want = estimate_repack_memory(cfg, p);
/*
* Only allow 1/2 of memory for pack-objects, leave
@@ -456,14 +503,14 @@ static int need_to_gc(void)
string_list_clear(&keep_pack, 0);
}
- add_repack_all_option(&keep_pack);
+ add_repack_all_option(cfg, &keep_pack);
string_list_clear(&keep_pack, 0);
- } else if (too_many_loose_objects())
+ } else if (too_many_loose_objects(cfg))
add_repack_incremental_option();
else
return 0;
- if (run_hooks("pre-auto-gc"))
+ if (run_hooks(the_repository, "pre-auto-gc"))
return 0;
return 1;
}
@@ -585,7 +632,8 @@ done:
return ret;
}
-static void gc_before_repack(struct maintenance_run_opts *opts)
+static void gc_before_repack(struct maintenance_run_opts *opts,
+ struct gc_config *cfg)
{
/*
* We may be called twice, as both the pre- and
@@ -596,10 +644,10 @@ static void gc_before_repack(struct maintenance_run_opts *opts)
if (done++)
return;
- if (pack_refs && maintenance_task_pack_refs(opts))
+ if (cfg->pack_refs && maintenance_task_pack_refs(opts, cfg))
die(FAILED_RUN, "pack-refs");
- if (prune_reflogs) {
+ if (cfg->prune_reflogs) {
struct child_process cmd = CHILD_PROCESS_INIT;
cmd.git_cmd = 1;
@@ -620,19 +668,25 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
int keep_largest_pack = -1;
timestamp_t dummy;
struct child_process rerere_cmd = CHILD_PROCESS_INIT;
- struct maintenance_run_opts opts = {0};
+ struct maintenance_run_opts opts = MAINTENANCE_RUN_OPTS_INIT;
+ struct gc_config cfg = GC_CONFIG_INIT;
+ const char *prune_expire_sentinel = "sentinel";
+ const char *prune_expire_arg = prune_expire_sentinel;
+ int ret;
struct option builtin_gc_options[] = {
OPT__QUIET(&quiet, N_("suppress progress reporting")),
- { OPTION_STRING, 0, "prune", &prune_expire, N_("date"),
+ { OPTION_STRING, 0, "prune", &prune_expire_arg, N_("date"),
N_("prune unreferenced objects"),
- PARSE_OPT_OPTARG, NULL, (intptr_t)prune_expire },
- OPT_BOOL(0, "cruft", &cruft_packs, N_("pack unreferenced objects separately")),
- OPT_MAGNITUDE(0, "max-cruft-size", &max_cruft_size,
+ PARSE_OPT_OPTARG, NULL, (intptr_t)prune_expire_arg },
+ OPT_BOOL(0, "cruft", &cfg.cruft_packs, N_("pack unreferenced objects separately")),
+ OPT_MAGNITUDE(0, "max-cruft-size", &cfg.max_cruft_size,
N_("with --cruft, limit the size of new cruft packs")),
OPT_BOOL(0, "aggressive", &aggressive, N_("be more thorough (increased runtime)")),
OPT_BOOL_F(0, "auto", &opts.auto_flag, N_("enable auto-gc mode"),
PARSE_OPT_NOCOMPLETE),
+ OPT_BOOL(0, "detach", &opts.detach,
+ N_("perform garbage collection in the background")),
OPT_BOOL_F(0, "force", &force,
N_("force running gc even if there may be another gc running"),
PARSE_OPT_NOCOMPLETE),
@@ -650,84 +704,103 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
strvec_pushl(&prune_worktrees, "worktree", "prune", "--expire", NULL);
strvec_pushl(&rerere, "rerere", "gc", NULL);
- /* default expiry time, overwritten in gc_config */
- gc_config();
- if (parse_expiry_date(gc_log_expire, &gc_log_expire_time))
- die(_("failed to parse gc.logExpiry value %s"), gc_log_expire);
+ gc_config(&cfg);
- if (pack_refs < 0)
- pack_refs = !is_bare_repository();
+ if (parse_expiry_date(cfg.gc_log_expire, &gc_log_expire_time))
+ die(_("failed to parse gc.logExpiry value %s"), cfg.gc_log_expire);
+
+ if (cfg.pack_refs < 0)
+ cfg.pack_refs = !is_bare_repository();
argc = parse_options(argc, argv, prefix, builtin_gc_options,
builtin_gc_usage, 0);
if (argc > 0)
usage_with_options(builtin_gc_usage, builtin_gc_options);
- if (prune_expire && parse_expiry_date(prune_expire, &dummy))
- die(_("failed to parse prune expiry value %s"), prune_expire);
+ if (prune_expire_arg != prune_expire_sentinel) {
+ free(cfg.prune_expire);
+ cfg.prune_expire = xstrdup_or_null(prune_expire_arg);
+ }
+ if (cfg.prune_expire && parse_expiry_date(cfg.prune_expire, &dummy))
+ die(_("failed to parse prune expiry value %s"), cfg.prune_expire);
if (aggressive) {
strvec_push(&repack, "-f");
- if (aggressive_depth > 0)
- strvec_pushf(&repack, "--depth=%d", aggressive_depth);
- if (aggressive_window > 0)
- strvec_pushf(&repack, "--window=%d", aggressive_window);
+ if (cfg.aggressive_depth > 0)
+ strvec_pushf(&repack, "--depth=%d", cfg.aggressive_depth);
+ if (cfg.aggressive_window > 0)
+ strvec_pushf(&repack, "--window=%d", cfg.aggressive_window);
}
if (quiet)
strvec_push(&repack, "-q");
if (opts.auto_flag) {
+ if (cfg.detach_auto && opts.detach < 0)
+ opts.detach = 1;
+
/*
* Auto-gc should be least intrusive as possible.
*/
- if (!need_to_gc())
- return 0;
+ if (!need_to_gc(&cfg)) {
+ ret = 0;
+ goto out;
+ }
+
if (!quiet) {
- if (detach_auto)
+ if (opts.detach > 0)
fprintf(stderr, _("Auto packing the repository in background for optimum performance.\n"));
else
fprintf(stderr, _("Auto packing the repository for optimum performance.\n"));
fprintf(stderr, _("See \"git help gc\" for manual housekeeping.\n"));
}
- if (detach_auto) {
- int ret = report_last_gc_error();
-
- if (ret == 1)
- /* Last gc --auto failed. Skip this one. */
- return 0;
- else if (ret)
- /* an I/O error occurred, already reported */
- return ret;
-
- if (lock_repo_for_gc(force, &pid))
- return 0;
- gc_before_repack(&opts); /* dies on failure */
- delete_tempfile(&pidfile);
-
- /*
- * failure to daemonize is ok, we'll continue
- * in foreground
- */
- daemonized = !daemonize();
- }
} else {
struct string_list keep_pack = STRING_LIST_INIT_NODUP;
if (keep_largest_pack != -1) {
if (keep_largest_pack)
find_base_packs(&keep_pack, 0);
- } else if (big_pack_threshold) {
- find_base_packs(&keep_pack, big_pack_threshold);
+ } else if (cfg.big_pack_threshold) {
+ find_base_packs(&keep_pack, cfg.big_pack_threshold);
}
- add_repack_all_option(&keep_pack);
+ add_repack_all_option(&cfg, &keep_pack);
string_list_clear(&keep_pack, 0);
}
+ if (opts.detach > 0) {
+ ret = report_last_gc_error();
+ if (ret == 1) {
+ /* Last gc --auto failed. Skip this one. */
+ ret = 0;
+ goto out;
+
+ } else if (ret) {
+ /* an I/O error occurred, already reported */
+ goto out;
+ }
+
+ if (lock_repo_for_gc(force, &pid)) {
+ ret = 0;
+ goto out;
+ }
+
+ gc_before_repack(&opts, &cfg); /* dies on failure */
+ delete_tempfile(&pidfile);
+
+ /*
+ * failure to daemonize is ok, we'll continue
+ * in foreground
+ */
+ daemonized = !daemonize();
+ }
+
name = lock_repo_for_gc(force, &pid);
if (name) {
- if (opts.auto_flag)
- return 0; /* be quiet on --auto */
+ if (opts.auto_flag) {
+ ret = 0;
+ goto out; /* be quiet on --auto */
+ }
+
die(_("gc is already running on machine '%s' pid %"PRIuMAX" (use --force if not)"),
name, (uintmax_t)pid);
}
@@ -737,11 +810,10 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
git_path("gc.log"),
LOCK_DIE_ON_ERROR);
dup2(get_lock_file_fd(&log_lock), 2);
- sigchain_push_common(process_log_file_on_signal);
atexit(process_log_file_at_exit);
}
- gc_before_repack(&opts);
+ gc_before_repack(&opts, &cfg);
if (!repository_format_precious_objects) {
struct child_process repack_cmd = CHILD_PROCESS_INIT;
@@ -752,11 +824,11 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
if (run_command(&repack_cmd))
die(FAILED_RUN, repack.v[0]);
- if (prune_expire) {
+ if (cfg.prune_expire) {
struct child_process prune_cmd = CHILD_PROCESS_INIT;
/* run `git prune` even if using cruft packs */
- strvec_push(&prune, prune_expire);
+ strvec_push(&prune, cfg.prune_expire);
if (quiet)
strvec_push(&prune, "--no-progress");
if (repo_has_promisor_remote(the_repository))
@@ -769,10 +841,10 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
}
}
- if (prune_worktrees_expire) {
+ if (cfg.prune_worktrees_expire) {
struct child_process prune_worktrees_cmd = CHILD_PROCESS_INIT;
- strvec_push(&prune_worktrees, prune_worktrees_expire);
+ strvec_push(&prune_worktrees, cfg.prune_worktrees_expire);
prune_worktrees_cmd.git_cmd = 1;
strvec_pushv(&prune_worktrees_cmd.args, prune_worktrees.v);
if (run_command(&prune_worktrees_cmd))
@@ -796,13 +868,15 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
!quiet && !daemonized ? COMMIT_GRAPH_WRITE_PROGRESS : 0,
NULL);
- if (opts.auto_flag && too_many_loose_objects())
+ if (opts.auto_flag && too_many_loose_objects(&cfg))
warning(_("There are too many unreachable loose objects; "
"run 'git prune' to remove them."));
if (!daemonized)
unlink(git_path("gc.log"));
+out:
+ gc_config_release(&cfg);
return 0;
}
@@ -893,7 +967,7 @@ static int dfs_on_ref(const char *refname UNUSED,
return result;
}
-static int should_write_commit_graph(void)
+static int should_write_commit_graph(struct gc_config *cfg)
{
int result;
struct cg_auto_data data;
@@ -930,7 +1004,8 @@ static int run_write_commit_graph(struct maintenance_run_opts *opts)
return !!run_command(&child);
}
-static int maintenance_task_commit_graph(struct maintenance_run_opts *opts)
+static int maintenance_task_commit_graph(struct maintenance_run_opts *opts,
+ struct gc_config *cfg)
{
prepare_repo_settings(the_repository);
if (!the_repository->settings.core_commit_graph)
@@ -964,7 +1039,8 @@ static int fetch_remote(struct remote *remote, void *cbdata)
return !!run_command(&child);
}
-static int maintenance_task_prefetch(struct maintenance_run_opts *opts)
+static int maintenance_task_prefetch(struct maintenance_run_opts *opts,
+ struct gc_config *cfg)
{
if (for_each_remote(fetch_remote, opts)) {
error(_("failed to prefetch remotes"));
@@ -974,7 +1050,8 @@ static int maintenance_task_prefetch(struct maintenance_run_opts *opts)
return 0;
}
-static int maintenance_task_gc(struct maintenance_run_opts *opts)
+static int maintenance_task_gc(struct maintenance_run_opts *opts,
+ struct gc_config *cfg)
{
struct child_process child = CHILD_PROCESS_INIT;
@@ -987,6 +1064,7 @@ static int maintenance_task_gc(struct maintenance_run_opts *opts)
strvec_push(&child.args, "--quiet");
else
strvec_push(&child.args, "--no-quiet");
+ strvec_push(&child.args, "--no-detach");
return run_command(&child);
}
@@ -1022,7 +1100,7 @@ static int loose_object_count(const struct object_id *oid UNUSED,
return 0;
}
-static int loose_object_auto_condition(void)
+static int loose_object_auto_condition(struct gc_config *cfg)
{
int count = 0;
@@ -1082,6 +1160,12 @@ static int pack_loose(struct maintenance_run_opts *opts)
pack_proc.in = -1;
+ /*
+ * git-pack-objects(1) ends up writing the pack hash to stdout, which
+ * we do not care for.
+ */
+ pack_proc.out = -1;
+
if (start_command(&pack_proc)) {
error(_("failed to start 'git pack-objects' process"));
return 1;
@@ -1107,12 +1191,13 @@ static int pack_loose(struct maintenance_run_opts *opts)
return result;
}
-static int maintenance_task_loose_objects(struct maintenance_run_opts *opts)
+static int maintenance_task_loose_objects(struct maintenance_run_opts *opts,
+ struct gc_config *cfg)
{
return prune_packed(opts) || pack_loose(opts);
}
-static int incremental_repack_auto_condition(void)
+static int incremental_repack_auto_condition(struct gc_config *cfg)
{
struct packed_git *p;
int incremental_repack_auto_limit = 10;
@@ -1231,7 +1316,8 @@ static int multi_pack_index_repack(struct maintenance_run_opts *opts)
return 0;
}
-static int maintenance_task_incremental_repack(struct maintenance_run_opts *opts)
+static int maintenance_task_incremental_repack(struct maintenance_run_opts *opts,
+ struct gc_config *cfg)
{
prepare_repo_settings(the_repository);
if (!the_repository->settings.core_multi_pack_index) {
@@ -1248,14 +1334,15 @@ static int maintenance_task_incremental_repack(struct maintenance_run_opts *opts
return 0;
}
-typedef int maintenance_task_fn(struct maintenance_run_opts *opts);
+typedef int maintenance_task_fn(struct maintenance_run_opts *opts,
+ struct gc_config *cfg);
/*
* An auto condition function returns 1 if the task should run
* and 0 if the task should NOT run. See needs_to_gc() for an
* example.
*/
-typedef int maintenance_auto_fn(void);
+typedef int maintenance_auto_fn(struct gc_config *cfg);
struct maintenance_task {
const char *name;
@@ -1322,7 +1409,8 @@ static int compare_tasks_by_selection(const void *a_, const void *b_)
return b->selected_order - a->selected_order;
}
-static int maintenance_run_tasks(struct maintenance_run_opts *opts)
+static int maintenance_run_tasks(struct maintenance_run_opts *opts,
+ struct gc_config *cfg)
{
int i, found_selected = 0;
int result = 0;
@@ -1346,6 +1434,13 @@ static int maintenance_run_tasks(struct maintenance_run_opts *opts)
}
free(lock_path);
+ /* Failure to daemonize is ok, we'll continue in foreground. */
+ if (opts->detach > 0) {
+ trace2_region_enter("maintenance", "detach", the_repository);
+ daemonize();
+ trace2_region_leave("maintenance", "detach", the_repository);
+ }
+
for (i = 0; !found_selected && i < TASK__COUNT; i++)
found_selected = tasks[i].selected_order >= 0;
@@ -1361,14 +1456,14 @@ static int maintenance_run_tasks(struct maintenance_run_opts *opts)
if (opts->auto_flag &&
(!tasks[i].auto_condition ||
- !tasks[i].auto_condition()))
+ !tasks[i].auto_condition(cfg)))
continue;
if (opts->schedule && tasks[i].schedule < opts->schedule)
continue;
trace2_region_enter("maintenance", tasks[i].name, r);
- if (tasks[i].fn(opts)) {
+ if (tasks[i].fn(opts, cfg)) {
error(_("task '%s' failed"), tasks[i].name);
result = 1;
}
@@ -1405,7 +1500,6 @@ static void initialize_task_config(int schedule)
{
int i;
struct strbuf config_name = STRBUF_INIT;
- gc_config();
if (schedule)
initialize_maintenance_strategy();
@@ -1468,10 +1562,13 @@ static int task_option_parse(const struct option *opt UNUSED,
static int maintenance_run(int argc, const char **argv, const char *prefix)
{
int i;
- struct maintenance_run_opts opts;
+ struct maintenance_run_opts opts = MAINTENANCE_RUN_OPTS_INIT;
+ struct gc_config cfg = GC_CONFIG_INIT;
struct option builtin_maintenance_run_options[] = {
OPT_BOOL(0, "auto", &opts.auto_flag,
N_("run tasks based on the state of the repository")),
+ OPT_BOOL(0, "detach", &opts.detach,
+ N_("perform maintenance in the background")),
OPT_CALLBACK(0, "schedule", &opts.schedule, N_("frequency"),
N_("run tasks based on frequency"),
maintenance_opt_schedule),
@@ -1482,7 +1579,7 @@ static int maintenance_run(int argc, const char **argv, const char *prefix)
PARSE_OPT_NONEG, task_option_parse),
OPT_END()
};
- memset(&opts, 0, sizeof(opts));
+ int ret;
opts.quiet = !isatty(2);
@@ -1497,12 +1594,16 @@ static int maintenance_run(int argc, const char **argv, const char *prefix)
if (opts.auto_flag && opts.schedule)
die(_("use at most one of --auto and --schedule=<frequency>"));
+ gc_config(&cfg);
initialize_task_config(opts.schedule);
if (argc != 0)
usage_with_options(builtin_maintenance_run_usage,
builtin_maintenance_run_options);
- return maintenance_run_tasks(&opts);
+
+ ret = maintenance_run_tasks(&opts, &cfg);
+ gc_config_release(&cfg);
+ return ret;
}
static char *get_maintpath(void)
diff --git a/builtin/hook.c b/builtin/hook.c
index 5234693a94..cc37438fde 100644
--- a/builtin/hook.c
+++ b/builtin/hook.c
@@ -58,7 +58,7 @@ static int run(int argc, const char **argv, const char *prefix)
hook_name = argv[0];
if (!ignore_missing)
opt.error_if_missing = 1;
- ret = run_hooks_opt(hook_name, &opt);
+ ret = run_hooks_opt(the_repository, hook_name, &opt);
if (ret < 0) /* error() return */
ret = 1;
return ret;
diff --git a/builtin/log.c b/builtin/log.c
index a73a767606..36769bab3b 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -707,6 +707,7 @@ static int show_blob_object(const struct object_id *oid, struct rev_info *rev, c
write_or_die(1, buf, size);
object_context_release(&obj_context);
+ free(buf);
return 0;
}
@@ -1827,12 +1828,14 @@ static struct commit *get_base_commit(const struct format_config *cfg,
if (die_on_failure) {
die(_("failed to find exact merge base"));
} else {
+ free_commit_list(merge_base);
free(rev);
return NULL;
}
}
rev[i] = merge_base->item;
+ free_commit_list(merge_base);
}
if (rev_nr % 2)
@@ -2023,6 +2026,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
const char *rfc = NULL;
int creation_factor = -1;
const char *signature = git_version_string;
+ char *signature_to_free = NULL;
char *signature_file_arg = NULL;
struct keep_callback_data keep_callback_data = {
.cfg = &cfg,
@@ -2443,7 +2447,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
if (strbuf_read_file(&buf, signature_file, 128) < 0)
die_errno(_("unable to read signature file '%s'"), signature_file);
- signature = strbuf_detach(&buf, NULL);
+ signature = signature_to_free = strbuf_detach(&buf, NULL);
} else if (cfg.signature) {
signature = cfg.signature;
}
@@ -2548,12 +2552,13 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
else
print_signature(signature, rev.diffopt.file);
}
- if (output_directory)
+ if (output_directory) {
fclose(rev.diffopt.file);
+ rev.diffopt.file = NULL;
+ }
}
stop_progress(&progress);
free(list);
- free(branch_name);
if (ignore_if_in_upstream)
free_patch_ids(&ids);
@@ -2565,11 +2570,14 @@ done:
strbuf_release(&rdiff_title);
free(description_file);
free(signature_file_arg);
+ free(signature_to_free);
+ free(branch_name);
free(to_free);
free(rev.message_id);
if (rev.ref_message_ids)
string_list_clear(rev.ref_message_ids, 0);
free(rev.ref_message_ids);
+ rev.diffopt.no_free = 0;
release_revisions(&rev);
format_config_release(&cfg);
return 0;
diff --git a/builtin/merge.c b/builtin/merge.c
index c896b18d1a..662a49a0e8 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -478,7 +478,7 @@ static void finish(struct commit *head_commit,
}
/* Run a post-merge hook */
- run_hooks_l("post-merge", squash ? "1" : "0", NULL);
+ run_hooks_l(the_repository, "post-merge", squash ? "1" : "0", NULL);
if (new_head)
apply_autostash_ref(the_repository, "MERGE_AUTOSTASH");
diff --git a/builtin/notes.c b/builtin/notes.c
index 4cc5bfedc3..04f9dfb7fb 100644
--- a/builtin/notes.c
+++ b/builtin/notes.c
@@ -805,7 +805,7 @@ static int merge_commit(struct notes_merge_options *o)
{
struct strbuf msg = STRBUF_INIT;
struct object_id oid, parent_oid;
- struct notes_tree *t;
+ struct notes_tree t = {0};
struct commit *partial;
struct pretty_print_context pretty_ctx;
void *local_ref_to_free;
@@ -828,8 +828,7 @@ static int merge_commit(struct notes_merge_options *o)
else
oidclr(&parent_oid, the_repository->hash_algo);
- CALLOC_ARRAY(t, 1);
- init_notes(t, "NOTES_MERGE_PARTIAL", combine_notes_overwrite, 0);
+ init_notes(&t, "NOTES_MERGE_PARTIAL", combine_notes_overwrite, 0);
o->local_ref = local_ref_to_free =
refs_resolve_refdup(get_main_ref_store(the_repository),
@@ -837,7 +836,7 @@ static int merge_commit(struct notes_merge_options *o)
if (!o->local_ref)
die(_("failed to resolve NOTES_MERGE_REF"));
- if (notes_merge_commit(o, t, partial, &oid))
+ if (notes_merge_commit(o, &t, partial, &oid))
die(_("failed to finalize notes merge"));
/* Reuse existing commit message in reflog message */
@@ -851,7 +850,7 @@ static int merge_commit(struct notes_merge_options *o)
is_null_oid(&parent_oid) ? NULL : &parent_oid,
0, UPDATE_REFS_DIE_ON_ERR);
- free_notes(t);
+ free_notes(&t);
strbuf_release(&msg);
ret = merge_abort(o);
free(local_ref_to_free);
@@ -866,7 +865,7 @@ static int git_config_get_notes_strategy(const char *key,
if (git_config_get_string(key, &value))
return 1;
if (parse_notes_merge_strategy(value, strategy))
- git_die_config(key, _("unknown notes merge strategy %s"), value);
+ git_die_config(the_repository, key, _("unknown notes merge strategy %s"), value);
free(value);
return 0;
diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
index c481feadbf..778be80f56 100644
--- a/builtin/pack-objects.c
+++ b/builtin/pack-objects.c
@@ -1342,10 +1342,10 @@ static void write_pack_file(void)
if (write_bitmap_index) {
bitmap_writer_init(&bitmap_writer,
- the_repository);
+ the_repository, &to_pack);
bitmap_writer_set_checksum(&bitmap_writer, hash);
bitmap_writer_build_type_index(&bitmap_writer,
- &to_pack, written_list, nr_written);
+ written_list);
}
if (cruft)
@@ -1367,10 +1367,10 @@ static void write_pack_file(void)
bitmap_writer_select_commits(&bitmap_writer,
indexed_commits,
indexed_commits_nr);
- if (bitmap_writer_build(&bitmap_writer, &to_pack) < 0)
+ if (bitmap_writer_build(&bitmap_writer) < 0)
die(_("failed to write bitmap index"));
bitmap_writer_finish(&bitmap_writer,
- written_list, nr_written,
+ written_list,
tmpname.buf, write_bitmap_options);
bitmap_writer_free(&bitmap_writer);
write_bitmap_index = 0;
diff --git a/builtin/rebase.c b/builtin/rebase.c
index e3a8e74cfc..a2c96c080e 100644
--- a/builtin/rebase.c
+++ b/builtin/rebase.c
@@ -186,6 +186,7 @@ static struct replay_opts get_replay_opts(const struct rebase_options *opts)
replay.committer_date_is_author_date =
opts->committer_date_is_author_date;
replay.ignore_date = opts->ignore_date;
+ free(replay.gpg_sign);
replay.gpg_sign = xstrdup_or_null(opts->gpg_sign_opt);
replay.reflog_action = xstrdup(opts->reflog_action);
if (opts->strategy)
@@ -1774,7 +1775,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
/* If a hook exists, give it a chance to interrupt*/
if (!ok_to_skip_pre_rebase &&
- run_hooks_l("pre-rebase", options.upstream_arg,
+ run_hooks_l(the_repository, "pre-rebase", options.upstream_arg,
argc ? argv[0] : NULL, NULL))
die(_("The pre-rebase hook refused to rebase."));
diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c
index 6e0f462efb..3f35140e48 100644
--- a/builtin/receive-pack.c
+++ b/builtin/receive-pack.c
@@ -792,7 +792,7 @@ static int run_and_feed_hook(const char *hook_name, feed_fn feed,
struct child_process proc = CHILD_PROCESS_INIT;
struct async muxer;
int code;
- const char *hook_path = find_hook(hook_name);
+ const char *hook_path = find_hook(the_repository, hook_name);
if (!hook_path)
return 0;
@@ -922,7 +922,7 @@ static int run_update_hook(struct command *cmd)
{
struct child_process proc = CHILD_PROCESS_INIT;
int code;
- const char *hook_path = find_hook("update");
+ const char *hook_path = find_hook(the_repository, "update");
if (!hook_path)
return 0;
@@ -1098,7 +1098,7 @@ static int run_proc_receive_hook(struct command *commands,
int hook_use_push_options = 0;
int version = 0;
int code;
- const char *hook_path = find_hook("proc-receive");
+ const char *hook_path = find_hook(the_repository, "proc-receive");
if (!hook_path) {
rp_error("cannot find hook 'proc-receive'");
@@ -1409,7 +1409,7 @@ static const char *push_to_checkout(unsigned char *hash,
strvec_pushf(env, "GIT_WORK_TREE=%s", absolute_path(work_tree));
strvec_pushv(&opt.env, env->v);
strvec_push(&opt.args, hash_to_hex(hash));
- if (run_hooks_opt(push_to_checkout_hook, &opt))
+ if (run_hooks_opt(the_repository, push_to_checkout_hook, &opt))
return "push-to-checkout hook declined";
else
return NULL;
@@ -1618,7 +1618,7 @@ static void run_update_post_hook(struct command *commands)
struct child_process proc = CHILD_PROCESS_INIT;
const char *hook;
- hook = find_hook("post-update");
+ hook = find_hook(the_repository, "post-update");
if (!hook)
return;
diff --git a/builtin/remote.c b/builtin/remote.c
index 874f14a823..d1f9292ed2 100644
--- a/builtin/remote.c
+++ b/builtin/remote.c
@@ -747,7 +747,7 @@ static int mv(int argc, const char **argv, const char *prefix)
strbuf_addf(&buf, "remote.%s", rename.old_name);
strbuf_addf(&buf2, "remote.%s", rename.new_name);
- if (git_config_rename_section(buf.buf, buf2.buf) < 1)
+ if (repo_config_rename_section(the_repository, buf.buf, buf2.buf) < 1)
return error(_("Could not rename config section '%s' to '%s'"),
buf.buf, buf2.buf);
@@ -960,7 +960,7 @@ static int rm(int argc, const char **argv, const char *prefix)
if (!result) {
strbuf_addf(&buf, "remote.%s", remote->name);
- if (git_config_rename_section(buf.buf, NULL) < 1) {
+ if (repo_config_rename_section(the_repository, buf.buf, NULL) < 1) {
result = error(_("Could not remove config section '%s'"), buf.buf);
goto out;
}
diff --git a/builtin/stash.c b/builtin/stash.c
index d90e072ddc..fcfd97972a 100644
--- a/builtin/stash.c
+++ b/builtin/stash.c
@@ -1671,7 +1671,28 @@ static int do_push_stash(const struct pathspec *ps, const char *stash_msg, int q
}
}
- if (keep_index == 1 && !is_null_oid(&info.i_tree)) {
+ /*
+ * When keeping staged entries, we need to reset the working
+ * directory to match the state of our index. This can be
+ * skipped when the index is the empty tree, because there is
+ * nothing to reset in that case:
+ *
+ * - When the index has any file, regardless of whether
+ * staged or not, the tree cannot be empty by definition
+ * and thus we enter the condition.
+ *
+ * - When the index has no files, the only thing we need to
+ * care about is untracked files when `--include-untracked`
+ * is given. But as we already execute git-clean(1) further
+ * up to delete such untracked files we don't have to do
+ * anything here, either.
+ *
+ * We thus skip calling git-checkout(1) in this case, also
+ * because running it on an empty tree will cause it to fail
+ * due to the pathspec not matching anything.
+ */
+ if (keep_index == 1 && !is_null_oid(&info.i_tree) &&
+ !is_empty_tree_oid(&info.i_tree, the_repository->hash_algo)) {
struct child_process cp = CHILD_PROCESS_INIT;
cp.git_cmd = 1;
diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index 672a0b0490..85fb23dee8 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -1456,7 +1456,7 @@ static void deinit_submodule(const char *path, const char *prefix,
* remove the whole section so we have a clean state when
* the user later decides to init this submodule again
*/
- git_config_rename_section_in_file(NULL, sub_key, NULL);
+ repo_config_rename_section_in_file(the_repository, NULL, sub_key, NULL);
if (!(flags & OPT_QUIET))
printf(_("Submodule '%s' (%s) unregistered for path '%s'\n"),
sub->name, sub->url, displaypath);
diff --git a/builtin/update-index.c b/builtin/update-index.c
index d343416ae2..35a1f957ad 100644
--- a/builtin/update-index.c
+++ b/builtin/update-index.c
@@ -1156,7 +1156,7 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
end_odb_transaction();
if (split_index > 0) {
- if (git_config_get_split_index() == 0)
+ if (repo_config_get_split_index(the_repository) == 0)
warning(_("core.splitIndex is set to false; "
"remove or change it, if you really want to "
"enable split index"));
@@ -1165,7 +1165,7 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
else
add_split_index(the_repository->index);
} else if (!split_index) {
- if (git_config_get_split_index() == 1)
+ if (repo_config_get_split_index(the_repository) == 1)
warning(_("core.splitIndex is set to true; "
"remove or change it, if you really want to "
"disable split index"));
diff --git a/builtin/update-ref.c b/builtin/update-ref.c
index 6a6a2ff55d..8f31da9a4b 100644
--- a/builtin/update-ref.c
+++ b/builtin/update-ref.c
@@ -274,7 +274,7 @@ static void parse_cmd_update(struct ref_transaction *transaction,
}
static void parse_cmd_symref_update(struct ref_transaction *transaction,
- const char *next, const char *end)
+ const char *next, const char *end UNUSED)
{
char *refname, *new_target, *old_arg;
char *old_target = NULL;
@@ -360,7 +360,7 @@ static void parse_cmd_create(struct ref_transaction *transaction,
static void parse_cmd_symref_create(struct ref_transaction *transaction,
- const char *next, const char *end)
+ const char *next, const char *end UNUSED)
{
struct strbuf err = STRBUF_INIT;
char *refname, *new_target;
@@ -423,7 +423,7 @@ static void parse_cmd_delete(struct ref_transaction *transaction,
static void parse_cmd_symref_delete(struct ref_transaction *transaction,
- const char *next, const char *end)
+ const char *next, const char *end UNUSED)
{
struct strbuf err = STRBUF_INIT;
char *refname, *old_target;
@@ -479,7 +479,7 @@ static void parse_cmd_verify(struct ref_transaction *transaction,
}
static void parse_cmd_symref_verify(struct ref_transaction *transaction,
- const char *next, const char *end)
+ const char *next, const char *end UNUSED)
{
struct strbuf err = STRBUF_INIT;
struct object_id old_oid;
diff --git a/builtin/worktree.c b/builtin/worktree.c
index 01cd76dede..41e7f6a327 100644
--- a/builtin/worktree.c
+++ b/builtin/worktree.c
@@ -573,7 +573,7 @@ done:
NULL);
opt.dir = path;
- ret = run_hooks_opt("post-checkout", &opt);
+ ret = run_hooks_opt(the_repository, "post-checkout", &opt);
}
strvec_clear(&child_env);
@@ -1148,14 +1148,14 @@ static void validate_no_submodules(const struct worktree *wt)
struct strbuf path = STRBUF_INIT;
int i, found_submodules = 0;
- if (is_directory(worktree_git_path(wt, "modules"))) {
+ if (is_directory(worktree_git_path(the_repository, wt, "modules"))) {
/*
* There could be false positives, e.g. the "modules"
* directory exists but is empty. But it's a rare case and
* this simpler check is probably good enough for now.
*/
found_submodules = 1;
- } else if (read_index_from(&istate, worktree_git_path(wt, "index"),
+ } else if (read_index_from(&istate, worktree_git_path(the_repository, wt, "index"),
get_worktree_git_dir(wt)) > 0) {
for (i = 0; i < istate.cache_nr; i++) {
struct cache_entry *ce = istate.cache[i];
diff --git a/bulk-checkin.c b/bulk-checkin.c
index da8673199b..9089c214fa 100644
--- a/bulk-checkin.c
+++ b/bulk-checkin.c
@@ -61,6 +61,7 @@ static void flush_bulk_checkin_packfile(struct bulk_checkin_packfile *state)
if (state->nr_written == 0) {
close(state->f->fd);
+ free_hashfile(state->f);
unlink(state->pack_tmp_name);
goto clear_exit;
} else if (state->nr_written == 1) {
@@ -83,6 +84,7 @@ static void flush_bulk_checkin_packfile(struct bulk_checkin_packfile *state)
free(state->written[i]);
clear_exit:
+ free(state->pack_tmp_name);
free(state->written);
memset(state, 0, sizeof(*state));
diff --git a/bundle.c b/bundle.c
index ce164c37bc..b0a8a925cb 100644
--- a/bundle.c
+++ b/bundle.c
@@ -89,7 +89,12 @@ int read_bundle_header_fd(int fd, struct bundle_header *header,
goto abort;
}
- header->hash_algo = the_hash_algo;
+ /*
+ * The default hash format for bundles is SHA1, unless told otherwise
+ * by an "object-format=" capability, which is being handled in
+ * `parse_capability()`.
+ */
+ header->hash_algo = &hash_algos[GIT_HASH_SHA1];
/* The bundle header ends with an empty line */
while (!strbuf_getwholeline_fd(&buf, fd, '\n') &&
diff --git a/commit-reach.c b/commit-reach.c
index 02f8218b8e..c3518aa360 100644
--- a/commit-reach.c
+++ b/commit-reach.c
@@ -1229,3 +1229,129 @@ done:
repo_clear_commit_marks(r, SEEN);
free_commit_list(stack);
}
+
+/*
+ * This slab initializes integers to zero, so use "-1" for "tip is best" and
+ * "i + 1" for "bases[i] is best".
+ */
+define_commit_slab(best_branch_base, int);
+static struct best_branch_base best_branch_base;
+#define get_best(c) (*best_branch_base_at(&best_branch_base, (c)))
+#define set_best(c,v) (*best_branch_base_at(&best_branch_base, (c)) = (v))
+
+int get_branch_base_for_tip(struct repository *r,
+ struct commit *tip,
+ struct commit **bases,
+ size_t bases_nr)
+{
+ int best_index = -1;
+ struct commit *branch_point = NULL;
+ struct prio_queue queue = { compare_commits_by_gen_then_commit_date };
+ int found_missing_gen = 0;
+
+ if (!bases_nr)
+ return -1;
+
+ repo_parse_commit(r, tip);
+ if (commit_graph_generation(tip) == GENERATION_NUMBER_INFINITY)
+ found_missing_gen = 1;
+
+ /* Check for missing generation numbers. */
+ for (size_t i = 0; i < bases_nr; i++) {
+ struct commit *c = bases[i];
+ repo_parse_commit(r, c);
+ if (commit_graph_generation(c) == GENERATION_NUMBER_INFINITY)
+ found_missing_gen = 1;
+ }
+
+ if (found_missing_gen) {
+ struct commit **commits;
+ size_t commits_nr = bases_nr + 1;
+
+ CALLOC_ARRAY(commits, commits_nr);
+ COPY_ARRAY(commits, bases, bases_nr);
+ commits[bases_nr] = tip;
+ ensure_generations_valid(r, commits, commits_nr);
+ free(commits);
+ }
+
+ /* Initialize queue and slab now that generations are guaranteed. */
+ init_best_branch_base(&best_branch_base);
+ set_best(tip, -1);
+ prio_queue_put(&queue, tip);
+
+ for (size_t i = 0; i < bases_nr; i++) {
+ struct commit *c = bases[i];
+ int best = get_best(c);
+
+ /* Has this already been marked as best by another commit? */
+ if (best) {
+ if (best == -1) {
+ /* We agree at this position. Stop now. */
+ best_index = i + 1;
+ goto cleanup;
+ }
+ continue;
+ }
+
+ set_best(c, i + 1);
+ prio_queue_put(&queue, c);
+ }
+
+ while (queue.nr) {
+ struct commit *c = prio_queue_get(&queue);
+ int best_for_c = get_best(c);
+ int best_for_p, positive;
+ struct commit *parent;
+
+ /* Have we reached a known branch point? It's optimal. */
+ if (c == branch_point)
+ break;
+
+ repo_parse_commit(r, c);
+ if (!c->parents)
+ continue;
+
+ parent = c->parents->item;
+ repo_parse_commit(r, parent);
+ best_for_p = get_best(parent);
+
+ if (!best_for_p) {
+ /* 'parent' is new, so pass along best_for_c. */
+ set_best(parent, best_for_c);
+ prio_queue_put(&queue, parent);
+ continue;
+ }
+
+ if (best_for_p > 0 && best_for_c > 0) {
+ /* Collision among bases. Minimize. */
+ if (best_for_c < best_for_p)
+ set_best(parent, best_for_c);
+ continue;
+ }
+
+ /*
+ * At this point, we have reached a commit that is reachable
+ * from the tip, either from 'c' or from an earlier commit to
+ * have 'parent' as its first parent.
+ *
+ * Update 'best_index' to match the minimum of all base indices
+ * to reach 'parent'.
+ */
+
+ /* Exactly one is positive due to initial conditions. */
+ positive = (best_for_c < 0) ? best_for_p : best_for_c;
+
+ if (best_index < 0 || positive < best_index)
+ best_index = positive;
+
+ /* No matter what, track that the parent is reachable from tip. */
+ set_best(parent, -1);
+ branch_point = parent;
+ }
+
+cleanup:
+ clear_best_branch_base(&best_branch_base);
+ clear_prio_queue(&queue);
+ return best_index > 0 ? best_index - 1 : -1;
+}
diff --git a/commit-reach.h b/commit-reach.h
index bf63cc468f..9a745b7e17 100644
--- a/commit-reach.h
+++ b/commit-reach.h
@@ -139,4 +139,21 @@ void tips_reachable_from_bases(struct repository *r,
struct commit **tips, size_t tips_nr,
int mark);
+/*
+ * Given a 'tip' commit and a list potential 'bases', return the index 'i' that
+ * minimizes the number of commits in the first-parent history of 'tip' and not
+ * in the first-parent history of 'bases[i]'.
+ *
+ * Among a list of long-lived branches that are updated only by merges (with the
+ * first parent being the previous position of the branch), this would inform
+ * which branch was used to create the tip reference.
+ *
+ * Returns -1 if no common point is found in first-parent histories, which is
+ * rare, but possible with multiple root commits.
+ */
+int get_branch_base_for_tip(struct repository *r,
+ struct commit *tip,
+ struct commit **bases,
+ size_t bases_nr);
+
#endif
diff --git a/commit.c b/commit.c
index 087cb19f4f..3238772f52 100644
--- a/commit.c
+++ b/commit.c
@@ -85,12 +85,18 @@ struct commit *lookup_commit(struct repository *r, const struct object_id *oid)
struct commit *lookup_commit_reference_by_name(const char *name)
{
+ return lookup_commit_reference_by_name_gently(name, 0);
+}
+
+struct commit *lookup_commit_reference_by_name_gently(const char *name,
+ int quiet)
+{
struct object_id oid;
struct commit *commit;
if (repo_get_oid_committish(the_repository, name, &oid))
return NULL;
- commit = lookup_commit_reference(the_repository, &oid);
+ commit = lookup_commit_reference_gently(the_repository, &oid, quiet);
if (repo_parse_commit(the_repository, commit))
return NULL;
return commit;
@@ -1960,5 +1966,5 @@ int run_commit_hook(int editor_is_used, const char *index_file,
va_end(args);
opt.invoked_hook = invoked_hook;
- return run_hooks_opt(name, &opt);
+ return run_hooks_opt(the_repository, name, &opt);
}
diff --git a/commit.h b/commit.h
index d62b1d93f9..0e5fce543c 100644
--- a/commit.h
+++ b/commit.h
@@ -81,6 +81,8 @@ struct commit *lookup_commit_reference_gently(struct repository *r,
const struct object_id *oid,
int quiet);
struct commit *lookup_commit_reference_by_name(const char *name);
+struct commit *lookup_commit_reference_by_name_gently(const char *name,
+ int quiet);
/*
* Look up object named by "oid", dereference tag as necessary,
diff --git a/compat/fsmonitor/fsm-ipc-darwin.c b/compat/fsmonitor/fsm-ipc-darwin.c
index 52f4f29720..fe149a1b37 100644
--- a/compat/fsmonitor/fsm-ipc-darwin.c
+++ b/compat/fsmonitor/fsm-ipc-darwin.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "config.h"
#include "gettext.h"
diff --git a/compat/precompose_utf8.c b/compat/precompose_utf8.c
index 0bd5c24250..f7cc7b3be5 100644
--- a/compat/precompose_utf8.c
+++ b/compat/precompose_utf8.c
@@ -4,6 +4,7 @@
*/
#define PRECOMPOSE_UNICODE_C
+#define USE_THE_REPOSITORY_VARIABLE
#include "git-compat-util.h"
#include "config.h"
diff --git a/config.c b/config.c
index 05f369ec0d..56b5862e59 100644
--- a/config.c
+++ b/config.c
@@ -6,8 +6,6 @@
*
*/
-#define USE_THE_REPOSITORY_VARIABLE
-
#include "git-compat-util.h"
#include "abspath.h"
#include "advice.h"
@@ -300,13 +298,14 @@ done:
return ret;
}
-static int include_by_branch(const char *cond, size_t cond_len)
+static int include_by_branch(struct config_include_data *data,
+ const char *cond, size_t cond_len)
{
int flags;
int ret;
struct strbuf pattern = STRBUF_INIT;
- const char *refname = !the_repository->gitdir ?
- NULL : refs_resolve_ref_unsafe(get_main_ref_store(the_repository),
+ const char *refname = (!data->repo || !data->repo->gitdir) ?
+ NULL : refs_resolve_ref_unsafe(get_main_ref_store(data->repo),
"HEAD", 0, NULL, &flags);
const char *shortname;
@@ -406,7 +405,7 @@ static int include_condition_is_true(const struct key_value_info *kvi,
else if (skip_prefix_mem(cond, cond_len, "gitdir/i:", &cond, &cond_len))
return include_by_gitdir(kvi, opts, cond, cond_len, 1);
else if (skip_prefix_mem(cond, cond_len, "onbranch:", &cond, &cond_len))
- return include_by_branch(cond, cond_len);
+ return include_by_branch(inc, cond, cond_len);
else if (skip_prefix_mem(cond, cond_len, "hasconfig:remote.*.url:", &cond,
&cond_len))
return include_by_remote_url(inc, cond, cond_len);
@@ -1596,7 +1595,8 @@ static int git_default_core_config(const char *var, const char *value,
else if (value[0]) {
if (strchr(value, '\n'))
return error(_("%s cannot contain newline"), var);
- comment_line_str = xstrdup(value);
+ comment_line_str = value;
+ FREE_AND_NULL(comment_line_str_to_free);
auto_comment_line_char = 0;
} else
return error(_("%s must have at least one character"), var);
@@ -2564,7 +2564,7 @@ static void git_config_check_init(struct repository *repo)
repo_read_config(repo);
}
-static void repo_config_clear(struct repository *repo)
+void repo_config_clear(struct repository *repo)
{
if (!repo->config || !repo->config->hash_initialized)
return;
@@ -2611,7 +2611,7 @@ int repo_config_get_string(struct repository *repo,
git_config_check_init(repo);
ret = git_configset_get_string(repo->config, key, dest);
if (ret < 0)
- git_die_config(key, NULL);
+ git_die_config(repo, key, NULL);
return ret;
}
@@ -2622,7 +2622,7 @@ int repo_config_get_string_tmp(struct repository *repo,
git_config_check_init(repo);
ret = git_configset_get_string_tmp(repo->config, key, dest);
if (ret < 0)
- git_die_config(key, NULL);
+ git_die_config(repo, key, NULL);
return ret;
}
@@ -2668,7 +2668,7 @@ int repo_config_get_pathname(struct repository *repo,
git_config_check_init(repo);
ret = git_configset_get_pathname(repo->config, key, dest);
if (ret < 0)
- git_die_config(key, NULL);
+ git_die_config(repo, key, NULL);
return ret;
}
@@ -2694,98 +2694,28 @@ void git_protected_config(config_fn_t fn, void *data)
configset_iter(&protected_config, fn, data);
}
-/* Functions used historically to read configuration from 'the_repository' */
-void git_config(config_fn_t fn, void *data)
+int repo_config_get_expiry(struct repository *r, const char *key, char **output)
{
- repo_config(the_repository, fn, data);
-}
+ int ret = repo_config_get_string(r, key, output);
-void git_config_clear(void)
-{
- repo_config_clear(the_repository);
-}
-
-int git_config_get(const char *key)
-{
- return repo_config_get(the_repository, key);
-}
-
-int git_config_get_value(const char *key, const char **value)
-{
- return repo_config_get_value(the_repository, key, value);
-}
-
-int git_config_get_value_multi(const char *key, const struct string_list **dest)
-{
- return repo_config_get_value_multi(the_repository, key, dest);
-}
-
-int git_config_get_string_multi(const char *key,
- const struct string_list **dest)
-{
- return repo_config_get_string_multi(the_repository, key, dest);
-}
-
-int git_config_get_string(const char *key, char **dest)
-{
- return repo_config_get_string(the_repository, key, dest);
-}
-
-int git_config_get_string_tmp(const char *key, const char **dest)
-{
- return repo_config_get_string_tmp(the_repository, key, dest);
-}
-
-int git_config_get_int(const char *key, int *dest)
-{
- return repo_config_get_int(the_repository, key, dest);
-}
-
-int git_config_get_ulong(const char *key, unsigned long *dest)
-{
- return repo_config_get_ulong(the_repository, key, dest);
-}
-
-int git_config_get_bool(const char *key, int *dest)
-{
- return repo_config_get_bool(the_repository, key, dest);
-}
-
-int git_config_get_bool_or_int(const char *key, int *is_bool, int *dest)
-{
- return repo_config_get_bool_or_int(the_repository, key, is_bool, dest);
-}
-
-int git_config_get_maybe_bool(const char *key, int *dest)
-{
- return repo_config_get_maybe_bool(the_repository, key, dest);
-}
-
-int git_config_get_pathname(const char *key, char **dest)
-{
- return repo_config_get_pathname(the_repository, key, dest);
-}
-
-int git_config_get_expiry(const char *key, const char **output)
-{
- int ret = git_config_get_string(key, (char **)output);
if (ret)
return ret;
if (strcmp(*output, "now")) {
timestamp_t now = approxidate("now");
if (approxidate(*output) >= now)
- git_die_config(key, _("Invalid %s: '%s'"), key, *output);
+ git_die_config(r, key, _("Invalid %s: '%s'"), key, *output);
}
return ret;
}
-int git_config_get_expiry_in_days(const char *key, timestamp_t *expiry, timestamp_t now)
+int repo_config_get_expiry_in_days(struct repository *r, const char *key,
+ timestamp_t *expiry, timestamp_t now)
{
const char *expiry_string;
intmax_t days;
timestamp_t when;
- if (git_config_get_string_tmp(key, &expiry_string))
+ if (repo_config_get_string_tmp(r, key, &expiry_string))
return 1; /* no such thing */
if (git_parse_signed(expiry_string, &days, maximum_signed_value_of_type(int))) {
@@ -2801,21 +2731,21 @@ int git_config_get_expiry_in_days(const char *key, timestamp_t *expiry, timestam
return -1; /* thing exists but cannot be parsed */
}
-int git_config_get_split_index(void)
+int repo_config_get_split_index(struct repository *r)
{
int val;
- if (!git_config_get_maybe_bool("core.splitindex", &val))
+ if (!repo_config_get_maybe_bool(r, "core.splitindex", &val))
return val;
return -1; /* default value */
}
-int git_config_get_max_percent_split_change(void)
+int repo_config_get_max_percent_split_change(struct repository *r)
{
int val = -1;
- if (!git_config_get_int("splitindex.maxpercentchange", &val)) {
+ if (!repo_config_get_int(r, "splitindex.maxpercentchange", &val)) {
if (0 <= val && val <= 100)
return val;
@@ -2826,7 +2756,7 @@ int git_config_get_max_percent_split_change(void)
return -1; /* default value */
}
-int git_config_get_index_threads(int *dest)
+int repo_config_get_index_threads(struct repository *r, int *dest)
{
int is_bool, val;
@@ -2836,7 +2766,7 @@ int git_config_get_index_threads(int *dest)
return 0;
}
- if (!git_config_get_bool_or_int("index.threads", &is_bool, &val)) {
+ if (!repo_config_get_bool_or_int(r, "index.threads", &is_bool, &val)) {
if (is_bool)
*dest = val ? 0 : 1;
else
@@ -2857,7 +2787,7 @@ void git_die_config_linenr(const char *key, const char *filename, int linenr)
key, filename, linenr);
}
-void git_die_config(const char *key, const char *err, ...)
+void git_die_config(struct repository *r, const char *key, const char *err, ...)
{
const struct string_list *values;
struct key_value_info *kv_info;
@@ -2869,7 +2799,7 @@ void git_die_config(const char *key, const char *err, ...)
error_fn(err, params);
va_end(params);
}
- if (git_config_get_value_multi(key, &values))
+ if (repo_config_get_value_multi(r, key, &values))
BUG("for key '%s' we must have a value to report on", key);
kv_info = values->items[values->nr - 1].util;
git_die_config_linenr(key, kv_info->filename, kv_info->linenr);
@@ -3178,21 +3108,21 @@ static void maybe_remove_section(struct config_store_data *store,
*end_offset = store->parsed[store->parsed_nr - 1].end;
}
-int git_config_set_in_file_gently(const char *config_filename,
- const char *key, const char *comment, const char *value)
+int repo_config_set_in_file_gently(struct repository *r, const char *config_filename,
+ const char *key, const char *comment, const char *value)
{
- return git_config_set_multivar_in_file_gently(config_filename, key, value, NULL, comment, 0);
+ return repo_config_set_multivar_in_file_gently(r, config_filename, key, value, NULL, comment, 0);
}
-void git_config_set_in_file(const char *config_filename,
- const char *key, const char *value)
+void repo_config_set_in_file(struct repository *r, const char *config_filename,
+ const char *key, const char *value)
{
- git_config_set_multivar_in_file(config_filename, key, value, NULL, 0);
+ repo_config_set_multivar_in_file(r, config_filename, key, value, NULL, 0);
}
-int git_config_set_gently(const char *key, const char *value)
+int repo_config_set_gently(struct repository *r, const char *key, const char *value)
{
- return git_config_set_multivar_gently(key, value, NULL, 0);
+ return repo_config_set_multivar_gently(r, key, value, NULL, 0);
}
int repo_config_set_worktree_gently(struct repository *r,
@@ -3201,17 +3131,17 @@ int repo_config_set_worktree_gently(struct repository *r,
/* Only use worktree-specific config if it is already enabled. */
if (r->repository_format_worktree_config) {
char *file = repo_git_path(r, "config.worktree");
- int ret = git_config_set_multivar_in_file_gently(
- file, key, value, NULL, NULL, 0);
+ int ret = repo_config_set_multivar_in_file_gently(
+ r, file, key, value, NULL, NULL, 0);
free(file);
return ret;
}
return repo_config_set_multivar_gently(r, key, value, NULL, 0);
}
-void git_config_set(const char *key, const char *value)
+void repo_config_set(struct repository *r, const char *key, const char *value)
{
- git_config_set_multivar(key, value, NULL, 0);
+ repo_config_set_multivar(r, key, value, NULL, 0);
trace2_cmd_set_config(key, value);
}
@@ -3293,11 +3223,12 @@ static void validate_comment_string(const char *comment)
* - the config file is removed and the lock file rename()d to it.
*
*/
-int git_config_set_multivar_in_file_gently(const char *config_filename,
- const char *key, const char *value,
- const char *value_pattern,
- const char *comment,
- unsigned flags)
+int repo_config_set_multivar_in_file_gently(struct repository *r,
+ const char *config_filename,
+ const char *key, const char *value,
+ const char *value_pattern,
+ const char *comment,
+ unsigned flags)
{
int fd = -1, in_fd = -1;
int ret;
@@ -3317,7 +3248,7 @@ int git_config_set_multivar_in_file_gently(const char *config_filename,
store.multi_replace = (flags & CONFIG_FLAGS_MULTI_REPLACE) != 0;
if (!config_filename)
- config_filename = filename_buf = git_pathdup("config");
+ config_filename = filename_buf = repo_git_path(r, "config");
/*
* The lock serves a purpose in addition to locking: the new
@@ -3526,7 +3457,7 @@ int git_config_set_multivar_in_file_gently(const char *config_filename,
ret = 0;
/* Invalidate the config cache */
- git_config_clear();
+ repo_config_clear(r);
out_free:
rollback_lock_file(&lock);
@@ -3543,12 +3474,13 @@ write_err_out:
goto out_free;
}
-void git_config_set_multivar_in_file(const char *config_filename,
- const char *key, const char *value,
- const char *value_pattern, unsigned flags)
+void repo_config_set_multivar_in_file(struct repository *r,
+ const char *config_filename,
+ const char *key, const char *value,
+ const char *value_pattern, unsigned flags)
{
- if (!git_config_set_multivar_in_file_gently(config_filename, key, value,
- value_pattern, NULL, flags))
+ if (!repo_config_set_multivar_in_file_gently(r, config_filename, key, value,
+ value_pattern, NULL, flags))
return;
if (value)
die(_("could not set '%s' to '%s'"), key, value);
@@ -3556,32 +3488,27 @@ void git_config_set_multivar_in_file(const char *config_filename,
die(_("could not unset '%s'"), key);
}
-int git_config_set_multivar_gently(const char *key, const char *value,
- const char *value_pattern, unsigned flags)
-{
- return repo_config_set_multivar_gently(the_repository, key, value,
- value_pattern, flags);
-}
-
int repo_config_set_multivar_gently(struct repository *r, const char *key,
const char *value,
const char *value_pattern, unsigned flags)
{
char *file = repo_git_path(r, "config");
- int res = git_config_set_multivar_in_file_gently(file,
- key, value,
- value_pattern,
- NULL, flags);
+ int res = repo_config_set_multivar_in_file_gently(r, file,
+ key, value,
+ value_pattern,
+ NULL, flags);
free(file);
return res;
}
-void git_config_set_multivar(const char *key, const char *value,
- const char *value_pattern, unsigned flags)
+void repo_config_set_multivar(struct repository *r,
+ const char *key, const char *value,
+ const char *value_pattern, unsigned flags)
{
- git_config_set_multivar_in_file(git_path("config"),
- key, value, value_pattern,
- flags);
+ char *file = repo_git_path(r, "config");
+ repo_config_set_multivar_in_file(r, file, key, value,
+ value_pattern, flags);
+ free(file);
}
static size_t section_name_match (const char *buf, const char *name)
@@ -3643,9 +3570,11 @@ static int section_name_is_ok(const char *name)
#define GIT_CONFIG_MAX_LINE_LEN (512 * 1024)
/* if new_name == NULL, the section is removed instead */
-static int git_config_copy_or_rename_section_in_file(const char *config_filename,
- const char *old_name,
- const char *new_name, int copy)
+static int repo_config_copy_or_rename_section_in_file(
+ struct repository *r,
+ const char *config_filename,
+ const char *old_name,
+ const char *new_name, int copy)
{
int ret = 0, remove = 0;
char *filename_buf = NULL;
@@ -3666,7 +3595,7 @@ static int git_config_copy_or_rename_section_in_file(const char *config_filename
}
if (!config_filename)
- config_filename = filename_buf = git_pathdup("config");
+ config_filename = filename_buf = repo_git_path(r, "config");
out_fd = hold_lock_file_for_update(&lock, config_filename, 0);
if (out_fd < 0) {
@@ -3809,28 +3738,28 @@ out_no_rollback:
return ret;
}
-int git_config_rename_section_in_file(const char *config_filename,
- const char *old_name, const char *new_name)
+int repo_config_rename_section_in_file(struct repository *r, const char *config_filename,
+ const char *old_name, const char *new_name)
{
- return git_config_copy_or_rename_section_in_file(config_filename,
+ return repo_config_copy_or_rename_section_in_file(r, config_filename,
old_name, new_name, 0);
}
-int git_config_rename_section(const char *old_name, const char *new_name)
+int repo_config_rename_section(struct repository *r, const char *old_name, const char *new_name)
{
- return git_config_rename_section_in_file(NULL, old_name, new_name);
+ return repo_config_rename_section_in_file(r, NULL, old_name, new_name);
}
-int git_config_copy_section_in_file(const char *config_filename,
- const char *old_name, const char *new_name)
+int repo_config_copy_section_in_file(struct repository *r, const char *config_filename,
+ const char *old_name, const char *new_name)
{
- return git_config_copy_or_rename_section_in_file(config_filename,
+ return repo_config_copy_or_rename_section_in_file(r, config_filename,
old_name, new_name, 1);
}
-int git_config_copy_section(const char *old_name, const char *new_name)
+int repo_config_copy_section(struct repository *r, const char *old_name, const char *new_name)
{
- return git_config_copy_section_in_file(NULL, old_name, new_name);
+ return repo_config_copy_section_in_file(r, NULL, old_name, new_name);
}
/*
diff --git a/config.h b/config.h
index 54b47dec9e..d0497157c5 100644
--- a/config.h
+++ b/config.h
@@ -26,7 +26,7 @@ struct object_id;
/* git_config_parse_key() returns these negated: */
#define CONFIG_INVALID_KEY 1
#define CONFIG_NO_SECTION_OR_NAME 2
-/* git_config_set_gently(), git_config_set_multivar_gently() return the above or these: */
+/* repo_config_set_gently(), repo_config_set_multivar_gently() return the above or these: */
#define CONFIG_NO_LOCK -1
#define CONFIG_INVALID_FILE 3
#define CONFIG_NO_WRITE 4
@@ -170,9 +170,9 @@ int git_default_config(const char *, const char *,
/**
* Read a specific file in git-config format.
- * This function takes the same callback and data parameters as `git_config`.
+ * This function takes the same callback and data parameters as `repo_config`.
*
- * Unlike git_config(), this function does not respect includes.
+ * Unlike repo_config(), this function does not respect includes.
*/
int git_config_from_file(config_fn_t fn, const char *, void *);
@@ -198,9 +198,9 @@ void read_very_early_config(config_fn_t cb, void *data);
/**
* Most programs will simply want to look up variables in all config files
* that Git knows about, using the normal precedence rules. To do this,
- * call `git_config` with a callback function and void data pointer.
+ * call `repo_config` with a callback function and void data pointer.
*
- * `git_config` will read all config sources in order of increasing
+ * `repo_config` will read all config sources in order of increasing
* priority. Thus a callback should typically overwrite previously-seen
* entries with new ones (e.g., if both the user-wide `~/.gitconfig` and
* repo-specific `.git/config` contain `color.ui`, the config machinery
@@ -210,11 +210,11 @@ void read_very_early_config(config_fn_t cb, void *data);
*
* Unlike git_config_from_file(), this function respects includes.
*/
-void git_config(config_fn_t fn, void *);
+void repo_config(struct repository *r, config_fn_t fn, void *);
/**
* Lets the caller examine config while adjusting some of the default
- * behavior of `git_config`. It should almost never be used by "regular"
+ * behavior of `repo_config`. It should almost never be used by "regular"
* Git code that is looking up configuration variables.
* It is intended for advanced callers like `git-config`, which are
* intentionally tweaking the normal config-lookup process.
@@ -223,12 +223,12 @@ void git_config(config_fn_t fn, void *);
* - `config_source`
* If this parameter is non-NULL, it specifies the source to parse for
* configuration, rather than looking in the usual files. See `struct
- * git_config_source` in `config.h` for details. Regular `git_config` defaults
+ * git_config_source` in `config.h` for details. Regular `repo_config` defaults
* to `NULL`.
*
* - `opts`
* Specify options to adjust the behavior of parsing config files. See `struct
- * config_options` in `config.h` for details. As an example: regular `git_config`
+ * config_options` in `config.h` for details. As an example: regular `repo_config`
* sets `opts.respect_includes` to `1` by default.
*/
int config_with_options(config_fn_t fn, void *,
@@ -297,15 +297,16 @@ int git_config_pathname(char **, const char *, const char *);
int git_config_expiry_date(timestamp_t *, const char *, const char *);
int git_config_color(char *, const char *, const char *);
-int git_config_set_in_file_gently(const char *, const char *, const char *, const char *);
+int repo_config_set_in_file_gently(struct repository *r, const char *config_filename,
+ const char *key, const char *comment, const char *value);
/**
* write config values to a specific config file, takes a key/value pair as
* parameter.
*/
-void git_config_set_in_file(const char *, const char *, const char *);
+void repo_config_set_in_file(struct repository *, const char *, const char *, const char *);
-int git_config_set_gently(const char *, const char *);
+int repo_config_set_gently(struct repository *r, const char *, const char *);
/**
* Write a config value that should apply to the current worktree. If
@@ -317,13 +318,13 @@ int repo_config_set_worktree_gently(struct repository *, const char *, const cha
/**
* write config values to `.git/config`, takes a key/value pair as parameter.
*/
-void git_config_set(const char *, const char *);
+void repo_config_set(struct repository *, const char *, const char *);
int git_config_parse_key(const char *, char **, size_t *);
/*
* The following macros specify flag bits that alter the behavior
- * of the git_config_set_multivar*() methods.
+ * of the repo_config_set_multivar*() methods.
*/
/*
@@ -340,10 +341,9 @@ int git_config_parse_key(const char *, char **, size_t *);
*/
#define CONFIG_FLAGS_FIXED_VALUE (1 << 1)
-int git_config_set_multivar_gently(const char *, const char *, const char *, unsigned);
-void git_config_set_multivar(const char *, const char *, const char *, unsigned);
int repo_config_set_multivar_gently(struct repository *, const char *, const char *, const char *, unsigned);
-int git_config_set_multivar_in_file_gently(const char *, const char *, const char *, const char *, const char *, unsigned);
+void repo_config_set_multivar(struct repository *r, const char *, const char *, const char *, unsigned);
+int repo_config_set_multivar_in_file_gently(struct repository *, const char *, const char *, const char *, const char *, const char *, unsigned);
char *git_config_prepare_comment_string(const char *);
@@ -367,11 +367,12 @@ char *git_config_prepare_comment_string(const char *);
*
* It returns 0 on success.
*/
-void git_config_set_multivar_in_file(const char *config_filename,
- const char *key,
- const char *value,
- const char *value_pattern,
- unsigned flags);
+void repo_config_set_multivar_in_file(struct repository *r,
+ const char *config_filename,
+ const char *key,
+ const char *value,
+ const char *value_pattern,
+ unsigned flags);
/**
* rename or remove sections in the config file
@@ -379,11 +380,11 @@ void git_config_set_multivar_in_file(const char *config_filename,
* If NULL is passed through `new_name` parameter,
* the section will be removed from the config file.
*/
-int git_config_rename_section(const char *, const char *);
+int repo_config_rename_section(struct repository *, const char *, const char *);
-int git_config_rename_section_in_file(const char *, const char *, const char *);
-int git_config_copy_section(const char *, const char *);
-int git_config_copy_section_in_file(const char *, const char *, const char *);
+int repo_config_rename_section_in_file(struct repository *, const char *, const char *, const char *);
+int repo_config_copy_section(struct repository *, const char *, const char *);
+int repo_config_copy_section_in_file(struct repository *, const char *, const char *, const char *);
int git_config_system(void);
int config_error_nonbool(const char *);
#if defined(__GNUC__)
@@ -550,39 +551,11 @@ int git_configset_get_bool_or_int(struct config_set *cs, const char *key, int *i
int git_configset_get_maybe_bool(struct config_set *cs, const char *key, int *dest);
int git_configset_get_pathname(struct config_set *cs, const char *key, char **dest);
-/* Functions for reading a repository's config */
-struct repository;
-void repo_config(struct repository *repo, config_fn_t fn, void *data);
-
/**
* Run only the discover part of the repo_config_get_*() functions
* below, in addition to 1 if not found, returns negative values on
* error (e.g. if the key itself is invalid).
*/
-RESULT_MUST_BE_USED
-int repo_config_get(struct repository *repo, const char *key);
-int repo_config_get_value(struct repository *repo,
- const char *key, const char **value);
-RESULT_MUST_BE_USED
-int repo_config_get_value_multi(struct repository *repo, const char *key,
- const struct string_list **dest);
-RESULT_MUST_BE_USED
-int repo_config_get_string_multi(struct repository *repo, const char *key,
- const struct string_list **dest);
-int repo_config_get_string(struct repository *repo,
- const char *key, char **dest);
-int repo_config_get_string_tmp(struct repository *repo,
- const char *key, const char **dest);
-int repo_config_get_int(struct repository *repo,
- const char *key, int *dest);
-int repo_config_get_ulong(struct repository *repo,
- const char *key, unsigned long *dest);
-int repo_config_get_bool(struct repository *repo,
- const char *key, int *dest);
-int repo_config_get_bool_or_int(struct repository *repo,
- const char *key, int *is_bool, int *dest);
-int repo_config_get_maybe_bool(struct repository *repo,
- const char *key, int *dest);
int repo_config_get_pathname(struct repository *repo,
const char *key, char **dest);
@@ -598,17 +571,17 @@ void git_protected_config(config_fn_t fn, void *data);
* -------------------------------
*
* For programs wanting to query for specific variables in a non-callback
- * manner, the config API provides two functions `git_config_get_value`
- * and `git_config_get_value_multi`. They both read values from an internal
+ * manner, the config API provides two functions `repo_config_get_value`
+ * and `repo_config_get_value_multi`. They both read values from an internal
* cache generated previously from reading the config files.
*
- * For those git_config_get*() functions that aren't documented,
+ * For those repo_config_get*() functions that aren't documented,
* consult the corresponding repo_config_get*() function's
* documentation.
*/
RESULT_MUST_BE_USED
-int git_config_get(const char *key);
+int repo_config_get(struct repository *r, const char *key);
/**
* Finds the highest-priority value for the configuration variable `key`,
@@ -617,7 +590,7 @@ int git_config_get(const char *key);
* `value`. The caller should not free or modify `value`, as it is owned
* by the cache.
*/
-int git_config_get_value(const char *key, const char **value);
+int repo_config_get_value(struct repository *r, const char *key, const char **value);
/**
* Finds and returns the value list, sorted in order of increasing priority
@@ -628,16 +601,16 @@ int git_config_get_value(const char *key, const char **value);
* owned by the cache.
*/
RESULT_MUST_BE_USED
-int git_config_get_value_multi(const char *key,
- const struct string_list **dest);
-RESULT_MUST_BE_USED
-int git_config_get_string_multi(const char *key,
+int repo_config_get_value_multi(struct repository *r, const char *key,
const struct string_list **dest);
+RESULT_MUST_BE_USED
+int repo_config_get_string_multi(struct repository *r, const char *key,
+ const struct string_list **dest);
/**
* Resets and invalidates the config cache.
*/
-void git_config_clear(void);
+void repo_config_clear(struct repository *repo);
/**
* Allocates and copies the retrieved string into the `dest` parameter for
@@ -645,14 +618,15 @@ void git_config_clear(void);
* error message and returns -1. When the configuration variable `key` is
* not found, returns 1 without touching `dest`.
*/
-int git_config_get_string(const char *key, char **dest);
+int repo_config_get_string(struct repository *r, const char *key, char **dest);
/**
- * Similar to `git_config_get_string`, but does not allocate any new
+ * Similar to `repo_config_get_string`, but does not allocate any new
* memory; on success `dest` will point to memory owned by the config
* machinery, which could be invalidated if it is discarded and reloaded.
*/
-int git_config_get_string_tmp(const char *key, const char **dest);
+int repo_config_get_string_tmp(struct repository *r,
+ const char *key, const char **dest);
/**
* Finds and parses the value to an integer for the configuration variable
@@ -660,12 +634,13 @@ int git_config_get_string_tmp(const char *key, const char **dest);
* `dest` and returns 0. When the configuration variable `key` is not found,
* returns 1 without touching `dest`.
*/
-int git_config_get_int(const char *key, int *dest);
+int repo_config_get_int(struct repository *r, const char *key, int *dest);
/**
- * Similar to `git_config_get_int` but for unsigned longs.
+ * Similar to `repo_config_get_int` but for unsigned longs.
*/
-int git_config_get_ulong(const char *key, unsigned long *dest);
+int repo_config_get_ulong(struct repository *r,
+ const char *key, unsigned long *dest);
/**
* Finds and parses the value into a boolean value, for the configuration
@@ -676,47 +651,45 @@ int git_config_get_ulong(const char *key, unsigned long *dest);
* configuration variable `key` is not found, returns 1 without touching
* `dest`.
*/
-int git_config_get_bool(const char *key, int *dest);
+int repo_config_get_bool(struct repository *r, const char *key, int *dest);
/**
- * Similar to `git_config_get_bool`, except that integers are copied as-is,
+ * Similar to `repo_config_get_bool`, except that integers are copied as-is,
* and `is_bool` flag is unset.
*/
-int git_config_get_bool_or_int(const char *key, int *is_bool, int *dest);
+int repo_config_get_bool_or_int(struct repository *r, const char *key,
+ int *is_bool, int *dest);
/**
- * Similar to `git_config_get_bool`, except that it returns -1 on error
+ * Similar to `repo_config_get_bool`, except that it returns -1 on error
* rather than dying.
*/
-int git_config_get_maybe_bool(const char *key, int *dest);
-
-/**
- * Similar to `git_config_get_string`, but expands `~` or `~user` into
- * the user's home directory when found at the beginning of the path.
- */
-int git_config_get_pathname(const char *key, char **dest);
+int repo_config_get_maybe_bool(struct repository *r,
+ const char *key, int *dest);
-int git_config_get_index_threads(int *dest);
-int git_config_get_split_index(void);
-int git_config_get_max_percent_split_change(void);
+int repo_config_get_index_threads(struct repository *r, int *dest);
+int repo_config_get_split_index(struct repository *r);
+int repo_config_get_max_percent_split_change(struct repository *r);
/* This dies if the configured or default date is in the future */
-int git_config_get_expiry(const char *key, const char **output);
+int repo_config_get_expiry(struct repository *r, const char *key, char **output);
/* parse either "this many days" integer, or "5.days.ago" approxidate */
-int git_config_get_expiry_in_days(const char *key, timestamp_t *, timestamp_t now);
+int repo_config_get_expiry_in_days(struct repository *r, const char *key,
+ timestamp_t *, timestamp_t now);
/**
* First prints the error message specified by the caller in `err` and then
* dies printing the line number and the file name of the highest priority
* value for the configuration variable `key`.
*/
-NORETURN void git_die_config(const char *key, const char *err, ...) __attribute__((format(printf, 2, 3)));
+NORETURN void git_die_config(struct repository *r, const char *key, const char *err, ...)
+ __attribute__((format(printf, 3, 4)));
/**
* Helper function which formats the die error message according to the
* parameters entered. Used by `git_die_config()`. It can be used by callers
- * handling `git_config_get_value_multi()` to print the correct error message
+ * handling `repo_config_get_value_multi()` to print the correct error message
* for the desired value.
*/
NORETURN void git_die_config_linenr(const char *key, const char *filename, int linenr);
@@ -725,4 +698,140 @@ NORETURN void git_die_config_linenr(const char *key, const char *filename, int l
lookup_config(mapping, ARRAY_SIZE(mapping), var)
int lookup_config(const char **mapping, int nr_mapping, const char *var);
+# ifdef USE_THE_REPOSITORY_VARIABLE
+static inline void git_config(config_fn_t fn, void *data)
+{
+ repo_config(the_repository, fn, data);
+}
+
+static inline void git_config_clear(void)
+{
+ repo_config_clear(the_repository);
+}
+
+static inline int git_config_get(const char *key)
+{
+ return repo_config_get(the_repository, key);
+}
+
+static inline int git_config_get_value(const char *key, const char **value)
+{
+ return repo_config_get_value(the_repository, key, value);
+}
+
+static inline int git_config_get_value_multi(const char *key, const struct string_list **dest)
+{
+ return repo_config_get_value_multi(the_repository, key, dest);
+}
+
+static inline int git_config_get_string_multi(const char *key,
+ const struct string_list **dest)
+{
+ return repo_config_get_string_multi(the_repository, key, dest);
+}
+
+static inline int git_config_get_string(const char *key, char **dest)
+{
+ return repo_config_get_string(the_repository, key, dest);
+}
+
+static inline int git_config_get_string_tmp(const char *key, const char **dest)
+{
+ return repo_config_get_string_tmp(the_repository, key, dest);
+}
+
+static inline int git_config_get_int(const char *key, int *dest)
+{
+ return repo_config_get_int(the_repository, key, dest);
+}
+
+static inline int git_config_get_ulong(const char *key, unsigned long *dest)
+{
+ return repo_config_get_ulong(the_repository, key, dest);
+}
+
+static inline int git_config_get_bool(const char *key, int *dest)
+{
+ return repo_config_get_bool(the_repository, key, dest);
+}
+
+static inline int git_config_get_bool_or_int(const char *key, int *is_bool, int *dest)
+{
+ return repo_config_get_bool_or_int(the_repository, key, is_bool, dest);
+}
+
+static inline int git_config_get_maybe_bool(const char *key, int *dest)
+{
+ return repo_config_get_maybe_bool(the_repository, key, dest);
+}
+
+static inline int git_config_get_pathname(const char *key, char **dest)
+{
+ return repo_config_get_pathname(the_repository, key, dest);
+}
+
+static inline void git_config_set_in_file(const char *config_filename,
+ const char *key, const char *value)
+{
+ repo_config_set_in_file(the_repository, config_filename, key, value);
+}
+
+static inline int git_config_set_gently(const char *key, const char *value)
+{
+ return repo_config_set_gently(the_repository, key, value);
+}
+
+static inline void git_config_set(const char *key, const char *value)
+{
+ repo_config_set(the_repository, key, value);
+}
+
+static inline int git_config_set_in_file_gently(
+ const char *config_filename,
+ const char *key,
+ const char *comment,
+ const char *value)
+{
+ return repo_config_set_in_file_gently(the_repository, config_filename,
+ key, comment, value);
+}
+
+static inline int git_config_set_multivar_in_file_gently(
+ const char *config_filename,
+ const char *key, const char *value,
+ const char *value_pattern,
+ const char *comment,
+ unsigned flags)
+{
+ return repo_config_set_multivar_in_file_gently(the_repository, config_filename,
+ key, value, value_pattern,
+ comment, flags);
+}
+
+static inline void git_config_set_multivar_in_file(
+ const char *config_filename,
+ const char *key,
+ const char *value,
+ const char *value_pattern,
+ unsigned flags)
+{
+ repo_config_set_multivar_in_file(the_repository, config_filename,
+ key, value, value_pattern, flags);
+}
+
+static inline int git_config_set_multivar_gently(const char *key, const char *value,
+ const char *value_pattern, unsigned flags)
+{
+ return repo_config_set_multivar_gently(the_repository, key, value,
+ value_pattern, flags);
+}
+
+static inline void git_config_set_multivar(const char *key, const char *value,
+ const char *value_pattern, unsigned flags)
+{
+ repo_config_set_multivar(the_repository, key, value,
+ value_pattern, flags);
+}
+# endif /* USE_THE_REPOSITORY_VARIABLE */
+
#endif /* CONFIG_H */
diff --git a/connect.c b/connect.c
index cf84e631e9..6829ab3974 100644
--- a/connect.c
+++ b/connect.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "config.h"
#include "environment.h"
diff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh
index 5330e769a7..6186c474ba 100644
--- a/contrib/completion/git-prompt.sh
+++ b/contrib/completion/git-prompt.sh
@@ -8,8 +8,8 @@
# To enable:
#
# 1) Copy this file to somewhere (e.g. ~/.git-prompt.sh).
-# 2) Add the following line to your .bashrc/.zshrc:
-# source ~/.git-prompt.sh
+# 2) Add the following line to your .bashrc/.zshrc/.profile:
+# . ~/.git-prompt.sh # dot path/to/this-file
# 3a) Change your PS1 to call __git_ps1 as
# command-substitution:
# Bash: PS1='[\u@\h \W$(__git_ps1 " (%s)")]\$ '
@@ -30,6 +30,8 @@
# Optionally, you can supply a third argument with a printf
# format string to finetune the output of the branch status
#
+# See notes below about compatibility with other shells.
+#
# The repository status will be displayed only if you are currently in a
# git repository. The %s token is the placeholder for the shown status.
#
@@ -106,38 +108,78 @@
# directory is set up to be ignored by git, then set
# GIT_PS1_HIDE_IF_PWD_IGNORED to a nonempty value. Override this on the
# repository level by setting bash.hideIfPwdIgnored to "false".
+#
+# Compatibility with other shells (beyond bash/zsh):
+#
+# We require posix-ish shell plus "local" support, which is most
+# shells (even pdksh), but excluding ksh93 (because no "local").
+#
+# Prompt integration might differ between shells, but the gist is
+# to load it once on shell init with '. path/to/git-prompt.sh',
+# set GIT_PS1* vars once as needed, and either place $(__git_ps1..)
+# inside PS1 once (0/1 args), or, before each prompt is displayed,
+# call __git_ps1 (2/3 args) which sets PS1 with the status embedded.
+#
+# Many shells support the 1st method of command substitution,
+# though some might need to first enable cmd substitution in PS1.
+#
+# When using colors, each escape sequence is wrapped between byte
+# values 1 and 2 (control chars SOH, STX, respectively), which are
+# invisible at the output, but for bash/readline they mark 0-width
+# strings (SGR color sequences) when calculating the on-screen
+# prompt width, to maintain correct input editing at the prompt.
+#
+# To replace or disable the 0-width markers, set GIT_PS1_COLOR_PRE
+# and GIT_PS1_COLOR_POST to other markers, or empty (nul) to not
+# use markers. For instance, some shells support '\[' and '\]' as
+# start/end markers in PS1 - when invoking __git_ps1 with 3/4 args,
+# but it may or may not work in command substitution mode. YMMV.
+#
+# If the shell doesn't support 0-width markers and editing behaves
+# incorrectly when using colors in __git_ps1, then, other than
+# disabling color, it might be solved using multi-line prompt,
+# where the git status is not at the last line, e.g.:
+# PS1='\n\w \u@\h$(__git_ps1 " (%s)")\n\$ '
# check whether printf supports -v
__git_printf_supports_v=
printf -v __git_printf_supports_v -- '%s' yes >/dev/null 2>&1
+# like __git_SOH=$'\001' etc but works also in shells without $'...'
+eval "$(printf '
+ __git_SOH="\001" __git_STX="\002" __git_ESC="\033"
+ __git_LF="\n" __git_CRLF="\r\n"
+')"
+
# stores the divergence from upstream in $p
# used by GIT_PS1_SHOWUPSTREAM
__git_ps1_show_upstream ()
{
local key value
- local svn_remote svn_url_pattern count n
+ local svn_remotes="" svn_url_pattern="" count n
local upstream_type=git legacy="" verbose="" name=""
+ local LF="$__git_LF"
- svn_remote=()
# get some config options from git-config
local output="$(git config -z --get-regexp '^(svn-remote\..*\.url|bash\.showupstream)$' 2>/dev/null | tr '\0\n' '\n ')"
while read -r key value; do
case "$key" in
bash.showupstream)
GIT_PS1_SHOWUPSTREAM="$value"
- if [[ -z "${GIT_PS1_SHOWUPSTREAM}" ]]; then
+ if [ -z "${GIT_PS1_SHOWUPSTREAM}" ]; then
p=""
return
fi
;;
svn-remote.*.url)
- svn_remote[$((${#svn_remote[@]} + 1))]="$value"
+ svn_remotes=${svn_remotes}${value}${LF} # URI\nURI\n...
svn_url_pattern="$svn_url_pattern\\|$value"
upstream_type=svn+git # default upstream type is SVN if available, else git
;;
esac
- done <<< "$output"
+ done <<-OUTPUT
+ $output
+ OUTPUT
# parse configuration values
local option
@@ -154,33 +196,45 @@ __git_ps1_show_upstream ()
case "$upstream_type" in
git) upstream_type="@{upstream}" ;;
svn*)
- # get the upstream from the "git-svn-id: ..." in a commit message
- # (git-svn uses essentially the same procedure internally)
- local -a svn_upstream
- svn_upstream=($(git log --first-parent -1 \
- --grep="^git-svn-id: \(${svn_url_pattern#??}\)" 2>/dev/null))
- if [[ 0 -ne ${#svn_upstream[@]} ]]; then
- svn_upstream=${svn_upstream[${#svn_upstream[@]} - 2]}
- svn_upstream=${svn_upstream%@*}
- local n_stop="${#svn_remote[@]}"
- for ((n=1; n <= n_stop; n++)); do
- svn_upstream=${svn_upstream#${svn_remote[$n]}}
- done
+ # successful svn-upstream resolution:
+ # - get the list of configured svn-remotes ($svn_remotes set above)
+ # - get the last commit which seems from one of our svn-remotes
+ # - confirm that it is from one of the svn-remotes
+ # - use $GIT_SVN_ID if set, else "git-svn"
- if [[ -z "$svn_upstream" ]]; then
+ # get upstream from "git-svn-id: UPSTRM@N HASH" in a commit message
+ # (git-svn uses essentially the same procedure internally)
+ local svn_upstream="$(
+ git log --first-parent -1 \
+ --grep="^git-svn-id: \(${svn_url_pattern#??}\)" 2>/dev/null
+ )"
+
+ if [ -n "$svn_upstream" ]; then
+ # extract the URI, assuming --grep matched the last line
+ svn_upstream=${svn_upstream##*$LF} # last line
+ svn_upstream=${svn_upstream#*: } # UPSTRM@N HASH
+ svn_upstream=${svn_upstream%@*} # UPSTRM
+
+ case ${LF}${svn_remotes} in
+ *"${LF}${svn_upstream}${LF}"*)
+ # grep indeed matched the last line - it's our remote
# default branch name for checkouts with no layout:
upstream_type=${GIT_SVN_ID:-git-svn}
- else
+ ;;
+ *)
+ # the commit message includes one of our remotes, but
+ # it's not at the last line. is $svn_upstream junk?
upstream_type=${svn_upstream#/}
- fi
- elif [[ "svn+git" = "$upstream_type" ]]; then
+ ;;
+ esac
+ elif [ "svn+git" = "$upstream_type" ]; then
upstream_type="@{upstream}"
fi
;;
esac
# Find how many commits we are ahead/behind our upstream
- if [[ -z "$legacy" ]]; then
+ if [ -z "$legacy" ]; then
count="$(git rev-list --count --left-right \
"$upstream_type"...HEAD 2>/dev/null)"
else
@@ -192,8 +246,8 @@ __git_ps1_show_upstream ()
for commit in $commits
do
case "$commit" in
- "<"*) ((behind++)) ;;
- *) ((ahead++)) ;;
+ "<"*) behind=$((behind+1)) ;;
+ *) ahead=$((ahead+1)) ;;
esac
done
count="$behind $ahead"
@@ -203,7 +257,7 @@ __git_ps1_show_upstream ()
fi
# calculate the result
- if [[ -z "$verbose" ]]; then
+ if [ -z "$verbose" ]; then
case "$count" in
"") # no upstream
p="" ;;
@@ -229,10 +283,10 @@ __git_ps1_show_upstream ()
*) # diverged from upstream
upstream="|u+${count#* }-${count% *}" ;;
esac
- if [[ -n "$count" && -n "$name" ]]; then
+ if [ -n "$count" ] && [ -n "$name" ]; then
__git_ps1_upstream_name=$(git rev-parse \
--abbrev-ref "$upstream_type" 2>/dev/null)
- if [ $pcmode = yes ] && [ $ps1_expanded = yes ]; then
+ if [ "$pcmode" = yes ] && [ "$ps1_expanded" = yes ]; then
upstream="$upstream \${__git_ps1_upstream_name}"
else
upstream="$upstream ${__git_ps1_upstream_name}"
@@ -251,25 +305,29 @@ __git_ps1_show_upstream ()
# their own color.
__git_ps1_colorize_gitstring ()
{
- if [[ -n ${ZSH_VERSION-} ]]; then
+ if [ -n "${ZSH_VERSION-}" ]; then
local c_red='%F{red}'
local c_green='%F{green}'
local c_lblue='%F{blue}'
local c_clear='%f'
else
- # Using \001 and \002 around colors is necessary to prevent
- # issues with command line editing/browsing/completion!
- local c_red=$'\001\e[31m\002'
- local c_green=$'\001\e[32m\002'
- local c_lblue=$'\001\e[1;34m\002'
- local c_clear=$'\001\e[0m\002'
+ # \001 (SOH) and \002 (STX) are 0-width substring markers
+ # which bash/readline identify while calculating the prompt
+ # on-screen width - to exclude 0-screen-width esc sequences.
+ local c_pre="${GIT_PS1_COLOR_PRE-$__git_SOH}${__git_ESC}["
+ local c_post="m${GIT_PS1_COLOR_POST-$__git_STX}"
+
+ local c_red="${c_pre}31${c_post}"
+ local c_green="${c_pre}32${c_post}"
+ local c_lblue="${c_pre}1;34${c_post}"
+ local c_clear="${c_pre}0${c_post}"
fi
- local bad_color=$c_red
- local ok_color=$c_green
+ local bad_color="$c_red"
+ local ok_color="$c_green"
local flags_color="$c_lblue"
local branch_color=""
- if [ $detached = no ]; then
+ if [ "$detached" = no ]; then
branch_color="$ok_color"
else
branch_color="$bad_color"
@@ -298,7 +356,7 @@ __git_ps1_colorize_gitstring ()
# variable, in that order.
__git_eread ()
{
- test -r "$1" && IFS=$'\r\n' read -r "$2" <"$1"
+ test -r "$1" && IFS=$__git_CRLF read -r "$2" <"$1"
}
# see if a cherry-pick or revert is in progress, if the user has committed a
@@ -346,7 +404,7 @@ __git_sequencer_status ()
__git_ps1 ()
{
# preserve exit status
- local exit=$?
+ local exit="$?"
local pcmode=no
local detached=no
local ps1pc_start='\u@\h:\w '
@@ -365,7 +423,7 @@ __git_ps1 ()
;;
0|1) printf_format="${1:-$printf_format}"
;;
- *) return $exit
+ *) return "$exit"
;;
esac
@@ -403,7 +461,7 @@ __git_ps1 ()
# incorrect.)
#
local ps1_expanded=yes
- [ -z "${ZSH_VERSION-}" ] || [[ -o PROMPT_SUBST ]] || ps1_expanded=no
+ [ -z "${ZSH_VERSION-}" ] || eval '[[ -o PROMPT_SUBST ]]' || ps1_expanded=no
[ -z "${BASH_VERSION-}" ] || shopt -q promptvars || ps1_expanded=no
local repo_info rev_parse_exit_code
@@ -413,29 +471,30 @@ __git_ps1 ()
rev_parse_exit_code="$?"
if [ -z "$repo_info" ]; then
- return $exit
+ return "$exit"
fi
+ local LF="$__git_LF"
local short_sha=""
if [ "$rev_parse_exit_code" = "0" ]; then
- short_sha="${repo_info##*$'\n'}"
- repo_info="${repo_info%$'\n'*}"
+ short_sha="${repo_info##*$LF}"
+ repo_info="${repo_info%$LF*}"
fi
- local ref_format="${repo_info##*$'\n'}"
- repo_info="${repo_info%$'\n'*}"
- local inside_worktree="${repo_info##*$'\n'}"
- repo_info="${repo_info%$'\n'*}"
- local bare_repo="${repo_info##*$'\n'}"
- repo_info="${repo_info%$'\n'*}"
- local inside_gitdir="${repo_info##*$'\n'}"
- local g="${repo_info%$'\n'*}"
+ local ref_format="${repo_info##*$LF}"
+ repo_info="${repo_info%$LF*}"
+ local inside_worktree="${repo_info##*$LF}"
+ repo_info="${repo_info%$LF*}"
+ local bare_repo="${repo_info##*$LF}"
+ repo_info="${repo_info%$LF*}"
+ local inside_gitdir="${repo_info##*$LF}"
+ local g="${repo_info%$LF*}"
if [ "true" = "$inside_worktree" ] &&
[ -n "${GIT_PS1_HIDE_IF_PWD_IGNORED-}" ] &&
[ "$(git config --bool bash.hideIfPwdIgnored)" != "false" ] &&
git check-ignore -q .
then
- return $exit
+ return "$exit"
fi
local sparse=""
@@ -485,14 +544,16 @@ __git_ps1 ()
case "$ref_format" in
files)
if ! __git_eread "$g/HEAD" head; then
- return $exit
+ return "$exit"
fi
- if [[ $head == "ref: "* ]]; then
+ case $head in
+ "ref: "*)
head="${head#ref: }"
- else
+ ;;
+ *)
head=""
- fi
+ esac
;;
*)
head="$(git symbolic-ref HEAD 2>/dev/null)"
@@ -528,8 +589,8 @@ __git_ps1 ()
fi
local conflict="" # state indicator for unresolved conflicts
- if [[ "${GIT_PS1_SHOWCONFLICTSTATE-}" == "yes" ]] &&
- [[ $(git ls-files --unmerged 2>/dev/null) ]]; then
+ if [ "${GIT_PS1_SHOWCONFLICTSTATE-}" = "yes" ] &&
+ [ "$(git ls-files --unmerged 2>/dev/null)" ]; then
conflict="|CONFLICT"
fi
@@ -581,10 +642,10 @@ __git_ps1 ()
fi
fi
- local z="${GIT_PS1_STATESEPARATOR-" "}"
+ local z="${GIT_PS1_STATESEPARATOR- }"
b=${b##refs/heads/}
- if [ $pcmode = yes ] && [ $ps1_expanded = yes ]; then
+ if [ "$pcmode" = yes ] && [ "$ps1_expanded" = yes ]; then
__git_ps1_branch_name=$b
b="\${__git_ps1_branch_name}"
fi
@@ -596,7 +657,7 @@ __git_ps1 ()
local f="$h$w$i$s$u$p"
local gitstring="$c$b${f:+$z$f}${sparse}$r${upstream}${conflict}"
- if [ $pcmode = yes ]; then
+ if [ "$pcmode" = yes ]; then
if [ "${__git_printf_supports_v-}" != yes ]; then
gitstring=$(printf -- "$printf_format" "$gitstring")
else
@@ -607,5 +668,5 @@ __git_ps1 ()
printf -- "$printf_format" "$gitstring"
fi
- return $exit
+ return "$exit"
}
diff --git a/credential.c b/credential.c
index 4b1a2b94fe..ee46351ce0 100644
--- a/credential.c
+++ b/credential.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "abspath.h"
#include "config.h"
diff --git a/csum-file.c b/csum-file.c
index 2131ee6b12..bf82ad8f9f 100644
--- a/csum-file.c
+++ b/csum-file.c
@@ -56,7 +56,7 @@ void hashflush(struct hashfile *f)
}
}
-static void free_hashfile(struct hashfile *f)
+void free_hashfile(struct hashfile *f)
{
free(f->buffer);
free(f->check_buffer);
diff --git a/csum-file.h b/csum-file.h
index 36c7c5585f..7c73da0a40 100644
--- a/csum-file.h
+++ b/csum-file.h
@@ -46,6 +46,16 @@ int hashfile_truncate(struct hashfile *, struct hashfile_checkpoint *);
struct hashfile *hashfd(int fd, const char *name);
struct hashfile *hashfd_check(const char *name);
struct hashfile *hashfd_throughput(int fd, const char *name, struct progress *tp);
+
+/*
+ * Free the hashfile without flushing its contents to disk. This only
+ * needs to be called when not calling `finalize_hashfile()`.
+ */
+void free_hashfile(struct hashfile *f);
+
+/*
+ * Finalize the hashfile by flushing data to disk and free'ing it.
+ */
int finalize_hashfile(struct hashfile *, unsigned char *, enum fsync_component, unsigned int);
void discard_hashfile(struct hashfile *);
void hashwrite(struct hashfile *, const void *, unsigned int);
diff --git a/daemon.c b/daemon.c
index 17d331b2f3..cb946e3c95 100644
--- a/daemon.c
+++ b/daemon.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "abspath.h"
#include "config.h"
@@ -1175,13 +1177,13 @@ static int service_loop(struct socketlist *socklist)
struct credentials;
-static void drop_privileges(struct credentials *cred)
+static void drop_privileges(struct credentials *cred UNUSED)
{
/* nothing */
}
-static struct credentials *prepare_credentials(const char *user_name,
- const char *group_name)
+static struct credentials *prepare_credentials(const char *user_name UNUSED,
+ const char *group_name UNUSED)
{
die("--user not supported on this platform");
}
diff --git a/diff-lib.c b/diff-lib.c
index 7a1eb63757..a680768ee7 100644
--- a/diff-lib.c
+++ b/diff-lib.c
@@ -308,8 +308,7 @@ static void diff_index_show_file(struct rev_info *revs,
oid, oid_valid, ce->name, dirty_submodule);
}
-static int get_stat_data(const struct index_state *istate,
- const struct cache_entry *ce,
+static int get_stat_data(const struct cache_entry *ce,
const struct object_id **oidp,
unsigned int *modep,
int cached, int match_missing,
@@ -352,7 +351,6 @@ static void show_new_file(struct rev_info *revs,
const struct object_id *oid;
unsigned int mode;
unsigned dirty_submodule = 0;
- struct index_state *istate = revs->diffopt.repo->index;
if (new_file && S_ISSPARSEDIR(new_file->ce_mode)) {
diff_tree_oid(NULL, &new_file->oid, new_file->name, &revs->diffopt);
@@ -363,7 +361,7 @@ static void show_new_file(struct rev_info *revs,
* New file in the index: it might actually be different in
* the working tree.
*/
- if (get_stat_data(istate, new_file, &oid, &mode, cached, match_missing,
+ if (get_stat_data(new_file, &oid, &mode, cached, match_missing,
&dirty_submodule, &revs->diffopt) < 0)
return;
@@ -379,7 +377,6 @@ static int show_modified(struct rev_info *revs,
unsigned int mode, oldmode;
const struct object_id *oid;
unsigned dirty_submodule = 0;
- struct index_state *istate = revs->diffopt.repo->index;
assert(S_ISSPARSEDIR(old_entry->ce_mode) ==
S_ISSPARSEDIR(new_entry->ce_mode));
@@ -395,7 +392,7 @@ static int show_modified(struct rev_info *revs,
return 0;
}
- if (get_stat_data(istate, new_entry, &oid, &mode, cached, match_missing,
+ if (get_stat_data(new_entry, &oid, &mode, cached, match_missing,
&dirty_submodule, &revs->diffopt) < 0) {
if (report_missing)
diff_index_show_file(revs, "-", old_entry,
diff --git a/diff.c b/diff.c
index ebb7538e04..4035a9374d 100644
--- a/diff.c
+++ b/diff.c
@@ -5464,9 +5464,13 @@ static int diff_opt_ignore_regex(const struct option *opt,
regex_t *regex;
BUG_ON_OPT_NEG(unset);
+
regex = xmalloc(sizeof(*regex));
- if (regcomp(regex, arg, REG_EXTENDED | REG_NEWLINE))
+ if (regcomp(regex, arg, REG_EXTENDED | REG_NEWLINE)) {
+ free(regex);
return error(_("invalid regex given to -I: '%s'"), arg);
+ }
+
ALLOC_GROW(options->ignore_regex, options->ignore_regex_nr + 1,
options->ignore_regex_alloc);
options->ignore_regex[options->ignore_regex_nr++] = regex;
@@ -6713,6 +6717,16 @@ void diff_free(struct diff_options *options)
if (options->no_free)
return;
+ if (options->objfind) {
+ oidset_clear(options->objfind);
+ FREE_AND_NULL(options->objfind);
+ }
+
+ for (size_t i = 0; i < options->anchors_nr; i++)
+ free(options->anchors[i]);
+ FREE_AND_NULL(options->anchors);
+ options->anchors_nr = options->anchors_alloc = 0;
+
diff_free_file(options);
diff_free_ignore_regex(options);
clear_pathspec(&options->pathspec);
diff --git a/editor.c b/editor.c
index d1ba2d7c34..6b9ce81d5f 100644
--- a/editor.c
+++ b/editor.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "abspath.h"
#include "advice.h"
@@ -133,14 +135,17 @@ int launch_sequence_editor(const char *path, struct strbuf *buffer,
return launch_specified_editor(git_sequence_editor(), path, buffer, env);
}
-int strbuf_edit_interactively(struct strbuf *buffer, const char *path,
+int strbuf_edit_interactively(struct repository *r,
+ struct strbuf *buffer, const char *path,
const char *const *env)
{
- char *path2 = NULL;
+ struct strbuf sb = STRBUF_INIT;
int fd, res = 0;
- if (!is_absolute_path(path))
- path = path2 = xstrdup(git_path("%s", path));
+ if (!is_absolute_path(path)) {
+ strbuf_repo_git_path(&sb, r, "%s", path);
+ path = sb.buf;
+ }
fd = open(path, O_WRONLY | O_CREAT | O_TRUNC, 0666);
if (fd < 0)
@@ -157,6 +162,6 @@ int strbuf_edit_interactively(struct strbuf *buffer, const char *path,
unlink(path);
}
- free(path2);
+ strbuf_release(&sb);
return res;
}
diff --git a/editor.h b/editor.h
index 8016bb5e00..f1c41df378 100644
--- a/editor.h
+++ b/editor.h
@@ -1,6 +1,7 @@
#ifndef EDITOR_H
#define EDITOR_H
+struct repository;
struct strbuf;
const char *git_editor(void);
@@ -28,7 +29,7 @@ int launch_sequence_editor(const char *path, struct strbuf *buffer,
*
* If `path` is relative, it refers to a file in the `.git` directory.
*/
-int strbuf_edit_interactively(struct strbuf *buffer, const char *path,
- const char *const *env);
+int strbuf_edit_interactively(struct repository *r, struct strbuf *buffer,
+ const char *path, const char *const *env);
#endif
diff --git a/environment.c b/environment.c
index 5cea2c9f54..1d6c48b52d 100644
--- a/environment.c
+++ b/environment.c
@@ -114,6 +114,7 @@ int protect_ntfs = PROTECT_NTFS_DEFAULT;
* that is subject to stripspace.
*/
const char *comment_line_str = "#";
+char *comment_line_str_to_free;
int auto_comment_line_char;
/* Parallel index stat data preload? */
diff --git a/environment.h b/environment.h
index e9f01d4d11..0148738ed6 100644
--- a/environment.h
+++ b/environment.h
@@ -9,6 +9,7 @@ struct strvec;
* that is subject to stripspace.
*/
extern const char *comment_line_str;
+extern char *comment_line_str_to_free;
extern int auto_comment_line_char;
/*
diff --git a/fsmonitor.c b/fsmonitor.c
index 2b17d60bbb..28130f748f 100644
--- a/fsmonitor.c
+++ b/fsmonitor.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "config.h"
#include "dir.h"
diff --git a/git-send-email.perl b/git-send-email.perl
index 72044e5ef3..cdcee1d0cf 100755
--- a/git-send-email.perl
+++ b/git-send-email.perl
@@ -31,6 +31,7 @@ sub usage {
git send-email [<options>] <file|directory>
git send-email [<options>] <format-patch options>
git send-email --dump-aliases
+git send-email --translate-aliases
Composing:
--from <str> * Email From:
@@ -99,6 +100,10 @@ git send-email --dump-aliases
Information:
--dump-aliases * Dump configured aliases and exit.
+ --translate-aliases * Translate aliases read from standard
+ input according to the configured email
+ alias file(s), outputting the result to
+ standard output.
EOT
exit(1);
@@ -212,6 +217,7 @@ my $format_patch;
my $compose_filename;
my $force = 0;
my $dump_aliases = 0;
+my $translate_aliases = 0;
# Variables to prevent short format-patch options from being captured
# as abbreviated send-email options
@@ -476,11 +482,14 @@ my $git_completion_helper;
my %dump_aliases_options = (
"h" => \$help,
"dump-aliases" => \$dump_aliases,
+ "translate-aliases" => \$translate_aliases,
);
$rc = GetOptions(%dump_aliases_options);
usage() unless $rc;
die __("--dump-aliases incompatible with other options\n")
- if !$help and $dump_aliases and @ARGV;
+ if !$help and ($dump_aliases or $translate_aliases) and @ARGV;
+die __("--dump-aliases and --translate-aliases are mutually exclusive\n")
+ if !$help and $dump_aliases and $translate_aliases;
my %options = (
"sender|from=s" => \$sender,
"in-reply-to=s" => \$initial_in_reply_to,
@@ -724,6 +733,16 @@ if ($dump_aliases) {
exit(0);
}
+if ($translate_aliases) {
+ while (<STDIN>) {
+ my @addr_list = parse_address_line($_);
+ @addr_list = expand_aliases(@addr_list);
+ @addr_list = sanitize_address_list(@addr_list);
+ print "$_\n" for @addr_list;
+ }
+ exit(0);
+}
+
# is_format_patch_arg($f) returns 0 if $f names a patch, or 1 if
# $f is a revision list specification to be passed to format-patch.
sub is_format_patch_arg {
diff --git a/git-svn.perl b/git-svn.perl
index b0d0a50984..01e7a70de1 100755
--- a/git-svn.perl
+++ b/git-svn.perl
@@ -219,11 +219,11 @@ my %cmd = (
"Set an SVN repository to a git tree-ish",
{ 'stdin' => \$_stdin, %cmt_opts, %fc_opts, } ],
'create-ignore' => [ \&cmd_create_ignore,
- 'Create a .gitignore per svn:ignore',
+ "Create a .gitignore per directory with SVN ignore properties",
{ 'revision|r=i' => \$_revision
} ],
'mkdirs' => [ \&cmd_mkdirs ,
- "recreate empty directories after a checkout",
+ "Recreate empty directories after a checkout",
{ 'revision|r=i' => \$_revision } ],
'propget' => [ \&cmd_propget,
'Print the value of a property on a file or directory',
@@ -234,7 +234,7 @@ my %cmd = (
'proplist' => [ \&cmd_proplist,
'List all properties of a file or directory',
{ 'revision|r=i' => \$_revision } ],
- 'show-ignore' => [ \&cmd_show_ignore, "Show svn:ignore listings",
+ 'show-ignore' => [ \&cmd_show_ignore, "Show .gitignore patterns from SVN ignore properties",
{ 'revision|r=i' => \$_revision
} ],
'show-externals' => [ \&cmd_show_externals, "Show svn:externals listings",
@@ -1279,12 +1279,20 @@ sub cmd_show_ignore {
$gs->prop_walk($gs->path, $r, sub {
my ($gs, $path, $props) = @_;
print STDOUT "\n# $path\n";
- my $s = $props->{'svn:ignore'} or return;
- $s =~ s/[\r\n]+/\n/g;
- $s =~ s/^\n+//;
- chomp $s;
- $s =~ s#^#$path#gm;
- print STDOUT "$s\n";
+ if (my $s = $props->{'svn:ignore'}) {
+ $s =~ s/[\r\n]+/\n/g;
+ $s =~ s/^\n+//;
+ chomp $s;
+ $s =~ s#^#$path#gm;
+ print STDOUT "$s\n";
+ }
+ if (my $s = $props->{'svn:global-ignores'}) {
+ $s =~ s/[\r\n]+/\n/g;
+ $s =~ s/^\n+//;
+ chomp $s;
+ $s =~ s#^#$path**/#gm;
+ print STDOUT "$s\n";
+ }
});
}
@@ -1315,16 +1323,25 @@ sub cmd_create_ignore {
# which git won't track
mkpath([$path]) unless -d $path;
my $ignore = $path . '.gitignore';
- my $s = $props->{'svn:ignore'} or return;
open(GITIGNORE, '>', $ignore)
or fatal("Failed to open `$ignore' for writing: $!");
- $s =~ s/[\r\n]+/\n/g;
- $s =~ s/^\n+//;
- chomp $s;
- # Prefix all patterns so that the ignore doesn't apply
- # to sub-directories.
- $s =~ s#^#/#gm;
- print GITIGNORE "$s\n";
+ if (my $s = $props->{'svn:ignore'}) {
+ $s =~ s/[\r\n]+/\n/g;
+ $s =~ s/^\n+//;
+ chomp $s;
+ # Prefix all patterns so that the ignore doesn't apply
+ # to sub-directories.
+ $s =~ s#^#/#gm;
+ print GITIGNORE "$s\n";
+ }
+ if (my $s = $props->{'svn:global-ignores'}) {
+ $s =~ s/[\r\n]+/\n/g;
+ $s =~ s/^\n+//;
+ chomp $s;
+ # Global ignores apply to sub-directories, so they are
+ # not prefixed.
+ print GITIGNORE "$s\n";
+ }
close(GITIGNORE)
or fatal("Failed to close `$ignore': $!");
command_noisy('add', '-f', $ignore);
diff --git a/git.c b/git.c
index e35af9b0e5..9a618a2740 100644
--- a/git.c
+++ b/git.c
@@ -143,6 +143,13 @@ void setup_auto_pager(const char *cmd, int def)
commit_pager_choice();
}
+static void print_system_path(const char *path)
+{
+ char *s_path = system_path(path);
+ puts(s_path);
+ free(s_path);
+}
+
static int handle_options(const char ***argv, int *argc, int *envchanged)
{
const char **orig_argv = *argv;
@@ -173,15 +180,15 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)
exit(0);
}
} else if (!strcmp(cmd, "--html-path")) {
- puts(system_path(GIT_HTML_PATH));
+ print_system_path(GIT_HTML_PATH);
trace2_cmd_name("_query_");
exit(0);
} else if (!strcmp(cmd, "--man-path")) {
- puts(system_path(GIT_MAN_PATH));
+ print_system_path(GIT_MAN_PATH);
trace2_cmd_name("_query_");
exit(0);
} else if (!strcmp(cmd, "--info-path")) {
- puts(system_path(GIT_INFO_PATH));
+ print_system_path(GIT_INFO_PATH);
trace2_cmd_name("_query_");
exit(0);
} else if (!strcmp(cmd, "-p") || !strcmp(cmd, "--paginate")) {
diff --git a/gpg-interface.c b/gpg-interface.c
index 5c824aeb25..6587085cd1 100644
--- a/gpg-interface.c
+++ b/gpg-interface.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "commit.h"
#include "config.h"
diff --git a/graph.c b/graph.c
index 1ca34770ee..091c14cf4f 100644
--- a/graph.c
+++ b/graph.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "gettext.h"
#include "config.h"
diff --git a/hook.c b/hook.c
index 7e90787bca..a9320cb0ce 100644
--- a/hook.c
+++ b/hook.c
@@ -10,14 +10,14 @@
#include "environment.h"
#include "setup.h"
-const char *find_hook(const char *name)
+const char *find_hook(struct repository *r, const char *name)
{
static struct strbuf path = STRBUF_INIT;
int found_hook;
strbuf_reset(&path);
- strbuf_git_path(&path, "hooks/%s", name);
+ strbuf_repo_git_path(&path, r, "hooks/%s", name);
found_hook = access(path.buf, X_OK) >= 0;
#ifdef STRIP_EXTENSION
if (!found_hook) {
@@ -48,9 +48,9 @@ const char *find_hook(const char *name)
return path.buf;
}
-int hook_exists(const char *name)
+int hook_exists(struct repository *r, const char *name)
{
- return !!find_hook(name);
+ return !!find_hook(r, name);
}
static int pick_next_hook(struct child_process *cp,
@@ -121,7 +121,8 @@ static void run_hooks_opt_clear(struct run_hooks_opt *options)
strvec_clear(&options->args);
}
-int run_hooks_opt(const char *hook_name, struct run_hooks_opt *options)
+int run_hooks_opt(struct repository *r, const char *hook_name,
+ struct run_hooks_opt *options)
{
struct strbuf abs_path = STRBUF_INIT;
struct hook_cb_data cb_data = {
@@ -129,7 +130,7 @@ int run_hooks_opt(const char *hook_name, struct run_hooks_opt *options)
.hook_name = hook_name,
.options = options,
};
- const char *const hook_path = find_hook(hook_name);
+ const char *const hook_path = find_hook(r, hook_name);
int ret = 0;
const struct run_process_parallel_opts opts = {
.tr2_category = "hook",
@@ -173,14 +174,14 @@ cleanup:
return ret;
}
-int run_hooks(const char *hook_name)
+int run_hooks(struct repository *r, const char *hook_name)
{
struct run_hooks_opt opt = RUN_HOOKS_OPT_INIT;
- return run_hooks_opt(hook_name, &opt);
+ return run_hooks_opt(r, hook_name, &opt);
}
-int run_hooks_l(const char *hook_name, ...)
+int run_hooks_l(struct repository *r, const char *hook_name, ...)
{
struct run_hooks_opt opt = RUN_HOOKS_OPT_INIT;
va_list ap;
@@ -191,5 +192,5 @@ int run_hooks_l(const char *hook_name, ...)
strvec_push(&opt.args, arg);
va_end(ap);
- return run_hooks_opt(hook_name, &opt);
+ return run_hooks_opt(r, hook_name, &opt);
}
diff --git a/hook.h b/hook.h
index 6511525aeb..11863fa734 100644
--- a/hook.h
+++ b/hook.h
@@ -2,6 +2,8 @@
#define HOOK_H
#include "strvec.h"
+struct repository;
+
struct run_hooks_opt
{
/* Environment vars to be set for each hook */
@@ -55,12 +57,12 @@ struct hook_cb_data {
* or disabled. Note that this points to static storage that will be
* overwritten by further calls to find_hook and run_hook_*.
*/
-const char *find_hook(const char *name);
+const char *find_hook(struct repository *r, const char *name);
/**
* A boolean version of find_hook()
*/
-int hook_exists(const char *hookname);
+int hook_exists(struct repository *r, const char *hookname);
/**
* Takes a `hook_name`, resolves it to a path with find_hook(), and
@@ -70,13 +72,14 @@ int hook_exists(const char *hookname);
* Returns the status code of the run hook, or a negative value on
* error().
*/
-int run_hooks_opt(const char *hook_name, struct run_hooks_opt *options);
+int run_hooks_opt(struct repository *r, const char *hook_name,
+ struct run_hooks_opt *options);
/**
* A wrapper for run_hooks_opt() which provides a dummy "struct
* run_hooks_opt" initialized with "RUN_HOOKS_OPT_INIT".
*/
-int run_hooks(const char *hook_name);
+int run_hooks(struct repository *r, const char *hook_name);
/**
* Like run_hooks(), a wrapper for run_hooks_opt().
@@ -87,5 +90,5 @@ int run_hooks(const char *hook_name);
* hook. This function behaves like the old run_hook_le() API.
*/
LAST_ARG_MUST_BE_NULL
-int run_hooks_l(const char *hook_name, ...);
+int run_hooks_l(struct repository *r, const char *hook_name, ...);
#endif
diff --git a/imap-send.c b/imap-send.c
index 01404e5047..2dd42807cd 100644
--- a/imap-send.c
+++ b/imap-send.c
@@ -21,6 +21,8 @@
* along with this program; if not, see <https://www.gnu.org/licenses/>.
*/
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "config.h"
#include "credential.h"
@@ -190,7 +192,7 @@ static void socket_perror(const char *func, struct imap_socket *sock, int ret)
#ifdef NO_OPENSSL
static int ssl_socket_connect(struct imap_socket *sock UNUSED,
- const struct imap_server_conf *cfg,
+ const struct imap_server_conf *cfg UNUSED,
int use_tls_only UNUSED)
{
fprintf(stderr, "SSL requested but SSL support not compiled in\n");
diff --git a/mailinfo.c b/mailinfo.c
index 94b9b0abf2..95228531a6 100644
--- a/mailinfo.c
+++ b/mailinfo.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "config.h"
#include "gettext.h"
diff --git a/merge-ll.c b/merge-ll.c
index 180c19df67..badb6dea57 100644
--- a/merge-ll.c
+++ b/merge-ll.c
@@ -4,6 +4,8 @@
* Copyright (c) 2007 Junio C Hamano
*/
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "config.h"
#include "convert.h"
diff --git a/merge-ort.c b/merge-ort.c
index e9d01ac7f7..3752c7e595 100644
--- a/merge-ort.c
+++ b/merge-ort.c
@@ -689,8 +689,7 @@ static void clear_or_reinit_internal_opts(struct merge_options_internal *opti,
*/
strmap_clear_func(&opti->conflicted, 0);
- if (opti->attr_index.cache_nr) /* true iff opt->renormalize */
- discard_index(&opti->attr_index);
+ discard_index(&opti->attr_index);
/* Free memory used by various renames maps */
for (i = MERGE_SIDE1; i <= MERGE_SIDE2; ++i) {
diff --git a/midx-write.c b/midx-write.c
index e3fa33203f..c7413ae3ca 100644
--- a/midx-write.c
+++ b/midx-write.c
@@ -858,10 +858,9 @@ static int write_midx_bitmap(const char *midx_name,
for (i = 0; i < pdata->nr_objects; i++)
index[i] = &pdata->objects[i].idx;
- bitmap_writer_init(&writer, the_repository);
+ bitmap_writer_init(&writer, the_repository, pdata);
bitmap_writer_show_progress(&writer, flags & MIDX_PROGRESS);
- bitmap_writer_build_type_index(&writer, pdata, index,
- pdata->nr_objects);
+ bitmap_writer_build_type_index(&writer, index);
/*
* bitmap_writer_finish expects objects in lex order, but pack_order
@@ -880,13 +879,12 @@ static int write_midx_bitmap(const char *midx_name,
index[pack_order[i]] = &pdata->objects[i].idx;
bitmap_writer_select_commits(&writer, commits, commits_nr);
- ret = bitmap_writer_build(&writer, pdata);
+ ret = bitmap_writer_build(&writer);
if (ret < 0)
goto cleanup;
bitmap_writer_set_checksum(&writer, midx_hash);
- bitmap_writer_finish(&writer, index, pdata->nr_objects, bitmap_name,
- options);
+ bitmap_writer_finish(&writer, index, bitmap_name, options);
cleanup:
free(index);
diff --git a/object-file.c b/object-file.c
index 05ac6ebed6..c5994202ba 100644
--- a/object-file.c
+++ b/object-file.c
@@ -2953,6 +2953,7 @@ int read_loose_object(const char *path,
if (unpack_loose_header(&stream, map, mapsize, hdr, sizeof(hdr),
NULL) != ULHR_OK) {
error(_("unable to unpack header of %s"), path);
+ git_inflate_end(&stream);
goto out;
}
diff --git a/object-name.c b/object-name.c
index f340b740c5..09c1bd93a3 100644
--- a/object-name.c
+++ b/object-name.c
@@ -1772,6 +1772,7 @@ int strbuf_check_branch_ref(struct strbuf *sb, const char *name)
void object_context_release(struct object_context *ctx)
{
free(ctx->path);
+ strbuf_release(&ctx->symlink_path);
}
/*
diff --git a/oss-fuzz/dummy-cmd-main.c b/oss-fuzz/dummy-cmd-main.c
index 071cb231ba..8ef776d06f 100644
--- a/oss-fuzz/dummy-cmd-main.c
+++ b/oss-fuzz/dummy-cmd-main.c
@@ -8,7 +8,7 @@
* executed.
*/
-int cmd_main(int argc, const char **argv) {
+int cmd_main(int argc UNUSED, const char **argv UNUSED) {
BUG("We should not execute cmd_main() from a fuzz target");
return 1;
}
diff --git a/pack-bitmap-write.c b/pack-bitmap-write.c
index bf96c80898..4dc0fe8e40 100644
--- a/pack-bitmap-write.c
+++ b/pack-bitmap-write.c
@@ -41,17 +41,19 @@ static inline int bitmap_writer_nr_selected_commits(struct bitmap_writer *writer
return writer->selected_nr - writer->pseudo_merges_nr;
}
-void bitmap_writer_init(struct bitmap_writer *writer, struct repository *r)
+void bitmap_writer_init(struct bitmap_writer *writer, struct repository *r,
+ struct packing_data *pdata)
{
memset(writer, 0, sizeof(struct bitmap_writer));
if (writer->bitmaps)
BUG("bitmap writer already initialized");
writer->bitmaps = kh_init_oid_map();
writer->pseudo_merge_commits = kh_init_oid_map();
+ writer->to_pack = pdata;
string_list_init_dup(&writer->pseudo_merge_groups);
- load_pseudo_merges_from_config(&writer->pseudo_merge_groups);
+ load_pseudo_merges_from_config(r, &writer->pseudo_merge_groups);
}
static void free_pseudo_merge_commit_idx(struct pseudo_merge_commit_idx *idx)
@@ -99,9 +101,7 @@ void bitmap_writer_show_progress(struct bitmap_writer *writer, int show)
* Build the initial type index for the packfile or multi-pack-index
*/
void bitmap_writer_build_type_index(struct bitmap_writer *writer,
- struct packing_data *to_pack,
- struct pack_idx_entry **index,
- uint32_t index_nr)
+ struct pack_idx_entry **index)
{
uint32_t i;
@@ -109,13 +109,13 @@ void bitmap_writer_build_type_index(struct bitmap_writer *writer,
writer->trees = ewah_new();
writer->blobs = ewah_new();
writer->tags = ewah_new();
- ALLOC_ARRAY(to_pack->in_pack_pos, to_pack->nr_objects);
+ ALLOC_ARRAY(writer->to_pack->in_pack_pos, writer->to_pack->nr_objects);
- for (i = 0; i < index_nr; ++i) {
+ for (i = 0; i < writer->to_pack->nr_objects; ++i) {
struct object_entry *entry = (struct object_entry *)index[i];
enum object_type real_type;
- oe_set_in_pack_pos(to_pack, entry, i);
+ oe_set_in_pack_pos(writer->to_pack, entry, i);
switch (oe_type(entry)) {
case OBJ_COMMIT:
@@ -126,7 +126,7 @@ void bitmap_writer_build_type_index(struct bitmap_writer *writer,
break;
default:
- real_type = oid_object_info(to_pack->repo,
+ real_type = oid_object_info(writer->to_pack->repo,
&entry->idx.oid, NULL);
break;
}
@@ -569,8 +569,7 @@ static void store_selected(struct bitmap_writer *writer,
kh_value(writer->bitmaps, hash_pos) = stored;
}
-int bitmap_writer_build(struct bitmap_writer *writer,
- struct packing_data *to_pack)
+int bitmap_writer_build(struct bitmap_writer *writer)
{
struct bitmap_builder bb;
size_t i;
@@ -581,17 +580,15 @@ int bitmap_writer_build(struct bitmap_writer *writer,
uint32_t *mapping;
int closed = 1; /* until proven otherwise */
- writer->to_pack = to_pack;
-
if (writer->show_progress)
writer->progress = start_progress("Building bitmaps",
writer->selected_nr);
trace2_region_enter("pack-bitmap-write", "building_bitmaps_total",
the_repository);
- old_bitmap = prepare_bitmap_git(to_pack->repo);
+ old_bitmap = prepare_bitmap_git(writer->to_pack->repo);
if (old_bitmap)
- mapping = create_bitmap_mapping(old_bitmap, to_pack);
+ mapping = create_bitmap_mapping(old_bitmap, writer->to_pack);
else
mapping = NULL;
@@ -697,6 +694,9 @@ void bitmap_writer_select_commits(struct bitmap_writer *writer,
if (indexed_commits_nr < 100) {
for (i = 0; i < indexed_commits_nr; ++i)
bitmap_writer_push_commit(writer, indexed_commits[i], 0);
+
+ select_pseudo_merges(writer);
+
return;
}
@@ -737,7 +737,7 @@ void bitmap_writer_select_commits(struct bitmap_writer *writer,
stop_progress(&writer->progress);
- select_pseudo_merges(writer, indexed_commits, indexed_commits_nr);
+ select_pseudo_merges(writer);
}
@@ -1001,7 +1001,6 @@ void bitmap_writer_set_checksum(struct bitmap_writer *writer,
void bitmap_writer_finish(struct bitmap_writer *writer,
struct pack_idx_entry **index,
- uint32_t index_nr,
const char *filename,
uint16_t options)
{
@@ -1034,12 +1033,13 @@ void bitmap_writer_finish(struct bitmap_writer *writer,
dump_bitmap(f, writer->tags);
if (options & BITMAP_OPT_LOOKUP_TABLE)
- CALLOC_ARRAY(offsets, index_nr);
+ CALLOC_ARRAY(offsets, writer->to_pack->nr_objects);
for (i = 0; i < bitmap_writer_nr_selected_commits(writer); i++) {
struct bitmapped_commit *stored = &writer->selected[i];
int commit_pos = oid_pos(&stored->commit->object.oid, index,
- index_nr, oid_access);
+ writer->to_pack->nr_objects,
+ oid_access);
if (commit_pos < 0)
BUG(_("trying to write commit not in index"));
@@ -1055,7 +1055,7 @@ void bitmap_writer_finish(struct bitmap_writer *writer,
write_lookup_table(writer, f, offsets);
if (options & BITMAP_OPT_HASH_CACHE)
- write_hash_cache(f, index, index_nr);
+ write_hash_cache(f, index, writer->to_pack->nr_objects);
finalize_hashfile(f, NULL, FSYNC_COMPONENT_PACK_METADATA,
CSUM_HASH_IN_STREAM | CSUM_FSYNC | CSUM_CLOSE);
diff --git a/pack-bitmap.h b/pack-bitmap.h
index 1171e6d989..ff0fd815b8 100644
--- a/pack-bitmap.h
+++ b/pack-bitmap.h
@@ -123,14 +123,13 @@ struct bitmap_writer {
unsigned char pack_checksum[GIT_MAX_RAWSZ];
};
-void bitmap_writer_init(struct bitmap_writer *writer, struct repository *r);
+void bitmap_writer_init(struct bitmap_writer *writer, struct repository *r,
+ struct packing_data *pdata);
void bitmap_writer_show_progress(struct bitmap_writer *writer, int show);
void bitmap_writer_set_checksum(struct bitmap_writer *writer,
const unsigned char *sha1);
void bitmap_writer_build_type_index(struct bitmap_writer *writer,
- struct packing_data *to_pack,
- struct pack_idx_entry **index,
- uint32_t index_nr);
+ struct pack_idx_entry **index);
int bitmap_writer_has_bitmapped_object_id(struct bitmap_writer *writer,
const struct object_id *oid);
void bitmap_writer_push_commit(struct bitmap_writer *writer,
@@ -147,11 +146,9 @@ struct ewah_bitmap *pseudo_merge_bitmap_for_commit(struct bitmap_index *bitmap_g
void bitmap_writer_select_commits(struct bitmap_writer *writer,
struct commit **indexed_commits,
unsigned int indexed_commits_nr);
-int bitmap_writer_build(struct bitmap_writer *writer,
- struct packing_data *to_pack);
+int bitmap_writer_build(struct bitmap_writer *writer);
void bitmap_writer_finish(struct bitmap_writer *writer,
struct pack_idx_entry **index,
- uint32_t index_nr,
const char *filename,
uint16_t options);
void bitmap_writer_free(struct bitmap_writer *writer);
diff --git a/pager.c b/pager.c
index 896f40fcd2..9c24ce6263 100644
--- a/pager.c
+++ b/pager.c
@@ -234,6 +234,8 @@ int term_columns(void)
*/
void term_clear_line(void)
{
+ if (!isatty(2))
+ return;
if (is_terminal_dumb())
/*
* Fall back to print a terminal width worth of space
diff --git a/parallel-checkout.c b/parallel-checkout.c
index 08b960aac8..01736f1352 100644
--- a/parallel-checkout.c
+++ b/parallel-checkout.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "config.h"
#include "entry.h"
diff --git a/path.c b/path.c
index 19f7684f38..a3bf25b7de 100644
--- a/path.c
+++ b/path.c
@@ -2,8 +2,6 @@
* Utilities for paths and pathnames
*/
-#define USE_THE_REPOSITORY_VARIABLE
-
#include "git-compat-util.h"
#include "abspath.h"
#include "environment.h"
@@ -30,7 +28,7 @@ static int get_st_mode_bits(const char *path, int *mode)
return 0;
}
-static struct strbuf *get_pathname(void)
+struct strbuf *get_pathname(void)
{
static struct strbuf pathname_array[4] = {
STRBUF_INIT, STRBUF_INIT, STRBUF_INIT, STRBUF_INIT
@@ -365,15 +363,15 @@ static void update_common_dir(struct strbuf *buf, int git_dir_len,
strbuf_addstr(buf, LOCK_SUFFIX);
}
-void report_linked_checkout_garbage(void)
+void report_linked_checkout_garbage(struct repository *r)
{
struct strbuf sb = STRBUF_INIT;
const struct common_dir *p;
int len;
- if (!the_repository->different_commondir)
+ if (!r->different_commondir)
return;
- strbuf_addf(&sb, "%s/", get_git_dir());
+ strbuf_addf(&sb, "%s/", r->gitdir);
len = sb.len;
for (p = common_list; p->path; p++) {
const char *path = p->path;
@@ -417,9 +415,9 @@ static void strbuf_worktree_gitdir(struct strbuf *buf,
strbuf_git_common_path(buf, repo, "worktrees/%s", wt->id);
}
-static void do_git_path(const struct repository *repo,
- const struct worktree *wt, struct strbuf *buf,
- const char *fmt, va_list args)
+void repo_git_pathv(const struct repository *repo,
+ const struct worktree *wt, struct strbuf *buf,
+ const char *fmt, va_list args)
{
int gitdir_len;
strbuf_worktree_gitdir(buf, repo, wt);
@@ -438,7 +436,7 @@ char *repo_git_path(const struct repository *repo,
struct strbuf path = STRBUF_INIT;
va_list args;
va_start(args, fmt);
- do_git_path(repo, NULL, &path, fmt, args);
+ repo_git_pathv(repo, NULL, &path, fmt, args);
va_end(args);
return strbuf_detach(&path, NULL);
}
@@ -449,48 +447,10 @@ void strbuf_repo_git_path(struct strbuf *sb,
{
va_list args;
va_start(args, fmt);
- do_git_path(repo, NULL, sb, fmt, args);
- va_end(args);
-}
-
-char *git_path_buf(struct strbuf *buf, const char *fmt, ...)
-{
- va_list args;
- strbuf_reset(buf);
- va_start(args, fmt);
- do_git_path(the_repository, NULL, buf, fmt, args);
- va_end(args);
- return buf->buf;
-}
-
-void strbuf_git_path(struct strbuf *sb, const char *fmt, ...)
-{
- va_list args;
- va_start(args, fmt);
- do_git_path(the_repository, NULL, sb, fmt, args);
+ repo_git_pathv(repo, NULL, sb, fmt, args);
va_end(args);
}
-const char *git_path(const char *fmt, ...)
-{
- struct strbuf *pathname = get_pathname();
- va_list args;
- va_start(args, fmt);
- do_git_path(the_repository, NULL, pathname, fmt, args);
- va_end(args);
- return pathname->buf;
-}
-
-char *git_pathdup(const char *fmt, ...)
-{
- struct strbuf path = STRBUF_INIT;
- va_list args;
- va_start(args, fmt);
- do_git_path(the_repository, NULL, &path, fmt, args);
- va_end(args);
- return strbuf_detach(&path, NULL);
-}
-
char *mkpathdup(const char *fmt, ...)
{
struct strbuf sb = STRBUF_INIT;
@@ -512,12 +472,17 @@ const char *mkpath(const char *fmt, ...)
return cleanup_path(pathname->buf);
}
-const char *worktree_git_path(const struct worktree *wt, const char *fmt, ...)
+const char *worktree_git_path(struct repository *r,
+ const struct worktree *wt, const char *fmt, ...)
{
struct strbuf *pathname = get_pathname();
va_list args;
+
+ if (wt && wt->repo != r)
+ BUG("worktree not connected to expected repository");
+
va_start(args, fmt);
- do_git_path(the_repository, wt, pathname, fmt, args);
+ repo_git_pathv(r, wt, pathname, fmt, args);
va_end(args);
return pathname->buf;
}
@@ -617,26 +582,16 @@ int strbuf_git_path_submodule(struct strbuf *buf, const char *path,
return err;
}
-static void do_git_common_path(const struct repository *repo,
- struct strbuf *buf,
- const char *fmt,
- va_list args)
+void repo_common_pathv(const struct repository *repo,
+ struct strbuf *sb,
+ const char *fmt,
+ va_list args)
{
- strbuf_addstr(buf, repo->commondir);
- if (buf->len && !is_dir_sep(buf->buf[buf->len - 1]))
- strbuf_addch(buf, '/');
- strbuf_vaddf(buf, fmt, args);
- strbuf_cleanup_path(buf);
-}
-
-const char *git_common_path(const char *fmt, ...)
-{
- struct strbuf *pathname = get_pathname();
- va_list args;
- va_start(args, fmt);
- do_git_common_path(the_repository, pathname, fmt, args);
- va_end(args);
- return pathname->buf;
+ strbuf_addstr(sb, repo->commondir);
+ if (sb->len && !is_dir_sep(sb->buf[sb->len - 1]))
+ strbuf_addch(sb, '/');
+ strbuf_vaddf(sb, fmt, args);
+ strbuf_cleanup_path(sb);
}
void strbuf_git_common_path(struct strbuf *sb,
@@ -645,7 +600,7 @@ void strbuf_git_common_path(struct strbuf *sb,
{
va_list args;
va_start(args, fmt);
- do_git_common_path(repo, sb, fmt, args);
+ repo_common_pathv(repo, sb, fmt, args);
va_end(args);
}
diff --git a/path.h b/path.h
index a6f0b70692..e91d19fff6 100644
--- a/path.h
+++ b/path.h
@@ -25,7 +25,7 @@ char *mkpathdup(const char *fmt, ...)
__attribute__((format (printf, 1, 2)));
/*
- * The `git_common_path` family of functions will construct a path into a
+ * The `strbuf_git_common_path` family of functions will construct a path into a
* repository's common git directory, which is shared by all worktrees.
*/
@@ -37,17 +37,13 @@ void strbuf_git_common_path(struct strbuf *sb,
const struct repository *repo,
const char *fmt, ...)
__attribute__((format (printf, 3, 4)));
+void repo_common_pathv(const struct repository *repo,
+ struct strbuf *buf,
+ const char *fmt,
+ va_list args);
/*
- * Return a statically allocated path into the main repository's
- * (the_repository) common git directory.
- */
-const char *git_common_path(const char *fmt, ...)
- __attribute__((format (printf, 1, 2)));
-
-
-/*
- * The `git_path` family of functions will construct a path into a repository's
+ * The `repo_git_path` family of functions will construct a path into a repository's
* git directory.
*
* These functions will perform adjustments to the resultant path to account
@@ -67,6 +63,14 @@ char *repo_git_path(const struct repository *repo,
__attribute__((format (printf, 2, 3)));
/*
+ * Print a path into the git directory of repository `repo` into the provided
+ * buffer.
+ */
+void repo_git_pathv(const struct repository *repo,
+ const struct worktree *wt, struct strbuf *buf,
+ const char *fmt, va_list args);
+
+/*
* Construct a path into the git directory of repository `repo` and append it
* to the provided buffer `sb`.
*/
@@ -76,40 +80,14 @@ void strbuf_repo_git_path(struct strbuf *sb,
__attribute__((format (printf, 3, 4)));
/*
- * Return a statically allocated path into the main repository's
- * (the_repository) git directory.
- */
-const char *git_path(const char *fmt, ...)
- __attribute__((format (printf, 1, 2)));
-
-/*
- * Similar to git_path() but can produce paths for a specified
- * worktree instead of current one
+ * Similar to repo_git_path() but can produce paths for a specified
+ * worktree instead of current one. When no worktree is given, then the path is
+ * computed relative to main worktree of the given repository.
*/
-const char *worktree_git_path(const struct worktree *wt,
+const char *worktree_git_path(struct repository *r,
+ const struct worktree *wt,
const char *fmt, ...)
- __attribute__((format (printf, 2, 3)));
-
-/*
- * Return a path into the main repository's (the_repository) git directory.
- */
-char *git_pathdup(const char *fmt, ...)
- __attribute__((format (printf, 1, 2)));
-
-/*
- * Construct a path into the main repository's (the_repository) git directory
- * and place it in the provided buffer `buf`, the contents of the buffer will
- * be overridden.
- */
-char *git_path_buf(struct strbuf *buf, const char *fmt, ...)
- __attribute__((format (printf, 2, 3)));
-
-/*
- * Construct a path into the main repository's (the_repository) git directory
- * and append it to the provided buffer `sb`.
- */
-void strbuf_git_path(struct strbuf *sb, const char *fmt, ...)
- __attribute__((format (printf, 2, 3)));
+ __attribute__((format (printf, 3, 4)));
/*
* Return a path into the worktree of repository `repo`.
@@ -147,24 +125,15 @@ int strbuf_git_path_submodule(struct strbuf *sb, const char *path,
const char *fmt, ...)
__attribute__((format (printf, 3, 4)));
-void report_linked_checkout_garbage(void);
+void report_linked_checkout_garbage(struct repository *r);
/*
* You can define a static memoized git path like:
*
- * static GIT_PATH_FUNC(git_path_foo, "FOO")
+ * static REPO_GIT_PATH_FUNC(git_path_foo, "FOO")
*
* or use one of the global ones below.
*/
-#define GIT_PATH_FUNC(func, filename) \
- const char *func(void) \
- { \
- static char *ret; \
- if (!ret) \
- ret = git_pathdup(filename); \
- return ret; \
- }
-
#define REPO_GIT_PATH_FUNC(var, filename) \
const char *git_path_##var(struct repository *r) \
{ \
@@ -248,4 +217,99 @@ char *xdg_cache_home(const char *filename);
*/
void safe_create_dir(const char *dir, int share);
+/*
+ * Do not use this function. It is only exported to other subsystems until we
+ * can get rid of the below block of functions that implicitly rely on
+ * `the_repository`.
+ */
+struct strbuf *get_pathname(void);
+
+# ifdef USE_THE_REPOSITORY_VARIABLE
+# include "strbuf.h"
+# include "repository.h"
+
+/*
+ * Return a statically allocated path into the main repository's
+ * (the_repository) common git directory.
+ */
+__attribute__((format (printf, 1, 2)))
+static inline const char *git_common_path(const char *fmt, ...)
+{
+ struct strbuf *pathname = get_pathname();
+ va_list args;
+ va_start(args, fmt);
+ repo_common_pathv(the_repository, pathname, fmt, args);
+ va_end(args);
+ return pathname->buf;
+}
+
+/*
+ * Construct a path into the main repository's (the_repository) git directory
+ * and place it in the provided buffer `buf`, the contents of the buffer will
+ * be overridden.
+ */
+__attribute__((format (printf, 2, 3)))
+static inline char *git_path_buf(struct strbuf *buf, const char *fmt, ...)
+{
+ va_list args;
+ strbuf_reset(buf);
+ va_start(args, fmt);
+ repo_git_pathv(the_repository, NULL, buf, fmt, args);
+ va_end(args);
+ return buf->buf;
+}
+
+/*
+ * Construct a path into the main repository's (the_repository) git directory
+ * and append it to the provided buffer `sb`.
+ */
+__attribute__((format (printf, 2, 3)))
+static inline void strbuf_git_path(struct strbuf *sb, const char *fmt, ...)
+{
+ va_list args;
+ va_start(args, fmt);
+ repo_git_pathv(the_repository, NULL, sb, fmt, args);
+ va_end(args);
+}
+
+/*
+ * Return a statically allocated path into the main repository's
+ * (the_repository) git directory.
+ */
+__attribute__((format (printf, 1, 2)))
+static inline const char *git_path(const char *fmt, ...)
+{
+ struct strbuf *pathname = get_pathname();
+ va_list args;
+ va_start(args, fmt);
+ repo_git_pathv(the_repository, NULL, pathname, fmt, args);
+ va_end(args);
+ return pathname->buf;
+}
+
+#define GIT_PATH_FUNC(func, filename) \
+ const char *func(void) \
+ { \
+ static char *ret; \
+ if (!ret) \
+ ret = git_pathdup(filename); \
+ return ret; \
+ }
+
+/*
+ * Return a path into the main repository's (the_repository) git directory.
+ */
+__attribute__((format (printf, 1, 2)))
+static inline char *git_pathdup(const char *fmt, ...)
+{
+ struct strbuf path = STRBUF_INIT;
+ va_list args;
+ va_start(args, fmt);
+ repo_git_pathv(the_repository, NULL, &path, fmt, args);
+ va_end(args);
+ return strbuf_detach(&path, NULL);
+}
+
+# endif /* USE_THE_REPOSITORY_VARIABLE */
+
#endif /* PATH_H */
diff --git a/perl/Git/SVN.pm b/perl/Git/SVN.pm
index 7721708ce5..b0913ca1b6 100644
--- a/perl/Git/SVN.pm
+++ b/perl/Git/SVN.pm
@@ -763,7 +763,7 @@ sub prop_walk {
# this needs to be updated.
++$interesting_props if /^svn:(?:ignore|keywords|executable
|eol-style|mime-type
- |externals|needs-lock)$/x;
+ |externals|needs-lock|global-ignores)$/x;
}
&$sub($self, $p, $props) if $interesting_props;
diff --git a/protocol.c b/protocol.c
index 079ba75acf..bae7226ff4 100644
--- a/protocol.c
+++ b/protocol.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "config.h"
#include "environment.h"
diff --git a/pseudo-merge.c b/pseudo-merge.c
index 77a83b9c5c..10ebd9a4e9 100644
--- a/pseudo-merge.c
+++ b/pseudo-merge.c
@@ -183,11 +183,12 @@ done:
return ret;
}
-void load_pseudo_merges_from_config(struct string_list *list)
+void load_pseudo_merges_from_config(struct repository *r,
+ struct string_list *list)
{
struct string_list_item *item;
- git_config(pseudo_merge_config, list);
+ repo_config(r, pseudo_merge_config, list);
for_each_string_list_item(item, list) {
struct pseudo_merge_group *group = item->util;
@@ -218,6 +219,8 @@ static int find_pseudo_merge_group_for_ref(const char *refname,
c = lookup_commit(the_repository, oid);
if (!c)
return 0;
+ if (!packlist_find(writer->to_pack, oid))
+ return 0;
has_bitmap = bitmap_writer_has_bitmapped_object_id(writer, oid);
@@ -358,8 +361,10 @@ static void select_pseudo_merges_1(struct bitmap_writer *writer,
p = commit_list_append(c, p);
} while (j % group->stable_size);
- bitmap_writer_push_commit(writer, merge, 1);
- writer->pseudo_merges_nr++;
+ if (merge->parents) {
+ bitmap_writer_push_commit(writer, merge, 1);
+ writer->pseudo_merges_nr++;
+ }
}
/* make up to group->max_merges pseudo merges for unstable commits */
@@ -399,8 +404,9 @@ static void select_pseudo_merges_1(struct bitmap_writer *writer,
p = commit_list_append(c, p);
}
- bitmap_writer_push_commit(writer, merge, 1);
- writer->pseudo_merges_nr++;
+ if (merge->parents) {
+ bitmap_writer_push_commit(writer, merge, 1);
+ writer->pseudo_merges_nr++; }
if (end >= matches->unstable_nr)
break;
}
@@ -424,8 +430,7 @@ static void sort_pseudo_merge_matches(struct pseudo_merge_matches *matches)
QSORT(matches->unstable, matches->unstable_nr, commit_date_cmp);
}
-void select_pseudo_merges(struct bitmap_writer *writer,
- struct commit **commits, size_t commits_nr)
+void select_pseudo_merges(struct bitmap_writer *writer)
{
struct progress *progress = NULL;
uint32_t i;
diff --git a/pseudo-merge.h b/pseudo-merge.h
index 2aca01d056..4b5febaa63 100644
--- a/pseudo-merge.h
+++ b/pseudo-merge.h
@@ -10,6 +10,7 @@ struct commit;
struct string_list;
struct bitmap_index;
struct bitmap_writer;
+struct repository;
/*
* A pseudo-merge group tracks the set of non-bitmapped reference tips
@@ -72,7 +73,7 @@ struct pseudo_merge_matches {
* entry keys are the pseudo-merge group names, and the values are
* pointers to the pseudo_merge_group structure itself.
*/
-void load_pseudo_merges_from_config(struct string_list *list);
+void load_pseudo_merges_from_config(struct repository *r, struct string_list *list);
/*
* A pseudo-merge commit index (pseudo_merge_commit_idx) maps a
@@ -94,8 +95,7 @@ struct pseudo_merge_commit_idx {
*
* Optionally shows a progress meter.
*/
-void select_pseudo_merges(struct bitmap_writer *writer,
- struct commit **commits, size_t commits_nr);
+void select_pseudo_merges(struct bitmap_writer *writer);
/*
* Represents a serialized view of a file containing pseudo-merge(s)
diff --git a/range-diff.c b/range-diff.c
index 5f01605550..bbb0952264 100644
--- a/range-diff.c
+++ b/range-diff.c
@@ -450,8 +450,10 @@ static void output_pair_header(struct diff_options *diffopt,
}
static struct userdiff_driver section_headers = {
- .funcname = { "^ ## (.*) ##$\n"
- "^.?@@ (.*)$", REG_EXTENDED }
+ .funcname = {
+ .pattern = "^ ## (.*) ##$\n^.?@@ (.*)$",
+ .cflags = REG_EXTENDED,
+ },
};
static struct diff_filespec *get_filespec(const char *name, const char *p)
diff --git a/read-cache.c b/read-cache.c
index 1f67bb755b..4e67dc182e 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -1945,7 +1945,7 @@ static void tweak_untracked_cache(struct index_state *istate)
static void tweak_split_index(struct index_state *istate)
{
- switch (git_config_get_split_index()) {
+ switch (repo_config_get_split_index(the_repository)) {
case -1: /* unset: do nothing */
break;
case 0: /* false */
@@ -2267,7 +2267,7 @@ int do_read_index(struct index_state *istate, const char *path, int must_exist)
src_offset = sizeof(*hdr);
- if (git_config_get_index_threads(&nr_threads))
+ if (repo_config_get_index_threads(the_repository, &nr_threads))
nr_threads = 1;
/* TODO: does creating more threads than cores help? */
@@ -2787,7 +2787,7 @@ static int record_eoie(void)
* used for threading is written by default if the user
* explicitly requested threaded index reads.
*/
- return !git_config_get_index_threads(&val) && val != 1;
+ return !repo_config_get_index_threads(the_repository, &val) && val != 1;
}
static int record_ieot(void)
@@ -2802,7 +2802,7 @@ static int record_ieot(void)
* written by default if the user explicitly requested
* threaded index reads.
*/
- return !git_config_get_index_threads(&val) && val != 1;
+ return !repo_config_get_index_threads(the_repository, &val) && val != 1;
}
enum write_extensions {
@@ -2840,8 +2840,9 @@ static int do_write_index(struct index_state *istate, struct tempfile *tempfile,
int csum_fsync_flag;
int ieot_entries = 1;
struct index_entry_offset_table *ieot = NULL;
- int nr, nr_threads;
struct repository *r = istate->repo;
+ struct strbuf sb = STRBUF_INIT;
+ int nr, nr_threads, ret;
f = hashfd(tempfile->fd, tempfile->filename.buf);
@@ -2875,7 +2876,7 @@ static int do_write_index(struct index_state *istate, struct tempfile *tempfile,
hashwrite(f, &hdr, sizeof(hdr));
- if (!HAVE_THREADS || git_config_get_index_threads(&nr_threads))
+ if (!HAVE_THREADS || repo_config_get_index_threads(the_repository, &nr_threads))
nr_threads = 1;
if (nr_threads != 1 && record_ieot()) {
@@ -2962,8 +2963,8 @@ static int do_write_index(struct index_state *istate, struct tempfile *tempfile,
strbuf_release(&previous_name_buf);
if (err) {
- free(ieot);
- goto cleanup;
+ ret = err;
+ goto out;
}
offset = hashfile_total(f);
@@ -2985,26 +2986,20 @@ static int do_write_index(struct index_state *istate, struct tempfile *tempfile,
* index.
*/
if (ieot) {
- struct strbuf sb = STRBUF_INIT;
+ strbuf_reset(&sb);
write_ieot_extension(&sb, ieot);
err = write_index_ext_header(f, eoie_c, CACHE_EXT_INDEXENTRYOFFSETTABLE, sb.len) < 0;
hashwrite(f, sb.buf, sb.len);
- strbuf_release(&sb);
- free(ieot);
- /*
- * NEEDSWORK: write_index_ext_header() never returns a failure,
- * and this part may want to be simplified.
- */
if (err) {
- err = -1;
- goto cleanup;
+ ret = -1;
+ goto out;
}
}
if (write_extensions & WRITE_SPLIT_INDEX_EXTENSION &&
istate->split_index) {
- struct strbuf sb = STRBUF_INIT;
+ strbuf_reset(&sb);
if (istate->sparse_index)
die(_("cannot write split index for a sparse index"));
@@ -3013,95 +3008,65 @@ static int do_write_index(struct index_state *istate, struct tempfile *tempfile,
write_index_ext_header(f, eoie_c, CACHE_EXT_LINK,
sb.len) < 0;
hashwrite(f, sb.buf, sb.len);
- strbuf_release(&sb);
- /*
- * NEEDSWORK: write_link_extension() never returns a failure,
- * and this part may want to be simplified.
- */
if (err) {
- err = -1;
- goto cleanup;
+ ret = -1;
+ goto out;
}
}
if (write_extensions & WRITE_CACHE_TREE_EXTENSION &&
!drop_cache_tree && istate->cache_tree) {
- struct strbuf sb = STRBUF_INIT;
+ strbuf_reset(&sb);
cache_tree_write(&sb, istate->cache_tree);
err = write_index_ext_header(f, eoie_c, CACHE_EXT_TREE, sb.len) < 0;
hashwrite(f, sb.buf, sb.len);
- strbuf_release(&sb);
- /*
- * NEEDSWORK: write_index_ext_header() never returns a failure,
- * and this part may want to be simplified.
- */
if (err) {
- err = -1;
- goto cleanup;
+ ret = -1;
+ goto out;
}
}
if (write_extensions & WRITE_RESOLVE_UNDO_EXTENSION &&
istate->resolve_undo) {
- struct strbuf sb = STRBUF_INIT;
+ strbuf_reset(&sb);
resolve_undo_write(&sb, istate->resolve_undo);
err = write_index_ext_header(f, eoie_c, CACHE_EXT_RESOLVE_UNDO,
sb.len) < 0;
hashwrite(f, sb.buf, sb.len);
- strbuf_release(&sb);
- /*
- * NEEDSWORK: write_index_ext_header() never returns a failure,
- * and this part may want to be simplified.
- */
if (err) {
- err = -1;
- goto cleanup;
+ ret = -1;
+ goto out;
}
}
if (write_extensions & WRITE_UNTRACKED_CACHE_EXTENSION &&
istate->untracked) {
- struct strbuf sb = STRBUF_INIT;
+ strbuf_reset(&sb);
write_untracked_extension(&sb, istate->untracked);
err = write_index_ext_header(f, eoie_c, CACHE_EXT_UNTRACKED,
sb.len) < 0;
hashwrite(f, sb.buf, sb.len);
- strbuf_release(&sb);
- /*
- * NEEDSWORK: write_index_ext_header() never returns a failure,
- * and this part may want to be simplified.
- */
if (err) {
- err = -1;
- goto cleanup;
+ ret = -1;
+ goto out;
}
}
if (write_extensions & WRITE_FSMONITOR_EXTENSION &&
istate->fsmonitor_last_update) {
- struct strbuf sb = STRBUF_INIT;
+ strbuf_reset(&sb);
write_fsmonitor_extension(&sb, istate);
err = write_index_ext_header(f, eoie_c, CACHE_EXT_FSMONITOR, sb.len) < 0;
hashwrite(f, sb.buf, sb.len);
- strbuf_release(&sb);
- /*
- * NEEDSWORK: write_index_ext_header() never returns a failure,
- * and this part may want to be simplified.
- */
if (err) {
- err = -1;
- goto cleanup;
+ ret = -1;
+ goto out;
}
}
if (istate->sparse_index) {
- err = write_index_ext_header(f, eoie_c, CACHE_EXT_SPARSE_DIRECTORIES, 0);
- /*
- * NEEDSWORK: write_index_ext_header() never returns a failure,
- * and this part may want to be simplified.
- */
- if (err) {
- err = -1;
- goto cleanup;
+ if (write_index_ext_header(f, eoie_c, CACHE_EXT_SPARSE_DIRECTORIES, 0) < 0) {
+ ret = -1;
+ goto out;
}
}
@@ -3112,19 +3077,14 @@ static int do_write_index(struct index_state *istate, struct tempfile *tempfile,
* when loading the shared index.
*/
if (eoie_c) {
- struct strbuf sb = STRBUF_INIT;
+ strbuf_reset(&sb);
write_eoie_extension(&sb, eoie_c, offset);
err = write_index_ext_header(f, NULL, CACHE_EXT_ENDOFINDEXENTRIES, sb.len) < 0;
hashwrite(f, sb.buf, sb.len);
- strbuf_release(&sb);
- /*
- * NEEDSWORK: write_index_ext_header() never returns a failure,
- * and this part may want to be simplified.
- */
if (err) {
- err = -1;
- goto cleanup;
+ ret = -1;
+ goto out;
}
}
@@ -3137,12 +3097,12 @@ static int do_write_index(struct index_state *istate, struct tempfile *tempfile,
f = NULL;
if (close_tempfile_gently(tempfile)) {
- err = error(_("could not close '%s'"), get_tempfile_path(tempfile));
- goto cleanup;
+ ret = error(_("could not close '%s'"), get_tempfile_path(tempfile));
+ goto out;
}
if (stat(get_tempfile_path(tempfile), &st)) {
- err = error_errno(_("could not stat '%s'"), get_tempfile_path(tempfile));
- goto cleanup;
+ ret = -1;
+ goto out;
}
istate->timestamp.sec = (unsigned int)st.st_mtime;
istate->timestamp.nsec = ST_MTIME_NSEC(st);
@@ -3157,12 +3117,14 @@ static int do_write_index(struct index_state *istate, struct tempfile *tempfile,
trace2_data_intmax("index", the_repository, "write/cache_nr",
istate->cache_nr);
- return 0;
+ ret = 0;
-cleanup:
+out:
if (f)
- discard_hashfile(f);
- return err;
+ free_hashfile(f);
+ strbuf_release(&sb);
+ free(ieot);
+ return ret;
}
void set_alternate_index_output(const char *name)
@@ -3213,9 +3175,9 @@ static int do_write_locked_index(struct index_state *istate,
else
ret = close_lock_file_gently(lock);
- run_hooks_l("post-index-change",
- istate->updated_workdir ? "1" : "0",
- istate->updated_skipworktree ? "1" : "0", NULL);
+ run_hooks_l(the_repository, "post-index-change",
+ istate->updated_workdir ? "1" : "0",
+ istate->updated_skipworktree ? "1" : "0", NULL);
istate->updated_workdir = 0;
istate->updated_skipworktree = 0;
@@ -3233,18 +3195,24 @@ static int write_split_index(struct index_state *istate,
return ret;
}
-static const char *shared_index_expire = "2.weeks.ago";
-
static unsigned long get_shared_index_expire_date(void)
{
static unsigned long shared_index_expire_date;
static int shared_index_expire_date_prepared;
if (!shared_index_expire_date_prepared) {
- git_config_get_expiry("splitindex.sharedindexexpire",
- &shared_index_expire);
+ const char *shared_index_expire = "2.weeks.ago";
+ char *value = NULL;
+
+ repo_config_get_expiry(the_repository, "splitindex.sharedindexexpire",
+ &value);
+ if (value)
+ shared_index_expire = value;
+
shared_index_expire_date = approxidate(shared_index_expire);
shared_index_expire_date_prepared = 1;
+
+ free(value);
}
return shared_index_expire_date;
@@ -3332,7 +3300,7 @@ static const int default_max_percent_split_change = 20;
static int too_many_not_shared_entries(struct index_state *istate)
{
int i, not_shared = 0;
- int max_split = git_config_get_max_percent_split_change();
+ int max_split = repo_config_get_max_percent_split_change(the_repository);
switch (max_split) {
case -1:
diff --git a/ref-filter.c b/ref-filter.c
index 6d8b591930..b6c6c10127 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -169,6 +169,7 @@ enum atom_type {
ATOM_ELSE,
ATOM_REST,
ATOM_AHEADBEHIND,
+ ATOM_ISBASE,
};
/*
@@ -742,8 +743,7 @@ static int person_name_atom_parser(struct ref_format *format UNUSED,
return 0;
}
-static int email_atom_option_parser(struct used_atom *atom,
- const char **arg, struct strbuf *err)
+static int email_atom_option_parser(const char **arg)
{
if (!*arg)
return EO_RAW;
@@ -761,7 +761,7 @@ static int person_email_atom_parser(struct ref_format *format UNUSED,
const char *arg, struct strbuf *err)
{
for (;;) {
- int opt = email_atom_option_parser(atom, &arg, err);
+ int opt = email_atom_option_parser(&arg);
const char *bad_arg = arg;
if (opt < 0)
@@ -891,6 +891,23 @@ static int ahead_behind_atom_parser(struct ref_format *format,
return 0;
}
+static int is_base_atom_parser(struct ref_format *format,
+ struct used_atom *atom UNUSED,
+ const char *arg, struct strbuf *err)
+{
+ struct string_list_item *item;
+
+ if (!arg)
+ return strbuf_addf_ret(err, -1, _("expected format: %%(is-base:<committish>)"));
+
+ item = string_list_append(&format->is_base_tips, arg);
+ item->util = lookup_commit_reference_by_name(arg);
+ if (!item->util)
+ die("failed to find '%s'", arg);
+
+ return 0;
+}
+
static int head_atom_parser(struct ref_format *format UNUSED,
struct used_atom *atom,
const char *arg, struct strbuf *err)
@@ -956,6 +973,7 @@ static struct {
[ATOM_ELSE] = { "else", SOURCE_NONE },
[ATOM_REST] = { "rest", SOURCE_NONE, FIELD_STR, rest_atom_parser },
[ATOM_AHEADBEHIND] = { "ahead-behind", SOURCE_OTHER, FIELD_STR, ahead_behind_atom_parser },
+ [ATOM_ISBASE] = { "is-base", SOURCE_OTHER, FIELD_STR, is_base_atom_parser },
/*
* Please update $__git_ref_fieldlist in git-completion.bash
* when you add new atoms
@@ -2341,6 +2359,7 @@ static int populate_value(struct ref_array_item *ref, struct strbuf *err)
int i;
struct object_info empty = OBJECT_INFO_INIT;
int ahead_behind_atoms = 0;
+ int is_base_atoms = 0;
CALLOC_ARRAY(ref->value, used_atom_cnt);
@@ -2490,6 +2509,15 @@ static int populate_value(struct ref_array_item *ref, struct strbuf *err)
v->s = xstrdup("");
}
continue;
+ } else if (atom_type == ATOM_ISBASE) {
+ if (ref->is_base && ref->is_base[is_base_atoms]) {
+ v->s = xstrfmt("(%s)", ref->is_base[is_base_atoms]);
+ free(ref->is_base[is_base_atoms]);
+ } else {
+ v->s = xstrdup("");
+ }
+ is_base_atoms++;
+ continue;
} else
continue;
@@ -2896,6 +2924,7 @@ static void free_array_item(struct ref_array_item *item)
free(item->value);
}
free(item->counts);
+ free(item->is_base);
free(item);
}
@@ -3060,6 +3089,49 @@ void filter_ahead_behind(struct repository *r,
free(commits);
}
+void filter_is_base(struct repository *r,
+ struct ref_format *format,
+ struct ref_array *array)
+{
+ struct commit **bases;
+ size_t bases_nr = 0;
+ struct ref_array_item **back_index;
+
+ if (!format->is_base_tips.nr || !array->nr)
+ return;
+
+ CALLOC_ARRAY(back_index, array->nr);
+ CALLOC_ARRAY(bases, array->nr);
+
+ for (size_t i = 0; i < array->nr; i++) {
+ const char *name = array->items[i]->refname;
+ struct commit *c = lookup_commit_reference_by_name_gently(name, 1);
+
+ CALLOC_ARRAY(array->items[i]->is_base, format->is_base_tips.nr);
+
+ if (!c)
+ continue;
+
+ back_index[bases_nr] = array->items[i];
+ bases[bases_nr] = c;
+ bases_nr++;
+ }
+
+ for (size_t i = 0; i < format->is_base_tips.nr; i++) {
+ struct commit *tip = format->is_base_tips.items[i].util;
+ int base_index = get_branch_base_for_tip(r, tip, bases, bases_nr);
+
+ if (base_index < 0)
+ continue;
+
+ /* Store the string for use in output later. */
+ back_index[base_index]->is_base[i] = xstrdup(format->is_base_tips.items[i].string);
+ }
+
+ free(back_index);
+ free(bases);
+}
+
static int do_filter_refs(struct ref_filter *filter, unsigned int type, each_ref_fn fn, void *cb_data)
{
int ret = 0;
@@ -3153,7 +3225,8 @@ static inline int can_do_iterative_format(struct ref_filter *filter,
return !(filter->reachable_from ||
filter->unreachable_from ||
sorting ||
- format->bases.nr);
+ format->bases.nr ||
+ format->is_base_tips.nr);
}
void filter_and_format_refs(struct ref_filter *filter, unsigned int type,
@@ -3177,6 +3250,7 @@ void filter_and_format_refs(struct ref_filter *filter, unsigned int type,
struct ref_array array = { 0 };
filter_refs(&array, filter, type);
filter_ahead_behind(the_repository, format, &array);
+ filter_is_base(the_repository, format, &array);
ref_array_sort(sorting, &array);
print_formatted_ref_array(&array, format);
ref_array_clear(&array);
diff --git a/ref-filter.h b/ref-filter.h
index 27ae1aa0d1..e794b8a676 100644
--- a/ref-filter.h
+++ b/ref-filter.h
@@ -48,6 +48,7 @@ struct ref_array_item {
struct commit *commit;
struct atom_value *value;
struct ahead_behind_count **counts;
+ char **is_base;
char refname[FLEX_ARRAY];
};
@@ -101,6 +102,9 @@ struct ref_format {
/* List of bases for ahead-behind counts. */
struct string_list bases;
+ /* List of bases for is-base indicators. */
+ struct string_list is_base_tips;
+
struct {
int max_count;
int omit_empty;
@@ -114,6 +118,7 @@ struct ref_format {
#define REF_FORMAT_INIT { \
.use_color = -1, \
.bases = STRING_LIST_INIT_DUP, \
+ .is_base_tips = STRING_LIST_INIT_DUP, \
}
/* Macros for checking --merged and --no-merged options */
@@ -203,6 +208,16 @@ void filter_ahead_behind(struct repository *r,
struct ref_format *format,
struct ref_array *array);
+/*
+ * If the provided format includes is-base atoms, then compute the base checks
+ * for those tips against all refs.
+ *
+ * If this is not called, then any is-base atoms will be blank.
+ */
+void filter_is_base(struct repository *r,
+ struct ref_format *format,
+ struct ref_array *array);
+
void ref_filter_init(struct ref_filter *filter);
void ref_filter_clear(struct ref_filter *filter);
diff --git a/refs.c b/refs.c
index 74de3d3009..ceb72d4bd7 100644
--- a/refs.c
+++ b/refs.c
@@ -2,6 +2,8 @@
* The backend-independent part of the reference module.
*/
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "advice.h"
#include "config.h"
@@ -2137,7 +2139,7 @@ static int run_transaction_hook(struct ref_transaction *transaction,
const char *hook;
int ret = 0, i;
- hook = find_hook("reference-transaction");
+ hook = find_hook(transaction->ref_store->repo, "reference-transaction");
if (!hook)
return ret;
@@ -2390,9 +2392,10 @@ struct do_for_each_reflog_help {
void *cb_data;
};
-static int do_for_each_reflog_helper(const char *refname, const char *referent,
+static int do_for_each_reflog_helper(const char *refname,
+ const char *referent UNUSED,
const struct object_id *oid UNUSED,
- int flags,
+ int flags UNUSED,
void *cb_data)
{
struct do_for_each_reflog_help *hp = cb_data;
diff --git a/refs/files-backend.c b/refs/files-backend.c
index 8d6ec9458d..1cff65f6ae 100644
--- a/refs/files-backend.c
+++ b/refs/files-backend.c
@@ -1961,9 +1961,8 @@ static int create_ref_symlink(struct ref_lock *lock, const char *target)
return ret;
}
-static int create_symref_lock(struct files_ref_store *refs,
- struct ref_lock *lock, const char *refname,
- const char *target, struct strbuf *err)
+static int create_symref_lock(struct ref_lock *lock, const char *target,
+ struct strbuf *err)
{
if (!fdopen_lock_file(&lock->lk, "w")) {
strbuf_addf(err, "unable to fdopen %s: %s",
@@ -2579,8 +2578,7 @@ static int lock_ref_for_update(struct files_ref_store *refs,
}
if (update->new_target && !(update->flags & REF_LOG_ONLY)) {
- if (create_symref_lock(refs, lock, update->refname,
- update->new_target, err)) {
+ if (create_symref_lock(lock, update->new_target, err)) {
ret = TRANSACTION_GENERIC_ERROR;
goto out;
}
diff --git a/refs/packed-backend.c b/refs/packed-backend.c
index f00106df14..7a0a695ca2 100644
--- a/refs/packed-backend.c
+++ b/refs/packed-backend.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "../git-compat-util.h"
#include "../config.h"
#include "../dir.h"
@@ -1733,8 +1735,8 @@ static struct ref_iterator *packed_reflog_iterator_begin(struct ref_store *ref_s
return empty_ref_iterator_begin();
}
-static int packed_fsck(struct ref_store *ref_store,
- struct fsck_options *o)
+static int packed_fsck(struct ref_store *ref_store UNUSED,
+ struct fsck_options *o UNUSED)
{
return 0;
}
diff --git a/refs/reftable-backend.c b/refs/reftable-backend.c
index 8b7ffbf66f..1c4b19e737 100644
--- a/refs/reftable-backend.c
+++ b/refs/reftable-backend.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "../git-compat-util.h"
#include "../abspath.h"
#include "../chdir-notify.h"
@@ -614,7 +616,7 @@ done:
static struct ref_iterator *reftable_be_iterator_begin(struct ref_store *ref_store,
const char *prefix,
- const char **exclude_patterns,
+ const char **exclude_patterns UNUSED,
unsigned int flags)
{
struct reftable_ref_iterator *main_iter, *worktree_iter;
@@ -1123,9 +1125,9 @@ done:
return ret;
}
-static int reftable_be_transaction_abort(struct ref_store *ref_store,
+static int reftable_be_transaction_abort(struct ref_store *ref_store UNUSED,
struct ref_transaction *transaction,
- struct strbuf *err)
+ struct strbuf *err UNUSED)
{
struct reftable_transaction_data *tx_data = transaction->backend_data;
free_transaction_data(tx_data);
@@ -1315,7 +1317,7 @@ done:
return ret;
}
-static int reftable_be_transaction_finish(struct ref_store *ref_store,
+static int reftable_be_transaction_finish(struct ref_store *ref_store UNUSED,
struct ref_transaction *transaction,
struct strbuf *err)
{
@@ -1726,8 +1728,8 @@ static int reftable_reflog_iterator_advance(struct ref_iterator *ref_iterator)
return ITER_OK;
}
-static int reftable_reflog_iterator_peel(struct ref_iterator *ref_iterator,
- struct object_id *peeled)
+static int reftable_reflog_iterator_peel(struct ref_iterator *ref_iterator UNUSED,
+ struct object_id *peeled UNUSED)
{
BUG("reftable reflog iterator cannot be peeled");
return -1;
@@ -1988,7 +1990,7 @@ done:
static int reftable_be_create_reflog(struct ref_store *ref_store,
const char *refname,
- struct strbuf *errmsg)
+ struct strbuf *errmsg UNUSED)
{
struct reftable_ref_store *refs =
reftable_be_downcast(ref_store, REF_STORE_WRITE, "create_reflog");
@@ -2309,8 +2311,8 @@ done:
return ret;
}
-static int reftable_be_fsck(struct ref_store *ref_store,
- struct fsck_options *o)
+static int reftable_be_fsck(struct ref_store *ref_store UNUSED,
+ struct fsck_options *o UNUSED)
{
return 0;
}
diff --git a/reftable/blocksource.c b/reftable/blocksource.c
index eeed254ba9..abce4bb2e1 100644
--- a/reftable/blocksource.c
+++ b/reftable/blocksource.c
@@ -13,14 +13,14 @@ https://developers.google.com/open-source/licenses/bsd
#include "reftable-blocksource.h"
#include "reftable-error.h"
-static void strbuf_return_block(void *b, struct reftable_block *dest)
+static void strbuf_return_block(void *b UNUSED, struct reftable_block *dest)
{
if (dest->len)
memset(dest->data, 0xff, dest->len);
reftable_free(dest->data);
}
-static void strbuf_close(void *b)
+static void strbuf_close(void *b UNUSED)
{
}
@@ -55,7 +55,7 @@ void block_source_from_strbuf(struct reftable_block_source *bs,
bs->arg = buf;
}
-static void malloc_return_block(void *b, struct reftable_block *dest)
+static void malloc_return_block(void *b UNUSED, struct reftable_block *dest)
{
if (dest->len)
memset(dest->data, 0xff, dest->len);
@@ -85,7 +85,7 @@ static uint64_t file_size(void *b)
return ((struct file_block_source *)b)->size;
}
-static void file_return_block(void *b, struct reftable_block *dest)
+static void file_return_block(void *b UNUSED, struct reftable_block *dest UNUSED)
{
}
diff --git a/reftable/dump.c b/reftable/dump.c
deleted file mode 100644
index dd65d9e8bb..0000000000
--- a/reftable/dump.c
+++ /dev/null
@@ -1,111 +0,0 @@
-/*
-Copyright 2020 Google LLC
-
-Use of this source code is governed by a BSD-style
-license that can be found in the LICENSE file or at
-https://developers.google.com/open-source/licenses/bsd
-*/
-
-#include "git-compat-util.h"
-#include "hash.h"
-
-#include "reftable-blocksource.h"
-#include "reftable-error.h"
-#include "reftable-record.h"
-#include "reftable-tests.h"
-#include "reftable-writer.h"
-#include "reftable-iterator.h"
-#include "reftable-reader.h"
-#include "reftable-stack.h"
-
-#include <stddef.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-
-static int compact_stack(const char *stackdir)
-{
- struct reftable_stack *stack = NULL;
- struct reftable_write_options opts = { 0 };
-
- int err = reftable_new_stack(&stack, stackdir, &opts);
- if (err < 0)
- goto done;
-
- err = reftable_stack_compact_all(stack, NULL);
- if (err < 0)
- goto done;
-done:
- if (stack) {
- reftable_stack_destroy(stack);
- }
- return err;
-}
-
-static void print_help(void)
-{
- printf("usage: dump [-cst] arg\n\n"
- "options: \n"
- " -c compact\n"
- " -b dump blocks\n"
- " -t dump table\n"
- " -s dump stack\n"
- " -6 sha256 hash format\n"
- " -h this help\n"
- "\n");
-}
-
-int reftable_dump_main(int argc, char *const *argv)
-{
- int err = 0;
- int opt_dump_blocks = 0;
- int opt_dump_table = 0;
- int opt_dump_stack = 0;
- int opt_compact = 0;
- uint32_t opt_hash_id = GIT_SHA1_FORMAT_ID;
- const char *arg = NULL, *argv0 = argv[0];
-
- for (; argc > 1; argv++, argc--)
- if (*argv[1] != '-')
- break;
- else if (!strcmp("-b", argv[1]))
- opt_dump_blocks = 1;
- else if (!strcmp("-t", argv[1]))
- opt_dump_table = 1;
- else if (!strcmp("-6", argv[1]))
- opt_hash_id = GIT_SHA256_FORMAT_ID;
- else if (!strcmp("-s", argv[1]))
- opt_dump_stack = 1;
- else if (!strcmp("-c", argv[1]))
- opt_compact = 1;
- else if (!strcmp("-?", argv[1]) || !strcmp("-h", argv[1])) {
- print_help();
- return 2;
- }
-
- if (argc != 2) {
- fprintf(stderr, "need argument\n");
- print_help();
- return 2;
- }
-
- arg = argv[1];
-
- if (opt_dump_blocks) {
- err = reftable_reader_print_blocks(arg);
- } else if (opt_dump_table) {
- err = reftable_reader_print_file(arg);
- } else if (opt_dump_stack) {
- err = reftable_stack_print_directory(arg, opt_hash_id);
- } else if (opt_compact) {
- err = compact_stack(arg);
- }
-
- if (err < 0) {
- fprintf(stderr, "%s: %s: %s\n", argv0, arg,
- reftable_error_str(err));
- return 1;
- }
- return 0;
-}
diff --git a/reftable/generic.c b/reftable/generic.c
deleted file mode 100644
index 28ae26145e..0000000000
--- a/reftable/generic.c
+++ /dev/null
@@ -1,229 +0,0 @@
-/*
-Copyright 2020 Google LLC
-
-Use of this source code is governed by a BSD-style
-license that can be found in the LICENSE file or at
-https://developers.google.com/open-source/licenses/bsd
-*/
-
-#include "constants.h"
-#include "record.h"
-#include "generic.h"
-#include "reftable-iterator.h"
-#include "reftable-generic.h"
-
-void table_init_iter(struct reftable_table *tab,
- struct reftable_iterator *it,
- uint8_t typ)
-{
-
- tab->ops->init_iter(tab->table_arg, it, typ);
-}
-
-void reftable_table_init_ref_iter(struct reftable_table *tab,
- struct reftable_iterator *it)
-{
- table_init_iter(tab, it, BLOCK_TYPE_REF);
-}
-
-void reftable_table_init_log_iter(struct reftable_table *tab,
- struct reftable_iterator *it)
-{
- table_init_iter(tab, it, BLOCK_TYPE_LOG);
-}
-
-int reftable_iterator_seek_ref(struct reftable_iterator *it,
- const char *name)
-{
- struct reftable_record want = {
- .type = BLOCK_TYPE_REF,
- .u.ref = {
- .refname = (char *)name,
- },
- };
- return it->ops->seek(it->iter_arg, &want);
-}
-
-int reftable_iterator_seek_log_at(struct reftable_iterator *it,
- const char *name, uint64_t update_index)
-{
- struct reftable_record want = {
- .type = BLOCK_TYPE_LOG,
- .u.log = {
- .refname = (char *)name,
- .update_index = update_index,
- },
- };
- return it->ops->seek(it->iter_arg, &want);
-}
-
-int reftable_iterator_seek_log(struct reftable_iterator *it,
- const char *name)
-{
- return reftable_iterator_seek_log_at(it, name, ~((uint64_t) 0));
-}
-
-int reftable_table_read_ref(struct reftable_table *tab, const char *name,
- struct reftable_ref_record *ref)
-{
- struct reftable_iterator it = { NULL };
- int err;
-
- reftable_table_init_ref_iter(tab, &it);
-
- err = reftable_iterator_seek_ref(&it, name);
- if (err)
- goto done;
-
- err = reftable_iterator_next_ref(&it, ref);
- if (err)
- goto done;
-
- if (strcmp(ref->refname, name) ||
- reftable_ref_record_is_deletion(ref)) {
- reftable_ref_record_release(ref);
- err = 1;
- goto done;
- }
-
-done:
- reftable_iterator_destroy(&it);
- return err;
-}
-
-int reftable_table_print(struct reftable_table *tab) {
- struct reftable_iterator it = { NULL };
- struct reftable_ref_record ref = { NULL };
- struct reftable_log_record log = { NULL };
- uint32_t hash_id = reftable_table_hash_id(tab);
- int err;
-
- reftable_table_init_ref_iter(tab, &it);
-
- err = reftable_iterator_seek_ref(&it, "");
- if (err < 0)
- return err;
-
- while (1) {
- err = reftable_iterator_next_ref(&it, &ref);
- if (err > 0) {
- break;
- }
- if (err < 0) {
- return err;
- }
- reftable_ref_record_print(&ref, hash_id);
- }
- reftable_iterator_destroy(&it);
- reftable_ref_record_release(&ref);
-
- reftable_table_init_log_iter(tab, &it);
-
- err = reftable_iterator_seek_log(&it, "");
- if (err < 0)
- return err;
-
- while (1) {
- err = reftable_iterator_next_log(&it, &log);
- if (err > 0) {
- break;
- }
- if (err < 0) {
- return err;
- }
- reftable_log_record_print(&log, hash_id);
- }
- reftable_iterator_destroy(&it);
- reftable_log_record_release(&log);
- return 0;
-}
-
-uint64_t reftable_table_max_update_index(struct reftable_table *tab)
-{
- return tab->ops->max_update_index(tab->table_arg);
-}
-
-uint64_t reftable_table_min_update_index(struct reftable_table *tab)
-{
- return tab->ops->min_update_index(tab->table_arg);
-}
-
-uint32_t reftable_table_hash_id(struct reftable_table *tab)
-{
- return tab->ops->hash_id(tab->table_arg);
-}
-
-void reftable_iterator_destroy(struct reftable_iterator *it)
-{
- if (!it->ops) {
- return;
- }
- it->ops->close(it->iter_arg);
- it->ops = NULL;
- FREE_AND_NULL(it->iter_arg);
-}
-
-int reftable_iterator_next_ref(struct reftable_iterator *it,
- struct reftable_ref_record *ref)
-{
- struct reftable_record rec = {
- .type = BLOCK_TYPE_REF,
- .u = {
- .ref = *ref
- },
- };
- int err = iterator_next(it, &rec);
- *ref = rec.u.ref;
- return err;
-}
-
-int reftable_iterator_next_log(struct reftable_iterator *it,
- struct reftable_log_record *log)
-{
- struct reftable_record rec = {
- .type = BLOCK_TYPE_LOG,
- .u = {
- .log = *log,
- },
- };
- int err = iterator_next(it, &rec);
- *log = rec.u.log;
- return err;
-}
-
-int iterator_seek(struct reftable_iterator *it, struct reftable_record *want)
-{
- return it->ops->seek(it->iter_arg, want);
-}
-
-int iterator_next(struct reftable_iterator *it, struct reftable_record *rec)
-{
- return it->ops->next(it->iter_arg, rec);
-}
-
-static int empty_iterator_seek(void *arg, struct reftable_record *want)
-{
- return 0;
-}
-
-static int empty_iterator_next(void *arg, struct reftable_record *rec)
-{
- return 1;
-}
-
-static void empty_iterator_close(void *arg)
-{
-}
-
-static struct reftable_iterator_vtable empty_vtable = {
- .seek = &empty_iterator_seek,
- .next = &empty_iterator_next,
- .close = &empty_iterator_close,
-};
-
-void iterator_set_empty(struct reftable_iterator *it)
-{
- assert(!it->ops);
- it->iter_arg = NULL;
- it->ops = &empty_vtable;
-}
diff --git a/reftable/generic.h b/reftable/generic.h
deleted file mode 100644
index 8341fa570e..0000000000
--- a/reftable/generic.h
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
-Copyright 2020 Google LLC
-
-Use of this source code is governed by a BSD-style
-license that can be found in the LICENSE file or at
-https://developers.google.com/open-source/licenses/bsd
-*/
-
-#ifndef GENERIC_H
-#define GENERIC_H
-
-#include "record.h"
-#include "reftable-generic.h"
-
-/* generic interface to reftables */
-struct reftable_table_vtable {
- void (*init_iter)(void *tab, struct reftable_iterator *it, uint8_t typ);
- uint32_t (*hash_id)(void *tab);
- uint64_t (*min_update_index)(void *tab);
- uint64_t (*max_update_index)(void *tab);
-};
-
-void table_init_iter(struct reftable_table *tab,
- struct reftable_iterator *it,
- uint8_t typ);
-
-struct reftable_iterator_vtable {
- int (*seek)(void *iter_arg, struct reftable_record *want);
- int (*next)(void *iter_arg, struct reftable_record *rec);
- void (*close)(void *iter_arg);
-};
-
-void iterator_set_empty(struct reftable_iterator *it);
-int iterator_seek(struct reftable_iterator *it, struct reftable_record *want);
-int iterator_next(struct reftable_iterator *it, struct reftable_record *rec);
-
-#endif
diff --git a/reftable/iter.c b/reftable/iter.c
index fddea31e51..416a9f6996 100644
--- a/reftable/iter.c
+++ b/reftable/iter.c
@@ -11,11 +11,47 @@ https://developers.google.com/open-source/licenses/bsd
#include "system.h"
#include "block.h"
-#include "generic.h"
#include "constants.h"
#include "reader.h"
#include "reftable-error.h"
+int iterator_seek(struct reftable_iterator *it, struct reftable_record *want)
+{
+ return it->ops->seek(it->iter_arg, want);
+}
+
+int iterator_next(struct reftable_iterator *it, struct reftable_record *rec)
+{
+ return it->ops->next(it->iter_arg, rec);
+}
+
+static int empty_iterator_seek(void *arg UNUSED, struct reftable_record *want UNUSED)
+{
+ return 0;
+}
+
+static int empty_iterator_next(void *arg UNUSED, struct reftable_record *rec UNUSED)
+{
+ return 1;
+}
+
+static void empty_iterator_close(void *arg UNUSED)
+{
+}
+
+static struct reftable_iterator_vtable empty_vtable = {
+ .seek = &empty_iterator_seek,
+ .next = &empty_iterator_next,
+ .close = &empty_iterator_close,
+};
+
+void iterator_set_empty(struct reftable_iterator *it)
+{
+ assert(!it->ops);
+ it->iter_arg = NULL;
+ it->ops = &empty_vtable;
+}
+
static void filtering_ref_iterator_close(void *iter_arg)
{
struct filtering_ref_iterator *fri = iter_arg;
@@ -42,26 +78,6 @@ static int filtering_ref_iterator_next(void *iter_arg,
break;
}
- if (fri->double_check) {
- struct reftable_iterator it = { NULL };
-
- reftable_table_init_ref_iter(&fri->tab, &it);
-
- err = reftable_iterator_seek_ref(&it, ref->refname);
- if (err == 0)
- err = reftable_iterator_next_ref(&it, ref);
-
- reftable_iterator_destroy(&it);
-
- if (err < 0) {
- break;
- }
-
- if (err > 0) {
- continue;
- }
- }
-
if (ref->value_type == REFTABLE_REF_VAL2 &&
(!memcmp(fri->oid.buf, ref->value.val2.target_value,
fri->oid.len) ||
@@ -127,7 +143,8 @@ static int indexed_table_ref_iter_next_block(struct indexed_table_ref_iter *it)
return 0;
}
-static int indexed_table_ref_iter_seek(void *p, struct reftable_record *want)
+static int indexed_table_ref_iter_seek(void *p UNUSED,
+ struct reftable_record *want UNUSED)
{
BUG("seeking indexed table is not supported");
return -1;
@@ -201,3 +218,71 @@ void iterator_from_indexed_table_ref_iter(struct reftable_iterator *it,
it->iter_arg = itr;
it->ops = &indexed_table_ref_iter_vtable;
}
+
+void reftable_iterator_destroy(struct reftable_iterator *it)
+{
+ if (!it->ops)
+ return;
+ it->ops->close(it->iter_arg);
+ it->ops = NULL;
+ FREE_AND_NULL(it->iter_arg);
+}
+
+int reftable_iterator_seek_ref(struct reftable_iterator *it,
+ const char *name)
+{
+ struct reftable_record want = {
+ .type = BLOCK_TYPE_REF,
+ .u.ref = {
+ .refname = (char *)name,
+ },
+ };
+ return it->ops->seek(it->iter_arg, &want);
+}
+
+int reftable_iterator_next_ref(struct reftable_iterator *it,
+ struct reftable_ref_record *ref)
+{
+ struct reftable_record rec = {
+ .type = BLOCK_TYPE_REF,
+ .u = {
+ .ref = *ref
+ },
+ };
+ int err = iterator_next(it, &rec);
+ *ref = rec.u.ref;
+ return err;
+}
+
+int reftable_iterator_seek_log_at(struct reftable_iterator *it,
+ const char *name, uint64_t update_index)
+{
+ struct reftable_record want = {
+ .type = BLOCK_TYPE_LOG,
+ .u.log = {
+ .refname = (char *)name,
+ .update_index = update_index,
+ },
+ };
+ return it->ops->seek(it->iter_arg, &want);
+}
+
+int reftable_iterator_seek_log(struct reftable_iterator *it,
+ const char *name)
+{
+ return reftable_iterator_seek_log_at(it, name, ~((uint64_t) 0));
+}
+
+int reftable_iterator_next_log(struct reftable_iterator *it,
+ struct reftable_log_record *log)
+{
+ struct reftable_record rec = {
+ .type = BLOCK_TYPE_LOG,
+ .u = {
+ .log = *log,
+ },
+ };
+ int err = iterator_next(it, &rec);
+ *log = rec.u.log;
+ return err;
+}
diff --git a/reftable/iter.h b/reftable/iter.h
index 537431baba..befc4597df 100644
--- a/reftable/iter.h
+++ b/reftable/iter.h
@@ -14,12 +14,36 @@ https://developers.google.com/open-source/licenses/bsd
#include "record.h"
#include "reftable-iterator.h"
-#include "reftable-generic.h"
+
+/*
+ * The virtual function table for implementing generic reftable iterators.
+ */
+struct reftable_iterator_vtable {
+ int (*seek)(void *iter_arg, struct reftable_record *want);
+ int (*next)(void *iter_arg, struct reftable_record *rec);
+ void (*close)(void *iter_arg);
+};
+
+/*
+ * Position the iterator at the wanted record such that a call to
+ * `iterator_next()` would return that record, if it exists.
+ */
+int iterator_seek(struct reftable_iterator *it, struct reftable_record *want);
+
+/*
+ * Yield the next record and advance the iterator. Returns <0 on error, 0 when
+ * a record was yielded, and >0 when the iterator hit an error.
+ */
+int iterator_next(struct reftable_iterator *it, struct reftable_record *rec);
+
+/*
+ * Set up the iterator such that it behaves the same as an iterator with no
+ * entries.
+ */
+void iterator_set_empty(struct reftable_iterator *it);
/* iterator that produces only ref records that point to `oid` */
struct filtering_ref_iterator {
- int double_check;
- struct reftable_table tab;
struct strbuf oid;
struct reftable_iterator it;
};
diff --git a/reftable/merged.c b/reftable/merged.c
index 6adce44f4b..128a810c55 100644
--- a/reftable/merged.c
+++ b/reftable/merged.c
@@ -11,8 +11,8 @@ https://developers.google.com/open-source/licenses/bsd
#include "constants.h"
#include "iter.h"
#include "pq.h"
+#include "reader.h"
#include "record.h"
-#include "generic.h"
#include "reftable-merged.h"
#include "reftable-error.h"
#include "system.h"
@@ -25,7 +25,7 @@ struct merged_subiter {
struct merged_iter {
struct merged_subiter *subiters;
struct merged_iter_pqueue pq;
- size_t stack_len;
+ size_t subiters_len;
int suppress_deletions;
ssize_t advance_index;
};
@@ -38,12 +38,12 @@ static void merged_iter_init(struct merged_iter *mi,
mi->advance_index = -1;
mi->suppress_deletions = mt->suppress_deletions;
- REFTABLE_CALLOC_ARRAY(mi->subiters, mt->stack_len);
- for (size_t i = 0; i < mt->stack_len; i++) {
+ REFTABLE_CALLOC_ARRAY(mi->subiters, mt->readers_len);
+ for (size_t i = 0; i < mt->readers_len; i++) {
reftable_record_init(&mi->subiters[i].rec, typ);
- table_init_iter(&mt->stack[i], &mi->subiters[i].iter, typ);
+ reader_init_iter(mt->readers[i], &mi->subiters[i].iter, typ);
}
- mi->stack_len = mt->stack_len;
+ mi->subiters_len = mt->readers_len;
}
static void merged_iter_close(void *p)
@@ -51,7 +51,7 @@ static void merged_iter_close(void *p)
struct merged_iter *mi = p;
merged_iter_pqueue_release(&mi->pq);
- for (size_t i = 0; i < mi->stack_len; i++) {
+ for (size_t i = 0; i < mi->subiters_len; i++) {
reftable_iterator_destroy(&mi->subiters[i].iter);
reftable_record_release(&mi->subiters[i].rec);
}
@@ -80,7 +80,7 @@ static int merged_iter_seek(struct merged_iter *mi, struct reftable_record *want
mi->advance_index = -1;
- for (size_t i = 0; i < mi->stack_len; i++) {
+ for (size_t i = 0; i < mi->subiters_len; i++) {
err = iterator_seek(&mi->subiters[i].iter, want);
if (err < 0)
return err;
@@ -192,8 +192,8 @@ static void iterator_from_merged_iter(struct reftable_iterator *it,
it->ops = &merged_iter_vtable;
}
-int reftable_new_merged_table(struct reftable_merged_table **dest,
- struct reftable_table *stack, size_t n,
+int reftable_merged_table_new(struct reftable_merged_table **dest,
+ struct reftable_reader **readers, size_t n,
uint32_t hash_id)
{
struct reftable_merged_table *m = NULL;
@@ -201,10 +201,10 @@ int reftable_new_merged_table(struct reftable_merged_table **dest,
uint64_t first_min = 0;
for (size_t i = 0; i < n; i++) {
- uint64_t min = reftable_table_min_update_index(&stack[i]);
- uint64_t max = reftable_table_max_update_index(&stack[i]);
+ uint64_t min = reftable_reader_min_update_index(readers[i]);
+ uint64_t max = reftable_reader_max_update_index(readers[i]);
- if (reftable_table_hash_id(&stack[i]) != hash_id) {
+ if (reftable_reader_hash_id(readers[i]) != hash_id) {
return REFTABLE_FORMAT_ERROR;
}
if (i == 0 || min < first_min) {
@@ -216,8 +216,8 @@ int reftable_new_merged_table(struct reftable_merged_table **dest,
}
REFTABLE_CALLOC_ARRAY(m, 1);
- m->stack = stack;
- m->stack_len = n;
+ m->readers = readers;
+ m->readers_len = n;
m->min = first_min;
m->max = last_max;
m->hash_id = hash_id;
@@ -229,7 +229,6 @@ void reftable_merged_table_free(struct reftable_merged_table *mt)
{
if (!mt)
return;
- FREE_AND_NULL(mt->stack);
reftable_free(mt);
}
@@ -254,44 +253,19 @@ void merged_table_init_iter(struct reftable_merged_table *mt,
iterator_from_merged_iter(it, mi);
}
-uint32_t reftable_merged_table_hash_id(struct reftable_merged_table *mt)
-{
- return mt->hash_id;
-}
-
-static void reftable_merged_table_init_iter_void(void *tab,
- struct reftable_iterator *it,
- uint8_t typ)
-{
- merged_table_init_iter(tab, it, typ);
-}
-
-static uint32_t reftable_merged_table_hash_id_void(void *tab)
+void reftable_merged_table_init_ref_iterator(struct reftable_merged_table *mt,
+ struct reftable_iterator *it)
{
- return reftable_merged_table_hash_id(tab);
+ merged_table_init_iter(mt, it, BLOCK_TYPE_REF);
}
-static uint64_t reftable_merged_table_min_update_index_void(void *tab)
+void reftable_merged_table_init_log_iterator(struct reftable_merged_table *mt,
+ struct reftable_iterator *it)
{
- return reftable_merged_table_min_update_index(tab);
+ merged_table_init_iter(mt, it, BLOCK_TYPE_LOG);
}
-static uint64_t reftable_merged_table_max_update_index_void(void *tab)
-{
- return reftable_merged_table_max_update_index(tab);
-}
-
-static struct reftable_table_vtable merged_table_vtable = {
- .init_iter = reftable_merged_table_init_iter_void,
- .hash_id = reftable_merged_table_hash_id_void,
- .min_update_index = reftable_merged_table_min_update_index_void,
- .max_update_index = reftable_merged_table_max_update_index_void,
-};
-
-void reftable_table_from_merged_table(struct reftable_table *tab,
- struct reftable_merged_table *merged)
+uint32_t reftable_merged_table_hash_id(struct reftable_merged_table *mt)
{
- assert(!tab->ops);
- tab->ops = &merged_table_vtable;
- tab->table_arg = merged;
+ return mt->hash_id;
}
diff --git a/reftable/merged.h b/reftable/merged.h
index 2efe571da6..de5fd33f01 100644
--- a/reftable/merged.h
+++ b/reftable/merged.h
@@ -12,8 +12,8 @@ https://developers.google.com/open-source/licenses/bsd
#include "system.h"
struct reftable_merged_table {
- struct reftable_table *stack;
- size_t stack_len;
+ struct reftable_reader **readers;
+ size_t readers_len;
uint32_t hash_id;
/* If unset, produce deletions. This is useful for compaction. For the
diff --git a/reftable/reader.c b/reftable/reader.c
index 29c99e2269..082cf00b60 100644
--- a/reftable/reader.c
+++ b/reftable/reader.c
@@ -11,11 +11,9 @@ https://developers.google.com/open-source/licenses/bsd
#include "system.h"
#include "block.h"
#include "constants.h"
-#include "generic.h"
#include "iter.h"
#include "record.h"
#include "reftable-error.h"
-#include "reftable-generic.h"
uint64_t block_source_size(struct reftable_block_source *source)
{
@@ -605,9 +603,9 @@ static void iterator_from_table_iter(struct reftable_iterator *it,
it->ops = &table_iter_vtable;
}
-static void reader_init_iter(struct reftable_reader *r,
- struct reftable_iterator *it,
- uint8_t typ)
+void reader_init_iter(struct reftable_reader *r,
+ struct reftable_iterator *it,
+ uint8_t typ)
{
struct reftable_reader_offsets *offs = reader_offsets_for(r, typ);
@@ -735,8 +733,6 @@ static int reftable_reader_refs_for_unindexed(struct reftable_reader *r,
*filter = empty;
strbuf_add(&filter->oid, oid, oid_len);
- reftable_table_from_reader(&filter->tab, r);
- filter->double_check = 0;
iterator_from_table_iter(&filter->it, ti);
iterator_from_filtering_ref_iterator(it, filter);
@@ -761,66 +757,6 @@ uint64_t reftable_reader_min_update_index(struct reftable_reader *r)
return r->min_update_index;
}
-/* generic table interface. */
-
-static void reftable_reader_init_iter_void(void *tab,
- struct reftable_iterator *it,
- uint8_t typ)
-{
- reader_init_iter(tab, it, typ);
-}
-
-static uint32_t reftable_reader_hash_id_void(void *tab)
-{
- return reftable_reader_hash_id(tab);
-}
-
-static uint64_t reftable_reader_min_update_index_void(void *tab)
-{
- return reftable_reader_min_update_index(tab);
-}
-
-static uint64_t reftable_reader_max_update_index_void(void *tab)
-{
- return reftable_reader_max_update_index(tab);
-}
-
-static struct reftable_table_vtable reader_vtable = {
- .init_iter = reftable_reader_init_iter_void,
- .hash_id = reftable_reader_hash_id_void,
- .min_update_index = reftable_reader_min_update_index_void,
- .max_update_index = reftable_reader_max_update_index_void,
-};
-
-void reftable_table_from_reader(struct reftable_table *tab,
- struct reftable_reader *reader)
-{
- assert(!tab->ops);
- tab->ops = &reader_vtable;
- tab->table_arg = reader;
-}
-
-
-int reftable_reader_print_file(const char *tablename)
-{
- struct reftable_block_source src = { NULL };
- int err = reftable_block_source_from_file(&src, tablename);
- struct reftable_reader *r = NULL;
- struct reftable_table tab = { NULL };
- if (err < 0)
- goto done;
-
- err = reftable_new_reader(&r, &src, tablename);
- if (err < 0)
- goto done;
-
- reftable_table_from_reader(&tab, r);
- err = reftable_table_print(&tab);
-done:
- reftable_reader_free(r);
- return err;
-}
-
int reftable_reader_print_blocks(const char *tablename)
{
struct {
diff --git a/reftable/reader.h b/reftable/reader.h
index e869165f23..a2c204d523 100644
--- a/reftable/reader.h
+++ b/reftable/reader.h
@@ -57,6 +57,10 @@ int init_reader(struct reftable_reader *r, struct reftable_block_source *source,
void reader_close(struct reftable_reader *r);
const char *reader_name(struct reftable_reader *r);
+void reader_init_iter(struct reftable_reader *r,
+ struct reftable_iterator *it,
+ uint8_t typ);
+
/* initialize a block reader to read from `r` */
int reader_init_block_reader(struct reftable_reader *r, struct block_reader *br,
uint64_t next_off, uint8_t want_typ);
diff --git a/reftable/record.c b/reftable/record.c
index a2cba5ef74..6b5a075b92 100644
--- a/reftable/record.c
+++ b/reftable/record.c
@@ -259,58 +259,6 @@ static void reftable_ref_record_copy_from(void *rec, const void *src_rec,
}
}
-static char hexdigit(int c)
-{
- if (c <= 9)
- return '0' + c;
- return 'a' + (c - 10);
-}
-
-static void hex_format(char *dest, const unsigned char *src, int hash_size)
-{
- assert(hash_size > 0);
- if (src) {
- int i = 0;
- for (i = 0; i < hash_size; i++) {
- dest[2 * i] = hexdigit(src[i] >> 4);
- dest[2 * i + 1] = hexdigit(src[i] & 0xf);
- }
- dest[2 * hash_size] = 0;
- }
-}
-
-static void reftable_ref_record_print_sz(const struct reftable_ref_record *ref,
- int hash_size)
-{
- char hex[GIT_MAX_HEXSZ + 1] = { 0 }; /* BUG */
- printf("ref{%s(%" PRIu64 ") ", ref->refname, ref->update_index);
- switch (ref->value_type) {
- case REFTABLE_REF_SYMREF:
- printf("=> %s", ref->value.symref);
- break;
- case REFTABLE_REF_VAL2:
- hex_format(hex, ref->value.val2.value, hash_size);
- printf("val 2 %s", hex);
- hex_format(hex, ref->value.val2.target_value,
- hash_size);
- printf("(T %s)", hex);
- break;
- case REFTABLE_REF_VAL1:
- hex_format(hex, ref->value.val1, hash_size);
- printf("val 1 %s", hex);
- break;
- case REFTABLE_REF_DELETION:
- printf("delete");
- break;
- }
- printf("}\n");
-}
-
-void reftable_ref_record_print(const struct reftable_ref_record *ref,
- uint32_t hash_id) {
- reftable_ref_record_print_sz(ref, hash_size(hash_id));
-}
-
static void reftable_ref_record_release_void(void *rec)
{
reftable_ref_record_release(rec);
@@ -480,12 +428,6 @@ static int reftable_ref_record_cmp_void(const void *_a, const void *_b)
return strcmp(a->refname, b->refname);
}
-static void reftable_ref_record_print_void(const void *rec,
- int hash_size)
-{
- reftable_ref_record_print_sz((struct reftable_ref_record *) rec, hash_size);
-}
-
static struct reftable_record_vtable reftable_ref_record_vtable = {
.key = &reftable_ref_record_key,
.type = BLOCK_TYPE_REF,
@@ -497,7 +439,6 @@ static struct reftable_record_vtable reftable_ref_record_vtable = {
.is_deletion = &reftable_ref_record_is_deletion_void,
.equal = &reftable_ref_record_equal_void,
.cmp = &reftable_ref_record_cmp_void,
- .print = &reftable_ref_record_print_void,
};
static void reftable_obj_record_key(const void *r, struct strbuf *dest)
@@ -516,23 +457,8 @@ static void reftable_obj_record_release(void *rec)
memset(obj, 0, sizeof(struct reftable_obj_record));
}
-static void reftable_obj_record_print(const void *rec, int hash_size)
-{
- const struct reftable_obj_record *obj = rec;
- char hex[GIT_MAX_HEXSZ + 1] = { 0 };
- struct strbuf offset_str = STRBUF_INIT;
- int i;
-
- for (i = 0; i < obj->offset_len; i++)
- strbuf_addf(&offset_str, "%" PRIu64 " ", obj->offsets[i]);
- hex_format(hex, obj->hash_prefix, obj->hash_prefix_len);
- printf("prefix %s (len %d), offsets [%s]\n",
- hex, obj->hash_prefix_len, offset_str.buf);
- strbuf_release(&offset_str);
-}
-
static void reftable_obj_record_copy_from(void *rec, const void *src_rec,
- int hash_size)
+ int hash_size UNUSED)
{
struct reftable_obj_record *obj = rec;
const struct reftable_obj_record *src =
@@ -559,7 +485,7 @@ static uint8_t reftable_obj_record_val_type(const void *rec)
}
static int reftable_obj_record_encode(const void *rec, struct string_view s,
- int hash_size)
+ int hash_size UNUSED)
{
const struct reftable_obj_record *r = rec;
struct string_view start = s;
@@ -594,7 +520,8 @@ static int reftable_obj_record_encode(const void *rec, struct string_view s,
static int reftable_obj_record_decode(void *rec, struct strbuf key,
uint8_t val_type, struct string_view in,
- int hash_size, struct strbuf *scratch UNUSED)
+ int hash_size UNUSED,
+ struct strbuf *scratch UNUSED)
{
struct string_view start = in;
struct reftable_obj_record *r = rec;
@@ -647,12 +574,13 @@ static int reftable_obj_record_decode(void *rec, struct strbuf key,
return start.len - in.len;
}
-static int not_a_deletion(const void *p)
+static int not_a_deletion(const void *p UNUSED)
{
return 0;
}
-static int reftable_obj_record_equal_void(const void *a, const void *b, int hash_size)
+static int reftable_obj_record_equal_void(const void *a, const void *b,
+ int hash_size UNUSED)
{
struct reftable_obj_record *ra = (struct reftable_obj_record *) a;
struct reftable_obj_record *rb = (struct reftable_obj_record *) b;
@@ -701,41 +629,8 @@ static struct reftable_record_vtable reftable_obj_record_vtable = {
.is_deletion = &not_a_deletion,
.equal = &reftable_obj_record_equal_void,
.cmp = &reftable_obj_record_cmp_void,
- .print = &reftable_obj_record_print,
};
-static void reftable_log_record_print_sz(struct reftable_log_record *log,
- int hash_size)
-{
- char hex[GIT_MAX_HEXSZ + 1] = { 0 };
-
- switch (log->value_type) {
- case REFTABLE_LOG_DELETION:
- printf("log{%s(%" PRIu64 ") delete\n", log->refname,
- log->update_index);
- break;
- case REFTABLE_LOG_UPDATE:
- printf("log{%s(%" PRIu64 ") %s <%s> %" PRIu64 " %04d\n",
- log->refname, log->update_index,
- log->value.update.name ? log->value.update.name : "",
- log->value.update.email ? log->value.update.email : "",
- log->value.update.time,
- log->value.update.tz_offset);
- hex_format(hex, log->value.update.old_hash, hash_size);
- printf("%s => ", hex);
- hex_format(hex, log->value.update.new_hash, hash_size);
- printf("%s\n\n%s\n}\n", hex,
- log->value.update.message ? log->value.update.message : "");
- break;
- }
-}
-
-void reftable_log_record_print(struct reftable_log_record *log,
- uint32_t hash_id)
-{
- reftable_log_record_print_sz(log, hash_size(hash_id));
-}
-
static void reftable_log_record_key(const void *r, struct strbuf *dest)
{
const struct reftable_log_record *rec =
@@ -1039,11 +934,6 @@ static int reftable_log_record_is_deletion_void(const void *p)
(const struct reftable_log_record *)p);
}
-static void reftable_log_record_print_void(const void *rec, int hash_size)
-{
- reftable_log_record_print_sz((struct reftable_log_record*)rec, hash_size);
-}
-
static struct reftable_record_vtable reftable_log_record_vtable = {
.key = &reftable_log_record_key,
.type = BLOCK_TYPE_LOG,
@@ -1055,7 +945,6 @@ static struct reftable_record_vtable reftable_log_record_vtable = {
.is_deletion = &reftable_log_record_is_deletion_void,
.equal = &reftable_log_record_equal_void,
.cmp = &reftable_log_record_cmp_void,
- .print = &reftable_log_record_print_void,
};
static void reftable_index_record_key(const void *r, struct strbuf *dest)
@@ -1066,7 +955,7 @@ static void reftable_index_record_key(const void *r, struct strbuf *dest)
}
static void reftable_index_record_copy_from(void *rec, const void *src_rec,
- int hash_size)
+ int hash_size UNUSED)
{
struct reftable_index_record *dst = rec;
const struct reftable_index_record *src = src_rec;
@@ -1082,13 +971,13 @@ static void reftable_index_record_release(void *rec)
strbuf_release(&idx->last_key);
}
-static uint8_t reftable_index_record_val_type(const void *rec)
+static uint8_t reftable_index_record_val_type(const void *rec UNUSED)
{
return 0;
}
static int reftable_index_record_encode(const void *rec, struct string_view out,
- int hash_size)
+ int hash_size UNUSED)
{
const struct reftable_index_record *r =
(const struct reftable_index_record *)rec;
@@ -1104,8 +993,10 @@ static int reftable_index_record_encode(const void *rec, struct string_view out,
}
static int reftable_index_record_decode(void *rec, struct strbuf key,
- uint8_t val_type, struct string_view in,
- int hash_size, struct strbuf *scratch UNUSED)
+ uint8_t val_type UNUSED,
+ struct string_view in,
+ int hash_size UNUSED,
+ struct strbuf *scratch UNUSED)
{
struct string_view start = in;
struct reftable_index_record *r = rec;
@@ -1122,7 +1013,8 @@ static int reftable_index_record_decode(void *rec, struct strbuf key,
return start.len - in.len;
}
-static int reftable_index_record_equal(const void *a, const void *b, int hash_size)
+static int reftable_index_record_equal(const void *a, const void *b,
+ int hash_size UNUSED)
{
struct reftable_index_record *ia = (struct reftable_index_record *) a;
struct reftable_index_record *ib = (struct reftable_index_record *) b;
@@ -1137,13 +1029,6 @@ static int reftable_index_record_cmp(const void *_a, const void *_b)
return strbuf_cmp(&a->last_key, &b->last_key);
}
-static void reftable_index_record_print(const void *rec, int hash_size)
-{
- const struct reftable_index_record *idx = rec;
- /* TODO: escape null chars? */
- printf("\"%s\" %" PRIu64 "\n", idx->last_key.buf, idx->offset);
-}
-
static struct reftable_record_vtable reftable_index_record_vtable = {
.key = &reftable_index_record_key,
.type = BLOCK_TYPE_INDEX,
@@ -1155,7 +1040,6 @@ static struct reftable_record_vtable reftable_index_record_vtable = {
.is_deletion = &not_a_deletion,
.equal = &reftable_index_record_equal,
.cmp = &reftable_index_record_cmp,
- .print = &reftable_index_record_print,
};
void reftable_record_key(struct reftable_record *rec, struct strbuf *dest)
@@ -1334,9 +1218,3 @@ void reftable_record_init(struct reftable_record *rec, uint8_t typ)
BUG("unhandled record type");
}
}
-
-void reftable_record_print(struct reftable_record *rec, int hash_size)
-{
- printf("'%c': ", rec->type);
- reftable_record_vtable(rec)->print(reftable_record_data(rec), hash_size);
-}
diff --git a/reftable/record.h b/reftable/record.h
index d778133e6e..5003bacdb0 100644
--- a/reftable/record.h
+++ b/reftable/record.h
@@ -136,7 +136,6 @@ void reftable_record_init(struct reftable_record *rec, uint8_t typ);
/* see struct record_vtable */
int reftable_record_cmp(struct reftable_record *a, struct reftable_record *b);
int reftable_record_equal(struct reftable_record *a, struct reftable_record *b, int hash_size);
-void reftable_record_print(struct reftable_record *rec, int hash_size);
void reftable_record_key(struct reftable_record *rec, struct strbuf *dest);
void reftable_record_copy_from(struct reftable_record *rec,
struct reftable_record *src, int hash_size);
diff --git a/reftable/reftable-generic.h b/reftable/reftable-generic.h
deleted file mode 100644
index 65670ea093..0000000000
--- a/reftable/reftable-generic.h
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
-Copyright 2020 Google LLC
-
-Use of this source code is governed by a BSD-style
-license that can be found in the LICENSE file or at
-https://developers.google.com/open-source/licenses/bsd
-*/
-
-#ifndef REFTABLE_GENERIC_H
-#define REFTABLE_GENERIC_H
-
-#include "reftable-iterator.h"
-
-struct reftable_table_vtable;
-
-/*
- * Provides a unified API for reading tables, either merged tables, or single
- * readers. */
-struct reftable_table {
- struct reftable_table_vtable *ops;
- void *table_arg;
-};
-
-void reftable_table_init_ref_iter(struct reftable_table *tab,
- struct reftable_iterator *it);
-
-void reftable_table_init_log_iter(struct reftable_table *tab,
- struct reftable_iterator *it);
-
-/* returns the hash ID from a generic reftable_table */
-uint32_t reftable_table_hash_id(struct reftable_table *tab);
-
-/* returns the max update_index covered by this table. */
-uint64_t reftable_table_max_update_index(struct reftable_table *tab);
-
-/* returns the min update_index covered by this table. */
-uint64_t reftable_table_min_update_index(struct reftable_table *tab);
-
-/* convenience function to read a single ref. Returns < 0 for error, 0
- for success, and 1 if ref not found. */
-int reftable_table_read_ref(struct reftable_table *tab, const char *name,
- struct reftable_ref_record *ref);
-
-/* dump table contents onto stdout for debugging */
-int reftable_table_print(struct reftable_table *tab);
-
-#endif
diff --git a/reftable/reftable-merged.h b/reftable/reftable-merged.h
index 14d5fc9f05..16d19f8df2 100644
--- a/reftable/reftable-merged.h
+++ b/reftable/reftable-merged.h
@@ -26,16 +26,24 @@ https://developers.google.com/open-source/licenses/bsd
/* A merged table is implements seeking/iterating over a stack of tables. */
struct reftable_merged_table;
-/* A generic reftable; see below. */
-struct reftable_table;
+struct reftable_reader;
-/* reftable_new_merged_table creates a new merged table. It takes ownership of
- the stack array.
-*/
-int reftable_new_merged_table(struct reftable_merged_table **dest,
- struct reftable_table *stack, size_t n,
+/*
+ * reftable_merged_table_new creates a new merged table. The readers must be
+ * kept alive as long as the merged table is still in use.
+ */
+int reftable_merged_table_new(struct reftable_merged_table **dest,
+ struct reftable_reader **readers, size_t n,
uint32_t hash_id);
+/* Initialize a merged table iterator for reading refs. */
+void reftable_merged_table_init_ref_iterator(struct reftable_merged_table *mt,
+ struct reftable_iterator *it);
+
+/* Initialize a merged table iterator for reading logs. */
+void reftable_merged_table_init_log_iterator(struct reftable_merged_table *mt,
+ struct reftable_iterator *it);
+
/* returns the max update_index covered by this merged table. */
uint64_t
reftable_merged_table_max_update_index(struct reftable_merged_table *mt);
@@ -50,8 +58,4 @@ void reftable_merged_table_free(struct reftable_merged_table *m);
/* return the hash ID of the merged table. */
uint32_t reftable_merged_table_hash_id(struct reftable_merged_table *m);
-/* create a generic table from reftable_merged_table */
-void reftable_table_from_merged_table(struct reftable_table *tab,
- struct reftable_merged_table *table);
-
#endif
diff --git a/reftable/reftable-reader.h b/reftable/reftable-reader.h
index a32f31d648..69621c5b0f 100644
--- a/reftable/reftable-reader.h
+++ b/reftable/reftable-reader.h
@@ -23,9 +23,6 @@
/* The reader struct is a handle to an open reftable file. */
struct reftable_reader;
-/* Generic table. */
-struct reftable_table;
-
/* reftable_new_reader opens a reftable for reading. If successful,
* returns 0 code and sets pp. The name is used for creating a
* stack. Typically, it is the basename of the file. The block source
@@ -60,12 +57,6 @@ uint64_t reftable_reader_max_update_index(struct reftable_reader *r);
/* return the min_update_index for a table */
uint64_t reftable_reader_min_update_index(struct reftable_reader *r);
-/* creates a generic table from a file reader. */
-void reftable_table_from_reader(struct reftable_table *tab,
- struct reftable_reader *reader);
-
-/* print table onto stdout for debugging. */
-int reftable_reader_print_file(const char *tablename);
/* print blocks onto stdout for debugging. */
int reftable_reader_print_blocks(const char *tablename);
diff --git a/reftable/reftable-record.h b/reftable/reftable-record.h
index ff486eb1f7..2d42463c58 100644
--- a/reftable/reftable-record.h
+++ b/reftable/reftable-record.h
@@ -60,10 +60,6 @@ const unsigned char *reftable_ref_record_val2(const struct reftable_ref_record *
/* returns whether 'ref' represents a deletion */
int reftable_ref_record_is_deletion(const struct reftable_ref_record *ref);
-/* prints a reftable_ref_record onto stdout. Useful for debugging. */
-void reftable_ref_record_print(const struct reftable_ref_record *ref,
- uint32_t hash_id);
-
/* frees and nulls all pointer values inside `ref`. */
void reftable_ref_record_release(struct reftable_ref_record *ref);
@@ -111,8 +107,4 @@ void reftable_log_record_release(struct reftable_log_record *log);
int reftable_log_record_equal(const struct reftable_log_record *a,
const struct reftable_log_record *b, int hash_size);
-/* dumps a reftable_log_record on stdout, for debugging/testing. */
-void reftable_log_record_print(struct reftable_log_record *log,
- uint32_t hash_id);
-
#endif
diff --git a/reftable/reftable-stack.h b/reftable/reftable-stack.h
index 09e97c9991..f4f8cabc7f 100644
--- a/reftable/reftable-stack.h
+++ b/reftable/reftable-stack.h
@@ -140,7 +140,4 @@ struct reftable_compaction_stats {
struct reftable_compaction_stats *
reftable_stack_compaction_stats(struct reftable_stack *st);
-/* print the entire stack represented by the directory */
-int reftable_stack_print_directory(const char *stackdir, uint32_t hash_id);
-
#endif
diff --git a/reftable/reftable-tests.h b/reftable/reftable-tests.h
index 3d9118b91b..5d725c69c7 100644
--- a/reftable/reftable-tests.h
+++ b/reftable/reftable-tests.h
@@ -9,10 +9,6 @@ https://developers.google.com/open-source/licenses/bsd
#ifndef REFTABLE_TESTS_H
#define REFTABLE_TESTS_H
-int basics_test_main(int argc, const char **argv);
-int record_test_main(int argc, const char **argv);
-int readwrite_test_main(int argc, const char **argv);
int stack_test_main(int argc, const char **argv);
-int reftable_dump_main(int argc, char *const *argv);
#endif
diff --git a/reftable/stack.c b/reftable/stack.c
index 2071e428a8..d3a95d2f1d 100644
--- a/reftable/stack.c
+++ b/reftable/stack.c
@@ -14,7 +14,6 @@ https://developers.google.com/open-source/licenses/bsd
#include "merged.h"
#include "reader.h"
#include "reftable-error.h"
-#include "reftable-generic.h"
#include "reftable-record.h"
#include "reftable-merged.h"
#include "writer.h"
@@ -225,13 +224,11 @@ static int reftable_stack_reload_once(struct reftable_stack *st,
const char **names,
int reuse_open)
{
- size_t cur_len = !st->merged ? 0 : st->merged->stack_len;
+ size_t cur_len = !st->merged ? 0 : st->merged->readers_len;
struct reftable_reader **cur = stack_copy_readers(st, cur_len);
size_t names_len = names_length(names);
struct reftable_reader **new_readers =
reftable_calloc(names_len, sizeof(*new_readers));
- struct reftable_table *new_tables =
- reftable_calloc(names_len, sizeof(*new_tables));
size_t new_readers_len = 0;
struct reftable_merged_table *new_merged = NULL;
struct strbuf table_path = STRBUF_INIT;
@@ -267,17 +264,15 @@ static int reftable_stack_reload_once(struct reftable_stack *st,
}
new_readers[new_readers_len] = rd;
- reftable_table_from_reader(&new_tables[new_readers_len], rd);
new_readers_len++;
}
/* success! */
- err = reftable_new_merged_table(&new_merged, new_tables,
+ err = reftable_merged_table_new(&new_merged, new_readers,
new_readers_len, st->opts.hash_id);
if (err < 0)
goto done;
- new_tables = NULL;
st->readers_len = new_readers_len;
if (st->merged)
reftable_merged_table_free(st->merged);
@@ -309,7 +304,6 @@ done:
reftable_reader_free(new_readers[i]);
}
reftable_free(new_readers);
- reftable_free(new_tables);
reftable_free(cur);
strbuf_release(&table_path);
return err;
@@ -520,7 +514,7 @@ static int stack_uptodate(struct reftable_stack *st)
}
}
- if (names[st->merged->stack_len]) {
+ if (names[st->merged->readers_len]) {
err = 1;
goto done;
}
@@ -659,7 +653,7 @@ int reftable_addition_commit(struct reftable_addition *add)
if (add->new_tables_len == 0)
goto done;
- for (i = 0; i < add->stack->merged->stack_len; i++) {
+ for (i = 0; i < add->stack->merged->readers_len; i++) {
strbuf_addstr(&table_list, add->stack->readers[i]->name);
strbuf_addstr(&table_list, "\n");
}
@@ -839,7 +833,7 @@ done:
uint64_t reftable_stack_next_update_index(struct reftable_stack *st)
{
- int sz = st->merged->stack_len;
+ int sz = st->merged->readers_len;
if (sz > 0)
return reftable_reader_max_update_index(st->readers[sz - 1]) +
1;
@@ -906,30 +900,23 @@ static int stack_write_compact(struct reftable_stack *st,
size_t first, size_t last,
struct reftable_log_expiry_config *config)
{
- size_t subtabs_len = last - first + 1;
- struct reftable_table *subtabs = reftable_calloc(
- last - first + 1, sizeof(*subtabs));
struct reftable_merged_table *mt = NULL;
struct reftable_iterator it = { NULL };
struct reftable_ref_record ref = { NULL };
struct reftable_log_record log = { NULL };
+ size_t subtabs_len = last - first + 1;
uint64_t entries = 0;
int err = 0;
- for (size_t i = first, j = 0; i <= last; i++) {
- struct reftable_reader *t = st->readers[i];
- reftable_table_from_reader(&subtabs[j++], t);
- st->stats.bytes += t->size;
- }
+ for (size_t i = first; i <= last; i++)
+ st->stats.bytes += st->readers[i]->size;
reftable_writer_set_limits(wr, st->readers[first]->min_update_index,
st->readers[last]->max_update_index);
- err = reftable_new_merged_table(&mt, subtabs, subtabs_len,
+ err = reftable_merged_table_new(&mt, st->readers + first, subtabs_len,
st->opts.hash_id);
- if (err < 0) {
- reftable_free(subtabs);
+ if (err < 0)
goto done;
- }
merged_table_init_iter(mt, &it, BLOCK_TYPE_REF);
err = reftable_iterator_seek_ref(&it, "");
@@ -1207,7 +1194,7 @@ static int stack_compact_range(struct reftable_stack *st,
* have compacted them.
*/
for (size_t j = 1; j < last - first + 1; j++) {
- const char *old = first + j < st->merged->stack_len ?
+ const char *old = first + j < st->merged->readers_len ?
st->readers[first + j]->name : NULL;
const char *new = names[i + j];
@@ -1248,10 +1235,10 @@ static int stack_compact_range(struct reftable_stack *st,
* `fd_read_lines()` uses a `NULL` sentinel to indicate that
* the array is at its end. As we use `free_names()` to free
* the array, we need to include this sentinel value here and
- * thus have to allocate `stack_len + 1` many entries.
+ * thus have to allocate `readers_len + 1` many entries.
*/
- REFTABLE_CALLOC_ARRAY(names, st->merged->stack_len + 1);
- for (size_t i = 0; i < st->merged->stack_len; i++)
+ REFTABLE_CALLOC_ARRAY(names, st->merged->readers_len + 1);
+ for (size_t i = 0; i < st->merged->readers_len; i++)
names[i] = xstrdup(st->readers[i]->name);
first_to_replace = first;
last_to_replace = last;
@@ -1358,7 +1345,7 @@ static int stack_compact_range_stats(struct reftable_stack *st,
int reftable_stack_compact_all(struct reftable_stack *st,
struct reftable_log_expiry_config *config)
{
- size_t last = st->merged->stack_len ? st->merged->stack_len - 1 : 0;
+ size_t last = st->merged->readers_len ? st->merged->readers_len - 1 : 0;
return stack_compact_range_stats(st, 0, last, config, 0);
}
@@ -1449,9 +1436,9 @@ static uint64_t *stack_table_sizes_for_compaction(struct reftable_stack *st)
int overhead = header_size(version) - 1;
uint64_t *sizes;
- REFTABLE_CALLOC_ARRAY(sizes, st->merged->stack_len);
+ REFTABLE_CALLOC_ARRAY(sizes, st->merged->readers_len);
- for (size_t i = 0; i < st->merged->stack_len; i++)
+ for (size_t i = 0; i < st->merged->readers_len; i++)
sizes[i] = st->readers[i]->size - overhead;
return sizes;
@@ -1461,7 +1448,7 @@ int reftable_stack_auto_compact(struct reftable_stack *st)
{
uint64_t *sizes = stack_table_sizes_for_compaction(st);
struct segment seg =
- suggest_compaction_segment(sizes, st->merged->stack_len,
+ suggest_compaction_segment(sizes, st->merged->readers_len,
st->opts.auto_compaction_factor);
reftable_free(sizes);
if (segment_size(&seg) > 0)
@@ -1480,9 +1467,28 @@ reftable_stack_compaction_stats(struct reftable_stack *st)
int reftable_stack_read_ref(struct reftable_stack *st, const char *refname,
struct reftable_ref_record *ref)
{
- struct reftable_table tab = { NULL };
- reftable_table_from_merged_table(&tab, reftable_stack_merged_table(st));
- return reftable_table_read_ref(&tab, refname, ref);
+ struct reftable_iterator it = { 0 };
+ int ret;
+
+ reftable_merged_table_init_ref_iterator(st->merged, &it);
+ ret = reftable_iterator_seek_ref(&it, refname);
+ if (ret)
+ goto out;
+
+ ret = reftable_iterator_next_ref(&it, ref);
+ if (ret)
+ goto out;
+
+ if (strcmp(ref->refname, refname) ||
+ reftable_ref_record_is_deletion(ref)) {
+ reftable_ref_record_release(ref);
+ ret = 1;
+ goto out;
+ }
+
+out:
+ reftable_iterator_destroy(&it);
+ return ret;
}
int reftable_stack_read_log(struct reftable_stack *st, const char *refname,
@@ -1596,23 +1602,3 @@ done:
reftable_addition_destroy(add);
return err;
}
-
-int reftable_stack_print_directory(const char *stackdir, uint32_t hash_id)
-{
- struct reftable_stack *stack = NULL;
- struct reftable_write_options opts = { .hash_id = hash_id };
- struct reftable_merged_table *merged = NULL;
- struct reftable_table table = { NULL };
-
- int err = reftable_new_stack(&stack, stackdir, &opts);
- if (err < 0)
- goto done;
-
- merged = reftable_stack_merged_table(stack);
- reftable_table_from_merged_table(&table, merged);
- err = reftable_table_print(&table);
-done:
- if (stack)
- reftable_stack_destroy(stack);
- return err;
-}
diff --git a/reftable/stack_test.c b/reftable/stack_test.c
index 8c36590ff0..311ad759d2 100644
--- a/reftable/stack_test.c
+++ b/reftable/stack_test.c
@@ -179,13 +179,6 @@ static void test_reftable_stack_add_one(void)
EXPECT(0 == strcmp("master", dest.value.symref));
EXPECT(st->readers_len > 0);
- printf("testing print functionality:\n");
- err = reftable_stack_print_directory(dir, GIT_SHA1_FORMAT_ID);
- EXPECT_ERR(err);
-
- err = reftable_stack_print_directory(dir, GIT_SHA256_FORMAT_ID);
- EXPECT(err == REFTABLE_FORMAT_ERROR);
-
#ifndef GIT_WINDOWS_NATIVE
strbuf_addstr(&scratch, dir);
strbuf_addstr(&scratch, "/tables.list");
@@ -347,9 +340,9 @@ static void test_reftable_stack_transaction_api_performs_auto_compaction(void)
* all tables in the stack.
*/
if (i != n)
- EXPECT(st->merged->stack_len == i + 1);
+ EXPECT(st->merged->readers_len == i + 1);
else
- EXPECT(st->merged->stack_len == 1);
+ EXPECT(st->merged->readers_len == 1);
}
reftable_stack_destroy(st);
@@ -375,7 +368,7 @@ static void test_reftable_stack_auto_compaction_fails_gracefully(void)
err = reftable_stack_add(st, write_test_ref, &ref);
EXPECT_ERR(err);
- EXPECT(st->merged->stack_len == 1);
+ EXPECT(st->merged->readers_len == 1);
EXPECT(st->stats.attempts == 0);
EXPECT(st->stats.failures == 0);
@@ -390,7 +383,7 @@ static void test_reftable_stack_auto_compaction_fails_gracefully(void)
ref.update_index = 2;
err = reftable_stack_add(st, write_test_ref, &ref);
EXPECT_ERR(err);
- EXPECT(st->merged->stack_len == 2);
+ EXPECT(st->merged->readers_len == 2);
EXPECT(st->stats.attempts == 1);
EXPECT(st->stats.failures == 1);
@@ -399,7 +392,7 @@ static void test_reftable_stack_auto_compaction_fails_gracefully(void)
clear_dir(dir);
}
-static int write_error(struct reftable_writer *wr, void *arg)
+static int write_error(struct reftable_writer *wr UNUSED, void *arg)
{
return *((int *)arg);
}
@@ -816,7 +809,7 @@ static void test_reflog_expire(void)
reftable_log_record_release(&log);
}
-static int write_nothing(struct reftable_writer *wr, void *arg)
+static int write_nothing(struct reftable_writer *wr, void *arg UNUSED)
{
reftable_writer_set_limits(wr, 1, 1);
return 0;
@@ -881,7 +874,7 @@ static void test_reftable_stack_auto_compaction(void)
err = reftable_stack_auto_compact(st);
EXPECT_ERR(err);
- EXPECT(i < 3 || st->merged->stack_len < 2 * fastlog2(i));
+ EXPECT(i < 3 || st->merged->readers_len < 2 * fastlog2(i));
}
EXPECT(reftable_stack_compaction_stats(st)->entries_written <
@@ -905,7 +898,7 @@ static void test_reftable_stack_auto_compaction_with_locked_tables(void)
EXPECT_ERR(err);
write_n_ref_tables(st, 5);
- EXPECT(st->merged->stack_len == 5);
+ EXPECT(st->merged->readers_len == 5);
/*
* Given that all tables we have written should be roughly the same
@@ -925,7 +918,7 @@ static void test_reftable_stack_auto_compaction_with_locked_tables(void)
err = reftable_stack_auto_compact(st);
EXPECT_ERR(err);
EXPECT(st->stats.failures == 0);
- EXPECT(st->merged->stack_len == 4);
+ EXPECT(st->merged->readers_len == 4);
reftable_stack_destroy(st);
strbuf_release(&buf);
@@ -970,9 +963,9 @@ static void test_reftable_stack_add_performs_auto_compaction(void)
* all tables in the stack.
*/
if (i != n)
- EXPECT(st->merged->stack_len == i + 1);
+ EXPECT(st->merged->readers_len == i + 1);
else
- EXPECT(st->merged->stack_len == 1);
+ EXPECT(st->merged->readers_len == 1);
}
reftable_stack_destroy(st);
@@ -994,7 +987,7 @@ static void test_reftable_stack_compaction_with_locked_tables(void)
EXPECT_ERR(err);
write_n_ref_tables(st, 3);
- EXPECT(st->merged->stack_len == 3);
+ EXPECT(st->merged->readers_len == 3);
/* Lock one of the tables that we're about to compact. */
strbuf_reset(&buf);
@@ -1008,7 +1001,7 @@ static void test_reftable_stack_compaction_with_locked_tables(void)
err = reftable_stack_compact_all(st, NULL);
EXPECT(err == REFTABLE_LOCK_ERROR);
EXPECT(st->stats.failures == 1);
- EXPECT(st->merged->stack_len == 3);
+ EXPECT(st->merged->readers_len == 3);
reftable_stack_destroy(st);
strbuf_release(&buf);
@@ -1084,7 +1077,7 @@ static void test_reftable_stack_compaction_concurrent_clean(void)
clear_dir(dir);
}
-int stack_test_main(int argc, const char *argv[])
+int stack_test_main(int argc UNUSED, const char *argv[] UNUSED)
{
RUN_TEST(test_empty_add);
RUN_TEST(test_read_file);
diff --git a/reftable/test_framework.c b/reftable/test_framework.c
index 4066924eee..a07fec5d84 100644
--- a/reftable/test_framework.c
+++ b/reftable/test_framework.c
@@ -21,7 +21,7 @@ ssize_t strbuf_add_void(void *b, const void *data, size_t sz)
return sz;
}
-int noop_flush(void *arg)
+int noop_flush(void *arg UNUSED)
{
return 0;
}
diff --git a/reftable/writer.c b/reftable/writer.c
index 45b3e9ce1f..9d5e6072bc 100644
--- a/reftable/writer.c
+++ b/reftable/writer.c
@@ -544,7 +544,7 @@ static void write_object_record(void *void_arg, void *key)
done:;
}
-static void object_record_free(void *void_arg, void *key)
+static void object_record_free(void *void_arg UNUSED, void *key)
{
struct obj_index_tree_node *entry = key;
diff --git a/remote.c b/remote.c
index 4a1269a47a..7d5b8f750d 100644
--- a/remote.c
+++ b/remote.c
@@ -499,6 +499,7 @@ static void alias_all_urls(struct remote_state *remote_state)
if (alias)
strvec_replace(&remote_state->remotes[i]->pushurl,
j, alias);
+ free(alias);
}
add_pushurl_aliases = remote_state->remotes[i]->pushurl.nr == 0;
for (j = 0; j < remote_state->remotes[i]->url.nr; j++) {
@@ -512,6 +513,7 @@ static void alias_all_urls(struct remote_state *remote_state)
if (alias)
strvec_replace(&remote_state->remotes[i]->url,
j, alias);
+ free(alias);
}
}
}
diff --git a/rerere.c b/rerere.c
index 525ed6cc1e..d01e98bf65 100644
--- a/rerere.c
+++ b/rerere.c
@@ -1208,8 +1208,10 @@ void rerere_gc(struct repository *r, struct string_list *rr)
if (setup_rerere(r, rr, 0) < 0)
return;
- git_config_get_expiry_in_days("gc.rerereresolved", &cutoff_resolve, now);
- git_config_get_expiry_in_days("gc.rerereunresolved", &cutoff_noresolve, now);
+ repo_config_get_expiry_in_days(the_repository, "gc.rerereresolved",
+ &cutoff_resolve, now);
+ repo_config_get_expiry_in_days(the_repository, "gc.rerereunresolved",
+ &cutoff_noresolve, now);
git_config(git_default_config, NULL);
dir = opendir(git_path("rr-cache"));
if (!dir)
diff --git a/reset.c b/reset.c
index 9550dea03d..b22b1be792 100644
--- a/reset.c
+++ b/reset.c
@@ -79,7 +79,7 @@ static int update_refs(const struct reset_head_opts *opts,
reflog_head);
}
if (!ret && run_hook)
- run_hooks_l("post-checkout",
+ run_hooks_l(the_repository, "post-checkout",
oid_to_hex(head ? head : null_oid()),
oid_to_hex(oid), "1", NULL);
strbuf_release(&msg);
diff --git a/revision.c b/revision.c
index 6b33bd814f..ac94f8d429 100644
--- a/revision.c
+++ b/revision.c
@@ -1872,7 +1872,7 @@ void add_index_objects_to_pending(struct rev_info *revs, unsigned int flags)
continue; /* current index already taken care of */
if (read_index_from(&istate,
- worktree_git_path(wt, "index"),
+ worktree_git_path(the_repository, wt, "index"),
get_worktree_git_dir(wt)) > 0)
do_add_index_objects_to_pending(revs, &istate, flags);
discard_index(&istate);
diff --git a/run-command.c b/run-command.c
index 45ba544932..94f2f3079f 100644
--- a/run-command.c
+++ b/run-command.c
@@ -1808,16 +1808,26 @@ void run_processes_parallel(const struct run_process_parallel_opts *opts)
int prepare_auto_maintenance(int quiet, struct child_process *maint)
{
- int enabled;
+ int enabled, auto_detach;
if (!git_config_get_bool("maintenance.auto", &enabled) &&
!enabled)
return 0;
+ /*
+ * When `maintenance.autoDetach` isn't set, then we fall back to
+ * honoring `gc.autoDetach`. This is somewhat weird, but required to
+ * retain behaviour from when we used to run git-gc(1) here.
+ */
+ if (git_config_get_bool("maintenance.autodetach", &auto_detach) &&
+ git_config_get_bool("gc.autodetach", &auto_detach))
+ auto_detach = 1;
+
maint->git_cmd = 1;
maint->close_object_store = 1;
strvec_pushl(&maint->args, "maintenance", "run", "--auto", NULL);
strvec_push(&maint->args, quiet ? "--quiet" : "--no-quiet");
+ strvec_push(&maint->args, auto_detach ? "--detach" : "--no-detach");
return 1;
}
diff --git a/scalar.c b/scalar.c
index 1fe8a93e65..6166a8dd4c 100644
--- a/scalar.c
+++ b/scalar.c
@@ -400,7 +400,8 @@ static int delete_enlistment(struct strbuf *enlistment)
* Dummy implementation; Using `get_version_info()` would cause a link error
* without this.
*/
-void load_builtin_commands(const char *prefix, struct cmdnames *cmds)
+void load_builtin_commands(const char *prefix UNUSED,
+ struct cmdnames *cmds UNUSED)
{
die("not implemented");
}
diff --git a/sequencer.c b/sequencer.c
index 0291920f0b..8d01cd50ac 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -303,6 +303,7 @@ static int git_sequencer_config(const char *k, const char *v,
}
if (!strcmp(k, "commit.gpgsign")) {
+ free(opts->gpg_sign);
opts->gpg_sign = git_config_bool(k, v) ? xstrdup("") : NULL;
return 0;
}
@@ -1316,7 +1317,7 @@ static int run_rewrite_hook(const struct object_id *oldoid,
struct child_process proc = CHILD_PROCESS_INIT;
int code;
struct strbuf sb = STRBUF_INIT;
- const char *hook_path = find_hook("post-rewrite");
+ const char *hook_path = find_hook(the_repository, "post-rewrite");
if (!hook_path)
return 0;
@@ -1614,7 +1615,7 @@ static int try_to_commit(struct repository *r,
}
}
- if (hook_exists("prepare-commit-msg")) {
+ if (hook_exists(r, "prepare-commit-msg")) {
res = run_prepare_commit_msg_hook(r, msg, hook_commit);
if (res)
goto out;
@@ -3793,12 +3794,13 @@ static int error_failed_squash(struct repository *r,
return error_with_patch(r, commit, subject, subject_len, opts, 1, 0);
}
-static int do_exec(struct repository *r, const char *command_line)
+static int do_exec(struct repository *r, const char *command_line, int quiet)
{
struct child_process cmd = CHILD_PROCESS_INIT;
int dirty, status;
- fprintf(stderr, _("Executing: %s\n"), command_line);
+ if (!quiet)
+ fprintf(stderr, _("Executing: %s\n"), command_line);
cmd.use_shell = 1;
strvec_push(&cmd.args, command_line);
strvec_push(&cmd.env, "GIT_CHERRY_PICK_HELP");
@@ -5013,7 +5015,7 @@ static int pick_commits(struct repository *r,
if (!opts->verbose)
term_clear_line();
*end_of_arg = '\0';
- res = do_exec(r, arg);
+ res = do_exec(r, arg, opts->quiet);
*end_of_arg = saved;
if (res) {
@@ -5149,7 +5151,7 @@ cleanup_head_ref:
hook_opt.path_to_stdin = rebase_path_rewritten_list();
strvec_push(&hook_opt.args, "rebase");
- run_hooks_opt("post-rewrite", &hook_opt);
+ run_hooks_opt(r, "post-rewrite", &hook_opt);
}
apply_autostash(rebase_path_autostash());
@@ -5489,8 +5491,10 @@ int sequencer_pick_revisions(struct repository *r,
int i, res;
assert(opts->revs);
- if (read_and_refresh_cache(r, opts))
- return -1;
+ if (read_and_refresh_cache(r, opts)) {
+ res = -1;
+ goto out;
+ }
for (i = 0; i < opts->revs->pending.nr; i++) {
struct object_id oid;
@@ -5505,11 +5509,14 @@ int sequencer_pick_revisions(struct repository *r,
enum object_type type = oid_object_info(r,
&oid,
NULL);
- return error(_("%s: can't cherry-pick a %s"),
- name, type_name(type));
+ res = error(_("%s: can't cherry-pick a %s"),
+ name, type_name(type));
+ goto out;
}
- } else
- return error(_("%s: bad revision"), name);
+ } else {
+ res = error(_("%s: bad revision"), name);
+ goto out;
+ }
}
/*
@@ -5524,14 +5531,23 @@ int sequencer_pick_revisions(struct repository *r,
opts->revs->no_walk &&
!opts->revs->cmdline.rev->flags) {
struct commit *cmit;
- if (prepare_revision_walk(opts->revs))
- return error(_("revision walk setup failed"));
+
+ if (prepare_revision_walk(opts->revs)) {
+ res = error(_("revision walk setup failed"));
+ goto out;
+ }
+
cmit = get_revision(opts->revs);
- if (!cmit)
- return error(_("empty commit set passed"));
+ if (!cmit) {
+ res = error(_("empty commit set passed"));
+ goto out;
+ }
+
if (get_revision(opts->revs))
BUG("unexpected extra commit from walk");
- return single_pick(r, cmit, opts);
+
+ res = single_pick(r, cmit, opts);
+ goto out;
}
/*
@@ -5541,16 +5557,30 @@ int sequencer_pick_revisions(struct repository *r,
*/
if (walk_revs_populate_todo(&todo_list, opts) ||
- create_seq_dir(r) < 0)
- return -1;
- if (repo_get_oid(r, "HEAD", &oid) && (opts->action == REPLAY_REVERT))
- return error(_("can't revert as initial commit"));
- if (save_head(oid_to_hex(&oid)))
- return -1;
- if (save_opts(opts))
- return -1;
+ create_seq_dir(r) < 0) {
+ res = -1;
+ goto out;
+ }
+
+ if (repo_get_oid(r, "HEAD", &oid) && (opts->action == REPLAY_REVERT)) {
+ res = error(_("can't revert as initial commit"));
+ goto out;
+ }
+
+ if (save_head(oid_to_hex(&oid))) {
+ res = -1;
+ goto out;
+ }
+
+ if (save_opts(opts)) {
+ res = -1;
+ goto out;
+ }
+
update_abort_safety_file();
res = pick_commits(r, &todo_list, opts);
+
+out:
todo_list_release(&todo_list);
return res;
}
diff --git a/setup.c b/setup.c
index 5f81d9fac0..29f8673921 100644
--- a/setup.c
+++ b/setup.c
@@ -1907,7 +1907,7 @@ struct template_dir_cb_data {
};
static int template_dir_cb(const char *key, const char *value,
- const struct config_context *ctx, void *d)
+ const struct config_context *ctx UNUSED, void *d)
{
struct template_dir_cb_data *data = d;
@@ -2320,14 +2320,67 @@ static void separate_git_dir(const char *git_dir, const char *git_link)
write_file(git_link, "gitdir: %s", git_dir);
}
-static void validate_hash_algorithm(struct repository_format *repo_fmt, int hash)
+struct default_format_config {
+ int hash;
+ enum ref_storage_format ref_format;
+};
+
+static int read_default_format_config(const char *key, const char *value,
+ const struct config_context *ctx UNUSED,
+ void *payload)
{
- const char *env = getenv(GIT_DEFAULT_HASH_ENVIRONMENT);
+ struct default_format_config *cfg = payload;
+ char *str = NULL;
+ int ret;
+
+ if (!strcmp(key, "init.defaultobjectformat")) {
+ ret = git_config_string(&str, key, value);
+ if (ret)
+ goto out;
+ cfg->hash = hash_algo_by_name(str);
+ if (cfg->hash == GIT_HASH_UNKNOWN)
+ warning(_("unknown hash algorithm '%s'"), str);
+ goto out;
+ }
+
+ if (!strcmp(key, "init.defaultrefformat")) {
+ ret = git_config_string(&str, key, value);
+ if (ret)
+ goto out;
+ cfg->ref_format = ref_storage_format_by_name(str);
+ if (cfg->ref_format == REF_STORAGE_FORMAT_UNKNOWN)
+ warning(_("unknown ref storage format '%s'"), str);
+ goto out;
+ }
+
+ ret = 0;
+out:
+ free(str);
+ return ret;
+}
+
+static void repository_format_configure(struct repository_format *repo_fmt,
+ int hash, enum ref_storage_format ref_format)
+{
+ struct default_format_config cfg = {
+ .hash = GIT_HASH_UNKNOWN,
+ .ref_format = REF_STORAGE_FORMAT_UNKNOWN,
+ };
+ struct config_options opts = {
+ .respect_includes = 1,
+ .ignore_repo = 1,
+ .ignore_worktree = 1,
+ };
+ const char *env;
+
+ config_with_options(read_default_format_config, &cfg, NULL, NULL, &opts);
+
/*
* If we already have an initialized repo, don't allow the user to
* specify a different algorithm, as that could cause corruption.
* Otherwise, if the user has specified one on the command line, use it.
*/
+ env = getenv(GIT_DEFAULT_HASH_ENVIRONMENT);
if (repo_fmt->version >= 0 && hash != GIT_HASH_UNKNOWN && hash != repo_fmt->hash_algo)
die(_("attempt to reinitialize repository with different hash"));
else if (hash != GIT_HASH_UNKNOWN)
@@ -2337,26 +2390,27 @@ static void validate_hash_algorithm(struct repository_format *repo_fmt, int hash
if (env_algo == GIT_HASH_UNKNOWN)
die(_("unknown hash algorithm '%s'"), env);
repo_fmt->hash_algo = env_algo;
+ } else if (cfg.hash != GIT_HASH_UNKNOWN) {
+ repo_fmt->hash_algo = cfg.hash;
}
-}
-
-static void validate_ref_storage_format(struct repository_format *repo_fmt,
- enum ref_storage_format format)
-{
- const char *name = getenv("GIT_DEFAULT_REF_FORMAT");
+ repo_set_hash_algo(the_repository, repo_fmt->hash_algo);
+ env = getenv("GIT_DEFAULT_REF_FORMAT");
if (repo_fmt->version >= 0 &&
- format != REF_STORAGE_FORMAT_UNKNOWN &&
- format != repo_fmt->ref_storage_format) {
+ ref_format != REF_STORAGE_FORMAT_UNKNOWN &&
+ ref_format != repo_fmt->ref_storage_format) {
die(_("attempt to reinitialize repository with different reference storage format"));
- } else if (format != REF_STORAGE_FORMAT_UNKNOWN) {
- repo_fmt->ref_storage_format = format;
- } else if (name) {
- format = ref_storage_format_by_name(name);
- if (format == REF_STORAGE_FORMAT_UNKNOWN)
- die(_("unknown ref storage format '%s'"), name);
- repo_fmt->ref_storage_format = format;
+ } else if (ref_format != REF_STORAGE_FORMAT_UNKNOWN) {
+ repo_fmt->ref_storage_format = ref_format;
+ } else if (env) {
+ ref_format = ref_storage_format_by_name(env);
+ if (ref_format == REF_STORAGE_FORMAT_UNKNOWN)
+ die(_("unknown ref storage format '%s'"), env);
+ repo_fmt->ref_storage_format = ref_format;
+ } else if (cfg.ref_format != REF_STORAGE_FORMAT_UNKNOWN) {
+ repo_fmt->ref_storage_format = cfg.ref_format;
}
+ repo_set_ref_storage_format(the_repository, repo_fmt->ref_storage_format);
}
int init_db(const char *git_dir, const char *real_git_dir,
@@ -2389,22 +2443,15 @@ int init_db(const char *git_dir, const char *real_git_dir,
}
startup_info->have_repository = 1;
- /* Check to see if the repository version is right.
+ /*
+ * Check to see if the repository version is right.
* Note that a newly created repository does not have
* config file, so this will not fail. What we are catching
* is an attempt to reinitialize new repository with an old tool.
*/
check_repository_format(&repo_fmt);
- validate_hash_algorithm(&repo_fmt, hash);
- validate_ref_storage_format(&repo_fmt, ref_storage_format);
-
- /*
- * Now that we have set up both the hash algorithm and the ref storage
- * format we can update the repository's settings accordingly.
- */
- repo_set_hash_algo(the_repository, repo_fmt.hash_algo);
- repo_set_ref_storage_format(the_repository, repo_fmt.ref_storage_format);
+ repository_format_configure(&repo_fmt, hash, ref_storage_format);
/*
* Ensure `core.hidedotfiles` is processed. This must happen after we
diff --git a/sideband.c b/sideband.c
index 5d8907151f..5b6b872a1c 100644
--- a/sideband.c
+++ b/sideband.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "color.h"
#include "config.h"
diff --git a/submodule-config.c b/submodule-config.c
index 9b0bb0b9f4..c8f2bb2bdd 100644
--- a/submodule-config.c
+++ b/submodule-config.c
@@ -899,27 +899,25 @@ static void traverse_tree_submodules(struct repository *r,
{
struct tree_desc tree;
struct submodule_tree_entry *st_entry;
- struct name_entry *name_entry;
+ struct name_entry name_entry;
char *tree_path = NULL;
- name_entry = xmalloc(sizeof(*name_entry));
-
fill_tree_descriptor(r, &tree, treeish_name);
- while (tree_entry(&tree, name_entry)) {
+ while (tree_entry(&tree, &name_entry)) {
if (prefix)
tree_path =
- mkpathdup("%s/%s", prefix, name_entry->path);
+ mkpathdup("%s/%s", prefix, name_entry.path);
else
- tree_path = xstrdup(name_entry->path);
+ tree_path = xstrdup(name_entry.path);
- if (S_ISGITLINK(name_entry->mode) &&
+ if (S_ISGITLINK(name_entry.mode) &&
is_tree_submodule_active(r, root_tree, tree_path)) {
ALLOC_GROW(out->entries, out->entry_nr + 1,
out->entry_alloc);
st_entry = &out->entries[out->entry_nr++];
st_entry->name_entry = xmalloc(sizeof(*st_entry->name_entry));
- *st_entry->name_entry = *name_entry;
+ *st_entry->name_entry = name_entry;
st_entry->submodule =
submodule_from_path(r, root_tree, tree_path);
st_entry->repo = xmalloc(sizeof(*st_entry->repo));
@@ -927,9 +925,9 @@ static void traverse_tree_submodules(struct repository *r,
root_tree))
FREE_AND_NULL(st_entry->repo);
- } else if (S_ISDIR(name_entry->mode))
+ } else if (S_ISDIR(name_entry.mode))
traverse_tree_submodules(r, root_tree, tree_path,
- &name_entry->oid, out);
+ &name_entry.oid, out);
free(tree_path);
}
}
diff --git a/submodule.c b/submodule.c
index 8afb0dde55..97516b0fec 100644
--- a/submodule.c
+++ b/submodule.c
@@ -159,7 +159,7 @@ int remove_path_from_gitmodules(const char *path)
}
strbuf_addstr(&sect, "submodule.");
strbuf_addstr(&sect, submodule->name);
- if (git_config_rename_section_in_file(GITMODULES_FILE, sect.buf, NULL) < 0) {
+ if (repo_config_rename_section_in_file(the_repository, GITMODULES_FILE, sect.buf, NULL) < 0) {
/* Maybe the user already did that, don't error out here */
warning(_("Could not remove .gitmodules entry for %s"), path);
strbuf_release(&sect);
diff --git a/t/helper/test-advise.c b/t/helper/test-advise.c
index 8a3fd0009a..6967c8e25c 100644
--- a/t/helper/test-advise.c
+++ b/t/helper/test-advise.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "test-tool.h"
#include "advice.h"
#include "config.h"
diff --git a/t/helper/test-config.c b/t/helper/test-config.c
index ed444ca4c2..e193079ed5 100644
--- a/t/helper/test-config.c
+++ b/t/helper/test-config.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "test-tool.h"
#include "config.h"
#include "setup.h"
diff --git a/t/helper/test-example-tap.c b/t/helper/test-example-tap.c
index 914af88e0a..229d495ecf 100644
--- a/t/helper/test-example-tap.c
+++ b/t/helper/test-example-tap.c
@@ -70,7 +70,7 @@ static void t_empty(void)
; /* empty */
}
-int cmd__example_tap(int argc, const char **argv)
+int cmd__example_tap(int argc UNUSED, const char **argv UNUSED)
{
check(1);
diff --git a/t/helper/test-hashmap.c b/t/helper/test-hashmap.c
index 195e6278be..7782ae585e 100644
--- a/t/helper/test-hashmap.c
+++ b/t/helper/test-hashmap.c
@@ -138,7 +138,7 @@ static void perf_hashmap(unsigned int method, unsigned int rounds)
*
* perfhashmap method rounds -> test hashmap.[ch] performance
*/
-int cmd__hashmap(int argc, const char **argv)
+int cmd__hashmap(int argc UNUSED, const char **argv UNUSED)
{
struct string_list parts = STRING_LIST_INIT_NODUP;
struct strbuf line = STRBUF_INIT;
diff --git a/t/helper/test-mergesort.c b/t/helper/test-mergesort.c
index 42ccc87051..328bfe2977 100644
--- a/t/helper/test-mergesort.c
+++ b/t/helper/test-mergesort.c
@@ -122,7 +122,7 @@ static const struct dist *get_dist_by_name(const char *name)
return NULL;
}
-static void mode_copy(int *arr, int n)
+static void mode_copy(int *arr UNUSED, int n UNUSED)
{
/* nothing */
}
diff --git a/t/helper/test-reach.c b/t/helper/test-reach.c
index 5dd374379c..7314f6c0d8 100644
--- a/t/helper/test-reach.c
+++ b/t/helper/test-reach.c
@@ -116,6 +116,8 @@ int cmd__reach(int ac, const char **av)
repo_in_merge_bases_many(the_repository, A, X_nr, X_array, 0));
else if (!strcmp(av[1], "is_descendant_of"))
printf("%s(A,X):%d\n", av[1], repo_is_descendant_of(r, A, X));
+ else if (!strcmp(av[1], "get_branch_base_for_tip"))
+ printf("%s(A,X):%d\n", av[1], get_branch_base_for_tip(r, A, X_array, X_nr));
else if (!strcmp(av[1], "get_merge_bases_many")) {
struct commit_list *list = NULL;
if (repo_get_merge_bases_many(the_repository,
diff --git a/t/helper/test-reftable.c b/t/helper/test-reftable.c
index 7bdd18430b..3cd3314f07 100644
--- a/t/helper/test-reftable.c
+++ b/t/helper/test-reftable.c
@@ -1,16 +1,202 @@
+#include "git-compat-util.h"
+#include "hash.h"
+#include "hex.h"
#include "reftable/system.h"
+#include "reftable/reftable-error.h"
+#include "reftable/reftable-merged.h"
+#include "reftable/reftable-reader.h"
+#include "reftable/reftable-stack.h"
#include "reftable/reftable-tests.h"
#include "test-tool.h"
int cmd__reftable(int argc, const char **argv)
{
/* test from simple to complex. */
- readwrite_test_main(argc, argv);
stack_test_main(argc, argv);
return 0;
}
+static void print_help(void)
+{
+ printf("usage: dump [-st] arg\n\n"
+ "options: \n"
+ " -b dump blocks\n"
+ " -t dump table\n"
+ " -s dump stack\n"
+ " -6 sha256 hash format\n"
+ " -h this help\n"
+ "\n");
+}
+
+static int dump_table(struct reftable_merged_table *mt)
+{
+ struct reftable_iterator it = { NULL };
+ struct reftable_ref_record ref = { NULL };
+ struct reftable_log_record log = { NULL };
+ const struct git_hash_algo *algop;
+ int err;
+
+ reftable_merged_table_init_ref_iterator(mt, &it);
+ err = reftable_iterator_seek_ref(&it, "");
+ if (err < 0)
+ return err;
+
+ algop = &hash_algos[hash_algo_by_id(reftable_merged_table_hash_id(mt))];
+
+ while (1) {
+ err = reftable_iterator_next_ref(&it, &ref);
+ if (err > 0)
+ break;
+ if (err < 0)
+ return err;
+
+ printf("ref{%s(%" PRIu64 ") ", ref.refname, ref.update_index);
+ switch (ref.value_type) {
+ case REFTABLE_REF_SYMREF:
+ printf("=> %s", ref.value.symref);
+ break;
+ case REFTABLE_REF_VAL2:
+ printf("val 2 %s", hash_to_hex_algop(ref.value.val2.value, algop));
+ printf("(T %s)", hash_to_hex_algop(ref.value.val2.target_value, algop));
+ break;
+ case REFTABLE_REF_VAL1:
+ printf("val 1 %s", hash_to_hex_algop(ref.value.val1, algop));
+ break;
+ case REFTABLE_REF_DELETION:
+ printf("delete");
+ break;
+ }
+ printf("}\n");
+ }
+ reftable_iterator_destroy(&it);
+ reftable_ref_record_release(&ref);
+
+ reftable_merged_table_init_log_iterator(mt, &it);
+ err = reftable_iterator_seek_log(&it, "");
+ if (err < 0)
+ return err;
+
+ while (1) {
+ err = reftable_iterator_next_log(&it, &log);
+ if (err > 0)
+ break;
+ if (err < 0)
+ return err;
+
+ switch (log.value_type) {
+ case REFTABLE_LOG_DELETION:
+ printf("log{%s(%" PRIu64 ") delete\n", log.refname,
+ log.update_index);
+ break;
+ case REFTABLE_LOG_UPDATE:
+ printf("log{%s(%" PRIu64 ") %s <%s> %" PRIu64 " %04d\n",
+ log.refname, log.update_index,
+ log.value.update.name ? log.value.update.name : "",
+ log.value.update.email ? log.value.update.email : "",
+ log.value.update.time,
+ log.value.update.tz_offset);
+ printf("%s => ", hash_to_hex_algop(log.value.update.old_hash, algop));
+ printf("%s\n\n%s\n}\n", hash_to_hex_algop(log.value.update.new_hash, algop),
+ log.value.update.message ? log.value.update.message : "");
+ break;
+ }
+ }
+ reftable_iterator_destroy(&it);
+ reftable_log_record_release(&log);
+ return 0;
+}
+
+static int dump_stack(const char *stackdir, uint32_t hash_id)
+{
+ struct reftable_stack *stack = NULL;
+ struct reftable_write_options opts = { .hash_id = hash_id };
+ struct reftable_merged_table *merged = NULL;
+
+ int err = reftable_new_stack(&stack, stackdir, &opts);
+ if (err < 0)
+ goto done;
+
+ merged = reftable_stack_merged_table(stack);
+ err = dump_table(merged);
+done:
+ if (stack)
+ reftable_stack_destroy(stack);
+ return err;
+}
+
+static int dump_reftable(const char *tablename)
+{
+ struct reftable_block_source src = { 0 };
+ struct reftable_merged_table *mt = NULL;
+ struct reftable_reader *r = NULL;
+ int err;
+
+ err = reftable_block_source_from_file(&src, tablename);
+ if (err < 0)
+ goto done;
+
+ err = reftable_new_reader(&r, &src, tablename);
+ if (err < 0)
+ goto done;
+
+ err = reftable_merged_table_new(&mt, &r, 1,
+ reftable_reader_hash_id(r));
+ if (err < 0)
+ goto done;
+
+ err = dump_table(mt);
+
+done:
+ reftable_merged_table_free(mt);
+ reftable_reader_free(r);
+ return err;
+}
+
int cmd__dump_reftable(int argc, const char **argv)
{
- return reftable_dump_main(argc, (char *const *)argv);
+ int err = 0;
+ int opt_dump_blocks = 0;
+ int opt_dump_table = 0;
+ int opt_dump_stack = 0;
+ uint32_t opt_hash_id = GIT_SHA1_FORMAT_ID;
+ const char *arg = NULL, *argv0 = argv[0];
+
+ for (; argc > 1; argv++, argc--)
+ if (*argv[1] != '-')
+ break;
+ else if (!strcmp("-b", argv[1]))
+ opt_dump_blocks = 1;
+ else if (!strcmp("-t", argv[1]))
+ opt_dump_table = 1;
+ else if (!strcmp("-6", argv[1]))
+ opt_hash_id = GIT_SHA256_FORMAT_ID;
+ else if (!strcmp("-s", argv[1]))
+ opt_dump_stack = 1;
+ else if (!strcmp("-?", argv[1]) || !strcmp("-h", argv[1])) {
+ print_help();
+ return 2;
+ }
+
+ if (argc != 2) {
+ fprintf(stderr, "need argument\n");
+ print_help();
+ return 2;
+ }
+
+ arg = argv[1];
+
+ if (opt_dump_blocks) {
+ err = reftable_reader_print_blocks(arg);
+ } else if (opt_dump_table) {
+ err = dump_reftable(arg);
+ } else if (opt_dump_stack) {
+ err = dump_stack(arg, opt_hash_id);
+ }
+
+ if (err < 0) {
+ fprintf(stderr, "%s: %s: %s\n", argv0, arg,
+ reftable_error_str(err));
+ return 1;
+ }
+ return 0;
}
diff --git a/t/helper/test-tool.c b/t/helper/test-tool.c
index da3e69128a..f8a67df7de 100644
--- a/t/helper/test-tool.c
+++ b/t/helper/test-tool.c
@@ -83,7 +83,6 @@ static struct test_cmd cmds[] = {
{ "trace2", cmd__trace2 },
{ "truncate", cmd__truncate },
{ "userdiff", cmd__userdiff },
- { "urlmatch-normalization", cmd__urlmatch_normalization },
{ "xml-encode", cmd__xml_encode },
{ "wildmatch", cmd__wildmatch },
#ifdef GIT_WINDOWS_NATIVE
diff --git a/t/helper/test-tool.h b/t/helper/test-tool.h
index 642a34578c..e74bc0ffd4 100644
--- a/t/helper/test-tool.h
+++ b/t/helper/test-tool.h
@@ -76,7 +76,6 @@ int cmd__subprocess(int argc, const char **argv);
int cmd__trace2(int argc, const char **argv);
int cmd__truncate(int argc, const char **argv);
int cmd__userdiff(int argc, const char **argv);
-int cmd__urlmatch_normalization(int argc, const char **argv);
int cmd__xml_encode(int argc, const char **argv);
int cmd__wildmatch(int argc, const char **argv);
#ifdef GIT_WINDOWS_NATIVE
diff --git a/t/helper/test-urlmatch-normalization.c b/t/helper/test-urlmatch-normalization.c
deleted file mode 100644
index 86edd454f5..0000000000
--- a/t/helper/test-urlmatch-normalization.c
+++ /dev/null
@@ -1,56 +0,0 @@
-#include "test-tool.h"
-#include "git-compat-util.h"
-#include "urlmatch.h"
-
-int cmd__urlmatch_normalization(int argc, const char **argv)
-{
- const char usage[] = "test-tool urlmatch-normalization [-p | -l] <url1> | <url1> <url2>";
- char *url1 = NULL, *url2 = NULL;
- int opt_p = 0, opt_l = 0;
- int ret = 0;
-
- /*
- * For one url, succeed if url_normalize succeeds on it, fail otherwise.
- * For two urls, succeed only if url_normalize succeeds on both and
- * the results compare equal with strcmp. If -p is given (one url only)
- * and url_normalize succeeds, print the result followed by "\n". If
- * -l is given (one url only) and url_normalize succeeds, print the
- * returned length in decimal followed by "\n".
- */
-
- if (argc > 1 && !strcmp(argv[1], "-p")) {
- opt_p = 1;
- argc--;
- argv++;
- } else if (argc > 1 && !strcmp(argv[1], "-l")) {
- opt_l = 1;
- argc--;
- argv++;
- }
-
- if (argc < 2 || argc > 3)
- die("%s", usage);
-
- if (argc == 2) {
- struct url_info info;
- url1 = url_normalize(argv[1], &info);
- if (!url1)
- return 1;
- if (opt_p)
- printf("%s\n", url1);
- if (opt_l)
- printf("%u\n", (unsigned)info.url_len);
- goto cleanup;
- }
-
- if (opt_p || opt_l)
- die("%s", usage);
-
- url1 = url_normalize(argv[1], NULL);
- url2 = url_normalize(argv[2], NULL);
- ret = (url1 && url2 && !strcmp(url1, url2)) ? 0 : 1;
-cleanup:
- free(url1);
- free(url2);
- return ret;
-}
diff --git a/t/helper/test-userdiff.c b/t/helper/test-userdiff.c
index 0ce31ce59f..94c48ababb 100644
--- a/t/helper/test-userdiff.c
+++ b/t/helper/test-userdiff.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "test-tool.h"
#include "setup.h"
#include "userdiff.h"
diff --git a/t/perf/p1500-graph-walks.sh b/t/perf/p1500-graph-walks.sh
index e14e7620cc..5b23ce5db9 100755
--- a/t/perf/p1500-graph-walks.sh
+++ b/t/perf/p1500-graph-walks.sh
@@ -20,6 +20,21 @@ test_expect_success 'setup' '
echo tag-$ref ||
return 1
done >tags &&
+
+ echo "A:HEAD" >test-tool-refs &&
+ for line in $(cat refs)
+ do
+ echo "X:$line" >>test-tool-refs || return 1
+ done &&
+ echo "A:HEAD" >test-tool-tags &&
+ for line in $(cat tags)
+ do
+ echo "X:$line" >>test-tool-tags || return 1
+ done &&
+
+ commit=$(git commit-tree $(git rev-parse HEAD^{tree})) &&
+ git update-ref refs/heads/disjoint-base $commit &&
+
git commit-graph write --reachable
'
@@ -47,4 +62,20 @@ test_perf 'contains: git tag --merged' '
xargs git tag --merged=HEAD <tags
'
+test_perf 'is-base check: test-tool reach (refs)' '
+ test-tool reach get_branch_base_for_tip <test-tool-refs
+'
+
+test_perf 'is-base check: test-tool reach (tags)' '
+ test-tool reach get_branch_base_for_tip <test-tool-tags
+'
+
+test_perf 'is-base check: git for-each-ref' '
+ git for-each-ref --format="%(is-base:HEAD)" --stdin <refs
+'
+
+test_perf 'is-base check: git for-each-ref (disjoint-base)' '
+ git for-each-ref --format="%(is-base:refs/heads/disjoint-base)" --stdin <refs
+'
+
test_done
diff --git a/t/t0001-init.sh b/t/t0001-init.sh
index 49e9bf77c6..0178aa62a4 100755
--- a/t/t0001-init.sh
+++ b/t/t0001-init.sh
@@ -500,6 +500,7 @@ test_expect_success 're-init from a linked worktree' '
'
test_expect_success 'init honors GIT_DEFAULT_HASH' '
+ test_when_finished "rm -rf sha1 sha256" &&
GIT_DEFAULT_HASH=sha1 git init sha1 &&
git -C sha1 rev-parse --show-object-format >actual &&
echo sha1 >expected &&
@@ -511,6 +512,7 @@ test_expect_success 'init honors GIT_DEFAULT_HASH' '
'
test_expect_success 'init honors --object-format' '
+ test_when_finished "rm -rf explicit-sha1 explicit-sha256" &&
git init --object-format=sha1 explicit-sha1 &&
git -C explicit-sha1 rev-parse --show-object-format >actual &&
echo sha1 >expected &&
@@ -521,7 +523,58 @@ test_expect_success 'init honors --object-format' '
test_cmp expected actual
'
+test_expect_success 'init honors init.defaultObjectFormat' '
+ test_when_finished "rm -rf sha1 sha256" &&
+
+ test_config_global init.defaultObjectFormat sha1 &&
+ (
+ sane_unset GIT_DEFAULT_HASH &&
+ git init sha1 &&
+ git -C sha1 rev-parse --show-object-format >actual &&
+ echo sha1 >expected &&
+ test_cmp expected actual
+ ) &&
+
+ test_config_global init.defaultObjectFormat sha256 &&
+ (
+ sane_unset GIT_DEFAULT_HASH &&
+ git init sha256 &&
+ git -C sha256 rev-parse --show-object-format >actual &&
+ echo sha256 >expected &&
+ test_cmp expected actual
+ )
+'
+
+test_expect_success 'init warns about invalid init.defaultObjectFormat' '
+ test_when_finished "rm -rf repo" &&
+ test_config_global init.defaultObjectFormat garbage &&
+
+ echo "warning: unknown hash algorithm ${SQ}garbage${SQ}" >expect &&
+ git init repo 2>err &&
+ test_cmp expect err &&
+
+ git -C repo rev-parse --show-object-format >actual &&
+ echo $GIT_DEFAULT_HASH >expected &&
+ test_cmp expected actual
+'
+
+test_expect_success '--object-format overrides GIT_DEFAULT_HASH' '
+ test_when_finished "rm -rf repo" &&
+ GIT_DEFAULT_HASH=sha1 git init --object-format=sha256 repo &&
+ git -C repo rev-parse --show-object-format >actual &&
+ echo sha256 >expected
+'
+
+test_expect_success 'GIT_DEFAULT_HASH overrides init.defaultObjectFormat' '
+ test_when_finished "rm -rf repo" &&
+ test_config_global init.defaultObjectFormat sha1 &&
+ GIT_DEFAULT_HASH=sha256 git init repo &&
+ git -C repo rev-parse --show-object-format >actual &&
+ echo sha256 >expected
+'
+
test_expect_success 'extensions.objectFormat is not allowed with repo version 0' '
+ test_when_finished "rm -rf explicit-v0" &&
git init --object-format=sha256 explicit-v0 &&
git -C explicit-v0 config core.repositoryformatversion 0 &&
test_must_fail git -C explicit-v0 rev-parse --show-object-format
@@ -558,15 +611,6 @@ test_expect_success DEFAULT_REPO_FORMAT 'extensions.refStorage with unknown back
grep "invalid value for ${SQ}extensions.refstorage${SQ}: ${SQ}garbage${SQ}" err
'
-test_expect_success DEFAULT_REPO_FORMAT 'init with GIT_DEFAULT_REF_FORMAT=files' '
- test_when_finished "rm -rf refformat" &&
- GIT_DEFAULT_REF_FORMAT=files git init refformat &&
- echo 0 >expect &&
- git -C refformat config core.repositoryformatversion >actual &&
- test_cmp expect actual &&
- test_must_fail git -C refformat config extensions.refstorage
-'
-
test_expect_success 'init with GIT_DEFAULT_REF_FORMAT=garbage' '
test_when_finished "rm -rf refformat" &&
cat >expect <<-EOF &&
@@ -576,15 +620,90 @@ test_expect_success 'init with GIT_DEFAULT_REF_FORMAT=garbage' '
test_cmp expect err
'
-test_expect_success 'init with --ref-format=files' '
+test_expect_success 'init warns about invalid init.defaultRefFormat' '
+ test_when_finished "rm -rf repo" &&
+ test_config_global init.defaultRefFormat garbage &&
+
+ echo "warning: unknown ref storage format ${SQ}garbage${SQ}" >expect &&
+ git init repo 2>err &&
+ test_cmp expect err &&
+
+ git -C repo rev-parse --show-ref-format >actual &&
+ echo $GIT_DEFAULT_REF_FORMAT >expected &&
+ test_cmp expected actual
+'
+
+backends="files reftable"
+for format in $backends
+do
+ test_expect_success DEFAULT_REPO_FORMAT "init with GIT_DEFAULT_REF_FORMAT=$format" '
+ test_when_finished "rm -rf refformat" &&
+ GIT_DEFAULT_REF_FORMAT=$format git init refformat &&
+
+ if test $format = files
+ then
+ test_must_fail git -C refformat config extensions.refstorage &&
+ echo 0 >expect
+ else
+ git -C refformat config extensions.refstorage &&
+ echo 1 >expect
+ fi &&
+ git -C refformat config core.repositoryformatversion >actual &&
+ test_cmp expect actual &&
+
+ echo $format >expect &&
+ git -C refformat rev-parse --show-ref-format >actual &&
+ test_cmp expect actual
+ '
+
+ test_expect_success "init with --ref-format=$format" '
+ test_when_finished "rm -rf refformat" &&
+ git init --ref-format=$format refformat &&
+ echo $format >expect &&
+ git -C refformat rev-parse --show-ref-format >actual &&
+ test_cmp expect actual
+ '
+
+ test_expect_success "init with init.defaultRefFormat=$format" '
+ test_when_finished "rm -rf refformat" &&
+ test_config_global init.defaultRefFormat $format &&
+ (
+ sane_unset GIT_DEFAULT_REF_FORMAT &&
+ git init refformat
+ ) &&
+
+ echo $format >expect &&
+ git -C refformat rev-parse --show-ref-format >actual &&
+ test_cmp expect actual
+ '
+
+ test_expect_success "--ref-format=$format overrides GIT_DEFAULT_REF_FORMAT" '
+ test_when_finished "rm -rf refformat" &&
+ GIT_DEFAULT_REF_FORMAT=garbage git init --ref-format=$format refformat &&
+ echo $format >expect &&
+ git -C refformat rev-parse --show-ref-format >actual &&
+ test_cmp expect actual
+ '
+done
+
+test_expect_success "--ref-format= overrides GIT_DEFAULT_REF_FORMAT" '
test_when_finished "rm -rf refformat" &&
- git init --ref-format=files refformat &&
- echo files >expect &&
+ GIT_DEFAULT_REF_FORMAT=files git init --ref-format=reftable refformat &&
+ echo reftable >expect &&
+ git -C refformat rev-parse --show-ref-format >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success "GIT_DEFAULT_REF_FORMAT= overrides init.defaultRefFormat" '
+ test_when_finished "rm -rf refformat" &&
+ test_config_global init.defaultRefFormat files &&
+
+ GIT_DEFAULT_REF_FORMAT=reftable git init refformat &&
+ echo reftable >expect &&
git -C refformat rev-parse --show-ref-format >actual &&
test_cmp expect actual
'
-backends="files reftable"
for from_format in $backends
do
test_expect_success "re-init with same format ($from_format)" '
diff --git a/t/t0110-urlmatch-normalization.sh b/t/t0110-urlmatch-normalization.sh
deleted file mode 100755
index 12d817fbd3..0000000000
--- a/t/t0110-urlmatch-normalization.sh
+++ /dev/null
@@ -1,182 +0,0 @@
-#!/bin/sh
-
-test_description='urlmatch URL normalization'
-
-TEST_PASSES_SANITIZE_LEAK=true
-. ./test-lib.sh
-
-# The base name of the test url files
-tu="$TEST_DIRECTORY/t0110/url"
-
-# Note that only file: URLs should be allowed without a host
-
-test_expect_success 'url scheme' '
- ! test-tool urlmatch-normalization "" &&
- ! test-tool urlmatch-normalization "_" &&
- ! test-tool urlmatch-normalization "scheme" &&
- ! test-tool urlmatch-normalization "scheme:" &&
- ! test-tool urlmatch-normalization "scheme:/" &&
- ! test-tool urlmatch-normalization "scheme://" &&
- ! test-tool urlmatch-normalization "file" &&
- ! test-tool urlmatch-normalization "file:" &&
- ! test-tool urlmatch-normalization "file:/" &&
- test-tool urlmatch-normalization "file://" &&
- ! test-tool urlmatch-normalization "://acme.co" &&
- ! test-tool urlmatch-normalization "x_test://acme.co" &&
- ! test-tool urlmatch-normalization "-test://acme.co" &&
- ! test-tool urlmatch-normalization "0test://acme.co" &&
- ! test-tool urlmatch-normalization "+test://acme.co" &&
- ! test-tool urlmatch-normalization ".test://acme.co" &&
- ! test-tool urlmatch-normalization "schem%6e://" &&
- test-tool urlmatch-normalization "x-Test+v1.0://acme.co" &&
- test "$(test-tool urlmatch-normalization -p "AbCdeF://x.Y")" = "abcdef://x.y/"
-'
-
-test_expect_success 'url authority' '
- ! test-tool urlmatch-normalization "scheme://user:pass@" &&
- ! test-tool urlmatch-normalization "scheme://?" &&
- ! test-tool urlmatch-normalization "scheme://#" &&
- ! test-tool urlmatch-normalization "scheme:///" &&
- ! test-tool urlmatch-normalization "scheme://:" &&
- ! test-tool urlmatch-normalization "scheme://:555" &&
- test-tool urlmatch-normalization "file://user:pass@" &&
- test-tool urlmatch-normalization "file://?" &&
- test-tool urlmatch-normalization "file://#" &&
- test-tool urlmatch-normalization "file:///" &&
- test-tool urlmatch-normalization "file://:" &&
- ! test-tool urlmatch-normalization "file://:555" &&
- test-tool urlmatch-normalization "scheme://user:pass@host" &&
- test-tool urlmatch-normalization "scheme://@host" &&
- test-tool urlmatch-normalization "scheme://%00@host" &&
- ! test-tool urlmatch-normalization "scheme://%%@host" &&
- test-tool urlmatch-normalization "scheme://host_" &&
- test-tool urlmatch-normalization "scheme://user:pass@host/" &&
- test-tool urlmatch-normalization "scheme://@host/" &&
- test-tool urlmatch-normalization "scheme://host/" &&
- test-tool urlmatch-normalization "scheme://host?x" &&
- test-tool urlmatch-normalization "scheme://host#x" &&
- test-tool urlmatch-normalization "scheme://host/@" &&
- test-tool urlmatch-normalization "scheme://host?@x" &&
- test-tool urlmatch-normalization "scheme://host#@x" &&
- test-tool urlmatch-normalization "scheme://[::1]" &&
- test-tool urlmatch-normalization "scheme://[::1]/" &&
- ! test-tool urlmatch-normalization "scheme://hos%41/" &&
- test-tool urlmatch-normalization "scheme://[invalid....:/" &&
- test-tool urlmatch-normalization "scheme://invalid....:]/" &&
- ! test-tool urlmatch-normalization "scheme://invalid....:[/" &&
- ! test-tool urlmatch-normalization "scheme://invalid....:["
-'
-
-test_expect_success 'url port checks' '
- test-tool urlmatch-normalization "xyz://q@some.host:" &&
- test-tool urlmatch-normalization "xyz://q@some.host:456/" &&
- ! test-tool urlmatch-normalization "xyz://q@some.host:0" &&
- ! test-tool urlmatch-normalization "xyz://q@some.host:0000000" &&
- test-tool urlmatch-normalization "xyz://q@some.host:0000001?" &&
- test-tool urlmatch-normalization "xyz://q@some.host:065535#" &&
- test-tool urlmatch-normalization "xyz://q@some.host:65535" &&
- ! test-tool urlmatch-normalization "xyz://q@some.host:65536" &&
- ! test-tool urlmatch-normalization "xyz://q@some.host:99999" &&
- ! test-tool urlmatch-normalization "xyz://q@some.host:100000" &&
- ! test-tool urlmatch-normalization "xyz://q@some.host:100001" &&
- test-tool urlmatch-normalization "http://q@some.host:80" &&
- test-tool urlmatch-normalization "https://q@some.host:443" &&
- test-tool urlmatch-normalization "http://q@some.host:80/" &&
- test-tool urlmatch-normalization "https://q@some.host:443?" &&
- ! test-tool urlmatch-normalization "http://q@:8008" &&
- ! test-tool urlmatch-normalization "http://:8080" &&
- ! test-tool urlmatch-normalization "http://:" &&
- test-tool urlmatch-normalization "xyz://q@some.host:456/" &&
- test-tool urlmatch-normalization "xyz://[::1]:456/" &&
- test-tool urlmatch-normalization "xyz://[::1]:/" &&
- ! test-tool urlmatch-normalization "xyz://[::1]:000/" &&
- ! test-tool urlmatch-normalization "xyz://[::1]:0%300/" &&
- ! test-tool urlmatch-normalization "xyz://[::1]:0x80/" &&
- ! test-tool urlmatch-normalization "xyz://[::1]:4294967297/" &&
- ! test-tool urlmatch-normalization "xyz://[::1]:030f/"
-'
-
-test_expect_success 'url port normalization' '
- test "$(test-tool urlmatch-normalization -p "http://x:800")" = "http://x:800/" &&
- test "$(test-tool urlmatch-normalization -p "http://x:0800")" = "http://x:800/" &&
- test "$(test-tool urlmatch-normalization -p "http://x:00000800")" = "http://x:800/" &&
- test "$(test-tool urlmatch-normalization -p "http://x:065535")" = "http://x:65535/" &&
- test "$(test-tool urlmatch-normalization -p "http://x:1")" = "http://x:1/" &&
- test "$(test-tool urlmatch-normalization -p "http://x:80")" = "http://x/" &&
- test "$(test-tool urlmatch-normalization -p "http://x:080")" = "http://x/" &&
- test "$(test-tool urlmatch-normalization -p "http://x:000000080")" = "http://x/" &&
- test "$(test-tool urlmatch-normalization -p "https://x:443")" = "https://x/" &&
- test "$(test-tool urlmatch-normalization -p "https://x:0443")" = "https://x/" &&
- test "$(test-tool urlmatch-normalization -p "https://x:000000443")" = "https://x/"
-'
-
-test_expect_success 'url general escapes' '
- ! test-tool urlmatch-normalization "http://x.y?%fg" &&
- test "$(test-tool urlmatch-normalization -p "X://W/%7e%41^%3a")" = "x://w/~A%5E%3A" &&
- test "$(test-tool urlmatch-normalization -p "X://W/:/?#[]@")" = "x://w/:/?#[]@" &&
- test "$(test-tool urlmatch-normalization -p "X://W/$&()*+,;=")" = "x://w/$&()*+,;=" &&
- test "$(test-tool urlmatch-normalization -p "X://W/'\''")" = "x://w/'\''" &&
- test "$(test-tool urlmatch-normalization -p "X://W?'\!'")" = "x://w/?'\!'"
-'
-
-test_expect_success !MINGW 'url high-bit escapes' '
- test "$(test-tool urlmatch-normalization -p "$(cat "$tu-1")")" = "x://q/%01%02%03%04%05%06%07%08%0E%0F%10%11%12" &&
- test "$(test-tool urlmatch-normalization -p "$(cat "$tu-2")")" = "x://q/%13%14%15%16%17%18%19%1B%1C%1D%1E%1F%7F" &&
- test "$(test-tool urlmatch-normalization -p "$(cat "$tu-3")")" = "x://q/%80%81%82%83%84%85%86%87%88%89%8A%8B%8C%8D%8E%8F" &&
- test "$(test-tool urlmatch-normalization -p "$(cat "$tu-4")")" = "x://q/%90%91%92%93%94%95%96%97%98%99%9A%9B%9C%9D%9E%9F" &&
- test "$(test-tool urlmatch-normalization -p "$(cat "$tu-5")")" = "x://q/%A0%A1%A2%A3%A4%A5%A6%A7%A8%A9%AA%AB%AC%AD%AE%AF" &&
- test "$(test-tool urlmatch-normalization -p "$(cat "$tu-6")")" = "x://q/%B0%B1%B2%B3%B4%B5%B6%B7%B8%B9%BA%BB%BC%BD%BE%BF" &&
- test "$(test-tool urlmatch-normalization -p "$(cat "$tu-7")")" = "x://q/%C0%C1%C2%C3%C4%C5%C6%C7%C8%C9%CA%CB%CC%CD%CE%CF" &&
- test "$(test-tool urlmatch-normalization -p "$(cat "$tu-8")")" = "x://q/%D0%D1%D2%D3%D4%D5%D6%D7%D8%D9%DA%DB%DC%DD%DE%DF" &&
- test "$(test-tool urlmatch-normalization -p "$(cat "$tu-9")")" = "x://q/%E0%E1%E2%E3%E4%E5%E6%E7%E8%E9%EA%EB%EC%ED%EE%EF" &&
- test "$(test-tool urlmatch-normalization -p "$(cat "$tu-10")")" = "x://q/%F0%F1%F2%F3%F4%F5%F6%F7%F8%F9%FA%FB%FC%FD%FE%FF"
-'
-
-test_expect_success 'url utf-8 escapes' '
- test "$(test-tool urlmatch-normalization -p "$(cat "$tu-11")")" = "x://q/%C2%80%DF%BF%E0%A0%80%EF%BF%BD%F0%90%80%80%F0%AF%BF%BD"
-'
-
-test_expect_success 'url username/password escapes' '
- test "$(test-tool urlmatch-normalization -p "x://%41%62(^):%70+d@foo")" = "x://Ab(%5E):p+d@foo/"
-'
-
-test_expect_success 'url normalized lengths' '
- test "$(test-tool urlmatch-normalization -l "Http://%4d%65:%4d^%70@The.Host")" = 25 &&
- test "$(test-tool urlmatch-normalization -l "http://%41:%42@x.y/%61/")" = 17 &&
- test "$(test-tool urlmatch-normalization -l "http://@x.y/^")" = 15
-'
-
-test_expect_success 'url . and .. segments' '
- test "$(test-tool urlmatch-normalization -p "x://y/.")" = "x://y/" &&
- test "$(test-tool urlmatch-normalization -p "x://y/./")" = "x://y/" &&
- test "$(test-tool urlmatch-normalization -p "x://y/a/.")" = "x://y/a" &&
- test "$(test-tool urlmatch-normalization -p "x://y/a/./")" = "x://y/a/" &&
- test "$(test-tool urlmatch-normalization -p "x://y/.?")" = "x://y/?" &&
- test "$(test-tool urlmatch-normalization -p "x://y/./?")" = "x://y/?" &&
- test "$(test-tool urlmatch-normalization -p "x://y/a/.?")" = "x://y/a?" &&
- test "$(test-tool urlmatch-normalization -p "x://y/a/./?")" = "x://y/a/?" &&
- test "$(test-tool urlmatch-normalization -p "x://y/a/./b/.././../c")" = "x://y/c" &&
- test "$(test-tool urlmatch-normalization -p "x://y/a/./b/../.././c/")" = "x://y/c/" &&
- test "$(test-tool urlmatch-normalization -p "x://y/a/./b/.././../c/././.././.")" = "x://y/" &&
- ! test-tool urlmatch-normalization "x://y/a/./b/.././../c/././.././.." &&
- test "$(test-tool urlmatch-normalization -p "x://y/a/./?/././..")" = "x://y/a/?/././.." &&
- test "$(test-tool urlmatch-normalization -p "x://y/%2e/")" = "x://y/" &&
- test "$(test-tool urlmatch-normalization -p "x://y/%2E/")" = "x://y/" &&
- test "$(test-tool urlmatch-normalization -p "x://y/a/%2e./")" = "x://y/" &&
- test "$(test-tool urlmatch-normalization -p "x://y/b/.%2E/")" = "x://y/" &&
- test "$(test-tool urlmatch-normalization -p "x://y/c/%2e%2E/")" = "x://y/"
-'
-
-# http://@foo specifies an empty user name but does not specify a password
-# http://foo specifies neither a user name nor a password
-# So they should not be equivalent
-test_expect_success 'url equivalents' '
- test-tool urlmatch-normalization "httP://x" "Http://X/" &&
- test-tool urlmatch-normalization "Http://%4d%65:%4d^%70@The.Host" "hTTP://Me:%4D^p@the.HOST:80/" &&
- ! test-tool urlmatch-normalization "https://@x.y/^" "httpS://x.y:443/^" &&
- test-tool urlmatch-normalization "https://@x.y/^" "httpS://@x.y:0443/^" &&
- test-tool urlmatch-normalization "https://@x.y/^/../abc" "httpS://@x.y:0443/abc" &&
- test-tool urlmatch-normalization "https://@x.y/^/.." "httpS://@x.y:0443/"
-'
-
-test_done
diff --git a/t/t0110/README b/t/t0110/README
deleted file mode 100644
index ad4a50ecd8..0000000000
--- a/t/t0110/README
+++ /dev/null
@@ -1,9 +0,0 @@
-The url data files in this directory contain URLs with characters
-in the range 0x01-0x1f and 0x7f-0xff to test the proper normalization
-of unprintable characters.
-
-A select few characters in the 0x01-0x1f range are skipped to help
-avoid problems running the test itself.
-
-The urls are in test files in this directory rather than being
-embedded in the test script for portability.
diff --git a/t/t0110/url-1 b/t/t0110/url-1
deleted file mode 100644
index 519019c5ce..0000000000
--- a/t/t0110/url-1
+++ /dev/null
@@ -1 +0,0 @@
-x://q/
diff --git a/t/t0110/url-10 b/t/t0110/url-10
deleted file mode 100644
index b9965de6a5..0000000000
--- a/t/t0110/url-10
+++ /dev/null
@@ -1 +0,0 @@
-x://q/����������������
diff --git a/t/t0110/url-11 b/t/t0110/url-11
deleted file mode 100644
index f0a50f1009..0000000000
--- a/t/t0110/url-11
+++ /dev/null
@@ -1 +0,0 @@
-x://q/€߿ࠀ�𐀀𯿽
diff --git a/t/t0110/url-2 b/t/t0110/url-2
deleted file mode 100644
index 43334b05b2..0000000000
--- a/t/t0110/url-2
+++ /dev/null
@@ -1 +0,0 @@
-x://q/
diff --git a/t/t0110/url-3 b/t/t0110/url-3
deleted file mode 100644
index 7378c7bec2..0000000000
--- a/t/t0110/url-3
+++ /dev/null
@@ -1 +0,0 @@
-x://q/����������������
diff --git a/t/t0110/url-4 b/t/t0110/url-4
deleted file mode 100644
index 220b198c97..0000000000
--- a/t/t0110/url-4
+++ /dev/null
@@ -1 +0,0 @@
-x://q/����������������
diff --git a/t/t0110/url-5 b/t/t0110/url-5
deleted file mode 100644
index 1ccd927779..0000000000
--- a/t/t0110/url-5
+++ /dev/null
@@ -1 +0,0 @@
-x://q/����������������
diff --git a/t/t0110/url-6 b/t/t0110/url-6
deleted file mode 100644
index e8283aac6d..0000000000
--- a/t/t0110/url-6
+++ /dev/null
@@ -1 +0,0 @@
-x://q/����������������
diff --git a/t/t0110/url-7 b/t/t0110/url-7
deleted file mode 100644
index fa7c10b615..0000000000
--- a/t/t0110/url-7
+++ /dev/null
@@ -1 +0,0 @@
-x://q/����������������
diff --git a/t/t0110/url-8 b/t/t0110/url-8
deleted file mode 100644
index 79a0ba836f..0000000000
--- a/t/t0110/url-8
+++ /dev/null
@@ -1 +0,0 @@
-x://q/����������������
diff --git a/t/t0110/url-9 b/t/t0110/url-9
deleted file mode 100644
index 8b44bec48b..0000000000
--- a/t/t0110/url-9
+++ /dev/null
@@ -1 +0,0 @@
-x://q/����������������
diff --git a/t/t0210-trace2-normal.sh b/t/t0210-trace2-normal.sh
index c312657a12..b9adc94aab 100755
--- a/t/t0210-trace2-normal.sh
+++ b/t/t0210-trace2-normal.sh
@@ -2,7 +2,7 @@
test_description='test trace2 facility (normal target)'
-TEST_PASSES_SANITIZE_LEAK=false
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
# Turn off any inherited trace2 settings for this test.
diff --git a/t/t1006-cat-file.sh b/t/t1006-cat-file.sh
index ff9bf213aa..d36cd7c086 100755
--- a/t/t1006-cat-file.sh
+++ b/t/t1006-cat-file.sh
@@ -2,6 +2,7 @@
test_description='git cat-file'
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
test_cmdmode_usage () {
diff --git a/t/t1050-large.sh b/t/t1050-large.sh
index c71932b024..ed638f6644 100755
--- a/t/t1050-large.sh
+++ b/t/t1050-large.sh
@@ -3,6 +3,7 @@
test_description='adding and checking out large blobs'
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
test_expect_success 'core.bigFileThreshold must be non-negative' '
diff --git a/t/t1450-fsck.sh b/t/t1450-fsck.sh
index 8a456b1142..280cbf3e03 100755
--- a/t/t1450-fsck.sh
+++ b/t/t1450-fsck.sh
@@ -6,6 +6,7 @@ test_description='git fsck random collection of tests
* (main) A
'
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
test_expect_success setup '
diff --git a/t/t1601-index-bogus.sh b/t/t1601-index-bogus.sh
index 4171f1e141..5dcc101882 100755
--- a/t/t1601-index-bogus.sh
+++ b/t/t1601-index-bogus.sh
@@ -1,6 +1,8 @@
#!/bin/sh
test_description='test handling of bogus index entries'
+
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
test_expect_success 'create tree with null sha1' '
diff --git a/t/t3310-notes-merge-manual-resolve.sh b/t/t3310-notes-merge-manual-resolve.sh
index 597df5ebc0..04866b89be 100755
--- a/t/t3310-notes-merge-manual-resolve.sh
+++ b/t/t3310-notes-merge-manual-resolve.sh
@@ -5,6 +5,7 @@
test_description='Test notes merging with manual conflict resolution'
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
# Set up a notes merge scenario with different kinds of conflicts
diff --git a/t/t3311-notes-merge-fanout.sh b/t/t3311-notes-merge-fanout.sh
index 5b675417e9..ce4144db0f 100755
--- a/t/t3311-notes-merge-fanout.sh
+++ b/t/t3311-notes-merge-fanout.sh
@@ -5,6 +5,7 @@
test_description='Test notes merging at various fanout levels'
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
verify_notes () {
diff --git a/t/t3400-rebase.sh b/t/t3400-rebase.sh
index ae34bfad60..bd8bcc381a 100755
--- a/t/t3400-rebase.sh
+++ b/t/t3400-rebase.sh
@@ -235,6 +235,12 @@ test_expect_success 'rebase --merge -q is quiet' '
test_must_be_empty output.out
'
+test_expect_success 'rebase --exec -q is quiet' '
+ git checkout -B quiet topic &&
+ git rebase --exec true -q main >output.out 2>&1 &&
+ test_must_be_empty output.out
+'
+
test_expect_success 'Rebase a commit that sprinkles CRs in' '
(
echo "One" &&
diff --git a/t/t3404-rebase-interactive.sh b/t/t3404-rebase-interactive.sh
index f92baad138..f171af3061 100755
--- a/t/t3404-rebase-interactive.sh
+++ b/t/t3404-rebase-interactive.sh
@@ -26,6 +26,7 @@ Initial setup:
touch file "conflict".
'
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
. "$TEST_DIRECTORY"/lib-rebase.sh
diff --git a/t/t3435-rebase-gpg-sign.sh b/t/t3435-rebase-gpg-sign.sh
index 6aa2aeb628..6e329fea7c 100755
--- a/t/t3435-rebase-gpg-sign.sh
+++ b/t/t3435-rebase-gpg-sign.sh
@@ -8,6 +8,7 @@ test_description='test rebase --[no-]gpg-sign'
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
. "$TEST_DIRECTORY/lib-rebase.sh"
. "$TEST_DIRECTORY/lib-gpg.sh"
diff --git a/t/t3507-cherry-pick-conflict.sh b/t/t3507-cherry-pick-conflict.sh
index f3947b400a..10e9c91dbb 100755
--- a/t/t3507-cherry-pick-conflict.sh
+++ b/t/t3507-cherry-pick-conflict.sh
@@ -13,6 +13,7 @@ GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
TEST_CREATE_REPO_NO_TEMPLATE=1
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
pristine_detach () {
diff --git a/t/t3510-cherry-pick-sequence.sh b/t/t3510-cherry-pick-sequence.sh
index 7eb52b12ed..93c725bac3 100755
--- a/t/t3510-cherry-pick-sequence.sh
+++ b/t/t3510-cherry-pick-sequence.sh
@@ -12,6 +12,7 @@ test_description='Test cherry-pick continuation features
'
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
# Repeat first match 10 times
diff --git a/t/t3705-add-sparse-checkout.sh b/t/t3705-add-sparse-checkout.sh
index 2bade9e804..6ae45a788d 100755
--- a/t/t3705-add-sparse-checkout.sh
+++ b/t/t3705-add-sparse-checkout.sh
@@ -2,6 +2,7 @@
test_description='git add in sparse checked out working trees'
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
SPARSE_ENTRY_BLOB=""
diff --git a/t/t3903-stash.sh b/t/t3903-stash.sh
index e4c0937f61..c87592ee2f 100755
--- a/t/t3903-stash.sh
+++ b/t/t3903-stash.sh
@@ -1398,6 +1398,21 @@ test_expect_success 'stash --keep-index with file deleted in index does not resu
test_path_is_missing to-remove
'
+test_expect_success 'stash --keep-index --include-untracked with empty tree' '
+ test_when_finished "rm -rf empty" &&
+ git init empty &&
+ (
+ cd empty &&
+ git commit --allow-empty --message "empty" &&
+ echo content >file &&
+ git stash push --keep-index --include-untracked &&
+ test_path_is_missing file &&
+ git stash pop &&
+ echo content >expect &&
+ test_cmp expect file
+ )
+'
+
test_expect_success 'stash apply should succeed with unmodified file' '
echo base >file &&
git add file &&
diff --git a/t/t4013-diff-various.sh b/t/t4013-diff-various.sh
index 3855d68dbc..87d248d034 100755
--- a/t/t4013-diff-various.sh
+++ b/t/t4013-diff-various.sh
@@ -8,6 +8,7 @@ test_description='Various diff formatting options'
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=master
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
. "$TEST_DIRECTORY"/lib-diff.sh
diff --git a/t/t4014-format-patch.sh b/t/t4014-format-patch.sh
index 884f83fb8a..1c46e963e4 100755
--- a/t/t4014-format-patch.sh
+++ b/t/t4014-format-patch.sh
@@ -8,6 +8,7 @@ test_description='various format-patch tests'
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
. "$TEST_DIRECTORY"/lib-terminal.sh
diff --git a/t/t4018-diff-funcname.sh b/t/t4018-diff-funcname.sh
index e026fac1f4..8128c30e7f 100755
--- a/t/t4018-diff-funcname.sh
+++ b/t/t4018-diff-funcname.sh
@@ -5,6 +5,7 @@
test_description='Test custom diff function name patterns'
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
test_expect_success 'setup' '
diff --git a/t/t4030-diff-textconv.sh b/t/t4030-diff-textconv.sh
index a39a626664..29f6d610c2 100755
--- a/t/t4030-diff-textconv.sh
+++ b/t/t4030-diff-textconv.sh
@@ -1,6 +1,8 @@
#!/bin/sh
test_description='diff.*.textconv tests'
+
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
find_diff() {
diff --git a/t/t4042-diff-textconv-caching.sh b/t/t4042-diff-textconv-caching.sh
index 8ebfa3c1be..a179205394 100755
--- a/t/t4042-diff-textconv-caching.sh
+++ b/t/t4042-diff-textconv-caching.sh
@@ -1,6 +1,8 @@
#!/bin/sh
test_description='test textconv caching'
+
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
cat >helper <<'EOF'
diff --git a/t/t4048-diff-combined-binary.sh b/t/t4048-diff-combined-binary.sh
index 0260cf64f5..f399484bce 100755
--- a/t/t4048-diff-combined-binary.sh
+++ b/t/t4048-diff-combined-binary.sh
@@ -4,6 +4,7 @@ test_description='combined and merge diff handle binary files and textconv'
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
test_expect_success 'setup binary merge conflict' '
diff --git a/t/t4064-diff-oidfind.sh b/t/t4064-diff-oidfind.sh
index 6d8c8986fc..846f285f77 100755
--- a/t/t4064-diff-oidfind.sh
+++ b/t/t4064-diff-oidfind.sh
@@ -1,6 +1,8 @@
#!/bin/sh
test_description='test finding specific blobs in the revision walking'
+
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
test_expect_success 'setup ' '
diff --git a/t/t4065-diff-anchored.sh b/t/t4065-diff-anchored.sh
index b3f510f040..647537c12e 100755
--- a/t/t4065-diff-anchored.sh
+++ b/t/t4065-diff-anchored.sh
@@ -2,6 +2,7 @@
test_description='anchored diff algorithm'
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
test_expect_success '--anchored' '
diff --git a/t/t4068-diff-symmetric-merge-base.sh b/t/t4068-diff-symmetric-merge-base.sh
index eff63c16b0..4d6565e728 100755
--- a/t/t4068-diff-symmetric-merge-base.sh
+++ b/t/t4068-diff-symmetric-merge-base.sh
@@ -5,6 +5,7 @@ test_description='behavior of diff with symmetric-diff setups and --merge-base'
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
# build these situations:
diff --git a/t/t4069-remerge-diff.sh b/t/t4069-remerge-diff.sh
index ca8f999cab..df342850a0 100755
--- a/t/t4069-remerge-diff.sh
+++ b/t/t4069-remerge-diff.sh
@@ -2,6 +2,7 @@
test_description='remerge-diff handling'
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
# This test is ort-specific
diff --git a/t/t4108-apply-threeway.sh b/t/t4108-apply-threeway.sh
index c558282bc0..3211e1e65f 100755
--- a/t/t4108-apply-threeway.sh
+++ b/t/t4108-apply-threeway.sh
@@ -5,6 +5,7 @@ test_description='git apply --3way'
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
print_sanitized_conflicted_diff () {
diff --git a/t/t4129-apply-samemode.sh b/t/t4129-apply-samemode.sh
index d9a1084b5e..87ffd2b8e1 100755
--- a/t/t4129-apply-samemode.sh
+++ b/t/t4129-apply-samemode.sh
@@ -153,8 +153,8 @@ test_expect_success POSIXPERM 'patch mode for new file is canonicalized' '
test_expect_success POSIXPERM 'patch mode for deleted file is canonicalized' '
test_when_finished "git reset --hard" &&
echo content >non-canon &&
- git add non-canon &&
chmod 666 non-canon &&
+ git add non-canon &&
cat >patch <<-\EOF &&
diff --git a/non-canon b/non-canon
diff --git a/t/t4209-log-pickaxe.sh b/t/t4209-log-pickaxe.sh
index 64e1623733..b42fdc54fc 100755
--- a/t/t4209-log-pickaxe.sh
+++ b/t/t4209-log-pickaxe.sh
@@ -1,6 +1,8 @@
#!/bin/sh
test_description='log --grep/--author/--regexp-ignore-case/-S/-G'
+
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
test_log () {
diff --git a/t/t5304-prune.sh b/t/t5304-prune.sh
index 1f1f664871..e641df0116 100755
--- a/t/t5304-prune.sh
+++ b/t/t5304-prune.sh
@@ -7,6 +7,7 @@ test_description='prune'
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
day=$((60*60*24))
diff --git a/t/t5333-pseudo-merge-bitmaps.sh b/t/t5333-pseudo-merge-bitmaps.sh
index f052f395a7..1dd6284756 100755
--- a/t/t5333-pseudo-merge-bitmaps.sh
+++ b/t/t5333-pseudo-merge-bitmaps.sh
@@ -390,4 +390,60 @@ test_expect_success 'pseudo-merge reuse' '
)
'
+test_expect_success 'empty pseudo-merge group' '
+ git init pseudo-merge-empty-group &&
+ (
+ cd pseudo-merge-empty-group &&
+
+ # Ensure that a pseudo-merge group with no unstable
+ # commits does not generate an empty pseudo-merge
+ # bitmap.
+ git config bitmapPseudoMerge.empty.pattern refs/ &&
+
+ test_commit base &&
+ git repack -adb &&
+
+ test-tool bitmap dump-pseudo-merges >merges &&
+ test_line_count = 1 merges &&
+
+ test 0 -eq "$(grep -c commits=0 <merges)"
+ )
+'
+
+test_expect_success 'pseudo-merge closure' '
+ git init pseudo-merge-closure &&
+ (
+ cd pseudo-merge-closure &&
+
+ test_commit A &&
+ git repack -d &&
+
+ test_commit B &&
+
+ # Note that the contents of A is packed, but B is not. A
+ # (and the objects reachable from it) are thus visible
+ # to the MIDX, but the same is not true for B and its
+ # objects.
+ #
+ # Ensure that we do not attempt to create a pseudo-merge
+ # for B, depsite it matching the below pseudo-merge
+ # group pattern, as doing so would result in a failure
+ # to write a non-closed bitmap.
+ git config bitmapPseudoMerge.test.pattern refs/ &&
+ git config bitmapPseudoMerge.test.threshold now &&
+
+ git multi-pack-index write --bitmap &&
+
+ test-tool bitmap dump-pseudo-merges >pseudo-merges &&
+ test_line_count = 1 pseudo-merges &&
+
+ git rev-parse A >expect &&
+
+ test-tool bitmap list-commits >actual &&
+ test_cmp expect actual &&
+ test-tool bitmap dump-pseudo-merge-commits 0 >actual &&
+ test_cmp expect actual
+ )
+'
+
test_done
diff --git a/t/t5616-partial-clone.sh b/t/t5616-partial-clone.sh
index 2da7291e37..8415884754 100755
--- a/t/t5616-partial-clone.sh
+++ b/t/t5616-partial-clone.sh
@@ -229,7 +229,7 @@ test_expect_success 'fetch --refetch triggers repacking' '
GIT_TRACE2_EVENT="$PWD/trace1.event" \
git -C pc1 fetch --refetch origin &&
- test_subcommand git maintenance run --auto --no-quiet <trace1.event &&
+ test_subcommand git maintenance run --auto --no-quiet --detach <trace1.event &&
grep \"param\":\"gc.autopacklimit\",\"value\":\"1\" trace1.event &&
grep \"param\":\"maintenance.incremental-repack.auto\",\"value\":\"-1\" trace1.event &&
@@ -238,7 +238,7 @@ test_expect_success 'fetch --refetch triggers repacking' '
-c gc.autoPackLimit=0 \
-c maintenance.incremental-repack.auto=1234 \
-C pc1 fetch --refetch origin &&
- test_subcommand git maintenance run --auto --no-quiet <trace2.event &&
+ test_subcommand git maintenance run --auto --no-quiet --detach <trace2.event &&
grep \"param\":\"gc.autopacklimit\",\"value\":\"0\" trace2.event &&
grep \"param\":\"maintenance.incremental-repack.auto\",\"value\":\"-1\" trace2.event &&
@@ -247,7 +247,7 @@ test_expect_success 'fetch --refetch triggers repacking' '
-c gc.autoPackLimit=1234 \
-c maintenance.incremental-repack.auto=0 \
-C pc1 fetch --refetch origin &&
- test_subcommand git maintenance run --auto --no-quiet <trace3.event &&
+ test_subcommand git maintenance run --auto --no-quiet --detach <trace3.event &&
grep \"param\":\"gc.autopacklimit\",\"value\":\"1\" trace3.event &&
grep \"param\":\"maintenance.incremental-repack.auto\",\"value\":\"0\" trace3.event
'
diff --git a/t/t6020-bundle-misc.sh b/t/t6020-bundle-misc.sh
index fe75a06572..34b5cd62c2 100755
--- a/t/t6020-bundle-misc.sh
+++ b/t/t6020-bundle-misc.sh
@@ -652,4 +652,36 @@ test_expect_success 'send a bundle to standard output' '
test_cmp expect actual
'
+test_expect_success 'unbundle outside of a repository' '
+ git bundle create some.bundle HEAD &&
+ echo "fatal: Need a repository to unbundle." >expect &&
+ nongit test_must_fail git bundle unbundle "$(pwd)/some.bundle" 2>err &&
+ test_cmp expect err
+'
+
+test_expect_success 'list-heads outside of a repository' '
+ git bundle create some.bundle HEAD &&
+ cat >expect <<-EOF &&
+ $(git rev-parse HEAD) HEAD
+ EOF
+ nongit git bundle list-heads "$(pwd)/some.bundle" >actual &&
+ test_cmp expect actual
+'
+
+for hash in sha1 sha256
+do
+ test_expect_success "list-heads with bundle using $hash" '
+ test_when_finished "rm -rf hash" &&
+ git init --object-format=$hash hash &&
+ test_commit -C hash initial &&
+ git -C hash bundle create hash.bundle HEAD &&
+
+ cat >expect <<-EOF &&
+ $(git -C hash rev-parse HEAD) HEAD
+ EOF
+ git bundle list-heads hash/hash.bundle >actual &&
+ test_cmp expect actual
+ '
+done
+
test_done
diff --git a/t/t6300-for-each-ref.sh b/t/t6300-for-each-ref.sh
index eb6c8204e8..8d15713cc6 100755
--- a/t/t6300-for-each-ref.sh
+++ b/t/t6300-for-each-ref.sh
@@ -1907,6 +1907,15 @@ test_expect_success 'git for-each-ref with nested tags' '
test_cmp expect actual
'
+test_expect_success 'is-base atom with non-commits' '
+ git for-each-ref --format="%(is-base:HEAD) %(refname)" >out 2>err &&
+ grep "(HEAD) refs/heads/main" out &&
+
+ test_line_count = 2 err &&
+ grep "error: object .* is a commit, not a blob" err &&
+ grep "error: bad tag pointer to" err
+'
+
GRADE_FORMAT="%(signature:grade)%0a%(signature:key)%0a%(signature:signer)%0a%(signature:fingerprint)%0a%(signature:primarykeyfingerprint)"
TRUSTLEVEL_FORMAT="%(signature:trustlevel)%0a%(signature:key)%0a%(signature:signer)%0a%(signature:fingerprint)%0a%(signature:primarykeyfingerprint)"
diff --git a/t/t6421-merge-partial-clone.sh b/t/t6421-merge-partial-clone.sh
index b99f29ef9b..30349a466e 100755
--- a/t/t6421-merge-partial-clone.sh
+++ b/t/t6421-merge-partial-clone.sh
@@ -26,6 +26,7 @@ test_description="limiting blob downloads when merging with partial clones"
# underscore notation is to differentiate different
# files that might be renamed into each other's paths.)
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
. "$TEST_DIRECTORY"/lib-merge.sh
diff --git a/t/t6428-merge-conflicts-sparse.sh b/t/t6428-merge-conflicts-sparse.sh
index 9919c3fa7c..8a79bc2e92 100755
--- a/t/t6428-merge-conflicts-sparse.sh
+++ b/t/t6428-merge-conflicts-sparse.sh
@@ -22,6 +22,7 @@ test_description="merge cases"
# underscore notation is to differentiate different
# files that might be renamed into each other's paths.)
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
. "$TEST_DIRECTORY"/lib-merge.sh
diff --git a/t/t6500-gc.sh b/t/t6500-gc.sh
index 1b5909d1b7..5378455968 100755
--- a/t/t6500-gc.sh
+++ b/t/t6500-gc.sh
@@ -338,14 +338,14 @@ test_expect_success 'gc.maxCruftSize sets appropriate repack options' '
test_subcommand $cruft_max_size_opts --max-cruft-size=3145728 <trace2.txt
'
-run_and_wait_for_auto_gc () {
+run_and_wait_for_gc () {
# We read stdout from gc for the side effect of waiting until the
# background gc process exits, closing its fd 9. Furthermore, the
# variable assignment from a command substitution preserves the
# exit status of the main gc process.
# Note: this fd trickery doesn't work on Windows, but there is no
# need to, because on Win the auto gc always runs in the foreground.
- doesnt_matter=$(git gc --auto 9>&1)
+ doesnt_matter=$(git gc "$@" 9>&1)
}
test_expect_success 'background auto gc does not run if gc.log is present and recent but does if it is old' '
@@ -361,7 +361,7 @@ test_expect_success 'background auto gc does not run if gc.log is present and re
test-tool chmtime =-345600 .git/gc.log &&
git gc --auto &&
test_config gc.logexpiry 2.days &&
- run_and_wait_for_auto_gc &&
+ run_and_wait_for_gc --auto &&
ls .git/objects/pack/pack-*.pack >packs &&
test_line_count = 1 packs
'
@@ -391,11 +391,48 @@ test_expect_success 'background auto gc respects lock for all operations' '
printf "%d %s" "$shell_pid" "$hostname" >.git/gc.pid &&
# our gc should exit zero without doing anything
- run_and_wait_for_auto_gc &&
+ run_and_wait_for_gc --auto &&
(ls -1 .git/refs/heads .git/reftable >actual || true) &&
test_cmp expect actual
'
+test_expect_success '--detach overrides gc.autoDetach=false' '
+ test_when_finished "rm -rf repo" &&
+ git init repo &&
+ (
+ cd repo &&
+
+ # Prepare the repository such that git-gc(1) ends up repacking.
+ test_commit "$(test_oid blob17_1)" &&
+ test_commit "$(test_oid blob17_2)" &&
+ git config gc.autodetach false &&
+ git config gc.auto 2 &&
+
+ # Note that we cannot use `test_cmp` here to compare stderr
+ # because it may contain output from `set -x`.
+ run_and_wait_for_gc --auto --detach 2>actual &&
+ test_grep "Auto packing the repository in background for optimum performance." actual
+ )
+'
+
+test_expect_success '--no-detach overrides gc.autoDetach=true' '
+ test_when_finished "rm -rf repo" &&
+ git init repo &&
+ (
+ cd repo &&
+
+ # Prepare the repository such that git-gc(1) ends up repacking.
+ test_commit "$(test_oid blob17_1)" &&
+ test_commit "$(test_oid blob17_2)" &&
+ git config gc.autodetach true &&
+ git config gc.auto 2 &&
+
+ GIT_PROGRESS_DELAY=0 git gc --auto --no-detach 2>output &&
+ test_grep "Auto packing the repository for optimum performance." output &&
+ test_grep "Collecting referenced commits: 2, done." output
+ )
+'
+
# DO NOT leave a detached auto gc process running near the end of the
# test script: it can run long enough in the background to racily
# interfere with the cleanup in 'test_done'.
diff --git a/t/t6600-test-reach.sh b/t/t6600-test-reach.sh
index b330945f49..2591f8b8b3 100755
--- a/t/t6600-test-reach.sh
+++ b/t/t6600-test-reach.sh
@@ -612,4 +612,125 @@ test_expect_success 'for-each-ref merged:none' '
--format="%(refname)" --stdin
'
+# For get_branch_base_for_tip, we only care about
+# first-parent history. Here is the test graph with
+# second parents removed:
+#
+# (10,10)
+# /
+# (10,9) (9,10)
+# / /
+# (10,8) (9,9) (8,10)
+# / / /
+# ( continued...)
+# \ / / /
+# (3,1) (2,2) (1,3)
+# \ / /
+# (2,1) (1,2)
+# \ /
+# (1,1)
+#
+# In short, for a commit (i,j), the first-parent history
+# walks all commits (i, k) with k from j to 1, then the
+# commits (l, 1) with l from i to 1.
+
+test_expect_success 'get_branch_base_for_tip: none reach' '
+ # (2,3) branched from the first tip (i,4) in X with i > 2
+ cat >input <<-\EOF &&
+ A:commit-2-3
+ X:commit-1-2
+ X:commit-1-4
+ X:commit-4-4
+ X:commit-8-4
+ X:commit-10-4
+ EOF
+ echo "get_branch_base_for_tip(A,X):2" >expect &&
+ test_all_modes get_branch_base_for_tip
+'
+
+test_expect_success 'get_branch_base_for_tip: equal to tip' '
+ # (2,3) branched from the first tip (i,4) in X with i > 2
+ cat >input <<-\EOF &&
+ A:commit-8-4
+ X:commit-1-2
+ X:commit-1-4
+ X:commit-4-4
+ X:commit-8-4
+ X:commit-10-4
+ EOF
+ echo "get_branch_base_for_tip(A,X):3" >expect &&
+ test_all_modes get_branch_base_for_tip
+'
+
+test_expect_success 'get_branch_base_for_tip: all reach tip' '
+ # (2,3) branched from the first tip (i,4) in X with i > 2
+ cat >input <<-\EOF &&
+ A:commit-4-1
+ X:commit-4-2
+ X:commit-5-1
+ EOF
+ echo "get_branch_base_for_tip(A,X):0" >expect &&
+ test_all_modes get_branch_base_for_tip
+'
+
+test_expect_success 'for-each-ref is-base: none reach' '
+ cat >input <<-\EOF &&
+ refs/heads/commit-1-1
+ refs/heads/commit-4-2
+ refs/heads/commit-4-4
+ refs/heads/commit-8-4
+ EOF
+ cat >expect <<-\EOF &&
+ refs/heads/commit-1-1:
+ refs/heads/commit-4-2:(commit-2-3)
+ refs/heads/commit-4-4:
+ refs/heads/commit-8-4:
+ EOF
+ run_all_modes git for-each-ref \
+ --format="%(refname):%(is-base:commit-2-3)" --stdin
+'
+
+test_expect_success 'for-each-ref is-base: all reach' '
+ cat >input <<-\EOF &&
+ refs/heads/commit-4-2
+ refs/heads/commit-5-1
+ EOF
+ cat >expect <<-\EOF &&
+ refs/heads/commit-4-2:(commit-4-1)
+ refs/heads/commit-5-1:
+ EOF
+ run_all_modes git for-each-ref \
+ --format="%(refname):%(is-base:commit-4-1)" --stdin
+'
+
+test_expect_success 'for-each-ref is-base: equal to tip' '
+ cat >input <<-\EOF &&
+ refs/heads/commit-4-2
+ refs/heads/commit-5-1
+ EOF
+ cat >expect <<-\EOF &&
+ refs/heads/commit-4-2:(commit-4-2)
+ refs/heads/commit-5-1:
+ EOF
+ run_all_modes git for-each-ref \
+ --format="%(refname):%(is-base:commit-4-2)" --stdin
+'
+
+test_expect_success 'for-each-ref is-base:multiple' '
+ cat >input <<-\EOF &&
+ refs/heads/commit-1-1
+ refs/heads/commit-4-2
+ refs/heads/commit-4-4
+ refs/heads/commit-8-4
+ EOF
+ cat >expect <<-\EOF &&
+ refs/heads/commit-1-1[-]
+ refs/heads/commit-4-2[(commit-2-3)-]
+ refs/heads/commit-4-4[-]
+ refs/heads/commit-8-4[-(commit-6-5)]
+ EOF
+ run_all_modes git for-each-ref \
+ --format="%(refname)[%(is-base:commit-2-3)-%(is-base:commit-6-5)]" --stdin
+'
+
test_done
diff --git a/t/t7008-filter-branch-null-sha1.sh b/t/t7008-filter-branch-null-sha1.sh
index 93fbc92b8d..0ce8fd2c89 100755
--- a/t/t7008-filter-branch-null-sha1.sh
+++ b/t/t7008-filter-branch-null-sha1.sh
@@ -2,6 +2,7 @@
test_description='filter-branch removal of trees with null sha1'
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
test_expect_success 'setup: base commits' '
diff --git a/t/t7030-verify-tag.sh b/t/t7030-verify-tag.sh
index 6f526c37c2..effa826744 100755
--- a/t/t7030-verify-tag.sh
+++ b/t/t7030-verify-tag.sh
@@ -4,6 +4,7 @@ test_description='signed tag tests'
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
. "$TEST_DIRECTORY/lib-gpg.sh"
diff --git a/t/t7817-grep-sparse-checkout.sh b/t/t7817-grep-sparse-checkout.sh
index eb59564565..0ba7817fb7 100755
--- a/t/t7817-grep-sparse-checkout.sh
+++ b/t/t7817-grep-sparse-checkout.sh
@@ -33,6 +33,7 @@ should leave the following structure in the working tree:
But note that sub2 should have the SKIP_WORKTREE bit set.
'
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
test_expect_success 'setup' '
diff --git a/t/t7900-maintenance.sh b/t/t7900-maintenance.sh
index 8595489ceb..abae7a9754 100755
--- a/t/t7900-maintenance.sh
+++ b/t/t7900-maintenance.sh
@@ -49,22 +49,47 @@ test_expect_success 'run [--auto|--quiet]' '
git maintenance run --auto 2>/dev/null &&
GIT_TRACE2_EVENT="$(pwd)/run-no-quiet.txt" \
git maintenance run --no-quiet 2>/dev/null &&
- test_subcommand git gc --quiet <run-no-auto.txt &&
- test_subcommand ! git gc --auto --quiet <run-auto.txt &&
- test_subcommand git gc --no-quiet <run-no-quiet.txt
+ test_subcommand git gc --quiet --no-detach <run-no-auto.txt &&
+ test_subcommand ! git gc --auto --quiet --no-detach <run-auto.txt &&
+ test_subcommand git gc --no-quiet --no-detach <run-no-quiet.txt
'
test_expect_success 'maintenance.auto config option' '
GIT_TRACE2_EVENT="$(pwd)/default" git commit --quiet --allow-empty -m 1 &&
- test_subcommand git maintenance run --auto --quiet <default &&
+ test_subcommand git maintenance run --auto --quiet --detach <default &&
GIT_TRACE2_EVENT="$(pwd)/true" \
git -c maintenance.auto=true \
commit --quiet --allow-empty -m 2 &&
- test_subcommand git maintenance run --auto --quiet <true &&
+ test_subcommand git maintenance run --auto --quiet --detach <true &&
GIT_TRACE2_EVENT="$(pwd)/false" \
git -c maintenance.auto=false \
commit --quiet --allow-empty -m 3 &&
- test_subcommand ! git maintenance run --auto --quiet <false
+ test_subcommand ! git maintenance run --auto --quiet --detach <false
+'
+
+for cfg in maintenance.autoDetach gc.autoDetach
+do
+ test_expect_success "$cfg=true config option" '
+ test_when_finished "rm -f trace" &&
+ test_config $cfg true &&
+ GIT_TRACE2_EVENT="$(pwd)/trace" git commit --quiet --allow-empty -m 1 &&
+ test_subcommand git maintenance run --auto --quiet --detach <trace
+ '
+
+ test_expect_success "$cfg=false config option" '
+ test_when_finished "rm -f trace" &&
+ test_config $cfg false &&
+ GIT_TRACE2_EVENT="$(pwd)/trace" git commit --quiet --allow-empty -m 1 &&
+ test_subcommand git maintenance run --auto --quiet --no-detach <trace
+ '
+done
+
+test_expect_success "maintenance.autoDetach overrides gc.autoDetach" '
+ test_when_finished "rm -f trace" &&
+ test_config maintenance.autoDetach false &&
+ test_config gc.autoDetach true &&
+ GIT_TRACE2_EVENT="$(pwd)/trace" git commit --quiet --allow-empty -m 1 &&
+ test_subcommand git maintenance run --auto --quiet --no-detach <trace
'
test_expect_success 'register uses XDG_CONFIG_HOME config if it exists' '
@@ -129,9 +154,9 @@ test_expect_success 'run --task=<task>' '
git maintenance run --task=commit-graph 2>/dev/null &&
GIT_TRACE2_EVENT="$(pwd)/run-both.txt" \
git maintenance run --task=commit-graph --task=gc 2>/dev/null &&
- test_subcommand ! git gc --quiet <run-commit-graph.txt &&
- test_subcommand git gc --quiet <run-gc.txt &&
- test_subcommand git gc --quiet <run-both.txt &&
+ test_subcommand ! git gc --quiet --no-detach <run-commit-graph.txt &&
+ test_subcommand git gc --quiet --no-detach <run-gc.txt &&
+ test_subcommand git gc --quiet --no-detach <run-both.txt &&
test_subcommand git commit-graph write --split --reachable --no-progress <run-commit-graph.txt &&
test_subcommand ! git commit-graph write --split --reachable --no-progress <run-gc.txt &&
test_subcommand git commit-graph write --split --reachable --no-progress <run-both.txt
@@ -908,4 +933,62 @@ test_expect_success 'failed schedule prevents config change' '
done
'
+test_expect_success '--no-detach causes maintenance to not run in background' '
+ test_when_finished "rm -rf repo" &&
+ git init repo &&
+ (
+ cd repo &&
+
+ # Prepare the repository such that git-maintenance(1) ends up
+ # outputting something.
+ test_commit something &&
+ git config set maintenance.gc.enabled false &&
+ git config set maintenance.loose-objects.enabled true &&
+ git config set maintenance.loose-objects.auto 1 &&
+ git config set maintenance.incremental-repack.enabled true &&
+
+ GIT_TRACE2_EVENT="$(pwd)/trace.txt" \
+ git maintenance run --no-detach >out 2>&1 &&
+ ! test_region maintenance detach trace.txt
+ )
+'
+
+test_expect_success '--detach causes maintenance to run in background' '
+ test_when_finished "rm -rf repo" &&
+ git init repo &&
+ (
+ cd repo &&
+
+ test_commit something &&
+ git config set maintenance.gc.enabled false &&
+ git config set maintenance.loose-objects.enabled true &&
+ git config set maintenance.loose-objects.auto 1 &&
+ git config set maintenance.incremental-repack.enabled true &&
+
+ # The extra file descriptor gets inherited to the child
+ # process, and by reading stdout we thus essentially wait for
+ # that descriptor to get closed, which indicates that the child
+ # is done, too.
+ does_not_matter=$(GIT_TRACE2_EVENT="$(pwd)/trace.txt" \
+ git maintenance run --detach 9>&1) &&
+ test_region maintenance detach trace.txt
+ )
+'
+
+test_expect_success 'repacking loose objects is quiet' '
+ test_when_finished "rm -rf repo" &&
+ git init repo &&
+ (
+ cd repo &&
+
+ test_commit something &&
+ git config set maintenance.gc.enabled false &&
+ git config set maintenance.loose-objects.enabled true &&
+ git config set maintenance.loose-objects.auto 1 &&
+
+ git maintenance run --quiet >out 2>&1 &&
+ test_must_be_empty out
+ )
+'
+
test_done
diff --git a/t/t9001-send-email.sh b/t/t9001-send-email.sh
index 64a4ab3736..c5e862694e 100755
--- a/t/t9001-send-email.sh
+++ b/t/t9001-send-email.sh
@@ -2084,22 +2084,24 @@ test_dump_aliases '--dump-aliases mailrc format' \
'bob' \
'chloe' \
'eve' <<-\EOF
- alias alice Alice W Land <awol@example.com>
- alias eve Eve <eve@example.com>
- alias bob Robert Bobbyton <bob@example.com>
+ alias alice "Alice W Land <awol@example.com>"
+ alias eve "Eve <eve@example.com>"
+ alias bob "Robert Bobbyton <bob@example.com>"
alias chloe chloe@example.com
EOF
test_dump_aliases '--dump-aliases pine format' \
'pine' \
'alice' \
+ 'bcgrp' \
'bob' \
'chloe' \
'eve' <<-\EOF
- alice Alice W Land <awol@example.com>
- eve Eve <eve@example.com>
- bob Robert Bobbyton <bob@example.com>
+ alice Alice W Land awol@example.com Friend
+ eve Eve eve@example.com
+ bob Robert Bobbyton bob@example.com
chloe chloe@example.com
+ bcgrp (bob, chloe, Other <o@example.com>)
EOF
test_dump_aliases '--dump-aliases gnus format' \
@@ -2118,6 +2120,110 @@ test_expect_success '--dump-aliases must be used alone' '
test_must_fail git send-email --dump-aliases --to=janice@example.com -1 refs/heads/accounting
'
+test_translate_aliases () {
+ msg="$1" && shift &&
+ filetype="$1" && shift &&
+ aliases="$1" && shift &&
+ printf '%s\n' "$@" >expect &&
+ cat >.tmp-email-aliases &&
+ printf '%s\n' "$aliases" >aliases &&
+
+ test_expect_success $PREREQ "$msg" '
+ clean_fake_sendmail && rm -fr outdir &&
+ git config --replace-all sendemail.aliasesfile \
+ "$(pwd)/.tmp-email-aliases" &&
+ git config sendemail.aliasfiletype "$filetype" &&
+ git send-email --translate-aliases <aliases 2>errors >actual &&
+ test_cmp expect actual
+ '
+}
+
+test_translate_aliases '--translate-aliases sendmail format' \
+ 'sendmail' \
+ 'alice bcgrp' \
+ 'Alice W Land <awol@example.com>' \
+ 'Robert Bobbyton <bob@example.com>' \
+ 'chloe@example.com' \
+ 'Other <o@example.com>' <<-\EOF
+ alice: Alice W Land <awol@example.com>
+ bob: Robert Bobbyton <bob@example.com>
+ chloe: chloe@example.com
+ abgroup: alice, bob
+ bcgrp: bob, chloe, Other <o@example.com>
+ EOF
+
+test_translate_aliases '--translate-aliases mutt format' \
+ 'mutt' \
+ 'donald bob' \
+ 'Donald C Carlton <donc@example.com>' \
+ 'Robert Bobbyton <bob@example.com>' <<-\EOF
+ alias alice Alice W Land <awol@example.com>
+ alias donald Donald C Carlton <donc@example.com>
+ alias bob Robert Bobbyton <bob@example.com>
+ alias chloe chloe@example.com
+ EOF
+
+test_translate_aliases '--translate-aliases mailrc format' \
+ 'mailrc' \
+ 'chloe eve alice' \
+ 'chloe@example.com' \
+ 'Eve <eve@example.com>' \
+ 'Alice W Land <awol@example.com>' <<-\EOF
+ alias alice "Alice W Land <awol@example.com>"
+ alias eve "Eve <eve@example.com>"
+ alias bob "Robert Bobbyton <bob@example.com>"
+ alias chloe chloe@example.com
+ EOF
+
+test_translate_aliases '--translate-aliases pine format' \
+ 'pine' \
+ 'eve bob bcgrp' \
+ 'eve@example.com' \
+ 'bob@example.com' \
+ 'bob@example.com' \
+ 'chloe@example.com' \
+ 'Other <o@example.com>' <<-\EOF
+ alice Alice W Land awol@example.com Friend
+ eve Eve eve@example.com
+ bob Robert Bobbyton bob@example.com
+ chloe chloe@example.com
+ bcgrp (bob, chloe, Other <o@example.com>)
+ EOF
+
+test_translate_aliases '--translate-aliases gnus format' \
+ 'gnus' \
+ 'alice chloe eve' \
+ 'awol@example.com' \
+ 'chloe@example.com' \
+ 'eve@example.com' <<-\EOF
+ (define-mail-alias "alice" "awol@example.com")
+ (define-mail-alias "eve" "eve@example.com")
+ (define-mail-alias "bob" "bob@example.com")
+ (define-mail-alias "chloe" "chloe@example.com")
+ EOF
+
+test_expect_success $PREREQ '--translate-aliases passes valid addresses through' '
+ cat >expect <<-\EOF &&
+ Other <o@example.com>
+ EOF
+ cat >aliases <<-\EOF &&
+ Other <o@example.com>
+ EOF
+ git send-email --translate-aliases <aliases >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success $PREREQ '--translate-aliases passes unknown aliases through' '
+ cat >expect <<-\EOF &&
+ blargh
+ EOF
+ cat >aliases <<-\EOF &&
+ blargh
+ EOF
+ git send-email --translate-aliases <aliases >actual &&
+ test_cmp expect actual
+'
+
test_expect_success $PREREQ 'aliases and sendemail.identity' '
test_must_fail git \
-c sendemail.identity=cloud \
diff --git a/t/t9300-fast-import.sh b/t/t9300-fast-import.sh
index 1e68426852..3b3c371740 100755
--- a/t/t9300-fast-import.sh
+++ b/t/t9300-fast-import.sh
@@ -7,6 +7,7 @@ test_description='test git fast-import utility'
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
. "$TEST_DIRECTORY"/lib-diff.sh ;# test-lib chdir's into trash
diff --git a/t/t9304-fast-import-marks.sh b/t/t9304-fast-import-marks.sh
index 410a871c52..1f776a80f3 100755
--- a/t/t9304-fast-import-marks.sh
+++ b/t/t9304-fast-import-marks.sh
@@ -1,6 +1,8 @@
#!/bin/sh
test_description='test exotic situations with marks'
+
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
test_expect_success 'setup dump of basic history' '
diff --git a/t/t9351-fast-export-anonymize.sh b/t/t9351-fast-export-anonymize.sh
index 156a647484..c0d9d7be75 100755
--- a/t/t9351-fast-export-anonymize.sh
+++ b/t/t9351-fast-export-anonymize.sh
@@ -4,6 +4,7 @@ test_description='basic tests for fast-export --anonymize'
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
test_expect_success 'setup simple repo' '
diff --git a/t/unit-tests/t-ctype.c b/t/unit-tests/t-ctype.c
index e28a7f50f9..6043f0d9bc 100644
--- a/t/unit-tests/t-ctype.c
+++ b/t/unit-tests/t-ctype.c
@@ -31,7 +31,7 @@
"\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f" \
"\x7f"
-int cmd_main(int argc, const char **argv) {
+int cmd_main(int argc UNUSED, const char **argv UNUSED) {
TEST_CHAR_CLASS(isspace, " \n\r\t");
TEST_CHAR_CLASS(isdigit, DIGIT);
TEST_CHAR_CLASS(isalpha, LOWER UPPER);
diff --git a/t/unit-tests/t-hash.c b/t/unit-tests/t-hash.c
index e9a78bf2c0..e62647019b 100644
--- a/t/unit-tests/t-hash.c
+++ b/t/unit-tests/t-hash.c
@@ -38,7 +38,7 @@ static void check_hash_data(const void *data, size_t data_length,
"SHA1 and SHA256 (%s) works", #literal); \
} while (0)
-int cmd_main(int argc, const char **argv)
+int cmd_main(int argc UNUSED, const char **argv UNUSED)
{
struct strbuf aaaaaaaaaa_100000 = STRBUF_INIT;
struct strbuf alphabet_100000 = STRBUF_INIT;
diff --git a/t/unit-tests/t-hashmap.c b/t/unit-tests/t-hashmap.c
index 09a48c2c4e..83b79dff39 100644
--- a/t/unit-tests/t-hashmap.c
+++ b/t/unit-tests/t-hashmap.c
@@ -322,7 +322,7 @@ static void t_alloc(struct hashmap *map, unsigned int ignore_case)
free(removed);
}
-static void t_intern(struct hashmap *map, unsigned int ignore_case)
+static void t_intern(void)
{
const char *values[] = { "value1", "Value1", "value2", "value2" };
@@ -356,6 +356,6 @@ int cmd_main(int argc UNUSED, const char **argv UNUSED)
TEST(setup(t_iterate, 0), "iterate works");
TEST(setup(t_iterate, 1), "iterate (case insensitive) works");
TEST(setup(t_alloc, 0), "grow / shrink works");
- TEST(setup(t_intern, 0), "string interning works");
+ TEST(t_intern(), "string interning works");
return test_done();
}
diff --git a/t/unit-tests/t-mem-pool.c b/t/unit-tests/t-mem-pool.c
index a0d57df761..fe500c704b 100644
--- a/t/unit-tests/t-mem-pool.c
+++ b/t/unit-tests/t-mem-pool.c
@@ -20,7 +20,7 @@ static void t_calloc_100(struct mem_pool *pool)
check(pool->mp_block->end != NULL);
}
-int cmd_main(int argc, const char **argv)
+int cmd_main(int argc UNUSED, const char **argv UNUSED)
{
TEST(setup_static(t_calloc_100, 1024 * 1024),
"mem_pool_calloc returns 100 zeroed bytes with big block");
diff --git a/t/unit-tests/t-prio-queue.c b/t/unit-tests/t-prio-queue.c
index 7a4e5780e1..fe6ae37935 100644
--- a/t/unit-tests/t-prio-queue.c
+++ b/t/unit-tests/t-prio-queue.c
@@ -69,7 +69,7 @@ static void test_prio_queue(int *input, size_t input_size,
#define TEST_INPUT(input, result) \
test_prio_queue(input, ARRAY_SIZE(input), result, ARRAY_SIZE(result))
-int cmd_main(int argc, const char **argv)
+int cmd_main(int argc UNUSED, const char **argv UNUSED)
{
TEST(TEST_INPUT(((int []){ 2, 6, 3, 10, 9, 5, 7, 4, 5, 8, 1, DUMP }),
((int []){ 1, 2, 3, 4, 5, 5, 6, 7, 8, 9, 10 })),
diff --git a/t/unit-tests/t-reftable-basics.c b/t/unit-tests/t-reftable-basics.c
index 1dd60ab5f0..e5556ebf52 100644
--- a/t/unit-tests/t-reftable-basics.c
+++ b/t/unit-tests/t-reftable-basics.c
@@ -20,7 +20,7 @@ static int integer_needle_lesseq(size_t i, void *_args)
return args->needle <= args->haystack[i];
}
-int cmd_main(int argc, const char *argv[])
+int cmd_main(int argc UNUSED, const char *argv[] UNUSED)
{
if_test ("binary search with binsearch works") {
int haystack[] = { 2, 4, 6, 8, 10 };
diff --git a/t/unit-tests/t-reftable-merged.c b/t/unit-tests/t-reftable-merged.c
index b6263ee8b5..c9aff3f1ea 100644
--- a/t/unit-tests/t-reftable-merged.c
+++ b/t/unit-tests/t-reftable-merged.c
@@ -12,7 +12,6 @@ https://developers.google.com/open-source/licenses/bsd
#include "reftable/merged.h"
#include "reftable/reader.h"
#include "reftable/reftable-error.h"
-#include "reftable/reftable-generic.h"
#include "reftable/reftable-merged.h"
#include "reftable/reftable-writer.h"
@@ -22,7 +21,7 @@ static ssize_t strbuf_add_void(void *b, const void *data, const size_t sz)
return sz;
}
-static int noop_flush(void *arg)
+static int noop_flush(void *arg UNUSED)
{
return 0;
}
@@ -94,10 +93,8 @@ merged_table_from_records(struct reftable_ref_record **refs,
struct strbuf *buf, const size_t n)
{
struct reftable_merged_table *mt = NULL;
- struct reftable_table *tabs;
int err;
- REFTABLE_CALLOC_ARRAY(tabs, n);
REFTABLE_CALLOC_ARRAY(*readers, n);
REFTABLE_CALLOC_ARRAY(*source, n);
@@ -108,10 +105,9 @@ merged_table_from_records(struct reftable_ref_record **refs,
err = reftable_new_reader(&(*readers)[i], &(*source)[i],
"name");
check(!err);
- reftable_table_from_reader(&tabs[i], (*readers)[i]);
}
- err = reftable_new_merged_table(&mt, tabs, n, GIT_SHA1_FORMAT_ID);
+ err = reftable_merged_table_new(&mt, *readers, n, GIT_SHA1_FORMAT_ID);
check(!err);
return mt;
}
@@ -272,10 +268,8 @@ merged_table_from_log_records(struct reftable_log_record **logs,
struct strbuf *buf, const size_t n)
{
struct reftable_merged_table *mt = NULL;
- struct reftable_table *tabs;
int err;
- REFTABLE_CALLOC_ARRAY(tabs, n);
REFTABLE_CALLOC_ARRAY(*readers, n);
REFTABLE_CALLOC_ARRAY(*source, n);
@@ -286,10 +280,9 @@ merged_table_from_log_records(struct reftable_log_record **logs,
err = reftable_new_reader(&(*readers)[i], &(*source)[i],
"name");
check(!err);
- reftable_table_from_reader(&tabs[i], (*readers)[i]);
}
- err = reftable_new_merged_table(&mt, tabs, n, GIT_SHA1_FORMAT_ID);
+ err = reftable_merged_table_new(&mt, *readers, n, GIT_SHA1_FORMAT_ID);
check(!err);
return mt;
}
@@ -418,7 +411,6 @@ static void t_default_write_opts(void)
};
int err;
struct reftable_block_source source = { 0 };
- struct reftable_table *tab = reftable_calloc(1, sizeof(*tab));
uint32_t hash_id;
struct reftable_reader *rd = NULL;
struct reftable_merged_table *merged = NULL;
@@ -440,10 +432,9 @@ static void t_default_write_opts(void)
hash_id = reftable_reader_hash_id(rd);
check_int(hash_id, ==, GIT_SHA1_FORMAT_ID);
- reftable_table_from_reader(&tab[0], rd);
- err = reftable_new_merged_table(&merged, tab, 1, GIT_SHA256_FORMAT_ID);
+ err = reftable_merged_table_new(&merged, &rd, 1, GIT_SHA256_FORMAT_ID);
check_int(err, ==, REFTABLE_FORMAT_ERROR);
- err = reftable_new_merged_table(&merged, tab, 1, GIT_SHA1_FORMAT_ID);
+ err = reftable_merged_table_new(&merged, &rd, 1, GIT_SHA1_FORMAT_ID);
check(!err);
reftable_reader_free(rd);
@@ -452,7 +443,7 @@ static void t_default_write_opts(void)
}
-int cmd_main(int argc, const char *argv[])
+int cmd_main(int argc UNUSED, const char *argv[] UNUSED)
{
TEST(t_default_write_opts(), "merged table with default write opts");
TEST(t_merged_logs(), "merged table with multiple log updates for same ref");
diff --git a/t/unit-tests/t-reftable-pq.c b/t/unit-tests/t-reftable-pq.c
index 039bd0f1f9..ada4c19f18 100644
--- a/t/unit-tests/t-reftable-pq.c
+++ b/t/unit-tests/t-reftable-pq.c
@@ -142,7 +142,7 @@ static void t_merged_iter_pqueue_top(void)
merged_iter_pqueue_release(&pq);
}
-int cmd_main(int argc, const char *argv[])
+int cmd_main(int argc UNUSED, const char *argv[] UNUSED)
{
TEST(t_pq_record(), "pq works with record-based comparison");
TEST(t_pq_index(), "pq works with index-based comparison");
diff --git a/reftable/readwrite_test.c b/t/unit-tests/t-reftable-readwrite.c
index f411abfe9c..1eae36cc60 100644
--- a/reftable/readwrite_test.c
+++ b/t/unit-tests/t-reftable-readwrite.c
@@ -6,37 +6,49 @@ license that can be found in the LICENSE file or at
https://developers.google.com/open-source/licenses/bsd
*/
-#include "system.h"
-
-#include "basics.h"
-#include "block.h"
-#include "blocksource.h"
-#include "reader.h"
-#include "record.h"
-#include "test_framework.h"
-#include "reftable-tests.h"
-#include "reftable-writer.h"
+#include "test-lib.h"
+#include "reftable/basics.h"
+#include "reftable/blocksource.h"
+#include "reftable/reader.h"
+#include "reftable/reftable-error.h"
+#include "reftable/reftable-writer.h"
static const int update_index = 5;
-static void test_buffer(void)
+static void set_test_hash(uint8_t *p, int i)
+{
+ memset(p, (uint8_t)i, hash_size(GIT_SHA1_FORMAT_ID));
+}
+
+static ssize_t strbuf_add_void(void *b, const void *data, size_t sz)
+{
+ strbuf_add(b, data, sz);
+ return sz;
+}
+
+static int noop_flush(void *arg)
+{
+ return 0;
+}
+
+static void t_buffer(void)
{
struct strbuf buf = STRBUF_INIT;
- struct reftable_block_source source = { NULL };
- struct reftable_block out = { NULL };
+ struct reftable_block_source source = { 0 };
+ struct reftable_block out = { 0 };
int n;
uint8_t in[] = "hello";
strbuf_add(&buf, in, sizeof(in));
block_source_from_strbuf(&source, &buf);
- EXPECT(block_source_size(&source) == 6);
+ check_int(block_source_size(&source), ==, 6);
n = block_source_read_block(&source, &out, 0, sizeof(in));
- EXPECT(n == sizeof(in));
- EXPECT(!memcmp(in, out.data, n));
+ check_int(n, ==, sizeof(in));
+ check(!memcmp(in, out.data, n));
reftable_block_done(&out);
n = block_source_read_block(&source, &out, 1, 2);
- EXPECT(n == 2);
- EXPECT(!memcmp(out.data, "el", 2));
+ check_int(n, ==, 2);
+ check(!memcmp(out.data, "el", 2));
reftable_block_done(&out);
block_source_close(&source);
@@ -52,9 +64,9 @@ static void write_table(char ***names, struct strbuf *buf, int N,
};
struct reftable_writer *w =
reftable_new_writer(&strbuf_add_void, &noop_flush, buf, &opts);
- struct reftable_ref_record ref = { NULL };
+ struct reftable_ref_record ref = { 0 };
int i = 0, n;
- struct reftable_log_record log = { NULL };
+ struct reftable_log_record log = { 0 };
const struct reftable_stats *stats = NULL;
REFTABLE_CALLOC_ARRAY(*names, N + 1);
@@ -73,7 +85,7 @@ static void write_table(char ***names, struct strbuf *buf, int N,
(*names)[i] = xstrdup(name);
n = reftable_writer_add_ref(w, &ref);
- EXPECT(n == 0);
+ check_int(n, ==, 0);
}
for (i = 0; i < N; i++) {
@@ -89,27 +101,25 @@ static void write_table(char ***names, struct strbuf *buf, int N,
log.value.update.message = (char *) "message";
n = reftable_writer_add_log(w, &log);
- EXPECT(n == 0);
+ check_int(n, ==, 0);
}
n = reftable_writer_close(w);
- EXPECT(n == 0);
+ check_int(n, ==, 0);
stats = reftable_writer_stats(w);
for (i = 0; i < stats->ref_stats.blocks; i++) {
int off = i * opts.block_size;
- if (off == 0) {
- off = header_size(
- (hash_id == GIT_SHA256_FORMAT_ID) ? 2 : 1);
- }
- EXPECT(buf->buf[off] == 'r');
+ if (!off)
+ off = header_size((hash_id == GIT_SHA256_FORMAT_ID) ? 2 : 1);
+ check_char(buf->buf[off], ==, 'r');
}
- EXPECT(stats->log_stats.blocks > 0);
+ check_int(stats->log_stats.blocks, >, 0);
reftable_writer_free(w);
}
-static void test_log_buffer_size(void)
+static void t_log_buffer_size(void)
{
struct strbuf buf = STRBUF_INIT;
struct reftable_write_options opts = {
@@ -140,14 +150,14 @@ static void test_log_buffer_size(void)
}
reftable_writer_set_limits(w, update_index, update_index);
err = reftable_writer_add_log(w, &log);
- EXPECT_ERR(err);
+ check(!err);
err = reftable_writer_close(w);
- EXPECT_ERR(err);
+ check(!err);
reftable_writer_free(w);
strbuf_release(&buf);
}
-static void test_log_overflow(void)
+static void t_log_overflow(void)
{
struct strbuf buf = STRBUF_INIT;
char msg[256] = { 0 };
@@ -177,12 +187,12 @@ static void test_log_overflow(void)
memset(msg, 'x', sizeof(msg) - 1);
reftable_writer_set_limits(w, update_index, update_index);
err = reftable_writer_add_log(w, &log);
- EXPECT(err == REFTABLE_ENTRY_TOO_BIG_ERROR);
+ check_int(err, ==, REFTABLE_ENTRY_TOO_BIG_ERROR);
reftable_writer_free(w);
strbuf_release(&buf);
}
-static void test_log_write_read(void)
+static void t_log_write_read(void)
{
int N = 2;
char **names = reftable_calloc(N + 1, sizeof(*names));
@@ -190,13 +200,13 @@ static void test_log_write_read(void)
struct reftable_write_options opts = {
.block_size = 256,
};
- struct reftable_ref_record ref = { NULL };
+ struct reftable_ref_record ref = { 0 };
int i = 0;
- struct reftable_log_record log = { NULL };
+ struct reftable_log_record log = { 0 };
int n;
- struct reftable_iterator it = { NULL };
- struct reftable_reader rd = { NULL };
- struct reftable_block_source source = { NULL };
+ struct reftable_iterator it = { 0 };
+ struct reftable_reader rd = { 0 };
+ struct reftable_block_source source = { 0 };
struct strbuf buf = STRBUF_INIT;
struct reftable_writer *w =
reftable_new_writer(&strbuf_add_void, &noop_flush, &buf, &opts);
@@ -204,17 +214,17 @@ static void test_log_write_read(void)
reftable_writer_set_limits(w, 0, N);
for (i = 0; i < N; i++) {
char name[256];
- struct reftable_ref_record ref = { NULL };
+ struct reftable_ref_record ref = { 0 };
snprintf(name, sizeof(name), "b%02d%0*d", i, 130, 7);
names[i] = xstrdup(name);
ref.refname = name;
ref.update_index = i;
err = reftable_writer_add_ref(w, &ref);
- EXPECT_ERR(err);
+ check(!err);
}
for (i = 0; i < N; i++) {
- struct reftable_log_record log = { NULL };
+ struct reftable_log_record log = { 0 };
log.refname = names[i];
log.update_index = i;
@@ -223,33 +233,33 @@ static void test_log_write_read(void)
set_test_hash(log.value.update.new_hash, i + 1);
err = reftable_writer_add_log(w, &log);
- EXPECT_ERR(err);
+ check(!err);
}
n = reftable_writer_close(w);
- EXPECT(n == 0);
+ check_int(n, ==, 0);
stats = reftable_writer_stats(w);
- EXPECT(stats->log_stats.blocks > 0);
+ check_int(stats->log_stats.blocks, >, 0);
reftable_writer_free(w);
w = NULL;
block_source_from_strbuf(&source, &buf);
err = init_reader(&rd, &source, "file.log");
- EXPECT_ERR(err);
+ check(!err);
reftable_reader_init_ref_iterator(&rd, &it);
err = reftable_iterator_seek_ref(&it, names[N - 1]);
- EXPECT_ERR(err);
+ check(!err);
err = reftable_iterator_next_ref(&it, &ref);
- EXPECT_ERR(err);
+ check(!err);
/* end of iteration. */
err = reftable_iterator_next_ref(&it, &ref);
- EXPECT(0 < err);
+ check_int(err, >, 0);
reftable_iterator_destroy(&it);
reftable_ref_record_release(&ref);
@@ -257,23 +267,19 @@ static void test_log_write_read(void)
reftable_reader_init_log_iterator(&rd, &it);
err = reftable_iterator_seek_log(&it, "");
- EXPECT_ERR(err);
+ check(!err);
- i = 0;
- while (1) {
+ for (i = 0; ; i++) {
int err = reftable_iterator_next_log(&it, &log);
- if (err > 0) {
+ if (err > 0)
break;
- }
-
- EXPECT_ERR(err);
- EXPECT_STREQ(names[i], log.refname);
- EXPECT(i == log.update_index);
- i++;
+ check(!err);
+ check_str(names[i], log.refname);
+ check_int(i, ==, log.update_index);
reftable_log_record_release(&log);
}
- EXPECT(i == N);
+ check_int(i, ==, N);
reftable_iterator_destroy(&it);
/* cleanup. */
@@ -282,7 +288,7 @@ static void test_log_write_read(void)
reader_close(&rd);
}
-static void test_log_zlib_corruption(void)
+static void t_log_zlib_corruption(void)
{
struct reftable_write_options opts = {
.block_size = 256,
@@ -316,13 +322,13 @@ static void test_log_zlib_corruption(void)
reftable_writer_set_limits(w, 1, 1);
err = reftable_writer_add_log(w, &log);
- EXPECT_ERR(err);
+ check(!err);
n = reftable_writer_close(w);
- EXPECT(n == 0);
+ check_int(n, ==, 0);
stats = reftable_writer_stats(w);
- EXPECT(stats->log_stats.blocks > 0);
+ check_int(stats->log_stats.blocks, >, 0);
reftable_writer_free(w);
w = NULL;
@@ -332,11 +338,11 @@ static void test_log_zlib_corruption(void)
block_source_from_strbuf(&source, &buf);
err = init_reader(&rd, &source, "file.log");
- EXPECT_ERR(err);
+ check(!err);
reftable_reader_init_log_iterator(&rd, &it);
err = reftable_iterator_seek_log(&it, "refname");
- EXPECT(err == REFTABLE_ZLIB_ERROR);
+ check_int(err, ==, REFTABLE_ZLIB_ERROR);
reftable_iterator_destroy(&it);
@@ -345,14 +351,14 @@ static void test_log_zlib_corruption(void)
reader_close(&rd);
}
-static void test_table_read_write_sequential(void)
+static void t_table_read_write_sequential(void)
{
char **names;
struct strbuf buf = STRBUF_INIT;
int N = 50;
- struct reftable_iterator it = { NULL };
- struct reftable_block_source source = { NULL };
- struct reftable_reader rd = { NULL };
+ struct reftable_iterator it = { 0 };
+ struct reftable_block_source source = { 0 };
+ struct reftable_reader rd = { 0 };
int err = 0;
int j = 0;
@@ -361,26 +367,23 @@ static void test_table_read_write_sequential(void)
block_source_from_strbuf(&source, &buf);
err = init_reader(&rd, &source, "file.ref");
- EXPECT_ERR(err);
+ check(!err);
reftable_reader_init_ref_iterator(&rd, &it);
err = reftable_iterator_seek_ref(&it, "");
- EXPECT_ERR(err);
+ check(!err);
- while (1) {
- struct reftable_ref_record ref = { NULL };
+ for (j = 0; ; j++) {
+ struct reftable_ref_record ref = { 0 };
int r = reftable_iterator_next_ref(&it, &ref);
- EXPECT(r >= 0);
- if (r > 0) {
+ check_int(r, >=, 0);
+ if (r > 0)
break;
- }
- EXPECT(0 == strcmp(names[j], ref.refname));
- EXPECT(update_index == ref.update_index);
-
- j++;
+ check_str(names[j], ref.refname);
+ check_int(update_index, ==, ref.update_index);
reftable_ref_record_release(&ref);
}
- EXPECT(j == N);
+ check_int(j, ==, N);
reftable_iterator_destroy(&it);
strbuf_release(&buf);
free_names(names);
@@ -388,90 +391,85 @@ static void test_table_read_write_sequential(void)
reader_close(&rd);
}
-static void test_table_write_small_table(void)
+static void t_table_write_small_table(void)
{
char **names;
struct strbuf buf = STRBUF_INIT;
int N = 1;
write_table(&names, &buf, N, 4096, GIT_SHA1_FORMAT_ID);
- EXPECT(buf.len < 200);
+ check_int(buf.len, <, 200);
strbuf_release(&buf);
free_names(names);
}
-static void test_table_read_api(void)
+static void t_table_read_api(void)
{
char **names;
struct strbuf buf = STRBUF_INIT;
int N = 50;
- struct reftable_reader rd = { NULL };
- struct reftable_block_source source = { NULL };
+ struct reftable_reader rd = { 0 };
+ struct reftable_block_source source = { 0 };
int err;
- int i;
- struct reftable_log_record log = { NULL };
- struct reftable_iterator it = { NULL };
+ struct reftable_log_record log = { 0 };
+ struct reftable_iterator it = { 0 };
write_table(&names, &buf, N, 256, GIT_SHA1_FORMAT_ID);
block_source_from_strbuf(&source, &buf);
err = init_reader(&rd, &source, "file.ref");
- EXPECT_ERR(err);
+ check(!err);
reftable_reader_init_ref_iterator(&rd, &it);
err = reftable_iterator_seek_ref(&it, names[0]);
- EXPECT_ERR(err);
+ check(!err);
err = reftable_iterator_next_log(&it, &log);
- EXPECT(err == REFTABLE_API_ERROR);
+ check_int(err, ==, REFTABLE_API_ERROR);
strbuf_release(&buf);
- for (i = 0; i < N; i++) {
- reftable_free(names[i]);
- }
+ free_names(names);
reftable_iterator_destroy(&it);
- reftable_free(names);
reader_close(&rd);
strbuf_release(&buf);
}
-static void test_table_read_write_seek(int index, int hash_id)
+static void t_table_read_write_seek(int index, int hash_id)
{
char **names;
struct strbuf buf = STRBUF_INIT;
int N = 50;
- struct reftable_reader rd = { NULL };
- struct reftable_block_source source = { NULL };
+ struct reftable_reader rd = { 0 };
+ struct reftable_block_source source = { 0 };
int err;
int i = 0;
- struct reftable_iterator it = { NULL };
+ struct reftable_iterator it = { 0 };
struct strbuf pastLast = STRBUF_INIT;
- struct reftable_ref_record ref = { NULL };
+ struct reftable_ref_record ref = { 0 };
write_table(&names, &buf, N, 256, hash_id);
block_source_from_strbuf(&source, &buf);
err = init_reader(&rd, &source, "file.ref");
- EXPECT_ERR(err);
- EXPECT(hash_id == reftable_reader_hash_id(&rd));
+ check(!err);
+ check_int(hash_id, ==, reftable_reader_hash_id(&rd));
- if (!index) {
+ if (!index)
rd.ref_offsets.index_offset = 0;
- } else {
- EXPECT(rd.ref_offsets.index_offset > 0);
- }
+ else
+ check_int(rd.ref_offsets.index_offset, >, 0);
for (i = 1; i < N; i++) {
reftable_reader_init_ref_iterator(&rd, &it);
err = reftable_iterator_seek_ref(&it, names[i]);
- EXPECT_ERR(err);
+ check(!err);
err = reftable_iterator_next_ref(&it, &ref);
- EXPECT_ERR(err);
- EXPECT(0 == strcmp(names[i], ref.refname));
- EXPECT(REFTABLE_REF_VAL1 == ref.value_type);
- EXPECT(i == ref.value.val1[0]);
+ check(!err);
+ check_str(names[i], ref.refname);
+ check_int(REFTABLE_REF_VAL1, ==, ref.value_type);
+ check_int(i, ==, ref.value.val1[0]);
reftable_ref_record_release(&ref);
reftable_iterator_destroy(&it);
@@ -483,40 +481,37 @@ static void test_table_read_write_seek(int index, int hash_id)
reftable_reader_init_ref_iterator(&rd, &it);
err = reftable_iterator_seek_ref(&it, pastLast.buf);
if (err == 0) {
- struct reftable_ref_record ref = { NULL };
+ struct reftable_ref_record ref = { 0 };
int err = reftable_iterator_next_ref(&it, &ref);
- EXPECT(err > 0);
+ check_int(err, >, 0);
} else {
- EXPECT(err > 0);
+ check_int(err, >, 0);
}
strbuf_release(&pastLast);
reftable_iterator_destroy(&it);
strbuf_release(&buf);
- for (i = 0; i < N; i++) {
- reftable_free(names[i]);
- }
- reftable_free(names);
+ free_names(names);
reader_close(&rd);
}
-static void test_table_read_write_seek_linear(void)
+static void t_table_read_write_seek_linear(void)
{
- test_table_read_write_seek(0, GIT_SHA1_FORMAT_ID);
+ t_table_read_write_seek(0, GIT_SHA1_FORMAT_ID);
}
-static void test_table_read_write_seek_linear_sha256(void)
+static void t_table_read_write_seek_linear_sha256(void)
{
- test_table_read_write_seek(0, GIT_SHA256_FORMAT_ID);
+ t_table_read_write_seek(0, GIT_SHA256_FORMAT_ID);
}
-static void test_table_read_write_seek_index(void)
+static void t_table_read_write_seek_index(void)
{
- test_table_read_write_seek(1, GIT_SHA1_FORMAT_ID);
+ t_table_read_write_seek(1, GIT_SHA1_FORMAT_ID);
}
-static void test_table_refs_for(int indexed)
+static void t_table_refs_for(int indexed)
{
int N = 50;
char **want_names = reftable_calloc(N + 1, sizeof(*want_names));
@@ -526,18 +521,18 @@ static void test_table_refs_for(int indexed)
struct reftable_write_options opts = {
.block_size = 256,
};
- struct reftable_ref_record ref = { NULL };
+ struct reftable_ref_record ref = { 0 };
int i = 0;
int n;
int err;
struct reftable_reader rd;
- struct reftable_block_source source = { NULL };
+ struct reftable_block_source source = { 0 };
struct strbuf buf = STRBUF_INIT;
struct reftable_writer *w =
reftable_new_writer(&strbuf_add_void, &noop_flush, &buf, &opts);
- struct reftable_iterator it = { NULL };
+ struct reftable_iterator it = { 0 };
int j;
set_test_hash(want_hash, 4);
@@ -546,7 +541,7 @@ static void test_table_refs_for(int indexed)
uint8_t hash[GIT_SHA1_RAWSZ];
char fill[51] = { 0 };
char name[100];
- struct reftable_ref_record ref = { NULL };
+ struct reftable_ref_record ref = { 0 };
memset(hash, i, sizeof(hash));
memset(fill, 'x', 50);
@@ -563,16 +558,15 @@ static void test_table_refs_for(int indexed)
*/
/* blocks. */
n = reftable_writer_add_ref(w, &ref);
- EXPECT(n == 0);
+ check_int(n, ==, 0);
if (!memcmp(ref.value.val2.value, want_hash, GIT_SHA1_RAWSZ) ||
- !memcmp(ref.value.val2.target_value, want_hash, GIT_SHA1_RAWSZ)) {
+ !memcmp(ref.value.val2.target_value, want_hash, GIT_SHA1_RAWSZ))
want_names[want_names_len++] = xstrdup(name);
- }
}
n = reftable_writer_close(w);
- EXPECT(n == 0);
+ check_int(n, ==, 0);
reftable_writer_free(w);
w = NULL;
@@ -580,33 +574,28 @@ static void test_table_refs_for(int indexed)
block_source_from_strbuf(&source, &buf);
err = init_reader(&rd, &source, "file.ref");
- EXPECT_ERR(err);
- if (!indexed) {
+ check(!err);
+ if (!indexed)
rd.obj_offsets.is_present = 0;
- }
reftable_reader_init_ref_iterator(&rd, &it);
err = reftable_iterator_seek_ref(&it, "");
- EXPECT_ERR(err);
+ check(!err);
reftable_iterator_destroy(&it);
err = reftable_reader_refs_for(&rd, &it, want_hash);
- EXPECT_ERR(err);
+ check(!err);
- j = 0;
- while (1) {
+ for (j = 0; ; j++) {
int err = reftable_iterator_next_ref(&it, &ref);
- EXPECT(err >= 0);
- if (err > 0) {
+ check_int(err, >=, 0);
+ if (err > 0)
break;
- }
-
- EXPECT(j < want_names_len);
- EXPECT(0 == strcmp(ref.refname, want_names[j]));
- j++;
+ check_int(j, <, want_names_len);
+ check_str(ref.refname, want_names[j]);
reftable_ref_record_release(&ref);
}
- EXPECT(j == want_names_len);
+ check_int(j, ==, want_names_len);
strbuf_release(&buf);
free_names(want_names);
@@ -614,54 +603,54 @@ static void test_table_refs_for(int indexed)
reader_close(&rd);
}
-static void test_table_refs_for_no_index(void)
+static void t_table_refs_for_no_index(void)
{
- test_table_refs_for(0);
+ t_table_refs_for(0);
}
-static void test_table_refs_for_obj_index(void)
+static void t_table_refs_for_obj_index(void)
{
- test_table_refs_for(1);
+ t_table_refs_for(1);
}
-static void test_write_empty_table(void)
+static void t_write_empty_table(void)
{
struct reftable_write_options opts = { 0 };
struct strbuf buf = STRBUF_INIT;
struct reftable_writer *w =
reftable_new_writer(&strbuf_add_void, &noop_flush, &buf, &opts);
- struct reftable_block_source source = { NULL };
+ struct reftable_block_source source = { 0 };
struct reftable_reader *rd = NULL;
- struct reftable_ref_record rec = { NULL };
- struct reftable_iterator it = { NULL };
+ struct reftable_ref_record rec = { 0 };
+ struct reftable_iterator it = { 0 };
int err;
reftable_writer_set_limits(w, 1, 1);
err = reftable_writer_close(w);
- EXPECT(err == REFTABLE_EMPTY_TABLE_ERROR);
+ check_int(err, ==, REFTABLE_EMPTY_TABLE_ERROR);
reftable_writer_free(w);
- EXPECT(buf.len == header_size(1) + footer_size(1));
+ check_int(buf.len, ==, header_size(1) + footer_size(1));
block_source_from_strbuf(&source, &buf);
err = reftable_new_reader(&rd, &source, "filename");
- EXPECT_ERR(err);
+ check(!err);
reftable_reader_init_ref_iterator(rd, &it);
err = reftable_iterator_seek_ref(&it, "");
- EXPECT_ERR(err);
+ check(!err);
err = reftable_iterator_next_ref(&it, &rec);
- EXPECT(err > 0);
+ check_int(err, >, 0);
reftable_iterator_destroy(&it);
reftable_reader_free(rd);
strbuf_release(&buf);
}
-static void test_write_object_id_min_length(void)
+static void t_write_object_id_min_length(void)
{
struct reftable_write_options opts = {
.block_size = 75,
@@ -686,17 +675,17 @@ static void test_write_object_id_min_length(void)
snprintf(name, sizeof(name), "ref%05d", i);
ref.refname = name;
err = reftable_writer_add_ref(w, &ref);
- EXPECT_ERR(err);
+ check(!err);
}
err = reftable_writer_close(w);
- EXPECT_ERR(err);
- EXPECT(reftable_writer_stats(w)->object_id_len == 2);
+ check(!err);
+ check_int(reftable_writer_stats(w)->object_id_len, ==, 2);
reftable_writer_free(w);
strbuf_release(&buf);
}
-static void test_write_object_id_length(void)
+static void t_write_object_id_length(void)
{
struct reftable_write_options opts = {
.block_size = 75,
@@ -722,17 +711,17 @@ static void test_write_object_id_length(void)
ref.refname = name;
ref.value.val1[15] = i;
err = reftable_writer_add_ref(w, &ref);
- EXPECT_ERR(err);
+ check(!err);
}
err = reftable_writer_close(w);
- EXPECT_ERR(err);
- EXPECT(reftable_writer_stats(w)->object_id_len == 16);
+ check(!err);
+ check_int(reftable_writer_stats(w)->object_id_len, ==, 16);
reftable_writer_free(w);
strbuf_release(&buf);
}
-static void test_write_empty_key(void)
+static void t_write_empty_key(void)
{
struct reftable_write_options opts = { 0 };
struct strbuf buf = STRBUF_INIT;
@@ -747,15 +736,15 @@ static void test_write_empty_key(void)
reftable_writer_set_limits(w, 1, 1);
err = reftable_writer_add_ref(w, &ref);
- EXPECT(err == REFTABLE_API_ERROR);
+ check_int(err, ==, REFTABLE_API_ERROR);
err = reftable_writer_close(w);
- EXPECT(err == REFTABLE_EMPTY_TABLE_ERROR);
+ check_int(err, ==, REFTABLE_EMPTY_TABLE_ERROR);
reftable_writer_free(w);
strbuf_release(&buf);
}
-static void test_write_key_order(void)
+static void t_write_key_order(void)
{
struct reftable_write_options opts = { 0 };
struct strbuf buf = STRBUF_INIT;
@@ -782,15 +771,20 @@ static void test_write_key_order(void)
reftable_writer_set_limits(w, 1, 1);
err = reftable_writer_add_ref(w, &refs[0]);
- EXPECT_ERR(err);
+ check(!err);
err = reftable_writer_add_ref(w, &refs[1]);
- EXPECT(err == REFTABLE_API_ERROR);
+ check_int(err, ==, REFTABLE_API_ERROR);
+
+ refs[0].update_index = 2;
+ err = reftable_writer_add_ref(w, &refs[0]);
+ check_int(err, ==, REFTABLE_API_ERROR);
+
reftable_writer_close(w);
reftable_writer_free(w);
strbuf_release(&buf);
}
-static void test_write_multiple_indices(void)
+static void t_write_multiple_indices(void)
{
struct reftable_write_options opts = {
.block_size = 100,
@@ -817,7 +811,7 @@ static void test_write_multiple_indices(void)
ref.refname = buf.buf,
err = reftable_writer_add_ref(writer, &ref);
- EXPECT_ERR(err);
+ check(!err);
}
for (i = 0; i < 100; i++) {
@@ -835,7 +829,7 @@ static void test_write_multiple_indices(void)
log.refname = buf.buf,
err = reftable_writer_add_log(writer, &log);
- EXPECT_ERR(err);
+ check(!err);
}
reftable_writer_close(writer);
@@ -845,13 +839,13 @@ static void test_write_multiple_indices(void)
* for each of the block types.
*/
stats = reftable_writer_stats(writer);
- EXPECT(stats->ref_stats.index_offset > 0);
- EXPECT(stats->obj_stats.index_offset > 0);
- EXPECT(stats->log_stats.index_offset > 0);
+ check_int(stats->ref_stats.index_offset, >, 0);
+ check_int(stats->obj_stats.index_offset, >, 0);
+ check_int(stats->log_stats.index_offset, >, 0);
block_source_from_strbuf(&source, &writer_buf);
err = reftable_new_reader(&reader, &source, "filename");
- EXPECT_ERR(err);
+ check(!err);
/*
* Seeking the log uses the log index now. In case there is any
@@ -859,7 +853,7 @@ static void test_write_multiple_indices(void)
*/
reftable_reader_init_log_iterator(reader, &it);
err = reftable_iterator_seek_log(&it, "");
- EXPECT_ERR(err);
+ check(!err);
reftable_iterator_destroy(&it);
reftable_writer_free(writer);
@@ -868,7 +862,7 @@ static void test_write_multiple_indices(void)
strbuf_release(&buf);
}
-static void test_write_multi_level_index(void)
+static void t_write_multi_level_index(void)
{
struct reftable_write_options opts = {
.block_size = 100,
@@ -895,7 +889,7 @@ static void test_write_multi_level_index(void)
ref.refname = buf.buf,
err = reftable_writer_add_ref(writer, &ref);
- EXPECT_ERR(err);
+ check(!err);
}
reftable_writer_close(writer);
@@ -904,18 +898,18 @@ static void test_write_multi_level_index(void)
* multi-level index.
*/
stats = reftable_writer_stats(writer);
- EXPECT(stats->ref_stats.max_index_level == 2);
+ check_int(stats->ref_stats.max_index_level, ==, 2);
block_source_from_strbuf(&source, &writer_buf);
err = reftable_new_reader(&reader, &source, "filename");
- EXPECT_ERR(err);
+ check(!err);
/*
* Seeking the last ref should work as expected.
*/
reftable_reader_init_ref_iterator(reader, &it);
err = reftable_iterator_seek_ref(&it, "refs/heads/199");
- EXPECT_ERR(err);
+ check(!err);
reftable_iterator_destroy(&it);
reftable_writer_free(writer);
@@ -924,56 +918,57 @@ static void test_write_multi_level_index(void)
strbuf_release(&buf);
}
-static void test_corrupt_table_empty(void)
+static void t_corrupt_table_empty(void)
{
struct strbuf buf = STRBUF_INIT;
- struct reftable_block_source source = { NULL };
- struct reftable_reader rd = { NULL };
+ struct reftable_block_source source = { 0 };
+ struct reftable_reader rd = { 0 };
int err;
block_source_from_strbuf(&source, &buf);
err = init_reader(&rd, &source, "file.log");
- EXPECT(err == REFTABLE_FORMAT_ERROR);
+ check_int(err, ==, REFTABLE_FORMAT_ERROR);
}
-static void test_corrupt_table(void)
+static void t_corrupt_table(void)
{
uint8_t zeros[1024] = { 0 };
struct strbuf buf = STRBUF_INIT;
- struct reftable_block_source source = { NULL };
- struct reftable_reader rd = { NULL };
+ struct reftable_block_source source = { 0 };
+ struct reftable_reader rd = { 0 };
int err;
strbuf_add(&buf, zeros, sizeof(zeros));
block_source_from_strbuf(&source, &buf);
err = init_reader(&rd, &source, "file.log");
- EXPECT(err == REFTABLE_FORMAT_ERROR);
+ check_int(err, ==, REFTABLE_FORMAT_ERROR);
strbuf_release(&buf);
}
-int readwrite_test_main(int argc, const char *argv[])
+int cmd_main(int argc UNUSED, const char *argv[] UNUSED)
{
- RUN_TEST(test_log_zlib_corruption);
- RUN_TEST(test_corrupt_table);
- RUN_TEST(test_corrupt_table_empty);
- RUN_TEST(test_log_write_read);
- RUN_TEST(test_write_key_order);
- RUN_TEST(test_table_read_write_seek_linear_sha256);
- RUN_TEST(test_log_buffer_size);
- RUN_TEST(test_table_write_small_table);
- RUN_TEST(test_buffer);
- RUN_TEST(test_table_read_api);
- RUN_TEST(test_table_read_write_sequential);
- RUN_TEST(test_table_read_write_seek_linear);
- RUN_TEST(test_table_read_write_seek_index);
- RUN_TEST(test_table_refs_for_no_index);
- RUN_TEST(test_table_refs_for_obj_index);
- RUN_TEST(test_write_empty_key);
- RUN_TEST(test_write_empty_table);
- RUN_TEST(test_log_overflow);
- RUN_TEST(test_write_object_id_length);
- RUN_TEST(test_write_object_id_min_length);
- RUN_TEST(test_write_multiple_indices);
- RUN_TEST(test_write_multi_level_index);
- return 0;
+ TEST(t_buffer(), "strbuf works as blocksource");
+ TEST(t_corrupt_table(), "read-write on corrupted table");
+ TEST(t_corrupt_table_empty(), "read-write on an empty table");
+ TEST(t_log_buffer_size(), "buffer extension for log compression");
+ TEST(t_log_overflow(), "log overflow returns expected error");
+ TEST(t_log_write_read(), "read-write on log records");
+ TEST(t_log_zlib_corruption(), "reading corrupted log record returns expected error");
+ TEST(t_table_read_api(), "read on a table");
+ TEST(t_table_read_write_seek_index(), "read-write on a table with index");
+ TEST(t_table_read_write_seek_linear(), "read-write on a table without index (SHA1)");
+ TEST(t_table_read_write_seek_linear_sha256(), "read-write on a table without index (SHA256)");
+ TEST(t_table_read_write_sequential(), "sequential read-write on a table");
+ TEST(t_table_refs_for_no_index(), "refs-only table with no index");
+ TEST(t_table_refs_for_obj_index(), "refs-only table with index");
+ TEST(t_table_write_small_table(), "write_table works");
+ TEST(t_write_empty_key(), "write on refs with empty keys");
+ TEST(t_write_empty_table(), "read-write on empty tables");
+ TEST(t_write_key_order(), "refs must be written in increasing order");
+ TEST(t_write_multi_level_index(), "table with multi-level index");
+ TEST(t_write_multiple_indices(), "table with indices for multiple block types");
+ TEST(t_write_object_id_length(), "prefix compression on writing refs");
+ TEST(t_write_object_id_min_length(), "prefix compression on writing refs");
+
+ return test_done();
}
diff --git a/t/unit-tests/t-reftable-record.c b/t/unit-tests/t-reftable-record.c
index cb649ee419..a7f67d4d9f 100644
--- a/t/unit-tests/t-reftable-record.c
+++ b/t/unit-tests/t-reftable-record.c
@@ -532,7 +532,7 @@ static void t_reftable_index_record_roundtrip(void)
strbuf_release(&in.u.idx.last_key);
}
-int cmd_main(int argc, const char *argv[])
+int cmd_main(int argc UNUSED, const char *argv[] UNUSED)
{
TEST(t_reftable_ref_record_comparison(), "comparison operations work on ref record");
TEST(t_reftable_log_record_comparison(), "comparison operations work on log record");
diff --git a/t/unit-tests/t-reftable-tree.c b/t/unit-tests/t-reftable-tree.c
index e7d774d774..700479d34b 100644
--- a/t/unit-tests/t-reftable-tree.c
+++ b/t/unit-tests/t-reftable-tree.c
@@ -75,7 +75,7 @@ static void t_infix_walk(void)
tree_free(root);
}
-int cmd_main(int argc, const char *argv[])
+int cmd_main(int argc UNUSED, const char *argv[] UNUSED)
{
TEST(t_tree_search(), "tree_search works");
TEST(t_infix_walk(), "infix_walk works");
diff --git a/t/unit-tests/t-strbuf.c b/t/unit-tests/t-strbuf.c
index 6027dafef7..3f4044d697 100644
--- a/t/unit-tests/t-strbuf.c
+++ b/t/unit-tests/t-strbuf.c
@@ -105,7 +105,7 @@ static void t_addstr(struct strbuf *buf, const void *data)
check_str(buf->buf + orig_len, text);
}
-int cmd_main(int argc, const char **argv)
+int cmd_main(int argc UNUSED, const char **argv UNUSED)
{
if (!TEST(t_static_init(), "static initialization works"))
test_skip_all("STRBUF_INIT is broken");
diff --git a/t/unit-tests/t-strcmp-offset.c b/t/unit-tests/t-strcmp-offset.c
index fe4c2706b1..6880f21161 100644
--- a/t/unit-tests/t-strcmp-offset.c
+++ b/t/unit-tests/t-strcmp-offset.c
@@ -24,7 +24,7 @@ static void check_strcmp_offset(const char *string1, const char *string2,
expect_offset), \
"strcmp_offset(%s, %s) works", #string1, #string2)
-int cmd_main(int argc, const char **argv)
+int cmd_main(int argc UNUSED, const char **argv UNUSED)
{
TEST_STRCMP_OFFSET("abc", "abc", 0, 3);
TEST_STRCMP_OFFSET("abc", "def", -1, 0);
diff --git a/t/unit-tests/t-strvec.c b/t/unit-tests/t-strvec.c
index c4bac8fc91..5c844cf0c9 100644
--- a/t/unit-tests/t-strvec.c
+++ b/t/unit-tests/t-strvec.c
@@ -19,7 +19,7 @@
} \
} while (0)
-int cmd_main(int argc, const char **argv)
+int cmd_main(int argc UNUSED, const char **argv UNUSED)
{
if_test ("static initialization") {
struct strvec vec = STRVEC_INIT;
diff --git a/t/unit-tests/t-trailer.c b/t/unit-tests/t-trailer.c
index 2ecca359d9..e1c6ad7461 100644
--- a/t/unit-tests/t-trailer.c
+++ b/t/unit-tests/t-trailer.c
@@ -308,7 +308,7 @@ static void run_t_trailer_iterator(void)
}
}
-int cmd_main(int argc, const char **argv)
+int cmd_main(int argc UNUSED, const char **argv UNUSED)
{
run_t_trailer_iterator();
return test_done();
diff --git a/t/unit-tests/t-urlmatch-normalization.c b/t/unit-tests/t-urlmatch-normalization.c
new file mode 100644
index 0000000000..1769c357b9
--- /dev/null
+++ b/t/unit-tests/t-urlmatch-normalization.c
@@ -0,0 +1,271 @@
+#include "test-lib.h"
+#include "urlmatch.h"
+
+static void check_url_normalizable(const char *url, unsigned int normalizable)
+{
+ char *url_norm = url_normalize(url, NULL);
+
+ if (!check_int(normalizable, ==, url_norm ? 1 : 0))
+ test_msg("input url: %s", url);
+ free(url_norm);
+}
+
+static void check_normalized_url(const char *url, const char *expect)
+{
+ char *url_norm = url_normalize(url, NULL);
+
+ if (!check_str(url_norm, expect))
+ test_msg("input url: %s", url);
+ free(url_norm);
+}
+
+static void compare_normalized_urls(const char *url1, const char *url2,
+ unsigned int equal)
+{
+ char *url1_norm = url_normalize(url1, NULL);
+ char *url2_norm = url_normalize(url2, NULL);
+
+ if (equal) {
+ if (!check_str(url1_norm, url2_norm))
+ test_msg("input url1: %s\n input url2: %s", url1,
+ url2);
+ } else if (!check_int(strcmp(url1_norm, url2_norm), !=, 0)) {
+ test_msg(" normalized url1: %s\n normalized url2: %s\n"
+ " input url1: %s\n input url2: %s",
+ url1_norm, url2_norm, url1, url2);
+ }
+ free(url1_norm);
+ free(url2_norm);
+}
+
+static void check_normalized_url_length(const char *url, size_t len)
+{
+ struct url_info info;
+ char *url_norm = url_normalize(url, &info);
+
+ if (!check_int(info.url_len, ==, len))
+ test_msg(" input url: %s\n normalized url: %s", url,
+ url_norm);
+ free(url_norm);
+}
+
+/* Note that only "file:" URLs should be allowed without a host */
+static void t_url_scheme(void)
+{
+ check_url_normalizable("", 0);
+ check_url_normalizable("_", 0);
+ check_url_normalizable("scheme", 0);
+ check_url_normalizable("scheme:", 0);
+ check_url_normalizable("scheme:/", 0);
+ check_url_normalizable("scheme://", 0);
+ check_url_normalizable("file", 0);
+ check_url_normalizable("file:", 0);
+ check_url_normalizable("file:/", 0);
+ check_url_normalizable("file://", 1);
+ check_url_normalizable("://acme.co", 0);
+ check_url_normalizable("x_test://acme.co", 0);
+ check_url_normalizable("-test://acme.co", 0);
+ check_url_normalizable("0test://acme.co", 0);
+ check_url_normalizable("+test://acme.co", 0);
+ check_url_normalizable(".test://acme.co", 0);
+ check_url_normalizable("schem%6e://", 0);
+ check_url_normalizable("x-Test+v1.0://acme.co", 1);
+ check_normalized_url("AbCdeF://x.Y", "abcdef://x.y/");
+}
+
+static void t_url_authority(void)
+{
+ check_url_normalizable("scheme://user:pass@", 0);
+ check_url_normalizable("scheme://?", 0);
+ check_url_normalizable("scheme://#", 0);
+ check_url_normalizable("scheme:///", 0);
+ check_url_normalizable("scheme://:", 0);
+ check_url_normalizable("scheme://:555", 0);
+ check_url_normalizable("file://user:pass@", 1);
+ check_url_normalizable("file://?", 1);
+ check_url_normalizable("file://#", 1);
+ check_url_normalizable("file:///", 1);
+ check_url_normalizable("file://:", 1);
+ check_url_normalizable("file://:555", 0);
+ check_url_normalizable("scheme://user:pass@host", 1);
+ check_url_normalizable("scheme://@host", 1);
+ check_url_normalizable("scheme://%00@host", 1);
+ check_url_normalizable("scheme://%%@host", 0);
+ check_url_normalizable("scheme://host_", 1);
+ check_url_normalizable("scheme://user:pass@host/", 1);
+ check_url_normalizable("scheme://@host/", 1);
+ check_url_normalizable("scheme://host/", 1);
+ check_url_normalizable("scheme://host?x", 1);
+ check_url_normalizable("scheme://host#x", 1);
+ check_url_normalizable("scheme://host/@", 1);
+ check_url_normalizable("scheme://host?@x", 1);
+ check_url_normalizable("scheme://host#@x", 1);
+ check_url_normalizable("scheme://[::1]", 1);
+ check_url_normalizable("scheme://[::1]/", 1);
+ check_url_normalizable("scheme://hos%41/", 0);
+ check_url_normalizable("scheme://[invalid....:/", 1);
+ check_url_normalizable("scheme://invalid....:]/", 1);
+ check_url_normalizable("scheme://invalid....:[/", 0);
+ check_url_normalizable("scheme://invalid....:[", 0);
+}
+
+static void t_url_port(void)
+{
+ check_url_normalizable("xyz://q@some.host:", 1);
+ check_url_normalizable("xyz://q@some.host:456/", 1);
+ check_url_normalizable("xyz://q@some.host:0", 0);
+ check_url_normalizable("xyz://q@some.host:0000000", 0);
+ check_url_normalizable("xyz://q@some.host:0000001?", 1);
+ check_url_normalizable("xyz://q@some.host:065535#", 1);
+ check_url_normalizable("xyz://q@some.host:65535", 1);
+ check_url_normalizable("xyz://q@some.host:65536", 0);
+ check_url_normalizable("xyz://q@some.host:99999", 0);
+ check_url_normalizable("xyz://q@some.host:100000", 0);
+ check_url_normalizable("xyz://q@some.host:100001", 0);
+ check_url_normalizable("http://q@some.host:80", 1);
+ check_url_normalizable("https://q@some.host:443", 1);
+ check_url_normalizable("http://q@some.host:80/", 1);
+ check_url_normalizable("https://q@some.host:443?", 1);
+ check_url_normalizable("http://q@:8008", 0);
+ check_url_normalizable("http://:8080", 0);
+ check_url_normalizable("http://:", 0);
+ check_url_normalizable("xyz://q@some.host:456/", 1);
+ check_url_normalizable("xyz://[::1]:456/", 1);
+ check_url_normalizable("xyz://[::1]:/", 1);
+ check_url_normalizable("xyz://[::1]:000/", 0);
+ check_url_normalizable("xyz://[::1]:0%300/", 0);
+ check_url_normalizable("xyz://[::1]:0x80/", 0);
+ check_url_normalizable("xyz://[::1]:4294967297/", 0);
+ check_url_normalizable("xyz://[::1]:030f/", 0);
+}
+
+static void t_url_port_normalization(void)
+{
+ check_normalized_url("http://x:800", "http://x:800/");
+ check_normalized_url("http://x:0800", "http://x:800/");
+ check_normalized_url("http://x:00000800", "http://x:800/");
+ check_normalized_url("http://x:065535", "http://x:65535/");
+ check_normalized_url("http://x:1", "http://x:1/");
+ check_normalized_url("http://x:80", "http://x/");
+ check_normalized_url("http://x:080", "http://x/");
+ check_normalized_url("http://x:000000080", "http://x/");
+ check_normalized_url("https://x:443", "https://x/");
+ check_normalized_url("https://x:0443", "https://x/");
+ check_normalized_url("https://x:000000443", "https://x/");
+}
+
+static void t_url_general_escape(void)
+{
+ check_url_normalizable("http://x.y?%fg", 0);
+ check_normalized_url("X://W/%7e%41^%3a", "x://w/~A%5E%3A");
+ check_normalized_url("X://W/:/?#[]@", "x://w/:/?#[]@");
+ check_normalized_url("X://W/$&()*+,;=", "x://w/$&()*+,;=");
+ check_normalized_url("X://W/'", "x://w/'");
+ check_normalized_url("X://W?!", "x://w/?!");
+}
+
+static void t_url_high_bit(void)
+{
+ check_normalized_url(
+ "x://q/\x01\x02\x03\x04\x05\x06\x07\x08\x0e\x0f\x10\x11\x12",
+ "x://q/%01%02%03%04%05%06%07%08%0E%0F%10%11%12");
+ check_normalized_url(
+ "x://q/\x13\x14\x15\x16\x17\x18\x19\x1b\x1c\x1d\x1e\x1f\x7f",
+ "x://q/%13%14%15%16%17%18%19%1B%1C%1D%1E%1F%7F");
+ check_normalized_url(
+ "x://q/\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f",
+ "x://q/%80%81%82%83%84%85%86%87%88%89%8A%8B%8C%8D%8E%8F");
+ check_normalized_url(
+ "x://q/\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f",
+ "x://q/%90%91%92%93%94%95%96%97%98%99%9A%9B%9C%9D%9E%9F");
+ check_normalized_url(
+ "x://q/\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf",
+ "x://q/%A0%A1%A2%A3%A4%A5%A6%A7%A8%A9%AA%AB%AC%AD%AE%AF");
+ check_normalized_url(
+ "x://q/\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf",
+ "x://q/%B0%B1%B2%B3%B4%B5%B6%B7%B8%B9%BA%BB%BC%BD%BE%BF");
+ check_normalized_url(
+ "x://q/\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf",
+ "x://q/%C0%C1%C2%C3%C4%C5%C6%C7%C8%C9%CA%CB%CC%CD%CE%CF");
+ check_normalized_url(
+ "x://q/\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf",
+ "x://q/%D0%D1%D2%D3%D4%D5%D6%D7%D8%D9%DA%DB%DC%DD%DE%DF");
+ check_normalized_url(
+ "x://q/\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef",
+ "x://q/%E0%E1%E2%E3%E4%E5%E6%E7%E8%E9%EA%EB%EC%ED%EE%EF");
+ check_normalized_url(
+ "x://q/\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff",
+ "x://q/%F0%F1%F2%F3%F4%F5%F6%F7%F8%F9%FA%FB%FC%FD%FE%FF");
+}
+
+static void t_url_utf8_escape(void)
+{
+ check_normalized_url(
+ "x://q/\xc2\x80\xdf\xbf\xe0\xa0\x80\xef\xbf\xbd\xf0\x90\x80\x80\xf0\xaf\xbf\xbd",
+ "x://q/%C2%80%DF%BF%E0%A0%80%EF%BF%BD%F0%90%80%80%F0%AF%BF%BD");
+}
+
+static void t_url_username_pass(void)
+{
+ check_normalized_url("x://%41%62(^):%70+d@foo", "x://Ab(%5E):p+d@foo/");
+}
+
+static void t_url_length(void)
+{
+ check_normalized_url_length("Http://%4d%65:%4d^%70@The.Host", 25);
+ check_normalized_url_length("http://%41:%42@x.y/%61/", 17);
+ check_normalized_url_length("http://@x.y/^", 15);
+}
+
+static void t_url_dots(void)
+{
+ check_normalized_url("x://y/.", "x://y/");
+ check_normalized_url("x://y/./", "x://y/");
+ check_normalized_url("x://y/a/.", "x://y/a");
+ check_normalized_url("x://y/a/./", "x://y/a/");
+ check_normalized_url("x://y/.?", "x://y/?");
+ check_normalized_url("x://y/./?", "x://y/?");
+ check_normalized_url("x://y/a/.?", "x://y/a?");
+ check_normalized_url("x://y/a/./?", "x://y/a/?");
+ check_normalized_url("x://y/a/./b/.././../c", "x://y/c");
+ check_normalized_url("x://y/a/./b/../.././c/", "x://y/c/");
+ check_normalized_url("x://y/a/./b/.././../c/././.././.", "x://y/");
+ check_url_normalizable("x://y/a/./b/.././../c/././.././..", 0);
+ check_normalized_url("x://y/a/./?/././..", "x://y/a/?/././..");
+ check_normalized_url("x://y/%2e/", "x://y/");
+ check_normalized_url("x://y/%2E/", "x://y/");
+ check_normalized_url("x://y/a/%2e./", "x://y/");
+ check_normalized_url("x://y/b/.%2E/", "x://y/");
+ check_normalized_url("x://y/c/%2e%2E/", "x://y/");
+}
+
+/*
+ * "http://@foo" specifies an empty user name but does not specify a password.
+ * "http://foo" specifies neither a user name nor a password.
+ * So they should not be equivalent.
+ */
+static void t_url_equivalents(void)
+{
+ compare_normalized_urls("httP://x", "Http://X/", 1);
+ compare_normalized_urls("Http://%4d%65:%4d^%70@The.Host", "hTTP://Me:%4D^p@the.HOST:80/", 1);
+ compare_normalized_urls("https://@x.y/^", "httpS://x.y:443/^", 0);
+ compare_normalized_urls("https://@x.y/^", "httpS://@x.y:0443/^", 1);
+ compare_normalized_urls("https://@x.y/^/../abc", "httpS://@x.y:0443/abc", 1);
+ compare_normalized_urls("https://@x.y/^/..", "httpS://@x.y:0443/", 1);
+}
+
+int cmd_main(int argc UNUSED, const char **argv UNUSED)
+{
+ TEST(t_url_scheme(), "url scheme");
+ TEST(t_url_authority(), "url authority");
+ TEST(t_url_port(), "url port checks");
+ TEST(t_url_port_normalization(), "url port normalization");
+ TEST(t_url_general_escape(), "url general escapes");
+ TEST(t_url_high_bit(), "url high-bit escapes");
+ TEST(t_url_utf8_escape(), "url utf8 escapes");
+ TEST(t_url_username_pass(), "url username/password escapes");
+ TEST(t_url_length(), "url normalized lengths");
+ TEST(t_url_dots(), "url . and .. segments");
+ TEST(t_url_equivalents(), "url equivalents");
+ return test_done();
+}
diff --git a/trailer.c b/trailer.c
index 72e5136c73..682d74505b 100644
--- a/trailer.c
+++ b/trailer.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "config.h"
#include "environment.h"
diff --git a/transport.c b/transport.c
index 7c4af9f56f..bab28965f9 100644
--- a/transport.c
+++ b/transport.c
@@ -1273,7 +1273,7 @@ static int run_pre_push_hook(struct transport *transport,
struct ref *r;
struct child_process proc = CHILD_PROCESS_INIT;
struct strbuf buf;
- const char *hook_path = find_hook("pre-push");
+ const char *hook_path = find_hook(the_repository, "pre-push");
if (!hook_path)
return 0;
diff --git a/unpack-trees.c b/unpack-trees.c
index 7dc884fafd..9a55cb6204 100644
--- a/unpack-trees.c
+++ b/unpack-trees.c
@@ -210,6 +210,7 @@ void clear_unpack_trees_porcelain(struct unpack_trees_options *opts)
{
strvec_clear(&opts->internal.msgs_to_free);
memset(opts->internal.msgs, 0, sizeof(opts->internal.msgs));
+ discard_index(&opts->internal.result);
}
static int do_add_entry(struct unpack_trees_options *o, struct cache_entry *ce,
@@ -2082,6 +2083,7 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
o->internal.result.updated_workdir = 1;
discard_index(o->dst_index);
*o->dst_index = o->internal.result;
+ memset(&o->internal.result, 0, sizeof(o->internal.result));
} else {
discard_index(&o->internal.result);
}
diff --git a/userdiff.c b/userdiff.c
index c4ebb9ff73..989629149f 100644
--- a/userdiff.c
+++ b/userdiff.c
@@ -399,8 +399,11 @@ static struct userdiff_driver *userdiff_find_by_namelen(const char *name, size_t
static int parse_funcname(struct userdiff_funcname *f, const char *k,
const char *v, int cflags)
{
- if (git_config_string((char **) &f->pattern, k, v) < 0)
+ f->pattern = NULL;
+ FREE_AND_NULL(f->pattern_owned);
+ if (git_config_string(&f->pattern_owned, k, v) < 0)
return -1;
+ f->pattern = f->pattern_owned;
f->cflags = cflags;
return 0;
}
@@ -444,20 +447,37 @@ int userdiff_config(const char *k, const char *v)
return parse_funcname(&drv->funcname, k, v, REG_EXTENDED);
if (!strcmp(type, "binary"))
return parse_tristate(&drv->binary, k, v);
- if (!strcmp(type, "command"))
- return git_config_string((char **) &drv->external.cmd, k, v);
+ if (!strcmp(type, "command")) {
+ FREE_AND_NULL(drv->external.cmd);
+ return git_config_string(&drv->external.cmd, k, v);
+ }
if (!strcmp(type, "trustexitcode")) {
drv->external.trust_exit_code = git_config_bool(k, v);
return 0;
}
- if (!strcmp(type, "textconv"))
- return git_config_string((char **) &drv->textconv, k, v);
+ if (!strcmp(type, "textconv")) {
+ int ret;
+ FREE_AND_NULL(drv->textconv_owned);
+ ret = git_config_string(&drv->textconv_owned, k, v);
+ drv->textconv = drv->textconv_owned;
+ return ret;
+ }
if (!strcmp(type, "cachetextconv"))
return parse_bool(&drv->textconv_want_cache, k, v);
- if (!strcmp(type, "wordregex"))
- return git_config_string((char **) &drv->word_regex, k, v);
- if (!strcmp(type, "algorithm"))
- return git_config_string((char **) &drv->algorithm, k, v);
+ if (!strcmp(type, "wordregex")) {
+ int ret;
+ FREE_AND_NULL(drv->word_regex_owned);
+ ret = git_config_string(&drv->word_regex_owned, k, v);
+ drv->word_regex = drv->word_regex_owned;
+ return ret;
+ }
+ if (!strcmp(type, "algorithm")) {
+ int ret;
+ FREE_AND_NULL(drv->algorithm_owned);
+ ret = git_config_string(&drv->algorithm_owned, k, v);
+ drv->algorithm = drv->algorithm_owned;
+ return ret;
+ }
return 0;
}
diff --git a/userdiff.h b/userdiff.h
index 7565930337..827361b0bc 100644
--- a/userdiff.h
+++ b/userdiff.h
@@ -8,6 +8,7 @@ struct repository;
struct userdiff_funcname {
const char *pattern;
+ char *pattern_owned;
int cflags;
};
@@ -20,11 +21,14 @@ struct userdiff_driver {
const char *name;
struct external_diff external;
const char *algorithm;
+ char *algorithm_owned;
int binary;
struct userdiff_funcname funcname;
const char *word_regex;
+ char *word_regex_owned;
const char *word_regex_multi_byte;
const char *textconv;
+ char *textconv_owned;
struct notes_cache *textconv_cache;
int textconv_want_cache;
};
diff --git a/versioncmp.c b/versioncmp.c
index 45e676cbca..e3b2a6e330 100644
--- a/versioncmp.c
+++ b/versioncmp.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "config.h"
#include "strbuf.h"
diff --git a/worktree.c b/worktree.c
index fd05f3741c..30a947426e 100644
--- a/worktree.c
+++ b/worktree.c
@@ -252,7 +252,7 @@ const char *worktree_lock_reason(struct worktree *wt)
if (!wt->lock_reason_valid) {
struct strbuf path = STRBUF_INIT;
- strbuf_addstr(&path, worktree_git_path(wt, "locked"));
+ strbuf_addstr(&path, worktree_git_path(the_repository, wt, "locked"));
if (file_exists(path.buf)) {
struct strbuf lock_reason = STRBUF_INIT;
if (strbuf_read_file(&lock_reason, path.buf, 0) < 0)
diff --git a/wt-status.c b/wt-status.c
index b778eef989..b477239039 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -1618,7 +1618,7 @@ static char *get_branch(const struct worktree *wt, const char *path)
struct object_id oid;
const char *branch_name;
- if (strbuf_read_file(&sb, worktree_git_path(wt, "%s", path), 0) <= 0)
+ if (strbuf_read_file(&sb, worktree_git_path(the_repository, wt, "%s", path), 0) <= 0)
goto got_nothing;
while (sb.len && sb.buf[sb.len - 1] == '\n')
@@ -1716,18 +1716,18 @@ int wt_status_check_rebase(const struct worktree *wt,
{
struct stat st;
- if (!stat(worktree_git_path(wt, "rebase-apply"), &st)) {
- if (!stat(worktree_git_path(wt, "rebase-apply/applying"), &st)) {
+ if (!stat(worktree_git_path(the_repository, wt, "rebase-apply"), &st)) {
+ if (!stat(worktree_git_path(the_repository, wt, "rebase-apply/applying"), &st)) {
state->am_in_progress = 1;
- if (!stat(worktree_git_path(wt, "rebase-apply/patch"), &st) && !st.st_size)
+ if (!stat(worktree_git_path(the_repository, wt, "rebase-apply/patch"), &st) && !st.st_size)
state->am_empty_patch = 1;
} else {
state->rebase_in_progress = 1;
state->branch = get_branch(wt, "rebase-apply/head-name");
state->onto = get_branch(wt, "rebase-apply/onto");
}
- } else if (!stat(worktree_git_path(wt, "rebase-merge"), &st)) {
- if (!stat(worktree_git_path(wt, "rebase-merge/interactive"), &st))
+ } else if (!stat(worktree_git_path(the_repository, wt, "rebase-merge"), &st)) {
+ if (!stat(worktree_git_path(the_repository, wt, "rebase-merge/interactive"), &st))
state->rebase_interactive_in_progress = 1;
else
state->rebase_in_progress = 1;
@@ -1743,7 +1743,7 @@ int wt_status_check_bisect(const struct worktree *wt,
{
struct stat st;
- if (!stat(worktree_git_path(wt, "BISECT_LOG"), &st)) {
+ if (!stat(worktree_git_path(the_repository, wt, "BISECT_LOG"), &st)) {
state->bisect_in_progress = 1;
state->bisecting_from = get_branch(wt, "BISECT_START");
return 1;