aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.github/workflows/main.yml2
-rw-r--r--.gitlab-ci.yml1
-rw-r--r--Documentation/RelNotes/2.50.0.adoc42
-rw-r--r--Documentation/config/maintenance.adoc17
-rw-r--r--Documentation/git-maintenance.adoc8
-rw-r--r--Documentation/git-send-email.adoc67
-rw-r--r--Documentation/gitcredentials.adoc4
-rw-r--r--Documentation/scalar.adoc31
-rw-r--r--Documentation/technical/bundle-uri.adoc14
-rw-r--r--Makefile2
-rw-r--r--builtin/am.c4
-rw-r--r--builtin/gc.c148
-rw-r--r--builtin/replay.c65
-rw-r--r--builtin/rev-list.c2
-rw-r--r--bundle-uri.c2
-rw-r--r--commit-graph.c2
-rw-r--r--compiler-tricks/not-constant.c2
-rwxr-xr-xgit-send-email.perl20
-rw-r--r--json-writer.c4
-rw-r--r--json-writer.h171
-rw-r--r--list-objects-filter.c2
-rw-r--r--mailinfo.c42
-rw-r--r--meson.build9
-rw-r--r--meson_options.txt4
-rw-r--r--object-store.c3
-rw-r--r--object-store.h3
-rw-r--r--oidmap.c2
-rw-r--r--oidmap.h9
-rw-r--r--pack-bitmap.c8
-rw-r--r--perl/FromCPAN/Mail/meson.build2
-rw-r--r--perl/FromCPAN/meson.build2
-rw-r--r--perl/Git/LoadCPAN/Mail/meson.build2
-rw-r--r--perl/Git/LoadCPAN/meson.build2
-rw-r--r--perl/Git/SVN/Memoize/meson.build2
-rw-r--r--perl/Git/SVN/meson.build2
-rw-r--r--perl/Git/meson.build2
-rw-r--r--perl/meson.build2
-rw-r--r--reftable/block.c7
-rw-r--r--reftable/reftable-block.h3
-rw-r--r--reftable/table.c11
-rw-r--r--reftable/writer.c8
-rw-r--r--replace-object.c8
-rw-r--r--replace-object.h2
-rw-r--r--scalar.c65
-rw-r--r--sequencer.c120
-rwxr-xr-xt/t1001-read-tree-m-2way.sh2
-rwxr-xr-xt/t3430-rebase-merges.sh11
-rw-r--r--t/t4018/bash-bashism-style-complete-line-capture4
-rw-r--r--t/t4018/bash-posix-style-complete-line-capture4
-rw-r--r--t/t4018/bash-posix-style-single-command-function3
-rwxr-xr-xt/t4034-diff-words.sh1
-rw-r--r--t/t4034/bash/expect36
-rw-r--r--t/t4034/bash/post31
-rw-r--r--t/t4034/bash/pre31
-rwxr-xr-xt/t5558-clone-bundle-uri.sh202
-rwxr-xr-xt/t6011-rev-list-with-bad-commit.sh1
-rwxr-xr-xt/t7900-maintenance.sh115
-rwxr-xr-xt/t9210-scalar.sh26
-rwxr-xr-xt/t9211-scalar-clone.sh11
-rw-r--r--t/unit-tests/t-reftable-block.c15
-rw-r--r--t/unit-tests/u-oidmap.c2
-rw-r--r--userdiff.c26
-rw-r--r--wrapper.c21
63 files changed, 1136 insertions, 336 deletions
diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
index 49bcd0a2a9..7dbf9f7f12 100644
--- a/.github/workflows/main.yml
+++ b/.github/workflows/main.yml
@@ -265,7 +265,7 @@ jobs:
run: pip install meson ninja
- name: Setup
shell: pwsh
- run: meson setup build --vsenv -Dperl=disabled -Dcredential_helpers=wincred
+ run: meson setup build --vsenv -Dbuildtype=release -Dperl=disabled -Dcredential_helpers=wincred
- name: Compile
shell: pwsh
run: meson compile -C build
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 4798b28374..bb6d5b976c 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -173,7 +173,6 @@ build:msvc-meson:
test:msvc-meson:
extends: .msvc-meson
stage: test
- when: manual
timeout: 6h
needs:
- job: "build:msvc-meson"
diff --git a/Documentation/RelNotes/2.50.0.adoc b/Documentation/RelNotes/2.50.0.adoc
index 7ae05bdbd6..f721ea350d 100644
--- a/Documentation/RelNotes/2.50.0.adoc
+++ b/Documentation/RelNotes/2.50.0.adoc
@@ -62,6 +62,20 @@ UI, Workflows & Features
delta chains from forming in a corner case even when there is no
such cycle.
+ * Make repository clean-up tasks "gc" can do available to "git
+ maintenance" front-end.
+
+ * Bundle-URI feature did not use refs recorded in the bundle other
+ than normal branches as anchoring points to optimize the follow-up
+ fetch during "git clone"; now it is told to utilize all.
+
+ * The `send-email` documentation has been updated with OAuth2.0
+ related examples.
+
+ * Two of the "scalar" subcommands that add a repository that hasn't
+ been under "scalar"'s control are taught an option not to enable the
+ scheduled maintenance on it.
+
Performance, Internal Implementation, Development Support etc.
--------------------------------------------------------------
@@ -145,6 +159,14 @@ Performance, Internal Implementation, Development Support etc.
* Further code clean-up in the object-store layer.
+ * Build performance fix.
+
+ * Teach "git send-email" to also consult `hostname -f` for mail
+ domain to compute the identity given to SMTP servers.
+
+ * The dependency on the_repository variable has been reduced from the
+ code paths in "git replay".
+
Fixes since v2.49
-----------------
@@ -286,6 +308,23 @@ Fixes since v2.49
also existed on the working tree, which has been corrected.
(merge ec727e189c kj/glob-path-with-special-char later to maint).
+ * The fallback implementation of open_nofollow() depended on
+ open("symlink", O_NOFOLLOW) to set errno to ELOOP, but a few BSD
+ derived systems use different errno, which has been worked around.
+ (merge f47bcc3413 cf/wrapper-bsd-eloop later to maint).
+
+ * Use-after-free fix in the sequencer.
+ (merge 5dbaec628d pw/sequencer-reflog-use-after-free later to maint).
+
+ * win+Meson CI pipeline, unlike other pipelines for Windows,
+ used to build artifacts in develper mode, which has been changed to
+ build them in release mode for consistency.
+ (merge 184abdcf05 js/ci-build-win-in-release-mode later to maint).
+
+ * CI settings at GitLab has been updated to run MSVC based Meson job
+ automatically (as opposed to be done only upon manual request).
+ (merge 6389579b2f ps/ci-gitlab-enable-msvc-meson-job later to maint).
+
* Other code cleanup, docfix, build fix, etc.
(merge 227c4f33a0 ja/doc-block-delimiter-markup-fix later to maint).
(merge 2bfd3b3685 ab/decorate-code-cleanup later to maint).
@@ -313,3 +352,6 @@ Fixes since v2.49
(merge 42cf4ac552 ps/ci-resurrect-p4-on-github later to maint).
(merge 104add8368 js/diff-codeql-false-positive-workaround later to maint).
(merge f62977b93c en/get-tree-entry-doc later to maint).
+ (merge e5dd0a05ed ly/am-split-stgit-leakfix later to maint).
+ (merge bac220e154 rc/t1001-test-path-is-file later to maint).
+ (merge 91db6c735d ly/reftable-writer-leakfix later to maint).
diff --git a/Documentation/config/maintenance.adoc b/Documentation/config/maintenance.adoc
index 41536162a7..2f71934218 100644
--- a/Documentation/config/maintenance.adoc
+++ b/Documentation/config/maintenance.adoc
@@ -83,3 +83,20 @@ maintenance.reflog-expire.auto::
positive value implies the command should run when the number of
expired reflog entries in the "HEAD" reflog is at least the value of
`maintenance.loose-objects.auto`. The default value is 100.
+
+maintenance.rerere-gc.auto::
+ This integer config option controls how often the `rerere-gc` task
+ should be run as part of `git maintenance run --auto`. If zero, then
+ the `rerere-gc` task will not run with the `--auto` option. A negative
+ value will force the task to run every time. Otherwise, any positive
+ value implies the command will run when the "rr-cache" directory exists
+ and has at least one entry, regardless of whether it is stale or not.
+ This heuristic may be refined in the future. The default value is 1.
+
+maintenance.worktree-prune.auto::
+ This integer config option controls how often the `worktree-prune` task
+ should be run as part of `git maintenance run --auto`. If zero, then
+ the `worktree-prune` task will not run with the `--auto` option. A
+ negative value will force the task to run every time. Otherwise, a
+ positive value implies the command should run when the number of
+ prunable worktrees exceeds the value. The default value is 1.
diff --git a/Documentation/git-maintenance.adoc b/Documentation/git-maintenance.adoc
index 3a1e2a69b6..931f3e02e8 100644
--- a/Documentation/git-maintenance.adoc
+++ b/Documentation/git-maintenance.adoc
@@ -166,6 +166,14 @@ reflog-expire::
The `reflog-expire` task deletes any entries in the reflog older than the
expiry threshold. See linkgit:git-reflog[1] for more information.
+rerere-gc::
+ The `rerere-gc` task invokes garbage collection for stale entries in
+ the rerere cache. See linkgit:git-rerere[1] for more information.
+
+worktree-prune::
+ The `worktree-prune` task deletes stale or broken worktrees. See
+ linkit:git-worktree[1] for more information.
+
OPTIONS
-------
--auto::
diff --git a/Documentation/git-send-email.adoc b/Documentation/git-send-email.adoc
index 92389036fa..26fda63c2f 100644
--- a/Documentation/git-send-email.adoc
+++ b/Documentation/git-send-email.adoc
@@ -509,12 +509,12 @@ include::includes/cmd-config-section-all.adoc[]
include::config/sendemail.adoc[]
-EXAMPLES
---------
-Use gmail as the smtp server
+EXAMPLES OF SMTP SERVERS
+------------------------
+Use Gmail as the SMTP Server
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-To use 'git send-email' to send your patches through the GMail SMTP server,
-edit ~/.gitconfig to specify your account settings:
+To use `git send-email` to send your patches through the Gmail SMTP server,
+edit `~/.gitconfig` to specify your account settings:
----
[sendemail]
@@ -528,6 +528,41 @@ If you have multi-factor authentication set up on your Gmail account, you can
generate an app-specific password for use with 'git send-email'. Visit
https://security.google.com/settings/security/apppasswords to create it.
+You can also use OAuth2.0 authentication with Gmail. `OAUTHBEARER` and
+`XOAUTH2` are common methods used for this type of authentication. Gmail
+supports both of them. As an example, if you want to use `OAUTHBEARER`, edit
+your `~/.gitconfig` file and add `smtpAuth = OAUTHBEARER` to your account
+settings:
+
+----
+[sendemail]
+ smtpEncryption = tls
+ smtpServer = smtp.gmail.com
+ smtpUser = yourname@gmail.com
+ smtpServerPort = 587
+ smtpAuth = OAUTHBEARER
+----
+
+Use Microsoft Outlook as the SMTP Server
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+Unlike Gmail, Microsoft Outlook no longer supports app-specific passwords.
+Therefore, OAuth2.0 authentication must be used for Outlook. Also, it only
+supports `XOAUTH2` authentication method.
+
+Edit `~/.gitconfig` to specify your account settings for Outlook and use its
+SMTP server with `git send-email`:
+
+----
+[sendemail]
+ smtpEncryption = tls
+ smtpServer = smtp.office365.com
+ smtpUser = yourname@outlook.com
+ smtpServerPort = 587
+ smtpAuth = XOAUTH2
+----
+
+SENDING PATCHES
+---------------
Once your commits are ready to be sent to the mailing list, run the
following commands:
@@ -536,9 +571,25 @@ following commands:
$ git send-email outgoing/*
The first time you run it, you will be prompted for your credentials. Enter the
-app-specific or your regular password as appropriate. If you have credential
-helper configured (see linkgit:git-credential[1]), the password will be saved in
-the credential store so you won't have to type it the next time.
+app-specific or your regular password as appropriate.
+
+If you have a credential helper configured (see linkgit:git-credential[1]), the
+password will be saved in the credential store so you won't have to type it the
+next time.
+
+If you are using OAuth2.0 authentication, you need to use an access token in
+place of a password when prompted. Various OAuth2.0 token generators are
+available online. Community maintained credential helpers for Gmail and Outlook
+are also available:
+
+ - https://github.com/AdityaGarg8/git-credential-email[git-credential-gmail]
+ (cross platform, dedicated helper for authenticating Gmail accounts)
+
+ - https://github.com/AdityaGarg8/git-credential-email[git-credential-outlook]
+ (cross platform, dedicated helper for authenticating Microsoft Outlook accounts)
+
+You can also see linkgit:gitcredentials[7] for more OAuth based authentication
+helpers.
Note: the following core Perl modules that may be installed with your
distribution of Perl are required:
diff --git a/Documentation/gitcredentials.adoc b/Documentation/gitcredentials.adoc
index 3337bb475d..b49923db02 100644
--- a/Documentation/gitcredentials.adoc
+++ b/Documentation/gitcredentials.adoc
@@ -133,6 +133,10 @@ Popular helpers with OAuth support include:
- https://github.com/hickford/git-credential-oauth[git-credential-oauth] (cross platform, included in many Linux distributions)
+ - https://github.com/AdityaGarg8/git-credential-email[git-credential-gmail] (cross platform, dedicated helper to authenticate Gmail accounts for linkgit:git-send-email[1])
+
+ - https://github.com/AdityaGarg8/git-credential-email[git-credential-outlook] (cross platform, dedicated helper to authenticate Microsoft Outlook accounts for linkgit:git-send-email[1])
+
CREDENTIAL CONTEXTS
-------------------
diff --git a/Documentation/scalar.adoc b/Documentation/scalar.adoc
index 7e4259c674..4bd5b150e8 100644
--- a/Documentation/scalar.adoc
+++ b/Documentation/scalar.adoc
@@ -9,12 +9,12 @@ SYNOPSIS
--------
[verse]
scalar clone [--single-branch] [--branch <main-branch>] [--full-clone]
- [--[no-]src] <url> [<enlistment>]
+ [--[no-]src] [--[no-]tags] [--[no-]maintenance] <url> [<enlistment>]
scalar list
-scalar register [<enlistment>]
+scalar register [--[no-]maintenance] [<enlistment>]
scalar unregister [<enlistment>]
scalar run ( all | config | commit-graph | fetch | loose-objects | pack-files ) [<enlistment>]
-scalar reconfigure [ --all | <enlistment> ]
+scalar reconfigure [--maintenance=(enable|disable|keep)] [ --all | <enlistment> ]
scalar diagnose [<enlistment>]
scalar delete <enlistment>
@@ -97,6 +97,11 @@ cloning. If the HEAD at the remote did not point at any branch when
A sparse-checkout is initialized by default. This behavior can be
turned off via `--full-clone`.
+--[no-]maintenance::
+ By default, `scalar clone` configures the enlistment to use Git's
+ background maintenance feature. Use the `--no-maintenance` to skip
+ this configuration.
+
List
~~~~
@@ -117,6 +122,12 @@ Note: when this subcommand is called in a worktree that is called `src/`, its
parent directory is considered to be the Scalar enlistment. If the worktree is
_not_ called `src/`, it itself will be considered to be the Scalar enlistment.
+--[no-]maintenance::
+ By default, `scalar register` configures the enlistment to use Git's
+ background maintenance feature. Use the `--no-maintenance` to skip
+ this configuration. This does not disable any maintenance that may
+ already be enabled in other ways.
+
Unregister
~~~~~~~~~~
@@ -149,8 +160,18 @@ After a Scalar upgrade, or when the configuration of a Scalar enlistment
was somehow corrupted or changed by mistake, this subcommand allows to
reconfigure the enlistment.
-With the `--all` option, all enlistments currently registered with Scalar
-will be reconfigured. Use this option after each Scalar upgrade.
+--all::
+ When `--all` is specified, reconfigure all enlistments currently
+ registered with Scalar by the `scalar.repo` config key. Use this
+ option after each upgrade to get the latest features.
+
+--maintenance=(enable|disable|keep)::
+ By default, Scalar configures the enlistment to use Git's
+ background maintenance feature; this is the same as using the
+ `enable` value for this option. Use the `disable` value to
+ remove each considered enlistment from background maintenance.
+ Use `keep' to leave the background maintenance configuration
+ untouched for these repositories.
Diagnose
~~~~~~~~
diff --git a/Documentation/technical/bundle-uri.adoc b/Documentation/technical/bundle-uri.adoc
index 91d3a13e32..12283fa9ed 100644
--- a/Documentation/technical/bundle-uri.adoc
+++ b/Documentation/technical/bundle-uri.adoc
@@ -232,13 +232,13 @@ will interact with bundle URIs according to the following flow:
are present in the client repository. If some are missing, then the
client delays unbundling until other bundles have been unbundled,
making those OIDs present. When all required OIDs are present, the
- client unbundles that data using a refspec. The default refspec is
- `+refs/heads/*:refs/bundles/*`, but this can be configured. These refs
- are stored so that later `git fetch` negotiations can communicate each
- bundled ref as a `have`, reducing the size of the fetch over the Git
- protocol. To allow pruning refs from this ref namespace, Git may
- introduce a numbered namespace (such as `refs/bundles/<i>/*`) such that
- stale bundle refs can be deleted.
+ client unbundles that data using a refspec. The refspec used is
+ `+refs/*:refs/bundles/*`. These refs are stored so that later
+ `git fetch` negotiations can communicate each bundled ref as a `have`,
+ reducing the size of the fetch over the Git protocol. To allow pruning
+ refs from this ref namespace, Git may introduce a numbered namespace
+ (such as `refs/bundles/<i>/*`) such that stale bundle refs can be
+ deleted.
3. If the file is instead a bundle list, then the client inspects the
`bundle.mode` to see if the list is of the `all` or `any` form.
diff --git a/Makefile b/Makefile
index de73c6ddcd..ecd590a643 100644
--- a/Makefile
+++ b/Makefile
@@ -2805,7 +2805,7 @@ endif
compdb_dir = compile_commands
ifeq ($(GENERATE_COMPILATION_DATABASE),yes)
-missing_compdb_dir = $(compdb_dir)
+missing_compdb_dir = $(filter-out $(wildcard $(compdb_dir)), $(compdb_dir))
$(missing_compdb_dir):
@mkdir -p $@
diff --git a/builtin/am.c b/builtin/am.c
index 4afb519830..e32a3b4c97 100644
--- a/builtin/am.c
+++ b/builtin/am.c
@@ -850,8 +850,10 @@ static int split_mail_stgit_series(struct am_state *state, const char **paths,
series_dir = dirname(series_dir_buf);
fp = fopen(*paths, "r");
- if (!fp)
+ if (!fp) {
+ free(series_dir_buf);
return error_errno(_("could not open '%s' for reading"), *paths);
+ }
while (!strbuf_getline_lf(&sb, fp)) {
if (*sb.buf == '#')
diff --git a/builtin/gc.c b/builtin/gc.c
index 78a2751aa8..e33ba946e4 100644
--- a/builtin/gc.c
+++ b/builtin/gc.c
@@ -16,6 +16,7 @@
#include "builtin.h"
#include "abspath.h"
#include "date.h"
+#include "dir.h"
#include "environment.h"
#include "hex.h"
#include "config.h"
@@ -33,6 +34,7 @@
#include "pack-objects.h"
#include "path.h"
#include "reflog.h"
+#include "rerere.h"
#include "blob.h"
#include "tree.h"
#include "promisor-remote.h"
@@ -43,6 +45,7 @@
#include "hook.h"
#include "setup.h"
#include "trace2.h"
+#include "worktree.h"
#define FAILED_RUN "failed to run %s"
@@ -52,15 +55,9 @@ static const char * const builtin_gc_usage[] = {
};
static timestamp_t gc_log_expire_time;
-
static struct strvec repack = STRVEC_INIT;
-static struct strvec prune = STRVEC_INIT;
-static struct strvec prune_worktrees = STRVEC_INIT;
-static struct strvec rerere = STRVEC_INIT;
-
static struct tempfile *pidfile;
static struct lock_file log_lock;
-
static struct string_list pack_garbage = STRING_LIST_INIT_DUP;
static void clean_pack_garbage(void)
@@ -339,6 +336,94 @@ static int maintenance_task_reflog_expire(struct maintenance_run_opts *opts UNUS
return run_command(&cmd);
}
+static int maintenance_task_worktree_prune(struct maintenance_run_opts *opts UNUSED,
+ struct gc_config *cfg)
+{
+ struct child_process prune_worktrees_cmd = CHILD_PROCESS_INIT;
+
+ prune_worktrees_cmd.git_cmd = 1;
+ strvec_pushl(&prune_worktrees_cmd.args, "worktree", "prune", "--expire", NULL);
+ strvec_push(&prune_worktrees_cmd.args, cfg->prune_worktrees_expire);
+
+ return run_command(&prune_worktrees_cmd);
+}
+
+static int worktree_prune_condition(struct gc_config *cfg)
+{
+ struct strbuf buf = STRBUF_INIT;
+ int should_prune = 0, limit = 1;
+ timestamp_t expiry_date;
+ struct dirent *d;
+ DIR *dir = NULL;
+
+ git_config_get_int("maintenance.worktree-prune.auto", &limit);
+ if (limit <= 0) {
+ should_prune = limit < 0;
+ goto out;
+ }
+
+ if (parse_expiry_date(cfg->prune_worktrees_expire, &expiry_date))
+ goto out;
+
+ dir = opendir(repo_git_path_replace(the_repository, &buf, "worktrees"));
+ if (!dir)
+ goto out;
+
+ while (limit && (d = readdir_skip_dot_and_dotdot(dir))) {
+ char *wtpath;
+ strbuf_reset(&buf);
+ if (should_prune_worktree(d->d_name, &buf, &wtpath, expiry_date))
+ limit--;
+ free(wtpath);
+ }
+
+ should_prune = !limit;
+
+out:
+ if (dir)
+ closedir(dir);
+ strbuf_release(&buf);
+ return should_prune;
+}
+
+static int maintenance_task_rerere_gc(struct maintenance_run_opts *opts UNUSED,
+ struct gc_config *cfg UNUSED)
+{
+ struct child_process rerere_cmd = CHILD_PROCESS_INIT;
+ rerere_cmd.git_cmd = 1;
+ strvec_pushl(&rerere_cmd.args, "rerere", "gc", NULL);
+ return run_command(&rerere_cmd);
+}
+
+static int rerere_gc_condition(struct gc_config *cfg UNUSED)
+{
+ struct strbuf path = STRBUF_INIT;
+ int should_gc = 0, limit = 1;
+ DIR *dir = NULL;
+
+ git_config_get_int("maintenance.rerere-gc.auto", &limit);
+ if (limit <= 0) {
+ should_gc = limit < 0;
+ goto out;
+ }
+
+ /*
+ * We skip garbage collection in case we either have no "rr-cache"
+ * directory or when it doesn't contain at least one entry.
+ */
+ repo_git_path_replace(the_repository, &path, "rr-cache");
+ dir = opendir(path.buf);
+ if (!dir)
+ goto out;
+ should_gc = !!readdir_skip_dot_and_dotdot(dir);
+
+out:
+ strbuf_release(&path);
+ if (dir)
+ closedir(dir);
+ return should_gc;
+}
+
static int too_many_loose_objects(struct gc_config *cfg)
{
/*
@@ -728,9 +813,9 @@ static void gc_before_repack(struct maintenance_run_opts *opts,
}
int cmd_gc(int argc,
-const char **argv,
-const char *prefix,
-struct repository *repo UNUSED)
+ const char **argv,
+ const char *prefix,
+ struct repository *repo UNUSED)
{
int aggressive = 0;
int quiet = 0;
@@ -740,7 +825,6 @@ struct repository *repo UNUSED)
int daemonized = 0;
int keep_largest_pack = -1;
timestamp_t dummy;
- struct child_process rerere_cmd = CHILD_PROCESS_INIT;
struct maintenance_run_opts opts = MAINTENANCE_RUN_OPTS_INIT;
struct gc_config cfg = GC_CONFIG_INIT;
const char *prune_expire_sentinel = "sentinel";
@@ -779,9 +863,6 @@ struct repository *repo UNUSED)
builtin_gc_usage, builtin_gc_options);
strvec_pushl(&repack, "repack", "-d", "-l", NULL);
- strvec_pushl(&prune, "prune", "--expire", NULL);
- strvec_pushl(&prune_worktrees, "worktree", "prune", "--expire", NULL);
- strvec_pushl(&rerere, "rerere", "gc", NULL);
gc_config(&cfg);
@@ -907,34 +988,27 @@ struct repository *repo UNUSED)
if (cfg.prune_expire) {
struct child_process prune_cmd = CHILD_PROCESS_INIT;
+ strvec_pushl(&prune_cmd.args, "prune", "--expire", NULL);
/* run `git prune` even if using cruft packs */
- strvec_push(&prune, cfg.prune_expire);
+ strvec_push(&prune_cmd.args, cfg.prune_expire);
if (quiet)
- strvec_push(&prune, "--no-progress");
+ strvec_push(&prune_cmd.args, "--no-progress");
if (repo_has_promisor_remote(the_repository))
- strvec_push(&prune,
+ strvec_push(&prune_cmd.args,
"--exclude-promisor-objects");
prune_cmd.git_cmd = 1;
- strvec_pushv(&prune_cmd.args, prune.v);
+
if (run_command(&prune_cmd))
- die(FAILED_RUN, prune.v[0]);
+ die(FAILED_RUN, prune_cmd.args.v[0]);
}
}
- if (cfg.prune_worktrees_expire) {
- struct child_process prune_worktrees_cmd = CHILD_PROCESS_INIT;
-
- 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))
- die(FAILED_RUN, prune_worktrees.v[0]);
- }
+ if (cfg.prune_worktrees_expire &&
+ maintenance_task_worktree_prune(&opts, &cfg))
+ die(FAILED_RUN, "worktree");
- rerere_cmd.git_cmd = 1;
- strvec_pushv(&rerere_cmd.args, rerere.v);
- if (run_command(&rerere_cmd))
- die(FAILED_RUN, rerere.v[0]);
+ if (maintenance_task_rerere_gc(&opts, &cfg))
+ die(FAILED_RUN, "rerere");
report_garbage = report_pack_garbage;
reprepare_packed_git(the_repository);
@@ -1467,6 +1541,8 @@ enum maintenance_task_label {
TASK_COMMIT_GRAPH,
TASK_PACK_REFS,
TASK_REFLOG_EXPIRE,
+ TASK_WORKTREE_PRUNE,
+ TASK_RERERE_GC,
/* Leave as final value */
TASK__COUNT
@@ -1508,6 +1584,16 @@ static struct maintenance_task tasks[] = {
maintenance_task_reflog_expire,
reflog_expire_condition,
},
+ [TASK_WORKTREE_PRUNE] = {
+ "worktree-prune",
+ maintenance_task_worktree_prune,
+ worktree_prune_condition,
+ },
+ [TASK_RERERE_GC] = {
+ "rerere-gc",
+ maintenance_task_rerere_gc,
+ rerere_gc_condition,
+ },
};
static int compare_tasks_by_selection(const void *a_, const void *b_)
diff --git a/builtin/replay.c b/builtin/replay.c
index 032c172b65..225cef0880 100644
--- a/builtin/replay.c
+++ b/builtin/replay.c
@@ -20,21 +20,22 @@
#include <oidset.h>
#include <tree.h>
-static const char *short_commit_name(struct commit *commit)
+static const char *short_commit_name(struct repository *repo,
+ struct commit *commit)
{
- return repo_find_unique_abbrev(the_repository, &commit->object.oid,
+ return repo_find_unique_abbrev(repo, &commit->object.oid,
DEFAULT_ABBREV);
}
-static struct commit *peel_committish(const char *name)
+static struct commit *peel_committish(struct repository *repo, const char *name)
{
struct object *obj;
struct object_id oid;
- if (repo_get_oid(the_repository, name, &oid))
+ if (repo_get_oid(repo, name, &oid))
return NULL;
- obj = parse_object(the_repository, &oid);
- return (struct commit *)repo_peel_to_type(the_repository, name, 0, obj,
+ obj = parse_object(repo, &oid);
+ return (struct commit *)repo_peel_to_type(repo, name, 0, obj,
OBJ_COMMIT);
}
@@ -50,7 +51,8 @@ static char *get_author(const char *message)
return NULL;
}
-static struct commit *create_commit(struct tree *tree,
+static struct commit *create_commit(struct repository *repo,
+ struct tree *tree,
struct commit *based_on,
struct commit *parent)
{
@@ -62,7 +64,7 @@ static struct commit *create_commit(struct tree *tree,
struct commit_extra_header *extra = NULL;
struct strbuf msg = STRBUF_INIT;
const char *out_enc = get_commit_output_encoding();
- const char *message = repo_logmsg_reencode(the_repository, based_on,
+ const char *message = repo_logmsg_reencode(repo, based_on,
NULL, out_enc);
const char *orig_message = NULL;
const char *exclude_gpgsig[] = { "gpgsig", NULL };
@@ -79,7 +81,7 @@ static struct commit *create_commit(struct tree *tree,
goto out;
}
- obj = parse_object(the_repository, &ret);
+ obj = parse_object(repo, &ret);
out:
free_commit_extra_headers(extra);
@@ -97,7 +99,8 @@ struct ref_info {
int negative_refexprs;
};
-static void get_ref_information(struct rev_cmdline_info *cmd_info,
+static void get_ref_information(struct repository *repo,
+ struct rev_cmdline_info *cmd_info,
struct ref_info *ref_info)
{
int i;
@@ -132,14 +135,14 @@ static void get_ref_information(struct rev_cmdline_info *cmd_info,
if (*refexpr == '^')
refexpr++;
- if (repo_dwim_ref(the_repository, refexpr, strlen(refexpr), &oid, &fullname, 0) != 1)
+ if (repo_dwim_ref(repo, refexpr, strlen(refexpr), &oid, &fullname, 0) != 1)
can_uniquely_dwim = 0;
if (e->flags & BOTTOM) {
if (can_uniquely_dwim)
strset_add(&ref_info->negative_refs, fullname);
if (!ref_info->negative_refexprs)
- ref_info->onto = lookup_commit_reference_gently(the_repository,
+ ref_info->onto = lookup_commit_reference_gently(repo,
&e->item->oid, 1);
ref_info->negative_refexprs++;
} else {
@@ -152,7 +155,8 @@ static void get_ref_information(struct rev_cmdline_info *cmd_info,
}
}
-static void determine_replay_mode(struct rev_cmdline_info *cmd_info,
+static void determine_replay_mode(struct repository *repo,
+ struct rev_cmdline_info *cmd_info,
const char *onto_name,
char **advance_name,
struct commit **onto,
@@ -160,14 +164,14 @@ static void determine_replay_mode(struct rev_cmdline_info *cmd_info,
{
struct ref_info rinfo;
- get_ref_information(cmd_info, &rinfo);
+ get_ref_information(repo, cmd_info, &rinfo);
if (!rinfo.positive_refexprs)
die(_("need some commits to replay"));
die_for_incompatible_opt2(!!onto_name, "--onto",
!!*advance_name, "--advance");
if (onto_name) {
- *onto = peel_committish(onto_name);
+ *onto = peel_committish(repo, onto_name);
if (rinfo.positive_refexprs <
strset_get_size(&rinfo.positive_refs))
die(_("all positive revisions given must be references"));
@@ -175,8 +179,8 @@ static void determine_replay_mode(struct rev_cmdline_info *cmd_info,
struct object_id oid;
char *fullname = NULL;
- *onto = peel_committish(*advance_name);
- if (repo_dwim_ref(the_repository, *advance_name, strlen(*advance_name),
+ *onto = peel_committish(repo, *advance_name);
+ if (repo_dwim_ref(repo, *advance_name, strlen(*advance_name),
&oid, &fullname, 0) == 1) {
free(*advance_name);
*advance_name = fullname;
@@ -245,7 +249,8 @@ static struct commit *mapped_commit(kh_oid_map_t *replayed_commits,
return kh_value(replayed_commits, pos);
}
-static struct commit *pick_regular_commit(struct commit *pickme,
+static struct commit *pick_regular_commit(struct repository *repo,
+ struct commit *pickme,
kh_oid_map_t *replayed_commits,
struct commit *onto,
struct merge_options *merge_opt,
@@ -257,12 +262,12 @@ static struct commit *pick_regular_commit(struct commit *pickme,
base = pickme->parents->item;
replayed_base = mapped_commit(replayed_commits, base, onto);
- result->tree = repo_get_commit_tree(the_repository, replayed_base);
- pickme_tree = repo_get_commit_tree(the_repository, pickme);
- base_tree = repo_get_commit_tree(the_repository, base);
+ result->tree = repo_get_commit_tree(repo, replayed_base);
+ pickme_tree = repo_get_commit_tree(repo, pickme);
+ base_tree = repo_get_commit_tree(repo, base);
- merge_opt->branch1 = short_commit_name(replayed_base);
- merge_opt->branch2 = short_commit_name(pickme);
+ merge_opt->branch1 = short_commit_name(repo, replayed_base);
+ merge_opt->branch2 = short_commit_name(repo, pickme);
merge_opt->ancestor = xstrfmt("parent of %s", merge_opt->branch2);
merge_incore_nonrecursive(merge_opt,
@@ -275,13 +280,13 @@ static struct commit *pick_regular_commit(struct commit *pickme,
merge_opt->ancestor = NULL;
if (!result->clean)
return NULL;
- return create_commit(result->tree, pickme, replayed_base);
+ return create_commit(repo, result->tree, pickme, replayed_base);
}
int cmd_replay(int argc,
const char **argv,
const char *prefix,
- struct repository *repo UNUSED)
+ struct repository *repo)
{
const char *advance_name_opt = NULL;
char *advance_name = NULL;
@@ -329,7 +334,7 @@ int cmd_replay(int argc,
"--advance", "--contained");
advance_name = xstrdup_or_null(advance_name_opt);
- repo_init_revisions(the_repository, &revs, prefix);
+ repo_init_revisions(repo, &revs, prefix);
/*
* Set desired values for rev walking options here. If they
@@ -380,7 +385,7 @@ int cmd_replay(int argc,
revs.simplify_history = 0;
}
- determine_replay_mode(&revs.cmdline, onto_name, &advance_name,
+ determine_replay_mode(repo, &revs.cmdline, onto_name, &advance_name,
&onto, &update_refs);
if (!onto) /* FIXME: Should handle replaying down to root commit */
@@ -391,7 +396,7 @@ int cmd_replay(int argc,
goto cleanup;
}
- init_basic_merge_options(&merge_opt, the_repository);
+ init_basic_merge_options(&merge_opt, repo);
memset(&result, 0, sizeof(result));
merge_opt.show_rename_progress = 0;
last_commit = onto;
@@ -406,8 +411,8 @@ int cmd_replay(int argc,
if (commit->parents->next)
die(_("replaying merge commits is not supported yet!"));
- last_commit = pick_regular_commit(commit, replayed_commits, onto,
- &merge_opt, &result);
+ last_commit = pick_regular_commit(repo, commit, replayed_commits,
+ onto, &merge_opt, &result);
if (!last_commit)
break;
diff --git a/builtin/rev-list.c b/builtin/rev-list.c
index c4cd4ed5c8..0984b607bf 100644
--- a/builtin/rev-list.c
+++ b/builtin/rev-list.c
@@ -924,7 +924,7 @@ int cmd_rev_list(int argc,
free((void *)entry->path);
}
- oidmap_free(&missing_objects, true);
+ oidmap_clear(&missing_objects, true);
}
stop_progress(&progress);
diff --git a/bundle-uri.c b/bundle-uri.c
index 96d2ba726d..dc120664d1 100644
--- a/bundle-uri.c
+++ b/bundle-uri.c
@@ -403,7 +403,7 @@ static int unbundle_from_file(struct repository *r, const char *file)
const char *branch_name;
int has_old;
- if (!skip_prefix(refname->string, "refs/heads/", &branch_name))
+ if (!skip_prefix(refname->string, "refs/", &branch_name))
continue;
strbuf_setlen(&bundle_ref, bundle_prefix_len);
diff --git a/commit-graph.c b/commit-graph.c
index 6394752b0b..4a6e34f8a0 100644
--- a/commit-graph.c
+++ b/commit-graph.c
@@ -222,7 +222,7 @@ static int commit_graph_compatible(struct repository *r)
if (replace_refs_enabled(r)) {
prepare_replace_object(r);
- if (hashmap_get_size(&r->objects->replace_map->map))
+ if (oidmap_get_size(&r->objects->replace_map))
return 0;
}
diff --git a/compiler-tricks/not-constant.c b/compiler-tricks/not-constant.c
index 1da3ffc2f5..9fb4f275b1 100644
--- a/compiler-tricks/not-constant.c
+++ b/compiler-tricks/not-constant.c
@@ -1,2 +1,2 @@
#include <git-compat-util.h>
-int false_but_the_compiler_does_not_know_it_;
+int false_but_the_compiler_does_not_know_it_ = 0;
diff --git a/git-send-email.perl b/git-send-email.perl
index 4215f8f7e9..659e6c588b 100755
--- a/git-send-email.perl
+++ b/git-send-email.perl
@@ -1359,7 +1359,9 @@ sub process_address_list {
sub valid_fqdn {
my $domain = shift;
- return defined $domain && !($^O eq 'darwin' && $domain =~ /\.local$/) && $domain =~ /\./;
+ my $subdomain = '(?!-)[A-Za-z0-9-]{1,63}(?<!-)';
+ return defined $domain && !($^O eq 'darwin' && $domain =~ /\.local$/)
+ && $domain =~ /^$subdomain(?:\.$subdomain)*$/;
}
sub maildomain_net {
@@ -1391,8 +1393,22 @@ sub maildomain_mta {
return $maildomain;
}
+sub maildomain_hostname_command {
+ my $maildomain;
+
+ if ($^O eq 'linux' || $^O eq 'darwin') {
+ my $domain = `(hostname -f) 2>/dev/null`;
+ if (!$?) {
+ chomp($domain);
+ $maildomain = $domain if valid_fqdn($domain);
+ }
+ }
+ return $maildomain;
+}
+
sub maildomain {
- return maildomain_net() || maildomain_mta() || 'localhost.localdomain';
+ return maildomain_net() || maildomain_mta() ||
+ maildomain_hostname_command || 'localhost.localdomain';
}
sub smtp_host_string {
diff --git a/json-writer.c b/json-writer.c
index 8c5187e9fd..34577dc25f 100644
--- a/json-writer.c
+++ b/json-writer.c
@@ -268,10 +268,6 @@ static void append_sub_jw(struct json_writer *jw,
strbuf_addbuf(&jw->json, &value->json);
}
-/*
- * Append existing (properly terminated) JSON sub-data (object or array)
- * as-is onto the given JSON data.
- */
void jw_object_sub_jw(struct json_writer *jw, const char *key,
const struct json_writer *value)
{
diff --git a/json-writer.h b/json-writer.h
index 04413bd1af..8f845d4d29 100644
--- a/json-writer.h
+++ b/json-writer.h
@@ -28,6 +28,34 @@
* object/array) -or- by building them inline in one pass. This is a
* personal style and/or data shape choice.
*
+ * USAGE:
+ * ======
+ *
+ * - Initialize the json_writer with jw_init.
+ *
+ * - Open an object as the main data structure with jw_object_begin.
+ * Append a key-value pair to it using the jw_object_<type> functions.
+ * Conclude with jw_end.
+ *
+ * - Alternatively, open an array as the main data structure with
+ * jw_array_begin. Append a value to it using the jw_array_<type>
+ * functions. Conclude with jw_end.
+ *
+ * - Append a new, unterminated array or object to the current
+ * object using the jw_object_inline_begin_{array, object} functions.
+ * Similarly, append a new, unterminated array or object to
+ * the current array using the jw_array_inline_begin_{array, object}
+ * functions.
+ *
+ * - Append other json_writer as a value to the current array or object
+ * using the jw_{array, object}_sub_jw functions.
+ *
+ * - Extend the current array with an null-terminated array of strings
+ * by using jw_array_argv or with a fixed number of elements of a
+ * array of string by using jw_array_argc_argv.
+ *
+ * - Release the json_writer after using it by calling jw_release.
+ *
* See t/helper/test-json-writer.c for various usage examples.
*
* LIMITATIONS:
@@ -69,42 +97,185 @@ struct json_writer
.open_stack = STRBUF_INIT, \
}
+/*
+ * Initialize a json_writer with empty values.
+ */
void jw_init(struct json_writer *jw);
+
+/*
+ * Release the internal buffers of a json_writer.
+ */
void jw_release(struct json_writer *jw);
+/*
+ * Begin the json_writer using an object as the top-level data structure. If
+ * pretty is set to 1, the result will be a human-readable and indented JSON,
+ * and if it is set to 0 the result will be minified single-line JSON.
+ */
void jw_object_begin(struct json_writer *jw, int pretty);
+
+/*
+ * Begin the json_writer using an array as the top-level data structure. If
+ * pretty is set to 1, the result will be a human-readable and indented JSON,
+ * and if it is set to 0 the result will be minified single-line JSON.
+ */
void jw_array_begin(struct json_writer *jw, int pretty);
+/*
+ * Append a string field to the current object of the json_writer, given its key
+ * and its value. Trigger a BUG when not in an object.
+ */
void jw_object_string(struct json_writer *jw, const char *key,
const char *value);
+
+/*
+ * Append an int field to the current object of the json_writer, given its key
+ * and its value. Trigger a BUG when not in an object.
+ */
void jw_object_intmax(struct json_writer *jw, const char *key, intmax_t value);
+
+/*
+ * Append a double field to the current object of the json_writer, given its key
+ * and its value. The precision parameter defines the number of significant
+ * digits, where -1 can be used for maximum precision. Trigger a BUG when not in
+ * an object.
+ */
void jw_object_double(struct json_writer *jw, const char *key, int precision,
double value);
+
+/*
+ * Append a boolean field set to true to the current object of the json_writer,
+ * given its key. Trigger a BUG when not in an object.
+ */
void jw_object_true(struct json_writer *jw, const char *key);
+
+/*
+ * Append a boolean field set to false to the current object of the json_writer,
+ * given its key. Trigger a BUG when not in an object.
+ */
void jw_object_false(struct json_writer *jw, const char *key);
+
+/*
+ * Append a boolean field to the current object of the json_writer, given its
+ * key and its value. Trigger a BUG when not in an object.
+ */
void jw_object_bool(struct json_writer *jw, const char *key, int value);
+
+/*
+ * Append a null field to the current object of the json_writer, given its key.
+ * Trigger a BUG when not in an object.
+ */
void jw_object_null(struct json_writer *jw, const char *key);
+
+/*
+ * Append a field to the current object of the json_writer, given its key and
+ * another json_writer that represents its content. Trigger a BUG when not in
+ * an object.
+ */
void jw_object_sub_jw(struct json_writer *jw, const char *key,
const struct json_writer *value);
+/*
+ * Start an object as the value of a field in the current object of the
+ * json_writer. Trigger a BUG when not in an object.
+ */
void jw_object_inline_begin_object(struct json_writer *jw, const char *key);
+
+/*
+ * Start an array as the value of a field in the current object of the
+ * json_writer. Trigger a BUG when not in an object.
+ */
void jw_object_inline_begin_array(struct json_writer *jw, const char *key);
+/*
+ * Append a string value to the current array of the json_writer. Trigger a BUG
+ * when not in an array.
+ */
void jw_array_string(struct json_writer *jw, const char *value);
+
+/*
+ * Append an int value to the current array of the json_writer. Trigger a BUG
+ * when not in an array.
+ */
void jw_array_intmax(struct json_writer *jw, intmax_t value);
+
+/*
+ * Append a double value to the current array of the json_writer. The precision
+ * parameter defines the number of significant digits, where -1 can be used for
+ * maximum precision. Trigger a BUG when not in an array.
+ */
void jw_array_double(struct json_writer *jw, int precision, double value);
+
+/*
+ * Append a true value to the current array of the json_writer. Trigger a BUG
+ * when not in an array.
+ */
void jw_array_true(struct json_writer *jw);
+
+/*
+ * Append a false value to the current array of the json_writer. Trigger a BUG
+ * when not in an array.
+ */
void jw_array_false(struct json_writer *jw);
+
+/*
+ * Append a boolean value to the current array of the json_writer. Trigger a BUG
+ * when not in an array.
+ */
void jw_array_bool(struct json_writer *jw, int value);
+
+/*
+ * Append a null value to the current array of the json_writer. Trigger a BUG
+ * when not in an array.
+ */
void jw_array_null(struct json_writer *jw);
+
+/*
+ * Append a json_writer as a value to the current array of the
+ * json_writer. Trigger a BUG when not in an array.
+ */
void jw_array_sub_jw(struct json_writer *jw, const struct json_writer *value);
+
+/*
+ * Append the first argc values from the argv array of strings to the current
+ * array of the json_writer. Trigger a BUG when not in an array.
+ *
+ * This function does not provide safety for cases where the array has less than
+ * argc values.
+ */
void jw_array_argc_argv(struct json_writer *jw, int argc, const char **argv);
+
+/*
+ * Append a null-terminated array of strings to the current array of the
+ * json_writer. Trigger a BUG when not in an array.
+ */
void jw_array_argv(struct json_writer *jw, const char **argv);
+/*
+ * Start an object as a value in the current array of the json_writer. Trigger a
+ * BUG when not in an array.
+ */
void jw_array_inline_begin_object(struct json_writer *jw);
+
+/*
+ * Start an array as a value in the current array. Trigger a BUG when not in an
+ * array.
+ */
void jw_array_inline_begin_array(struct json_writer *jw);
+/*
+ * Return whether the json_writer is terminated. In other words, if the all the
+ * objects and arrays are already closed.
+ */
int jw_is_terminated(const struct json_writer *jw);
+
+/*
+ * Terminates the current object or array of the json_writer. In other words,
+ * append a ] if the current array is not closed or } if the current object
+ * is not closed.
+ *
+ * Abort the execution if there's no object or array that can be terminated.
+ */
void jw_end(struct json_writer *jw);
#endif /* JSON_WRITER_H */
diff --git a/list-objects-filter.c b/list-objects-filter.c
index 7765761b3c..78b397bc19 100644
--- a/list-objects-filter.c
+++ b/list-objects-filter.c
@@ -244,7 +244,7 @@ static void filter_trees_free(void *filter_data) {
struct filter_trees_depth_data *d = filter_data;
if (!d)
return;
- oidmap_free(&d->seen_at_depth, 1);
+ oidmap_clear(&d->seen_at_depth, 1);
free(d);
}
diff --git a/mailinfo.c b/mailinfo.c
index 7b001fa5db..ee4597da6b 100644
--- a/mailinfo.c
+++ b/mailinfo.c
@@ -381,12 +381,12 @@ static int is_format_patch_separator(const char *line, int len)
return !memcmp(SAMPLE + (cp - line), cp, strlen(SAMPLE) - (cp - line));
}
-static struct strbuf *decode_q_segment(const struct strbuf *q_seg, int rfc2047)
+static int decode_q_segment(struct strbuf *out, const struct strbuf *q_seg,
+ int rfc2047)
{
const char *in = q_seg->buf;
int c;
- struct strbuf *out = xmalloc(sizeof(struct strbuf));
- strbuf_init(out, q_seg->len);
+ strbuf_grow(out, q_seg->len);
while ((c = *in++) != 0) {
if (c == '=') {
@@ -405,16 +405,15 @@ static struct strbuf *decode_q_segment(const struct strbuf *q_seg, int rfc2047)
c = 0x20;
strbuf_addch(out, c);
}
- return out;
+ return 0;
}
-static struct strbuf *decode_b_segment(const struct strbuf *b_seg)
+static int decode_b_segment(struct strbuf *out, const struct strbuf *b_seg)
{
/* Decode in..ep, possibly in-place to ot */
int c, pos = 0, acc = 0;
const char *in = b_seg->buf;
- struct strbuf *out = xmalloc(sizeof(struct strbuf));
- strbuf_init(out, b_seg->len);
+ strbuf_grow(out, b_seg->len);
while ((c = *in++) != 0) {
if (c == '+')
@@ -447,7 +446,7 @@ static struct strbuf *decode_b_segment(const struct strbuf *b_seg)
break;
}
}
- return out;
+ return 0;
}
static int convert_to_utf8(struct mailinfo *mi,
@@ -475,7 +474,7 @@ static int convert_to_utf8(struct mailinfo *mi,
static void decode_header(struct mailinfo *mi, struct strbuf *it)
{
char *in, *ep, *cp;
- struct strbuf outbuf = STRBUF_INIT, *dec;
+ struct strbuf outbuf = STRBUF_INIT, dec = STRBUF_INIT;
struct strbuf charset_q = STRBUF_INIT, piecebuf = STRBUF_INIT;
int found_error = 1; /* pessimism */
@@ -530,18 +529,19 @@ static void decode_header(struct mailinfo *mi, struct strbuf *it)
default:
goto release_return;
case 'b':
- dec = decode_b_segment(&piecebuf);
+ if ((found_error = decode_b_segment(&dec, &piecebuf)))
+ goto release_return;
break;
case 'q':
- dec = decode_q_segment(&piecebuf, 1);
+ if ((found_error = decode_q_segment(&dec, &piecebuf, 1)))
+ goto release_return;
break;
}
- if (convert_to_utf8(mi, dec, charset_q.buf))
+ if (convert_to_utf8(mi, &dec, charset_q.buf))
goto release_return;
- strbuf_addbuf(&outbuf, dec);
- strbuf_release(dec);
- free(dec);
+ strbuf_addbuf(&outbuf, &dec);
+ strbuf_release(&dec);
in = ep + 2;
}
strbuf_addstr(&outbuf, in);
@@ -552,6 +552,7 @@ release_return:
strbuf_release(&outbuf);
strbuf_release(&charset_q);
strbuf_release(&piecebuf);
+ strbuf_release(&dec);
if (found_error)
mi->input_error = -1;
@@ -634,23 +635,22 @@ static int is_inbody_header(const struct mailinfo *mi,
static void decode_transfer_encoding(struct mailinfo *mi, struct strbuf *line)
{
- struct strbuf *ret;
+ struct strbuf ret = STRBUF_INIT;
switch (mi->transfer_encoding) {
case TE_QP:
- ret = decode_q_segment(line, 0);
+ decode_q_segment(&ret, line, 0);
break;
case TE_BASE64:
- ret = decode_b_segment(line);
+ decode_b_segment(&ret, line);
break;
case TE_DONTCARE:
default:
return;
}
strbuf_reset(line);
- strbuf_addbuf(line, ret);
- strbuf_release(ret);
- free(ret);
+ strbuf_addbuf(line, &ret);
+ strbuf_release(&ret);
}
static inline int patchbreak(const struct strbuf *line)
diff --git a/meson.build b/meson.build
index 148ae668eb..a1476e5b32 100644
--- a/meson.build
+++ b/meson.build
@@ -1904,14 +1904,19 @@ if perl_features_enabled
perl_header_template = 'perl/header_templates/runtime_prefix.template.pl'
endif
+ perllibdir = get_option('perllibdir')
+ if perllibdir == ''
+ perllibdir = get_option('datadir') / 'perl5'
+ endif
+
perl_header = configure_file(
input: perl_header_template,
output: 'GIT-PERL-HEADER',
configuration: {
'GITEXECDIR_REL': get_option('libexecdir') / 'git-core',
- 'PERLLIBDIR_REL': get_option('datadir') / 'perl5',
+ 'PERLLIBDIR_REL': perllibdir,
'LOCALEDIR_REL': get_option('datadir') / 'locale',
- 'INSTLIBDIR': get_option('datadir') / 'perl5',
+ 'INSTLIBDIR': perllibdir,
'PATHSEP': pathsep,
},
)
diff --git a/meson_options.txt b/meson_options.txt
index 8547c0eb47..54c63614d4 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -1,3 +1,7 @@
+# Configuration for Git installation
+option('perllibdir', type: 'string', value: '',
+ description: 'Directory to install perl lib to. Defaults to <datadir>/perl5')
+
# Configuration for how Git behaves at runtime.
option('default_pager', type: 'string', value: 'less',
description: 'Fall-back pager.')
diff --git a/object-store.c b/object-store.c
index 2f51d0e3b0..517f1fd145 100644
--- a/object-store.c
+++ b/object-store.c
@@ -987,8 +987,7 @@ void raw_object_store_clear(struct raw_object_store *o)
{
FREE_AND_NULL(o->alternate_db);
- oidmap_free(o->replace_map, 1);
- FREE_AND_NULL(o->replace_map);
+ oidmap_clear(&o->replace_map, 1);
pthread_mutex_destroy(&o->replace_mutex);
free_commit_graph(o->commit_graph);
diff --git a/object-store.h b/object-store.h
index c2fe5a1960..141b801113 100644
--- a/object-store.h
+++ b/object-store.h
@@ -5,6 +5,7 @@
#include "object.h"
#include "list.h"
#include "oidset.h"
+#include "oidmap.h"
#include "thread-utils.h"
struct oidmap;
@@ -109,7 +110,7 @@ struct raw_object_store {
* Objects that should be substituted by other objects
* (see git-replace(1)).
*/
- struct oidmap *replace_map;
+ struct oidmap replace_map;
unsigned replace_map_initialized : 1;
pthread_mutex_t replace_mutex; /* protect object replace functions */
diff --git a/oidmap.c b/oidmap.c
index 8b1bc4dec9..508d6c7dec 100644
--- a/oidmap.c
+++ b/oidmap.c
@@ -22,7 +22,7 @@ void oidmap_init(struct oidmap *map, size_t initial_size)
hashmap_init(&map->map, oidmap_neq, NULL, initial_size);
}
-void oidmap_free(struct oidmap *map, int free_entries)
+void oidmap_clear(struct oidmap *map, int free_entries)
{
if (!map)
return;
diff --git a/oidmap.h b/oidmap.h
index fad412827a..67fb32290f 100644
--- a/oidmap.h
+++ b/oidmap.h
@@ -36,12 +36,13 @@ struct oidmap {
void oidmap_init(struct oidmap *map, size_t initial_size);
/*
- * Frees an oidmap structure and allocated memory.
+ * Clear an oidmap, freeing any allocated memory. The map is empty and
+ * can be reused without another explicit init.
*
* If `free_entries` is true, each oidmap_entry in the map is freed as well
* using stdlibs free().
*/
-void oidmap_free(struct oidmap *map, int free_entries);
+void oidmap_clear(struct oidmap *map, int free_entries);
/*
* Returns the oidmap entry for the specified oid, or NULL if not found.
@@ -66,6 +67,10 @@ void *oidmap_put(struct oidmap *map, void *entry);
*/
void *oidmap_remove(struct oidmap *map, const struct object_id *key);
+static inline unsigned int oidmap_get_size(struct oidmap *map)
+{
+ return hashmap_get_size(&map->map);
+}
struct oidmap_iter {
struct hashmap_iter h_iter;
diff --git a/pack-bitmap.c b/pack-bitmap.c
index b9f1d86604..ac6d62b980 100644
--- a/pack-bitmap.c
+++ b/pack-bitmap.c
@@ -388,10 +388,6 @@ static int load_bitmap_entries_v1(struct bitmap_index *index)
return error(_("corrupt ewah bitmap: commit index %u out of range"),
(unsigned)commit_idx_pos);
- bitmap = read_bitmap_1(index);
- if (!bitmap)
- return -1;
-
if (xor_offset > MAX_XOR_OFFSET || xor_offset > i)
return error(_("corrupted bitmap pack index"));
@@ -402,6 +398,10 @@ static int load_bitmap_entries_v1(struct bitmap_index *index)
return error(_("invalid XOR offset in bitmap pack index"));
}
+ bitmap = read_bitmap_1(index);
+ if (!bitmap)
+ return -1;
+
recent_bitmaps[i % MAX_XOR_OFFSET] = store_bitmap(
index, bitmap, &oid, xor_bitmap, flags);
}
diff --git a/perl/FromCPAN/Mail/meson.build b/perl/FromCPAN/Mail/meson.build
index b4ff2fc0b2..467507c5e6 100644
--- a/perl/FromCPAN/Mail/meson.build
+++ b/perl/FromCPAN/Mail/meson.build
@@ -3,6 +3,6 @@ test_dependencies += custom_target(
output: 'Address.pm',
command: generate_perl_command,
install: true,
- install_dir: get_option('datadir') / 'perl5/FromCPAN/Mail',
+ install_dir: perllibdir / 'FromCPAN/Mail',
depends: [git_version_file],
)
diff --git a/perl/FromCPAN/meson.build b/perl/FromCPAN/meson.build
index 1f9ea6ce8e..720c60283d 100644
--- a/perl/FromCPAN/meson.build
+++ b/perl/FromCPAN/meson.build
@@ -3,7 +3,7 @@ test_dependencies += custom_target(
output: 'Error.pm',
command: generate_perl_command,
install: true,
- install_dir: get_option('datadir') / 'perl5/FromCPAN',
+ install_dir: perllibdir / 'FromCPAN',
depends: [git_version_file],
)
diff --git a/perl/Git/LoadCPAN/Mail/meson.build b/perl/Git/LoadCPAN/Mail/meson.build
index 89cde56be8..05a5770560 100644
--- a/perl/Git/LoadCPAN/Mail/meson.build
+++ b/perl/Git/LoadCPAN/Mail/meson.build
@@ -3,6 +3,6 @@ test_dependencies += custom_target(
output: 'Address.pm',
command: generate_perl_command,
install: true,
- install_dir: get_option('datadir') / 'perl5/Git/LoadCPAN/Mail',
+ install_dir: perllibdir / 'Git/LoadCPAN/Mail',
depends: [git_version_file],
)
diff --git a/perl/Git/LoadCPAN/meson.build b/perl/Git/LoadCPAN/meson.build
index 1ee915c650..b975d49726 100644
--- a/perl/Git/LoadCPAN/meson.build
+++ b/perl/Git/LoadCPAN/meson.build
@@ -3,7 +3,7 @@ test_dependencies += custom_target(
output: 'Error.pm',
command: generate_perl_command,
install: true,
- install_dir: get_option('datadir') / 'perl5/Git/LoadCPAN',
+ install_dir: perllibdir / 'Git/LoadCPAN',
depends: [git_version_file],
)
diff --git a/perl/Git/SVN/Memoize/meson.build b/perl/Git/SVN/Memoize/meson.build
index 233ec670d7..4c589b30c3 100644
--- a/perl/Git/SVN/Memoize/meson.build
+++ b/perl/Git/SVN/Memoize/meson.build
@@ -3,6 +3,6 @@ test_dependencies += custom_target(
output: 'YAML.pm',
command: generate_perl_command,
install: true,
- install_dir: get_option('datadir') / 'perl5/Git/SVN',
+ install_dir: perllibdir / 'Git/SVN',
depends: [git_version_file],
)
diff --git a/perl/Git/SVN/meson.build b/perl/Git/SVN/meson.build
index 44abaf42b7..8858985fe8 100644
--- a/perl/Git/SVN/meson.build
+++ b/perl/Git/SVN/meson.build
@@ -13,7 +13,7 @@ foreach source : [
output: source,
command: generate_perl_command,
install: true,
- install_dir: get_option('datadir') / 'perl5/Git/SVN',
+ install_dir: perllibdir / 'Git/SVN',
depends: [git_version_file],
)
endforeach
diff --git a/perl/Git/meson.build b/perl/Git/meson.build
index b21fa5591e..a61b7b1f4a 100644
--- a/perl/Git/meson.build
+++ b/perl/Git/meson.build
@@ -10,7 +10,7 @@ foreach source : [
output: source,
command: generate_perl_command,
install: true,
- install_dir: get_option('datadir') / 'perl5/Git',
+ install_dir: perllibdir / 'Git',
depends: [git_version_file],
)
endforeach
diff --git a/perl/meson.build b/perl/meson.build
index 2d4ab1c4a9..3c66b007ea 100644
--- a/perl/meson.build
+++ b/perl/meson.build
@@ -3,7 +3,7 @@ test_dependencies += custom_target(
output: 'Git.pm',
command: generate_perl_command,
install: true,
- install_dir: get_option('datadir') / 'perl5',
+ install_dir: perllibdir,
depends: [git_version_file],
)
diff --git a/reftable/block.c b/reftable/block.c
index 471faa1642..920b3f4486 100644
--- a/reftable/block.c
+++ b/reftable/block.c
@@ -227,7 +227,8 @@ static int read_block(struct reftable_block_source *source,
int reftable_block_init(struct reftable_block *block,
struct reftable_block_source *source,
uint32_t offset, uint32_t header_size,
- uint32_t table_block_size, uint32_t hash_size)
+ uint32_t table_block_size, uint32_t hash_size,
+ uint8_t want_type)
{
uint32_t guess_block_size = table_block_size ?
table_block_size : DEFAULT_BLOCK_SIZE;
@@ -247,6 +248,10 @@ int reftable_block_init(struct reftable_block *block,
err = REFTABLE_FORMAT_ERROR;
goto done;
}
+ if (want_type != REFTABLE_BLOCK_TYPE_ANY && block_type != want_type) {
+ err = 1;
+ goto done;
+ }
block_size = reftable_get_be24(block->block_data.data + header_size + 1);
if (block_size > guess_block_size) {
diff --git a/reftable/reftable-block.h b/reftable/reftable-block.h
index 04c3b518c8..0b05a8f7e3 100644
--- a/reftable/reftable-block.h
+++ b/reftable/reftable-block.h
@@ -56,7 +56,8 @@ struct reftable_block {
int reftable_block_init(struct reftable_block *b,
struct reftable_block_source *source,
uint32_t offset, uint32_t header_size,
- uint32_t table_block_size, uint32_t hash_size);
+ uint32_t table_block_size, uint32_t hash_size,
+ uint8_t want_type);
/* Release resources allocated by the block. */
void reftable_block_release(struct reftable_block *b);
diff --git a/reftable/table.c b/reftable/table.c
index ee83127615..56362df0ed 100644
--- a/reftable/table.c
+++ b/reftable/table.c
@@ -173,16 +173,7 @@ int table_init_block(struct reftable_table *t, struct reftable_block *block,
return 1;
err = reftable_block_init(block, &t->source, next_off, header_off,
- t->block_size, hash_size(t->hash_id));
- if (err < 0)
- goto done;
-
- if (want_typ != REFTABLE_BLOCK_TYPE_ANY && block->block_type != want_typ) {
- err = 1;
- goto done;
- }
-
-done:
+ t->block_size, hash_size(t->hash_id), want_typ);
if (err)
reftable_block_release(block);
return err;
diff --git a/reftable/writer.c b/reftable/writer.c
index cb16f71be4..3b4ebdd6dc 100644
--- a/reftable/writer.c
+++ b/reftable/writer.c
@@ -57,8 +57,10 @@ static int padded_write(struct reftable_writer *w, uint8_t *data, size_t len,
return -1;
n = w->write(w->write_arg, zeroed, w->pending_padding);
- if (n < 0)
+ if (n < 0) {
+ reftable_free(zeroed);
return n;
+ }
w->pending_padding = 0;
reftable_free(zeroed);
@@ -256,8 +258,10 @@ static int writer_index_hash(struct reftable_writer *w, struct reftable_buf *has
reftable_buf_reset(&key->hash);
err = reftable_buf_add(&key->hash, hash->buf, hash->len);
- if (err < 0)
+ if (err < 0) {
+ reftable_free(key);
return err;
+ }
tree_insert(&w->obj_index_tree, key,
&obj_index_tree_node_compare);
} else {
diff --git a/replace-object.c b/replace-object.c
index 7b8a09b5cb..f8c5f68837 100644
--- a/replace-object.c
+++ b/replace-object.c
@@ -31,7 +31,7 @@ static int register_replace_ref(const char *refname,
oidcpy(&repl_obj->replacement, oid);
/* Register new object */
- if (oidmap_put(r->objects->replace_map, repl_obj))
+ if (oidmap_put(&r->objects->replace_map, repl_obj))
die(_("duplicate replace ref: %s"), refname);
return 0;
@@ -48,9 +48,7 @@ void prepare_replace_object(struct repository *r)
return;
}
- r->objects->replace_map =
- xmalloc(sizeof(*r->objects->replace_map));
- oidmap_init(r->objects->replace_map, 0);
+ oidmap_init(&r->objects->replace_map, 0);
refs_for_each_replace_ref(get_main_ref_store(r),
register_replace_ref, r);
@@ -80,7 +78,7 @@ const struct object_id *do_lookup_replace_object(struct repository *r,
/* Try to recursively replace the object */
while (depth-- > 0) {
struct replace_object *repl_obj =
- oidmap_get(r->objects->replace_map, cur);
+ oidmap_get(&r->objects->replace_map, cur);
if (!repl_obj)
return cur;
cur = &repl_obj->replacement;
diff --git a/replace-object.h b/replace-object.h
index ba478eb30c..3052e96a62 100644
--- a/replace-object.h
+++ b/replace-object.h
@@ -47,7 +47,7 @@ static inline const struct object_id *lookup_replace_object(struct repository *r
{
if (!replace_refs_enabled(r) ||
(r->objects->replace_map_initialized &&
- r->objects->replace_map->map.tablesize == 0))
+ oidmap_get_size(&r->objects->replace_map) == 0))
return oid;
return do_lookup_replace_object(r, oid);
}
diff --git a/scalar.c b/scalar.c
index d359f08bb8..355baf75e4 100644
--- a/scalar.c
+++ b/scalar.c
@@ -209,6 +209,12 @@ static int set_recommended_config(int reconfigure)
return 0;
}
+/**
+ * Enable or disable the maintenance mode for the current repository:
+ *
+ * * If 'enable' is nonzero, run 'git maintenance start'.
+ * * If 'enable' is zero, run 'git maintenance unregister --force'.
+ */
static int toggle_maintenance(int enable)
{
return run_git("maintenance",
@@ -259,7 +265,15 @@ static int stop_fsmonitor_daemon(void)
return 0;
}
-static int register_dir(void)
+/**
+ * Register the current directory as a Scalar enlistment, and set the
+ * recommended configuration.
+ *
+ * * If 'maintenance' is non-zero, then enable background maintenance.
+ * * If 'maintenance' is zero, then leave background maintenance as it is
+ * currently configured.
+ */
+static int register_dir(int maintenance)
{
if (add_or_remove_enlistment(1))
return error(_("could not add enlistment"));
@@ -267,8 +281,9 @@ static int register_dir(void)
if (set_recommended_config(0))
return error(_("could not set recommended config"));
- if (toggle_maintenance(1))
- warning(_("could not turn on maintenance"));
+ if (maintenance &&
+ toggle_maintenance(maintenance))
+ warning(_("could not toggle maintenance"));
if (have_fsmonitor_support() && start_fsmonitor_daemon()) {
return error(_("could not start the FSMonitor daemon"));
@@ -411,7 +426,7 @@ static int cmd_clone(int argc, const char **argv)
const char *branch = NULL;
char *branch_to_free = NULL;
int full_clone = 0, single_branch = 0, show_progress = isatty(2);
- int src = 1, tags = 1;
+ int src = 1, tags = 1, maintenance = 1;
struct option clone_options[] = {
OPT_STRING('b', "branch", &branch, N_("<branch>"),
N_("branch to checkout after clone")),
@@ -424,11 +439,13 @@ static int cmd_clone(int argc, const char **argv)
N_("create repository within 'src' directory")),
OPT_BOOL(0, "tags", &tags,
N_("specify if tags should be fetched during clone")),
+ OPT_BOOL(0, "maintenance", &maintenance,
+ N_("specify if background maintenance should be enabled")),
OPT_END(),
};
const char * const clone_usage[] = {
N_("scalar clone [--single-branch] [--branch <main-branch>] [--full-clone]\n"
- "\t[--[no-]src] [--[no-]tags] <url> [<enlistment>]"),
+ "\t[--[no-]src] [--[no-]tags] [--[no-]maintenance] <url> [<enlistment>]"),
NULL
};
const char *url;
@@ -550,7 +567,8 @@ static int cmd_clone(int argc, const char **argv)
if (res)
goto cleanup;
- res = register_dir();
+ /* If --no-maintenance, then skip maintenance command entirely. */
+ res = register_dir(maintenance);
cleanup:
free(branch_to_free);
@@ -597,11 +615,14 @@ static int cmd_list(int argc, const char **argv UNUSED)
static int cmd_register(int argc, const char **argv)
{
+ int maintenance = 1;
struct option options[] = {
+ OPT_BOOL(0, "maintenance", &maintenance,
+ N_("specify if background maintenance should be enabled")),
OPT_END(),
};
const char * const usage[] = {
- N_("scalar register [<enlistment>]"),
+ N_("scalar register [--[no-]maintenance] [<enlistment>]"),
NULL
};
@@ -610,7 +631,8 @@ static int cmd_register(int argc, const char **argv)
setup_enlistment_directory(argc, argv, usage, options, NULL);
- return register_dir();
+ /* If --no-maintenance, then leave maintenance as-is. */
+ return register_dir(maintenance);
}
static int get_scalar_repos(const char *key, const char *value,
@@ -646,13 +668,19 @@ static int remove_deleted_enlistment(struct strbuf *path)
static int cmd_reconfigure(int argc, const char **argv)
{
int all = 0;
+ const char *maintenance_str = NULL;
+ int maintenance = 1; /* Enable maintenance by default. */
+
struct option options[] = {
OPT_BOOL('a', "all", &all,
N_("reconfigure all registered enlistments")),
+ OPT_STRING(0, "maintenance", &maintenance_str,
+ N_("(enable|disable|keep)"),
+ N_("signal how to adjust background maintenance")),
OPT_END(),
};
const char * const usage[] = {
- N_("scalar reconfigure [--all | <enlistment>]"),
+ N_("scalar reconfigure [--maintenance=(enable|disable|keep)] [--all | <enlistment>]"),
NULL
};
struct string_list scalar_repos = STRING_LIST_INIT_DUP;
@@ -672,6 +700,18 @@ static int cmd_reconfigure(int argc, const char **argv)
usage_msg_opt(_("--all or <enlistment>, but not both"),
usage, options);
+ if (maintenance_str) {
+ if (!strcmp(maintenance_str, "enable"))
+ maintenance = 1;
+ else if (!strcmp(maintenance_str, "disable"))
+ maintenance = 0;
+ else if (!strcmp(maintenance_str, "keep"))
+ maintenance = -1;
+ else
+ die(_("unknown mode for --maintenance option: %s"),
+ maintenance_str);
+ }
+
git_config(get_scalar_repos, &scalar_repos);
for (size_t i = 0; i < scalar_repos.nr; i++) {
@@ -736,7 +776,8 @@ static int cmd_reconfigure(int argc, const char **argv)
the_repository = old_repo;
repo_clear(&r);
- if (toggle_maintenance(1) >= 0)
+ if (maintenance >= 0 &&
+ toggle_maintenance(maintenance) >= 0)
succeeded = 1;
loop_end:
@@ -803,13 +844,13 @@ static int cmd_run(int argc, const char **argv)
strbuf_release(&buf);
if (i == 0)
- return register_dir();
+ return register_dir(1);
if (i > 0)
return run_git("maintenance", "run",
"--task", tasks[i].task, NULL);
- if (register_dir())
+ if (register_dir(1))
return -1;
for (i = 1; tasks[i].arg; i++)
if (run_git("maintenance", "run",
diff --git a/sequencer.c b/sequencer.c
index 5fb7b68a7a..eacede6bf2 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -225,11 +225,6 @@ struct replay_ctx {
*/
struct strbuf current_fixups;
/*
- * Stores the reflog message that will be used when creating a
- * commit. Points to a static buffer and should not be free()'d.
- */
- const char *reflog_message;
- /*
* The number of completed fixup and squash commands in the
* current chain.
*/
@@ -1124,10 +1119,10 @@ static int run_command_silent_on_success(struct child_process *cmd)
* author metadata.
*/
static int run_git_commit(const char *defmsg,
+ const char *reflog_action,
struct replay_opts *opts,
unsigned int flags)
{
- struct replay_ctx *ctx = opts->ctx;
struct child_process cmd = CHILD_PROCESS_INIT;
if ((flags & CLEANUP_MSG) && (flags & VERBATIM_MSG))
@@ -1145,7 +1140,7 @@ static int run_git_commit(const char *defmsg,
gpg_opt, gpg_opt);
}
- strvec_pushf(&cmd.env, GIT_REFLOG_ACTION "=%s", ctx->reflog_message);
+ strvec_pushf(&cmd.env, GIT_REFLOG_ACTION "=%s", reflog_action);
if (opts->committer_date_is_author_date)
strvec_pushf(&cmd.env, "GIT_COMMITTER_DATE=%s",
@@ -1529,10 +1524,10 @@ static int parse_head(struct repository *r, struct commit **head)
*/
static int try_to_commit(struct repository *r,
struct strbuf *msg, const char *author,
+ const char *reflog_action,
struct replay_opts *opts, unsigned int flags,
struct object_id *oid)
{
- struct replay_ctx *ctx = opts->ctx;
struct object_id tree;
struct commit *current_head = NULL;
struct commit_list *parents = NULL;
@@ -1694,7 +1689,7 @@ static int try_to_commit(struct repository *r,
goto out;
}
- if (update_head_with_reflog(current_head, oid, ctx->reflog_message,
+ if (update_head_with_reflog(current_head, oid, reflog_action,
msg, &err)) {
res = error("%s", err.buf);
goto out;
@@ -1725,6 +1720,7 @@ static int write_rebase_head(struct object_id *oid)
static int do_commit(struct repository *r,
const char *msg_file, const char *author,
+ const char *reflog_action,
struct replay_opts *opts, unsigned int flags,
struct object_id *oid)
{
@@ -1740,7 +1736,7 @@ static int do_commit(struct repository *r,
msg_file);
res = try_to_commit(r, msg_file ? &sb : NULL,
- author, opts, flags, &oid);
+ author, reflog_action, opts, flags, &oid);
strbuf_release(&sb);
if (!res) {
refs_delete_ref(get_main_ref_store(r), "",
@@ -1756,7 +1752,7 @@ static int do_commit(struct repository *r,
if (is_rebase_i(opts) && oid)
if (write_rebase_head(oid))
return -1;
- return run_git_commit(msg_file, opts, flags);
+ return run_git_commit(msg_file, reflog_action, opts, flags);
}
return res;
@@ -2226,6 +2222,39 @@ static void refer_to_commit(struct replay_opts *opts,
}
}
+static const char *sequencer_reflog_action(struct replay_opts *opts)
+{
+ if (!opts->reflog_action) {
+ opts->reflog_action = getenv(GIT_REFLOG_ACTION);
+ opts->reflog_action =
+ xstrdup(opts->reflog_action ? opts->reflog_action
+ : action_name(opts));
+ }
+
+ return opts->reflog_action;
+}
+
+__attribute__((format (printf, 3, 4)))
+static const char *reflog_message(struct replay_opts *opts,
+ const char *sub_action, const char *fmt, ...)
+{
+ va_list ap;
+ static struct strbuf buf = STRBUF_INIT;
+
+ va_start(ap, fmt);
+ strbuf_reset(&buf);
+ strbuf_addstr(&buf, sequencer_reflog_action(opts));
+ if (sub_action)
+ strbuf_addf(&buf, " (%s)", sub_action);
+ if (fmt) {
+ strbuf_addstr(&buf, ": ");
+ strbuf_vaddf(&buf, fmt, ap);
+ }
+ va_end(ap);
+
+ return buf.buf;
+}
+
static int do_pick_commit(struct repository *r,
struct todo_item *item,
struct replay_opts *opts,
@@ -2236,13 +2265,19 @@ static int do_pick_commit(struct repository *r,
const char *msg_file = should_edit(opts) ? NULL : git_path_merge_msg(r);
struct object_id head;
struct commit *base, *next, *parent;
- const char *base_label, *next_label;
+ const char *base_label, *next_label, *reflog_action;
char *author = NULL;
struct commit_message msg = { NULL, NULL, NULL, NULL };
int res, unborn = 0, reword = 0, allow, drop_commit;
enum todo_command command = item->command;
struct commit *commit = item->commit;
+ if (is_rebase_i(opts))
+ reflog_action = reflog_message(
+ opts, command_to_string(item->command), NULL);
+ else
+ reflog_action = sequencer_reflog_action(opts);
+
if (opts->no_commit) {
/*
* We do not intend to commit immediately. We just want to
@@ -2494,7 +2529,8 @@ static int do_pick_commit(struct repository *r,
} /* else allow == 0 and there's nothing special to do */
if (!opts->no_commit && !drop_commit) {
if (author || command == TODO_REVERT || (flags & AMEND_MSG))
- res = do_commit(r, msg_file, author, opts, flags,
+ res = do_commit(r, msg_file, author, reflog_action,
+ opts, flags,
commit? &commit->object.oid : NULL);
else
res = error(_("unable to parse commit author"));
@@ -2509,7 +2545,7 @@ fast_forward_edit:
* got here.
*/
flags = EDIT_MSG | VERIFY_MSG | AMEND_MSG | ALLOW_EMPTY;
- res = run_git_commit(NULL, opts, flags);
+ res = run_git_commit(NULL, reflog_action, opts, flags);
*check_todo = 1;
}
}
@@ -3919,39 +3955,6 @@ static int do_label(struct repository *r, const char *name, int len)
return ret;
}
-static const char *sequencer_reflog_action(struct replay_opts *opts)
-{
- if (!opts->reflog_action) {
- opts->reflog_action = getenv(GIT_REFLOG_ACTION);
- opts->reflog_action =
- xstrdup(opts->reflog_action ? opts->reflog_action
- : action_name(opts));
- }
-
- return opts->reflog_action;
-}
-
-__attribute__((format (printf, 3, 4)))
-static const char *reflog_message(struct replay_opts *opts,
- const char *sub_action, const char *fmt, ...)
-{
- va_list ap;
- static struct strbuf buf = STRBUF_INIT;
-
- va_start(ap, fmt);
- strbuf_reset(&buf);
- strbuf_addstr(&buf, sequencer_reflog_action(opts));
- if (sub_action)
- strbuf_addf(&buf, " (%s)", sub_action);
- if (fmt) {
- strbuf_addstr(&buf, ": ");
- strbuf_vaddf(&buf, fmt, ap);
- }
- va_end(ap);
-
- return buf.buf;
-}
-
static struct commit *lookup_label(struct repository *r, const char *label,
int len, struct strbuf *buf)
{
@@ -4089,6 +4092,7 @@ static int do_merge(struct repository *r,
int merge_arg_len, oneline_offset, can_fast_forward, ret, k;
static struct lock_file lock;
const char *p;
+ const char *reflog_action = reflog_message(opts, "merge", NULL);
if (repo_hold_locked_index(r, &lock, LOCK_REPORT_ON_ERROR) < 0) {
ret = -1;
@@ -4360,14 +4364,15 @@ static int do_merge(struct repository *r,
* value (a negative one would indicate that the `merge`
* command needs to be rescheduled).
*/
- ret = !!run_git_commit(git_path_merge_msg(r), opts,
- run_commit_flags);
+ ret = !!run_git_commit(git_path_merge_msg(r), reflog_action,
+ opts, run_commit_flags);
if (!ret && flags & TODO_EDIT_MERGE_MSG) {
fast_forward_edit:
*check_todo = 1;
run_commit_flags |= AMEND_MSG | EDIT_MSG | VERIFY_MSG;
- ret = !!run_git_commit(NULL, opts, run_commit_flags);
+ ret = !!run_git_commit(NULL, reflog_action, opts,
+ run_commit_flags);
}
@@ -4882,13 +4887,9 @@ static int pick_one_commit(struct repository *r,
struct replay_opts *opts,
int *check_todo, int* reschedule)
{
- struct replay_ctx *ctx = opts->ctx;
int res;
struct todo_item *item = todo_list->items + todo_list->current;
const char *arg = todo_item_get_arg(todo_list, item);
- if (is_rebase_i(opts))
- ctx->reflog_message = reflog_message(
- opts, command_to_string(item->command), NULL);
res = do_pick_commit(r, item, opts, is_final_fixup(todo_list),
check_todo);
@@ -4947,7 +4948,6 @@ static int pick_commits(struct repository *r,
struct replay_ctx *ctx = opts->ctx;
int res = 0, reschedule = 0;
- ctx->reflog_message = sequencer_reflog_action(opts);
if (opts->allow_ff)
ASSERT(!(opts->signoff || opts->no_commit ||
opts->record_origin || should_edit(opts) ||
@@ -5208,6 +5208,7 @@ static int commit_staged_changes(struct repository *r,
unsigned int flags = ALLOW_EMPTY | EDIT_MSG;
unsigned int final_fixup = 0, is_clean;
struct strbuf rev = STRBUF_INIT;
+ const char *reflog_action = reflog_message(opts, "continue", NULL);
int ret;
if (has_unstaged_changes(r, 1)) {
@@ -5370,7 +5371,7 @@ static int commit_staged_changes(struct repository *r,
}
if (run_git_commit(final_fixup ? NULL : rebase_path_message(),
- opts, flags)) {
+ reflog_action, opts, flags)) {
ret = error(_("could not commit staged changes."));
goto out;
}
@@ -5402,7 +5403,6 @@ out:
int sequencer_continue(struct repository *r, struct replay_opts *opts)
{
- struct replay_ctx *ctx = opts->ctx;
struct todo_list todo_list = TODO_LIST_INIT;
int res;
@@ -5423,7 +5423,6 @@ int sequencer_continue(struct repository *r, struct replay_opts *opts)
unlink(rebase_path_dropped());
}
- ctx->reflog_message = reflog_message(opts, "continue", NULL);
if (commit_staged_changes(r, opts, &todo_list)) {
res = -1;
goto release_todo_list;
@@ -5475,7 +5474,6 @@ static int single_pick(struct repository *r,
TODO_PICK : TODO_REVERT;
item.commit = cmit;
- opts->ctx->reflog_message = sequencer_reflog_action(opts);
return do_pick_commit(r, &item, opts, 0, &check_todo);
}
@@ -6053,8 +6051,8 @@ static int make_script_with_merges(struct pretty_print_context *pp,
oidset_clear(&interesting);
oidset_clear(&child_seen);
oidset_clear(&shown);
- oidmap_free(&commit2todo, 1);
- oidmap_free(&state.commit2label, 1);
+ oidmap_clear(&commit2todo, 1);
+ oidmap_clear(&state.commit2label, 1);
hashmap_clear_and_free(&state.labels, struct labels_entry, entry);
strbuf_release(&state.buf);
diff --git a/t/t1001-read-tree-m-2way.sh b/t/t1001-read-tree-m-2way.sh
index 4a88bb9ef0..2e8d9384e1 100755
--- a/t/t1001-read-tree-m-2way.sh
+++ b/t/t1001-read-tree-m-2way.sh
@@ -362,7 +362,7 @@ test_expect_success 'a/b (untracked) vs a case setup.' '
test_expect_success 'a/b (untracked) vs a, plus c/d case test.' '
read_tree_u_must_fail -u -m "$treeH" "$treeM" &&
git ls-files --stage &&
- test -f a/b
+ test_path_is_file a/b
'
test_expect_success 'read-tree supports the super-prefix' '
diff --git a/t/t3430-rebase-merges.sh b/t/t3430-rebase-merges.sh
index b84d68c4b9..ff81adab8c 100755
--- a/t/t3430-rebase-merges.sh
+++ b/t/t3430-rebase-merges.sh
@@ -86,7 +86,7 @@ test_expect_success 'create completely different structure' '
test_config sequence.editor \""$PWD"/replace-editor.sh\" &&
test_tick &&
git rebase -i -r A main &&
- test_cmp_graph <<-\EOF
+ test_cmp_graph <<-\EOF &&
* Merge the topic branch '\''onebranch'\''
|\
| * D
@@ -99,6 +99,15 @@ test_expect_success 'create completely different structure' '
|/
* A
EOF
+
+ head="$(git show-ref --verify -s --abbrev HEAD)" &&
+ cat >expect <<-EOF &&
+ $head HEAD@{0}: rebase (finish): returning to refs/heads/main
+ $head HEAD@{1}: rebase (merge): Merge the topic branch ${SQ}onebranch${SQ}
+ EOF
+
+ git reflog -n2 HEAD >actual &&
+ test_cmp expect actual
'
test_expect_success 'generate correct todo list' '
diff --git a/t/t4018/bash-bashism-style-complete-line-capture b/t/t4018/bash-bashism-style-complete-line-capture
new file mode 100644
index 0000000000..070b979fa6
--- /dev/null
+++ b/t/t4018/bash-bashism-style-complete-line-capture
@@ -0,0 +1,4 @@
+function myfunc # RIGHT
+{
+ echo 'ChangeMe'
+}
diff --git a/t/t4018/bash-posix-style-complete-line-capture b/t/t4018/bash-posix-style-complete-line-capture
new file mode 100644
index 0000000000..b56942f322
--- /dev/null
+++ b/t/t4018/bash-posix-style-complete-line-capture
@@ -0,0 +1,4 @@
+func() { # RIGHT
+
+ ChangeMe
+}
diff --git a/t/t4018/bash-posix-style-single-command-function b/t/t4018/bash-posix-style-single-command-function
new file mode 100644
index 0000000000..398ae1c5d2
--- /dev/null
+++ b/t/t4018/bash-posix-style-single-command-function
@@ -0,0 +1,3 @@
+RIGHT() echo "hello"
+
+ ChangeMe
diff --git a/t/t4034-diff-words.sh b/t/t4034-diff-words.sh
index f51d3557f1..0be647c2fb 100755
--- a/t/t4034-diff-words.sh
+++ b/t/t4034-diff-words.sh
@@ -320,6 +320,7 @@ test_expect_success 'unset default driver' '
test_language_driver ada
test_language_driver bibtex
+test_language_driver bash
test_language_driver cpp
test_language_driver csharp
test_language_driver css
diff --git a/t/t4034/bash/expect b/t/t4034/bash/expect
new file mode 100644
index 0000000000..1864ab25dc
--- /dev/null
+++ b/t/t4034/bash/expect
@@ -0,0 +1,36 @@
+<BOLD>diff --git a/pre b/post<RESET>
+<BOLD>index 09ac008..60ba6a2 100644<RESET>
+<BOLD>--- a/pre<RESET>
+<BOLD>+++ b/post<RESET>
+<CYAN>@@ -1,31 +1,31 @@<RESET>
+<RED>my_var<RESET><GREEN>new_var<RESET>=10
+x=<RED>123<RESET><GREEN>456<RESET>
+echo <RED>$1<RESET><GREEN>$2<RESET>
+echo <RED>$USER<RESET><GREEN>$USERNAME<RESET>
+${<RED>HOME<RESET><GREEN>HOMEDIR<RESET>}
+((a<RED>+<RESET><GREEN>+=<RESET>b))
+((a<RED>*<RESET><GREEN>*=<RESET>b))
+((a<RED>/<RESET><GREEN>/=<RESET>b))
+((a<RED>%<RESET><GREEN>%=<RESET>b))
+((a<RED>|<RESET><GREEN>|=<RESET>b))
+((a<RED>^<RESET><GREEN>^=<RESET>b))
+((a<RED>=<RESET><GREEN>==<RESET>b))
+((a<RED>!<RESET><GREEN>!=<RESET>b))
+((a<RED><<RESET><GREEN><=<RESET>b))
+((a<RED>><RESET><GREEN>>=<RESET>b))
+$((a<RED><<RESET><GREEN><<<RESET>b))
+$((a<RED>><RESET><GREEN>>><RESET>b))
+$((a<RED>&<RESET><GREEN>&&<RESET>b))
+$((a<RED>|<RESET><GREEN>||<RESET>b))
+${a<RED>:<RESET><GREEN>:-<RESET>b}
+${a<RED>:<RESET><GREEN>:=<RESET>b}
+${a<RED>:<RESET><GREEN>:+<RESET>b}
+${a<RED>:<RESET><GREEN>:?<RESET>b}
+${a<RED>#<RESET><GREEN>##<RESET>*/}
+${a<RED>%<RESET><GREEN>%%<RESET>.*}
+${a<RED>^<RESET><GREEN>^^<RESET>}
+${a<RED>,<RESET><GREEN>,,<RESET>}
+${<GREEN>!<RESET>a}
+${a[<RED>*<RESET><GREEN>@<RESET>]}
+ls <RED>-a<RESET><GREEN>-x<RESET>
+ls <RED>--all<RESET><GREEN>--color<RESET>
diff --git a/t/t4034/bash/post b/t/t4034/bash/post
new file mode 100644
index 0000000000..2bbee8936d
--- /dev/null
+++ b/t/t4034/bash/post
@@ -0,0 +1,31 @@
+new_var=10
+x=456
+echo $2
+echo $USERNAME
+${HOMEDIR}
+((a+=b))
+((a*=b))
+((a/=b))
+((a%=b))
+((a|=b))
+((a^=b))
+((a==b))
+((a!=b))
+((a<=b))
+((a>=b))
+$((a<<b))
+$((a>>b))
+$((a&&b))
+$((a||b))
+${a:-b}
+${a:=b}
+${a:+b}
+${a:?b}
+${a##*/}
+${a%%.*}
+${a^^}
+${a,,}
+${!a}
+${a[@]}
+ls -x
+ls --color
diff --git a/t/t4034/bash/pre b/t/t4034/bash/pre
new file mode 100644
index 0000000000..8d22039c40
--- /dev/null
+++ b/t/t4034/bash/pre
@@ -0,0 +1,31 @@
+my_var=10
+x=123
+echo $1
+echo $USER
+${HOME}
+((a+b))
+((a*b))
+((a/b))
+((a%b))
+((a|b))
+((a^b))
+((a=b))
+((a!b))
+((a<b))
+((a>b))
+$((a<b))
+$((a>b))
+$((a&b))
+$((a|b))
+${a:b}
+${a:b}
+${a:b}
+${a:b}
+${a#*/}
+${a%.*}
+${a^}
+${a,}
+${a}
+${a[*]}
+ls -a
+ls --all
diff --git a/t/t5558-clone-bundle-uri.sh b/t/t5558-clone-bundle-uri.sh
index 3816ed5058..9b211a626b 100755
--- a/t/t5558-clone-bundle-uri.sh
+++ b/t/t5558-clone-bundle-uri.sh
@@ -58,7 +58,7 @@ test_expect_success 'create bundle' '
test_expect_success 'clone with path bundle' '
git clone --bundle-uri="clone-from/B.bundle" \
clone-from clone-path &&
- git -C clone-path rev-parse refs/bundles/topic >actual &&
+ git -C clone-path rev-parse refs/bundles/heads/topic >actual &&
git -C clone-from rev-parse topic >expect &&
test_cmp expect actual
'
@@ -68,9 +68,9 @@ test_expect_success 'clone with bundle that has bad header' '
git clone --bundle-uri="clone-from/bad-header.bundle" \
clone-from clone-bad-header 2>err &&
commit_b=$(git -C clone-from rev-parse B) &&
- test_grep "trying to write ref '\''refs/bundles/topic'\'' with nonexistent object $commit_b" err &&
+ test_grep "trying to write ref '\''refs/bundles/heads/topic'\'' with nonexistent object $commit_b" err &&
git -C clone-bad-header for-each-ref --format="%(refname)" >refs &&
- test_grep ! "refs/bundles/" refs
+ test_grep ! "refs/bundles/heads/" refs
'
test_expect_success 'clone with bundle that has bad object' '
@@ -78,8 +78,8 @@ test_expect_success 'clone with bundle that has bad object' '
git clone --bundle-uri="clone-from/bad-object.bundle" \
clone-from clone-bad-object-no-fsck &&
git -C clone-bad-object-no-fsck for-each-ref --format="%(refname)" >refs &&
- grep "refs/bundles/" refs >actual &&
- test_write_lines refs/bundles/bad >expect &&
+ grep "refs/bundles/heads/" refs >actual &&
+ test_write_lines refs/bundles/heads/bad >expect &&
test_cmp expect actual &&
# Unbundle fails with fsckObjects set true, but clone can still proceed.
@@ -87,14 +87,14 @@ test_expect_success 'clone with bundle that has bad object' '
clone-from clone-bad-object-fsck 2>err &&
test_grep "missingEmail" err &&
git -C clone-bad-object-fsck for-each-ref --format="%(refname)" >refs &&
- test_grep ! "refs/bundles/" refs
+ test_grep ! "refs/bundles/heads/" refs
'
test_expect_success 'clone with path bundle and non-default hash' '
test_when_finished "rm -rf clone-path-non-default-hash" &&
GIT_DEFAULT_HASH=sha256 git clone --bundle-uri="clone-from/B.bundle" \
clone-from clone-path-non-default-hash &&
- git -C clone-path-non-default-hash rev-parse refs/bundles/topic >actual &&
+ git -C clone-path-non-default-hash rev-parse refs/bundles/heads/topic >actual &&
git -C clone-from rev-parse topic >expect &&
test_cmp expect actual
'
@@ -102,11 +102,41 @@ test_expect_success 'clone with path bundle and non-default hash' '
test_expect_success 'clone with file:// bundle' '
git clone --bundle-uri="file://$(pwd)/clone-from/B.bundle" \
clone-from clone-file &&
- git -C clone-file rev-parse refs/bundles/topic >actual &&
+ git -C clone-file rev-parse refs/bundles/heads/topic >actual &&
git -C clone-from rev-parse topic >expect &&
test_cmp expect actual
'
+test_expect_success 'create bundle with tags' '
+ git init clone-from-tags &&
+ (
+ cd clone-from-tags &&
+ git checkout -b base &&
+ git checkout -b topic &&
+
+ test_commit A &&
+ git tag tag-A &&
+ git checkout -b base &&
+ git branch -d topic &&
+ test_commit B &&
+
+ git bundle create ALL.bundle --all &&
+ git bundle verify ALL.bundle
+ )
+'
+
+test_expect_success 'clone with tags bundle' '
+ git clone --bundle-uri="clone-from-tags/ALL.bundle" \
+ clone-from-tags clone-tags-path &&
+
+ git -C clone-from-tags for-each-ref --format="%(refname:lstrip=1)" \
+ >expect &&
+ git -C clone-tags-path for-each-ref --format="%(refname:lstrip=2)" \
+ refs/bundles >actual &&
+
+ test_cmp expect actual
+'
+
# To get interesting tests for bundle lists, we need to construct a
# somewhat-interesting commit history.
#
@@ -173,12 +203,12 @@ test_expect_success 'clone bundle list (file, no heuristic)' '
git -C clone-list-file cat-file --batch-check <oids &&
git -C clone-list-file for-each-ref --format="%(refname)" >refs &&
- grep "refs/bundles/" refs >actual &&
+ grep "refs/bundles/heads/" refs >actual &&
cat >expect <<-\EOF &&
- refs/bundles/base
- refs/bundles/left
- refs/bundles/merge
- refs/bundles/right
+ refs/bundles/heads/base
+ refs/bundles/heads/left
+ refs/bundles/heads/merge
+ refs/bundles/heads/right
EOF
test_cmp expect actual
'
@@ -220,10 +250,10 @@ test_expect_success 'clone bundle list (file, all mode, some failures)' '
git -C clone-all-some cat-file --batch-check <oids &&
git -C clone-all-some for-each-ref --format="%(refname)" >refs &&
- grep "refs/bundles/" refs >actual &&
+ grep "refs/bundles/heads/" refs >actual &&
cat >expect <<-\EOF &&
- refs/bundles/base
- refs/bundles/left
+ refs/bundles/heads/base
+ refs/bundles/heads/left
EOF
test_cmp expect actual
'
@@ -253,7 +283,7 @@ test_expect_success 'clone bundle list (file, all mode, all failures)' '
git -C clone-all-fail cat-file --batch-check <oids &&
git -C clone-all-fail for-each-ref --format="%(refname)" >refs &&
- ! grep "refs/bundles/" refs
+ ! grep "refs/bundles/heads/" refs
'
test_expect_success 'clone bundle list (file, any mode)' '
@@ -282,9 +312,9 @@ test_expect_success 'clone bundle list (file, any mode)' '
git -C clone-any-file cat-file --batch-check <oids &&
git -C clone-any-file for-each-ref --format="%(refname)" >refs &&
- grep "refs/bundles/" refs >actual &&
+ grep "refs/bundles/heads/" refs >actual &&
cat >expect <<-\EOF &&
- refs/bundles/base
+ refs/bundles/heads/base
EOF
test_cmp expect actual
'
@@ -313,7 +343,7 @@ test_expect_success 'clone bundle list (file, any mode, all failures)' '
git -C clone-any-fail cat-file --batch-check <oids &&
git -C clone-any-fail for-each-ref --format="%(refname)" >refs &&
- ! grep "refs/bundles/" refs
+ ! grep "refs/bundles/heads/" refs
'
test_expect_success 'negotiation: bundle with part of wanted commits' '
@@ -322,10 +352,10 @@ test_expect_success 'negotiation: bundle with part of wanted commits' '
git clone --no-local --bundle-uri="clone-from/A.bundle" \
clone-from nego-bundle-part &&
git -C nego-bundle-part for-each-ref --format="%(refname)" >refs &&
- grep "refs/bundles/" refs >actual &&
- test_write_lines refs/bundles/topic >expect &&
+ grep "refs/bundles/heads/" refs >actual &&
+ test_write_lines refs/bundles/heads/topic >expect &&
test_cmp expect actual &&
- # Ensure that refs/bundles/topic are sent as "have".
+ # Ensure that refs/bundles/heads/topic are sent as "have".
tip=$(git -C clone-from rev-parse A) &&
test_grep "clone> have $tip" trace-packet.txt
'
@@ -337,8 +367,8 @@ test_expect_success 'negotiation: bundle with all wanted commits' '
--bundle-uri="clone-from/B.bundle" \
clone-from nego-bundle-all &&
git -C nego-bundle-all for-each-ref --format="%(refname)" >refs &&
- grep "refs/bundles/" refs >actual &&
- test_write_lines refs/bundles/topic >expect &&
+ grep "refs/bundles/heads/" refs >actual &&
+ test_write_lines refs/bundles/heads/topic >expect &&
test_cmp expect actual &&
# We already have all needed commits so no "want" needed.
test_grep ! "clone> want " trace-packet.txt
@@ -363,13 +393,13 @@ test_expect_success 'negotiation: bundle list (no heuristic)' '
clone-from nego-bundle-list-no-heuristic &&
git -C nego-bundle-list-no-heuristic for-each-ref --format="%(refname)" >refs &&
- grep "refs/bundles/" refs >actual &&
+ grep "refs/bundles/heads/" refs >actual &&
cat >expect <<-\EOF &&
- refs/bundles/base
- refs/bundles/left
+ refs/bundles/heads/base
+ refs/bundles/heads/left
EOF
test_cmp expect actual &&
- tip=$(git -C nego-bundle-list-no-heuristic rev-parse refs/bundles/left) &&
+ tip=$(git -C nego-bundle-list-no-heuristic rev-parse refs/bundles/heads/left) &&
test_grep "clone> have $tip" trace-packet.txt
'
@@ -395,13 +425,13 @@ test_expect_success 'negotiation: bundle list (creationToken)' '
clone-from nego-bundle-list-heuristic &&
git -C nego-bundle-list-heuristic for-each-ref --format="%(refname)" >refs &&
- grep "refs/bundles/" refs >actual &&
+ grep "refs/bundles/heads/" refs >actual &&
cat >expect <<-\EOF &&
- refs/bundles/base
- refs/bundles/left
+ refs/bundles/heads/base
+ refs/bundles/heads/left
EOF
test_cmp expect actual &&
- tip=$(git -C nego-bundle-list-heuristic rev-parse refs/bundles/left) &&
+ tip=$(git -C nego-bundle-list-heuristic rev-parse refs/bundles/heads/left) &&
test_grep "clone> have $tip" trace-packet.txt
'
@@ -428,10 +458,10 @@ test_expect_success 'negotiation: bundle list with all wanted commits' '
clone-from nego-bundle-list-all &&
git -C nego-bundle-list-all for-each-ref --format="%(refname)" >refs &&
- grep "refs/bundles/" refs >actual &&
+ grep "refs/bundles/heads/" refs >actual &&
cat >expect <<-\EOF &&
- refs/bundles/base
- refs/bundles/left
+ refs/bundles/heads/base
+ refs/bundles/heads/left
EOF
test_cmp expect actual &&
# We already have all needed commits so no "want" needed.
@@ -465,7 +495,7 @@ test_expect_success 'clone HTTP bundle' '
git clone --bundle-uri="$HTTPD_URL/B.bundle" \
"$HTTPD_URL/smart/fetch.git" clone-http &&
- git -C clone-http rev-parse refs/bundles/topic >actual &&
+ git -C clone-http rev-parse refs/bundles/heads/topic >actual &&
git -C clone-from rev-parse topic >expect &&
test_cmp expect actual &&
@@ -476,7 +506,7 @@ test_expect_success 'clone HTTP bundle with non-default hash' '
test_when_finished "rm -rf clone-http-non-default-hash" &&
GIT_DEFAULT_HASH=sha256 git clone --bundle-uri="$HTTPD_URL/B.bundle" \
"$HTTPD_URL/smart/fetch.git" clone-http-non-default-hash &&
- git -C clone-http-non-default-hash rev-parse refs/bundles/topic >actual &&
+ git -C clone-http-non-default-hash rev-parse refs/bundles/heads/topic >actual &&
git -C clone-from rev-parse topic >expect &&
test_cmp expect actual
'
@@ -553,12 +583,12 @@ test_expect_success 'clone bundle list (HTTP, any mode)' '
git -C clone-any-http cat-file --batch-check <oids &&
git -C clone-list-file for-each-ref --format="%(refname)" >refs &&
- grep "refs/bundles/" refs >actual &&
+ grep "refs/bundles/heads/" refs >actual &&
cat >expect <<-\EOF &&
- refs/bundles/base
- refs/bundles/left
- refs/bundles/merge
- refs/bundles/right
+ refs/bundles/heads/base
+ refs/bundles/heads/left
+ refs/bundles/heads/merge
+ refs/bundles/heads/right
EOF
test_cmp expect actual
'
@@ -641,9 +671,9 @@ test_expect_success 'clone incomplete bundle list (http, creationToken)' '
test_cmp expect actual &&
# We now have only one bundle ref.
- git -C clone-token-http for-each-ref --format="%(refname)" "refs/bundles/*" >refs &&
+ git -C clone-token-http for-each-ref --format="%(refname)" "refs/bundles/heads/*" >refs &&
cat >expect <<-\EOF &&
- refs/bundles/base
+ refs/bundles/heads/base
EOF
test_cmp expect refs &&
@@ -679,13 +709,13 @@ test_expect_success 'clone incomplete bundle list (http, creationToken)' '
test_cmp expect actual &&
# We now have all bundle refs.
- git -C clone-token-http for-each-ref --format="%(refname)" "refs/bundles/*" >refs &&
+ git -C clone-token-http for-each-ref --format="%(refname)" "refs/bundles/heads/*" >refs &&
cat >expect <<-\EOF &&
- refs/bundles/base
- refs/bundles/left
- refs/bundles/merge
- refs/bundles/right
+ refs/bundles/heads/base
+ refs/bundles/heads/left
+ refs/bundles/heads/merge
+ refs/bundles/heads/right
EOF
test_cmp expect refs
'
@@ -721,9 +751,9 @@ test_expect_success 'http clone with bundle.heuristic creates fetch.bundleURI' '
test_cmp expect actual &&
# only received base ref from bundle-1
- git -C fetch-http-4 for-each-ref --format="%(refname)" "refs/bundles/*" >refs &&
+ git -C fetch-http-4 for-each-ref --format="%(refname)" "refs/bundles/heads/*" >refs &&
cat >expect <<-\EOF &&
- refs/bundles/base
+ refs/bundles/heads/base
EOF
test_cmp expect refs &&
@@ -749,10 +779,10 @@ test_expect_success 'http clone with bundle.heuristic creates fetch.bundleURI' '
test_cmp expect actual &&
# received left from bundle-2
- git -C fetch-http-4 for-each-ref --format="%(refname)" "refs/bundles/*" >refs &&
+ git -C fetch-http-4 for-each-ref --format="%(refname)" "refs/bundles/heads/*" >refs &&
cat >expect <<-\EOF &&
- refs/bundles/base
- refs/bundles/left
+ refs/bundles/heads/base
+ refs/bundles/heads/left
EOF
test_cmp expect refs &&
@@ -795,12 +825,12 @@ test_expect_success 'http clone with bundle.heuristic creates fetch.bundleURI' '
# received merge ref from bundle-4, but right is missing
# because we did not download bundle-3.
- git -C fetch-http-4 for-each-ref --format="%(refname)" "refs/bundles/*" >refs &&
+ git -C fetch-http-4 for-each-ref --format="%(refname)" "refs/bundles/heads/*" >refs &&
cat >expect <<-\EOF &&
- refs/bundles/base
- refs/bundles/left
- refs/bundles/merge
+ refs/bundles/heads/base
+ refs/bundles/heads/left
+ refs/bundles/heads/merge
EOF
test_cmp expect refs &&
@@ -862,7 +892,7 @@ test_expect_success 'creationToken heuristic with failed downloads (clone)' '
test_cmp expect actual &&
# All bundles failed to unbundle
- git -C download-1 for-each-ref --format="%(refname)" "refs/bundles/*" >refs &&
+ git -C download-1 for-each-ref --format="%(refname)" "refs/bundles/heads/*" >refs &&
test_must_be_empty refs &&
# Case 2: middle bundle does not exist, only two bundles can unbundle
@@ -909,10 +939,10 @@ test_expect_success 'creationToken heuristic with failed downloads (clone)' '
test_cmp expect actual &&
# bundle-1 and bundle-3 could unbundle, but bundle-4 could not
- git -C download-2 for-each-ref --format="%(refname)" "refs/bundles/*" >refs &&
+ git -C download-2 for-each-ref --format="%(refname)" "refs/bundles/heads/*" >refs &&
cat >expect <<-EOF &&
- refs/bundles/base
- refs/bundles/right
+ refs/bundles/heads/base
+ refs/bundles/heads/right
EOF
test_cmp expect refs &&
@@ -961,11 +991,11 @@ test_expect_success 'creationToken heuristic with failed downloads (clone)' '
test_cmp expect actual &&
# fake.bundle did not unbundle, but the others did.
- git -C download-3 for-each-ref --format="%(refname)" "refs/bundles/*" >refs &&
+ git -C download-3 for-each-ref --format="%(refname)" "refs/bundles/heads/*" >refs &&
cat >expect <<-EOF &&
- refs/bundles/base
- refs/bundles/left
- refs/bundles/right
+ refs/bundles/heads/base
+ refs/bundles/heads/left
+ refs/bundles/heads/right
EOF
test_cmp expect refs
'
@@ -1083,15 +1113,15 @@ test_expect_success 'creationToken heuristic with failed downloads (fetch)' '
test_cmp expect actual &&
# Check which bundles have unbundled by refs
- git -C fetch-1 for-each-ref --format="%(refname)" "refs/bundles/*" >refs &&
+ git -C fetch-1 for-each-ref --format="%(refname)" "refs/bundles/heads/*" >refs &&
cat >expect <<-EOF &&
- refs/bundles/base
- refs/bundles/left
- refs/bundles/lefter
- refs/bundles/merge
- refs/bundles/right
- refs/bundles/righter
- refs/bundles/top
+ refs/bundles/heads/base
+ refs/bundles/heads/left
+ refs/bundles/heads/lefter
+ refs/bundles/heads/merge
+ refs/bundles/heads/right
+ refs/bundles/heads/righter
+ refs/bundles/heads/top
EOF
test_cmp expect refs &&
@@ -1144,12 +1174,12 @@ test_expect_success 'creationToken heuristic with failed downloads (fetch)' '
test_cmp expect actual &&
# Check which bundles have unbundled by refs
- git -C fetch-2 for-each-ref --format="%(refname)" "refs/bundles/*" >refs &&
+ git -C fetch-2 for-each-ref --format="%(refname)" "refs/bundles/heads/*" >refs &&
cat >expect <<-EOF &&
- refs/bundles/base
- refs/bundles/left
- refs/bundles/merge
- refs/bundles/right
+ refs/bundles/heads/base
+ refs/bundles/heads/left
+ refs/bundles/heads/merge
+ refs/bundles/heads/right
EOF
test_cmp expect refs &&
@@ -1204,13 +1234,13 @@ test_expect_success 'creationToken heuristic with failed downloads (fetch)' '
test_cmp expect actual &&
# Check which bundles have unbundled by refs
- git -C fetch-3 for-each-ref --format="%(refname)" "refs/bundles/*" >refs &&
+ git -C fetch-3 for-each-ref --format="%(refname)" "refs/bundles/heads/*" >refs &&
cat >expect <<-EOF &&
- refs/bundles/base
- refs/bundles/left
- refs/bundles/lefter
- refs/bundles/right
- refs/bundles/righter
+ refs/bundles/heads/base
+ refs/bundles/heads/left
+ refs/bundles/heads/lefter
+ refs/bundles/heads/right
+ refs/bundles/heads/righter
EOF
test_cmp expect refs
'
diff --git a/t/t6011-rev-list-with-bad-commit.sh b/t/t6011-rev-list-with-bad-commit.sh
index b6f3344dbf..1dd1e50d21 100755
--- a/t/t6011-rev-list-with-bad-commit.sh
+++ b/t/t6011-rev-list-with-bad-commit.sh
@@ -38,6 +38,7 @@ test_expect_success 'verify number of revisions' \
test_expect_success 'corrupt second commit object' '
for p in .git/objects/pack/*.pack
do
+ chmod +w "$p" &&
sed "s/second commit/socond commit/" "$p" >"$p.munged" &&
mv "$p.munged" "$p" ||
return 1
diff --git a/t/t7900-maintenance.sh b/t/t7900-maintenance.sh
index 9b82e11c10..8cf89e285f 100755
--- a/t/t7900-maintenance.sh
+++ b/t/t7900-maintenance.sh
@@ -493,6 +493,121 @@ test_expect_success 'reflog-expire task --auto only packs when exceeding limits'
test_subcommand git reflog expire --all <reflog-expire-auto.txt
'
+test_expect_worktree_prune () {
+ negate=
+ if test "$1" = "!"
+ then
+ negate="!"
+ shift
+ fi
+
+ rm -f "worktree-prune.txt" &&
+ GIT_TRACE2_EVENT="$(pwd)/worktree-prune.txt" "$@" &&
+ test_subcommand $negate git worktree prune --expire 3.months.ago <worktree-prune.txt
+}
+
+test_expect_success 'worktree-prune task without --auto always prunes' '
+ test_expect_worktree_prune git maintenance run --task=worktree-prune
+'
+
+test_expect_success 'worktree-prune task --auto only prunes with prunable worktree' '
+ test_expect_worktree_prune ! git maintenance run --auto --task=worktree-prune &&
+ mkdir .git/worktrees &&
+ : >.git/worktrees/abc &&
+ test_expect_worktree_prune git maintenance run --auto --task=worktree-prune
+'
+
+test_expect_success 'worktree-prune task with --auto honors maintenance.worktree-prune.auto' '
+ # A negative value should always prune.
+ test_expect_worktree_prune git -c maintenance.worktree-prune.auto=-1 maintenance run --auto --task=worktree-prune &&
+
+ mkdir .git/worktrees &&
+ : >.git/worktrees/first &&
+ : >.git/worktrees/second &&
+ : >.git/worktrees/third &&
+
+ # Zero should never prune.
+ test_expect_worktree_prune ! git -c maintenance.worktree-prune.auto=0 maintenance run --auto --task=worktree-prune &&
+ # A positive value should require at least this many prunable worktrees.
+ test_expect_worktree_prune ! git -c maintenance.worktree-prune.auto=4 maintenance run --auto --task=worktree-prune &&
+ test_expect_worktree_prune git -c maintenance.worktree-prune.auto=3 maintenance run --auto --task=worktree-prune
+'
+
+test_expect_success 'worktree-prune task with --auto honors maintenance.worktree-prune.auto' '
+ # A negative value should always prune.
+ test_expect_worktree_prune git -c maintenance.worktree-prune.auto=-1 maintenance run --auto --task=worktree-prune &&
+
+ mkdir .git/worktrees &&
+ : >.git/worktrees/first &&
+ : >.git/worktrees/second &&
+ : >.git/worktrees/third &&
+
+ # Zero should never prune.
+ test_expect_worktree_prune ! git -c maintenance.worktree-prune.auto=0 maintenance run --auto --task=worktree-prune &&
+ # A positive value should require at least this many prunable worktrees.
+ test_expect_worktree_prune ! git -c maintenance.worktree-prune.auto=4 maintenance run --auto --task=worktree-prune &&
+ test_expect_worktree_prune git -c maintenance.worktree-prune.auto=3 maintenance run --auto --task=worktree-prune
+'
+
+test_expect_success 'worktree-prune task honors gc.worktreePruneExpire' '
+ git worktree add worktree &&
+ rm -rf worktree &&
+
+ rm -f worktree-prune.txt &&
+ GIT_TRACE2_EVENT="$(pwd)/worktree-prune.txt" git -c gc.worktreePruneExpire=1.week.ago maintenance run --auto --task=worktree-prune &&
+ test_subcommand ! git worktree prune --expire 1.week.ago <worktree-prune.txt &&
+ test_path_is_dir .git/worktrees/worktree &&
+
+ rm -f worktree-prune.txt &&
+ GIT_TRACE2_EVENT="$(pwd)/worktree-prune.txt" git -c gc.worktreePruneExpire=now maintenance run --auto --task=worktree-prune &&
+ test_subcommand git worktree prune --expire now <worktree-prune.txt &&
+ test_path_is_missing .git/worktrees/worktree
+'
+
+test_expect_rerere_gc () {
+ negate=
+ if test "$1" = "!"
+ then
+ negate="!"
+ shift
+ fi
+
+ rm -f "rerere-gc.txt" &&
+ GIT_TRACE2_EVENT="$(pwd)/rerere-gc.txt" "$@" &&
+ test_subcommand $negate git rerere gc <rerere-gc.txt
+}
+
+test_expect_success 'rerere-gc task without --auto always collects garbage' '
+ test_expect_rerere_gc git maintenance run --task=rerere-gc
+'
+
+test_expect_success 'rerere-gc task with --auto only prunes with prunable entries' '
+ test_when_finished "rm -rf .git/rr-cache" &&
+ test_expect_rerere_gc ! git maintenance run --auto --task=rerere-gc &&
+ mkdir .git/rr-cache &&
+ test_expect_rerere_gc ! git maintenance run --auto --task=rerere-gc &&
+ : >.git/rr-cache/entry &&
+ test_expect_rerere_gc git maintenance run --auto --task=rerere-gc
+'
+
+test_expect_success 'rerere-gc task with --auto honors maintenance.rerere-gc.auto' '
+ test_when_finished "rm -rf .git/rr-cache" &&
+
+ # A negative value should always prune.
+ test_expect_rerere_gc git -c maintenance.rerere-gc.auto=-1 maintenance run --auto --task=rerere-gc &&
+
+ # A positive value prunes when there is at least one entry.
+ test_expect_rerere_gc ! git -c maintenance.rerere-gc.auto=9000 maintenance run --auto --task=rerere-gc &&
+ mkdir .git/rr-cache &&
+ test_expect_rerere_gc ! git -c maintenance.rerere-gc.auto=9000 maintenance run --auto --task=rerere-gc &&
+ : >.git/rr-cache/entry-1 &&
+ test_expect_rerere_gc git -c maintenance.rerere-gc.auto=9000 maintenance run --auto --task=rerere-gc &&
+
+ # Zero should never prune.
+ : >.git/rr-cache/entry-1 &&
+ test_expect_rerere_gc ! git -c maintenance.rerere-gc.auto=0 maintenance run --auto --task=rerere-gc
+'
+
test_expect_success '--auto and --schedule incompatible' '
test_must_fail git maintenance run --auto --schedule=daily 2>err &&
test_grep "at most one" err
diff --git a/t/t9210-scalar.sh b/t/t9210-scalar.sh
index a81662713e..bd6f0c40d2 100755
--- a/t/t9210-scalar.sh
+++ b/t/t9210-scalar.sh
@@ -108,7 +108,7 @@ test_expect_success 'scalar register warns when background maintenance fails' '
git init register-repo &&
GIT_TEST_MAINT_SCHEDULER="crontab:false,launchctl:false,schtasks:false" \
scalar register register-repo 2>err &&
- grep "could not turn on maintenance" err
+ grep "could not toggle maintenance" err
'
test_expect_success 'scalar unregister' '
@@ -129,6 +129,17 @@ test_expect_success 'scalar unregister' '
scalar unregister vanish
'
+test_expect_success 'scalar register --no-maintenance' '
+ git init register-no-maint &&
+ event_log="$(pwd)/no-maint.event" &&
+ GIT_TEST_MAINT_SCHEDULER="crontab:false,launchctl:false,schtasks:false" \
+ GIT_TRACE2_EVENT="$event_log" \
+ GIT_TRACE2_EVENT_DEPTH=100 \
+ scalar register --no-maintenance register-no-maint 2>err &&
+ test_must_be_empty err &&
+ test_subcommand ! git maintenance unregister --force <no-maint.event
+'
+
test_expect_success 'set up repository to clone' '
test_commit first &&
test_commit second &&
@@ -199,7 +210,18 @@ test_expect_success 'scalar reconfigure' '
GIT_TRACE2_EVENT="$(pwd)/reconfigure" scalar reconfigure -a &&
test_path_is_file one/src/cron.txt &&
test true = "$(git -C one/src config core.preloadIndex)" &&
- test_subcommand git maintenance start <reconfigure
+ test_subcommand git maintenance start <reconfigure &&
+ test_subcommand ! git maintenance unregister --force <reconfigure &&
+
+ GIT_TRACE2_EVENT="$(pwd)/reconfigure-maint-disable" \
+ scalar reconfigure -a --maintenance=disable &&
+ test_subcommand ! git maintenance start <reconfigure-maint-disable &&
+ test_subcommand git maintenance unregister --force <reconfigure-maint-disable &&
+
+ GIT_TRACE2_EVENT="$(pwd)/reconfigure-maint-keep" \
+ scalar reconfigure --maintenance=keep -a &&
+ test_subcommand ! git maintenance start <reconfigure-maint-keep &&
+ test_subcommand ! git maintenance unregister --force <reconfigure-maint-keep
'
test_expect_success 'scalar reconfigure --all with includeIf.onbranch' '
diff --git a/t/t9211-scalar-clone.sh b/t/t9211-scalar-clone.sh
index 01f71910f5..bfbf22a462 100755
--- a/t/t9211-scalar-clone.sh
+++ b/t/t9211-scalar-clone.sh
@@ -177,7 +177,16 @@ test_expect_success 'progress without tty' '
test_expect_success 'scalar clone warns when background maintenance fails' '
GIT_TEST_MAINT_SCHEDULER="crontab:false,launchctl:false,schtasks:false" \
scalar clone "file://$(pwd)/to-clone" maint-fail 2>err &&
- grep "could not turn on maintenance" err
+ grep "could not toggle maintenance" err
+'
+
+test_expect_success 'scalar clone --no-maintenance' '
+ GIT_TEST_MAINT_SCHEDULER="crontab:false,launchctl:false,schtasks:false" \
+ GIT_TRACE2_EVENT="$(pwd)/no-maint.event" \
+ GIT_TRACE2_EVENT_DEPTH=100 \
+ scalar clone --no-maintenance "file://$(pwd)/to-clone" no-maint 2>err &&
+ ! grep "could not toggle maintenance" err &&
+ test_subcommand ! git maintenance unregister --force <no-maint.event
'
test_expect_success '`scalar clone --no-src`' '
diff --git a/t/unit-tests/t-reftable-block.c b/t/unit-tests/t-reftable-block.c
index 7dbd93601c..52f1dae1c9 100644
--- a/t/unit-tests/t-reftable-block.c
+++ b/t/unit-tests/t-reftable-block.c
@@ -64,7 +64,8 @@ static void t_ref_block_read_write(void)
block_writer_release(&bw);
block_source_from_buf(&source ,&block_data);
- reftable_block_init(&block, &source, 0, header_off, block_size, REFTABLE_HASH_SIZE_SHA1);
+ reftable_block_init(&block, &source, 0, header_off, block_size,
+ REFTABLE_HASH_SIZE_SHA1, REFTABLE_BLOCK_TYPE_REF);
block_iter_init(&it, &block);
@@ -153,7 +154,8 @@ static void t_log_block_read_write(void)
block_writer_release(&bw);
block_source_from_buf(&source, &block_data);
- reftable_block_init(&block, &source, 0, header_off, block_size, REFTABLE_HASH_SIZE_SHA1);
+ reftable_block_init(&block, &source, 0, header_off, block_size,
+ REFTABLE_HASH_SIZE_SHA1, REFTABLE_BLOCK_TYPE_LOG);
block_iter_init(&it, &block);
@@ -245,7 +247,8 @@ static void t_obj_block_read_write(void)
block_writer_release(&bw);
block_source_from_buf(&source, &block_data);
- reftable_block_init(&block, &source, 0, header_off, block_size, REFTABLE_HASH_SIZE_SHA1);
+ reftable_block_init(&block, &source, 0, header_off, block_size,
+ REFTABLE_HASH_SIZE_SHA1, REFTABLE_BLOCK_TYPE_OBJ);
block_iter_init(&it, &block);
@@ -329,7 +332,8 @@ static void t_index_block_read_write(void)
block_writer_release(&bw);
block_source_from_buf(&source, &block_data);
- reftable_block_init(&block, &source, 0, header_off, block_size, REFTABLE_HASH_SIZE_SHA1);
+ reftable_block_init(&block, &source, 0, header_off, block_size,
+ REFTABLE_HASH_SIZE_SHA1, REFTABLE_BLOCK_TYPE_INDEX);
block_iter_init(&it, &block);
@@ -411,7 +415,8 @@ static void t_block_iterator(void)
check_int(err, >, 0);
block_source_from_buf(&source, &data);
- reftable_block_init(&block, &source, 0, 0, data.len, REFTABLE_HASH_SIZE_SHA1);
+ reftable_block_init(&block, &source, 0, 0, data.len,
+ REFTABLE_HASH_SIZE_SHA1, REFTABLE_BLOCK_TYPE_REF);
err = reftable_block_init_iterator(&block, &it);
check_int(err, ==, 0);
diff --git a/t/unit-tests/u-oidmap.c b/t/unit-tests/u-oidmap.c
index dc805b7e3c..b23af449f6 100644
--- a/t/unit-tests/u-oidmap.c
+++ b/t/unit-tests/u-oidmap.c
@@ -35,7 +35,7 @@ void test_oidmap__initialize(void)
void test_oidmap__cleanup(void)
{
- oidmap_free(&map, 1);
+ oidmap_clear(&map, 1);
}
void test_oidmap__replace(void)
diff --git a/userdiff.c b/userdiff.c
index da75625020..05776ccd10 100644
--- a/userdiff.c
+++ b/userdiff.c
@@ -59,20 +59,30 @@ PATTERNS("bash",
"("
"("
/* POSIX identifier with mandatory parentheses */
- "[a-zA-Z_][a-zA-Z0-9_]*[ \t]*\\([ \t]*\\))"
+ "([a-zA-Z_][a-zA-Z0-9_]*[ \t]*\\([ \t]*\\))"
"|"
/* Bashism identifier with optional parentheses */
- "(function[ \t]+[a-zA-Z_][a-zA-Z0-9_]*(([ \t]*\\([ \t]*\\))|([ \t]+))"
+ "(function[ \t]+[a-zA-Z_][a-zA-Z0-9_]*(([ \t]*\\([ \t]*\\))|([ \t]+)))"
")"
- /* Optional whitespace */
- "[ \t]*"
- /* Compound command starting with `{`, `(`, `((` or `[[` */
- "(\\{|\\(\\(?|\\[\\[)"
+ /* Everything after the function header is captured */
+ ".*$"
/* End of captured text */
")",
/* -- */
- /* Characters not in the default $IFS value */
- "[^ \t]+"),
+ /* Identifiers: variable and function names */
+ "[a-zA-Z_][a-zA-Z0-9_]*"
+ /* Shell variables: $VAR, ${VAR} */
+ "|\\$[a-zA-Z0-9_]+|\\$\\{"
+ /*Command list separators and redirection operators */
+ "|\\|\\||&&|<<|>>"
+ /* Operators ending in '=' (comparison + compound assignment) */
+ "|==|!=|<=|>=|[-+*/%&|^]="
+ /* Additional parameter expansion operators */
+ "|:=|:-|:\\+|:\\?|##|%%|\\^\\^|,,"
+ /* Command-line options (to avoid splitting -option) */
+ "|[-a-zA-Z0-9_]+"
+ /* Brackets and grouping symbols */
+ "|\\(|\\)|\\{|\\}|\\[|\\]"),
PATTERNS("bibtex",
"(@[a-zA-Z]{1,}[ \t]*\\{{0,1}[ \t]*[^ \t\"@',\\#}{~%]*).*$",
/* -- */
diff --git a/wrapper.c b/wrapper.c
index 3c79778055..2f00d2ac87 100644
--- a/wrapper.c
+++ b/wrapper.c
@@ -737,7 +737,26 @@ int is_empty_or_missing_file(const char *filename)
int open_nofollow(const char *path, int flags)
{
#ifdef O_NOFOLLOW
- return open(path, flags | O_NOFOLLOW);
+ int ret = open(path, flags | O_NOFOLLOW);
+ /*
+ * NetBSD sets errno to EFTYPE when path is a symlink. The only other
+ * time this errno occurs when O_REGULAR is used. Since we don't use
+ * it anywhere we can avoid an lstat here. FreeBSD does the same with
+ * EMLINK.
+ */
+# ifdef __NetBSD__
+# define SYMLINK_ERRNO EFTYPE
+# elif defined(__FreeBSD__)
+# define SYMLINK_ERRNO EMLINK
+# endif
+# if SYMLINK_ERRNO
+ if (ret < 0 && errno == SYMLINK_ERRNO) {
+ errno = ELOOP;
+ return -1;
+ }
+# undef SYMLINK_ERRNO
+# endif
+ return ret;
#else
struct stat st;
if (lstat(path, &st) < 0)