diff options
52 files changed, 826 insertions, 291 deletions
@@ -257,6 +257,7 @@ Stefan Naewe <stefan.naewe@gmail.com> <stefan.naewe@googlemail.com> Stefan Sperling <stsp@elego.de> <stsp@stsp.name> Štěpán Němec <stepnem@gmail.com> <stepan.nemec@gmail.com> Stephen Boyd <bebarino@gmail.com> <sboyd@codeaurora.org> +Stephen P. Smith <ishchis2@gmail.com> <ischis2@cox.net> Steven Drake <sdrake@xnet.co.nz> <sdrake@ihug.co.nz> Steven Grimm <koreth@midwinter.com> <sgrimm@sgrimm-mbp.local> Steven Grimm <koreth@midwinter.com> koreth@midwinter.com diff --git a/Documentation/BreakingChanges.txt b/Documentation/BreakingChanges.txt index 0532bfcf7f..2b64665694 100644 --- a/Documentation/BreakingChanges.txt +++ b/Documentation/BreakingChanges.txt @@ -115,6 +115,26 @@ info/grafts as outdated, 2014-03-05) and will be removed. + Cf. <20140304174806.GA11561@sigill.intra.peff.net>. +* The git-pack-redundant(1) command can be used to remove redundant pack files. + The subcommand is unusably slow and the reason why nobody reports it as a + performance bug is suspected to be the absense of users. We have nominated + the command for removal and have started to emit a user-visible warning in + c3b58472be (pack-redundant: gauge the usage before proposing its removal, + 2020-08-25) whenever the command is executed. ++ +So far there was a single complaint about somebody still using the command, but +that complaint did not cause us to reverse course. On the contrary, we have +doubled down on the deprecation and starting with 4406522b76 (pack-redundant: +escalate deprecation warning to an error, 2023-03-23), the command dies unless +the user passes the `--i-still-use-this` option. ++ +There have not been any subsequent complaints, so this command will finally be +removed. ++ +Cf. <xmqq1rjuz6n3.fsf_-_@gitster.c.googlers.com>, + <CAKvOHKAFXQwt4D8yUCCkf_TQL79mYaJ=KAKhtpDNTvHJFuX1NA@mail.gmail.com>, + <20230323204047.GA9290@coredump.intra.peff.net>, + == Superseded features that will not be deprecated Some features have gained newer replacements that aim to improve the design in diff --git a/Documentation/CodingGuidelines b/Documentation/CodingGuidelines index ccaea39752..3263245b03 100644 --- a/Documentation/CodingGuidelines +++ b/Documentation/CodingGuidelines @@ -258,6 +258,14 @@ For C programs: ensure your patch is clear of all compiler warnings we care about, by e.g. "echo DEVELOPER=1 >>config.mak". + - When using DEVELOPER=1 mode, you may see warnings from the compiler + like "error: unused parameter 'foo' [-Werror=unused-parameter]", + which indicates that a function ignores its argument. If the unused + parameter can't be removed (e.g., because the function is used as a + callback and has to match a certain interface), you can annotate + the individual parameters with the UNUSED (or MAYBE_UNUSED) + keyword, like "int foo UNUSED". + - We try to support a wide range of C compilers to compile Git with, including old ones. As of Git v2.35.0 Git requires C99 (we check "__STDC_VERSION__"). You should not use features from a newer C diff --git a/Documentation/RelNotes/2.47.0.txt b/Documentation/RelNotes/2.47.0.txt index f614056467..2aee05e09a 100644 --- a/Documentation/RelNotes/2.47.0.txt +++ b/Documentation/RelNotes/2.47.0.txt @@ -48,6 +48,13 @@ UI, Workflows & Features * Support for the RUNTIME_PREFIX feature has been added to z/OS port. + * "git send-email" learned "--mailmap" option to allow rewriting the + recipient addresses. + + * "git mergetool" learned to use VSCode as a merge backend. + + * "git pack-redundant" has been marked for removal in Git 3.0. + Performance, Internal Implementation, Development Support etc. -------------------------------------------------------------- @@ -111,6 +118,9 @@ Performance, Internal Implementation, Development Support etc. * More trace2 events at key points on push and fetch code paths have been added. + * Make our codebase compilable with the -Werror=unused-parameter + option. + Fixes since v2.46 ----------------- @@ -190,6 +200,11 @@ Fixes since v2.46 * The code path for compacting reftable files saw some bugfixes against concurrent operation. + * The code forgot to discard unnecessary in-core commit buffer data + for commits that "git log --skip=<number>" traversed but omitted + from the output, which has been corrected. + (merge 6bd2ae67a5 jk/free-commit-buffer-of-skipped-commits later to maint). + * Other code cleanup, docfix, build fix, etc. (merge bb0498b1bb jc/how-to-maintain-updates later to maint). (merge 0d66f601a9 jc/tests-no-useless-tee later to maint). @@ -200,3 +215,4 @@ Fixes since v2.46 (merge 596f4ff6ad cl/config-regexp-docfix later to maint). (merge 4881328617 aa/cat-file-batch-output-doc later to maint). (merge 1609470409 jc/config-doc-update later to maint). + (merge d4dc0efd7d rj/compat-terminal-unused-fix later to maint). diff --git a/Documentation/git-check-mailmap.txt b/Documentation/git-check-mailmap.txt index 02f4418323..966c91c46a 100644 --- a/Documentation/git-check-mailmap.txt +++ b/Documentation/git-check-mailmap.txt @@ -15,10 +15,10 @@ SYNOPSIS DESCRIPTION ----------- -For each ``Name $$<user@host>$$'' or ``$$<user@host>$$'' from the command-line -or standard input (when using `--stdin`), look up the person's canonical name -and email address (see "Mapping Authors" below). If found, print them; -otherwise print the input as-is. +For each ``Name $$<user@host>$$'', ``$$<user@host>$$'', or ``$$user@host$$'' +from the command-line or standard input (when using `--stdin`), look up the +person's canonical name and email address (see "Mapping Authors" below). If +found, print them; otherwise print the input as-is. OPTIONS @@ -27,6 +27,16 @@ OPTIONS Read contacts, one per line, from the standard input after exhausting contacts provided on the command-line. +--mailmap-file=<file>:: + In addition to any configured mailmap files, read the specified + mailmap file. Entries in this file take precedence over entries in + either the default mailmap file or any configured mailmap file. + +--mailmap-blob=<blob>:: + Like `--mailmap-file`, but consider the value as a reference to a + blob in the repository. If both `--mailmap-file` and + `--mailmap-blob` are specified, entries in `--mailmap-file` will + take precedence. OUTPUT ------ @@ -812,7 +812,6 @@ TEST_BUILTINS_OBJS += test-lazy-init-name-hash.o TEST_BUILTINS_OBJS += test-match-trees.o TEST_BUILTINS_OBJS += test-mergesort.o TEST_BUILTINS_OBJS += test-mktemp.o -TEST_BUILTINS_OBJS += test-oid-array.o TEST_BUILTINS_OBJS += test-online-cpus.o TEST_BUILTINS_OBJS += test-pack-mtimes.o TEST_BUILTINS_OBJS += test-parse-options.o @@ -1340,6 +1339,7 @@ UNIT_TEST_PROGRAMS += t-example-decorate UNIT_TEST_PROGRAMS += t-hash UNIT_TEST_PROGRAMS += t-hashmap UNIT_TEST_PROGRAMS += t-mem-pool +UNIT_TEST_PROGRAMS += t-oid-array UNIT_TEST_PROGRAMS += t-oidmap UNIT_TEST_PROGRAMS += t-oidtree UNIT_TEST_PROGRAMS += t-prio-queue @@ -1130,16 +1130,6 @@ cleanup: return res; } -static inline int log2i(int n) -{ - int log2 = 0; - - for (; n > 1; n >>= 1) - log2++; - - return log2; -} - static inline int exp2i(int n) { return 1 << n; @@ -1162,7 +1152,7 @@ int estimate_bisect_steps(int all) if (all < 3) return 0; - n = log2i(all); + n = log2u(all); e = exp2i(n); x = all - e; diff --git a/builtin/check-mailmap.c b/builtin/check-mailmap.c index b8a05b8e07..2334b57222 100644 --- a/builtin/check-mailmap.c +++ b/builtin/check-mailmap.c @@ -9,6 +9,7 @@ #include "write-or-die.h" static int use_stdin; +static const char *mailmap_file, *mailmap_blob; static const char * const check_mailmap_usage[] = { N_("git check-mailmap [<options>] <contact>..."), NULL @@ -16,6 +17,8 @@ NULL static const struct option check_mailmap_options[] = { OPT_BOOL(0, "stdin", &use_stdin, N_("also read contacts from stdin")), + OPT_FILENAME(0, "mailmap-file", &mailmap_file, N_("read additional mailmap entries from file")), + OPT_STRING(0, "mailmap-blob", &mailmap_blob, N_("blob"), N_("read additional mailmap entries from blob")), OPT_END() }; @@ -25,13 +28,17 @@ static void check_mailmap(struct string_list *mailmap, const char *contact) size_t namelen, maillen; struct ident_split ident; - if (split_ident_line(&ident, contact, strlen(contact))) - die(_("unable to parse contact: %s"), contact); - - name = ident.name_begin; - namelen = ident.name_end - ident.name_begin; - mail = ident.mail_begin; - maillen = ident.mail_end - ident.mail_begin; + if (!split_ident_line(&ident, contact, strlen(contact))) { + name = ident.name_begin; + namelen = ident.name_end - ident.name_begin; + mail = ident.mail_begin; + maillen = ident.mail_end - ident.mail_begin; + } else { + name = NULL; + namelen = 0; + mail = contact; + maillen = strlen(contact); + } map_user(mailmap, &mail, &maillen, &name, &namelen); @@ -52,6 +59,10 @@ int cmd_check_mailmap(int argc, const char **argv, const char *prefix) die(_("no contacts specified")); read_mailmap(&mailmap); + if (mailmap_blob) + read_mailmap_blob(&mailmap, mailmap_blob); + if (mailmap_file) + read_mailmap_file(&mailmap, mailmap_file, 0); for (i = 0; i < argc; ++i) check_mailmap(&mailmap, argv[i]); diff --git a/builtin/gc.c b/builtin/gc.c index 427faf1cfe..7dac971405 100644 --- a/builtin/gc.c +++ b/builtin/gc.c @@ -260,7 +260,7 @@ static int pack_refs_condition(UNUSED struct gc_config *cfg) return 1; } -static int maintenance_task_pack_refs(MAYBE_UNUSED struct maintenance_run_opts *opts, +static int maintenance_task_pack_refs(struct maintenance_run_opts *opts, UNUSED struct gc_config *cfg) { struct child_process cmd = CHILD_PROCESS_INIT; @@ -967,7 +967,7 @@ static int dfs_on_ref(const char *refname UNUSED, return result; } -static int should_write_commit_graph(struct gc_config *cfg) +static int should_write_commit_graph(struct gc_config *cfg UNUSED) { int result; struct cg_auto_data data; @@ -1005,7 +1005,7 @@ static int run_write_commit_graph(struct maintenance_run_opts *opts) } static int maintenance_task_commit_graph(struct maintenance_run_opts *opts, - struct gc_config *cfg) + struct gc_config *cfg UNUSED) { prepare_repo_settings(the_repository); if (!the_repository->settings.core_commit_graph) @@ -1040,7 +1040,7 @@ static int fetch_remote(struct remote *remote, void *cbdata) } static int maintenance_task_prefetch(struct maintenance_run_opts *opts, - struct gc_config *cfg) + struct gc_config *cfg UNUSED) { if (for_each_remote(fetch_remote, opts)) { error(_("failed to prefetch remotes")); @@ -1051,7 +1051,7 @@ static int maintenance_task_prefetch(struct maintenance_run_opts *opts, } static int maintenance_task_gc(struct maintenance_run_opts *opts, - struct gc_config *cfg) + struct gc_config *cfg UNUSED) { struct child_process child = CHILD_PROCESS_INIT; @@ -1100,7 +1100,7 @@ static int loose_object_count(const struct object_id *oid UNUSED, return 0; } -static int loose_object_auto_condition(struct gc_config *cfg) +static int loose_object_auto_condition(struct gc_config *cfg UNUSED) { int count = 0; @@ -1192,12 +1192,12 @@ static int pack_loose(struct maintenance_run_opts *opts) } static int maintenance_task_loose_objects(struct maintenance_run_opts *opts, - struct gc_config *cfg) + struct gc_config *cfg UNUSED) { return prune_packed(opts) || pack_loose(opts); } -static int incremental_repack_auto_condition(struct gc_config *cfg) +static int incremental_repack_auto_condition(struct gc_config *cfg UNUSED) { struct packed_git *p; int incremental_repack_auto_limit = 10; @@ -1317,7 +1317,7 @@ static int multi_pack_index_repack(struct maintenance_run_opts *opts) } static int maintenance_task_incremental_repack(struct maintenance_run_opts *opts, - struct gc_config *cfg) + struct gc_config *cfg UNUSED) { prepare_repo_settings(the_repository); if (!the_repository->settings.core_multi_pack_index) { diff --git a/builtin/index-pack.c b/builtin/index-pack.c index fd968d673d..763b01372a 100644 --- a/builtin/index-pack.c +++ b/builtin/index-pack.c @@ -1868,6 +1868,15 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix) if (!index_name && pack_name) index_name = derive_filename(pack_name, "pack", "idx", &index_name_buf); + /* + * Packfiles and indices do not carry enough information to be able to + * identify their object hash. So when we are neither in a repository + * nor has the user told us which object hash to use we have no other + * choice but to guess the object hash. + */ + if (!the_repository->hash_algo) + repo_set_hash_algo(the_repository, GIT_HASH_SHA1); + opts.flags &= ~(WRITE_REV | WRITE_REV_VERIFY); if (rev_index) { opts.flags |= verify ? WRITE_REV_VERIFY : WRITE_REV; diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c index 778be80f56..c6e2852d3c 100644 --- a/builtin/pack-objects.c +++ b/builtin/pack-objects.c @@ -1072,7 +1072,7 @@ static void write_reused_pack_one(struct packed_git *reuse_packfile, fixup = find_reused_offset(offset) - find_reused_offset(base_offset); if (fixup) { - unsigned char ofs_header[10]; + unsigned char ofs_header[MAX_PACK_OBJECT_HEADER]; unsigned i, ofs_len; off_t ofs = offset - base_offset - fixup; @@ -1191,6 +1191,7 @@ static void write_reused_pack(struct bitmapped_pack *reuse_packfile, size_t pos = (i * BITS_IN_EWORD); for (offset = 0; offset < BITS_IN_EWORD; ++offset) { + uint32_t pack_pos; if ((word >> offset) == 0) break; @@ -1199,14 +1200,41 @@ static void write_reused_pack(struct bitmapped_pack *reuse_packfile, continue; if (pos + offset >= reuse_packfile->bitmap_pos + reuse_packfile->bitmap_nr) goto done; - /* - * Can use bit positions directly, even for MIDX - * bitmaps. See comment in try_partial_reuse() - * for why. - */ - write_reused_pack_one(reuse_packfile->p, - pos + offset - reuse_packfile->bitmap_pos, - f, pack_start, &w_curs); + + if (reuse_packfile->bitmap_pos) { + /* + * When doing multi-pack reuse on a + * non-preferred pack, translate bit positions + * from the MIDX pseudo-pack order back to their + * pack-relative positions before attempting + * reuse. + */ + struct multi_pack_index *m = reuse_packfile->from_midx; + uint32_t midx_pos; + off_t pack_ofs; + + if (!m) + BUG("non-zero bitmap position without MIDX"); + + midx_pos = pack_pos_to_midx(m, pos + offset); + pack_ofs = nth_midxed_offset(m, midx_pos); + + if (offset_to_pack_pos(reuse_packfile->p, + pack_ofs, &pack_pos) < 0) + BUG("could not find expected object at offset %"PRIuMAX" in pack %s", + (uintmax_t)pack_ofs, + pack_basename(reuse_packfile->p)); + } else { + /* + * Can use bit positions directly, even for MIDX + * bitmaps. See comment in try_partial_reuse() + * for why. + */ + pack_pos = pos + offset; + } + + write_reused_pack_one(reuse_packfile->p, pack_pos, f, + pack_start, &w_curs); display_progress(progress_state, ++written); } } diff --git a/compat/mingw.c b/compat/mingw.c index 29d3f09768..eb13c02a76 100644 --- a/compat/mingw.c +++ b/compat/mingw.c @@ -243,7 +243,8 @@ static enum hide_dotfiles_type hide_dotfiles = HIDE_DOTFILES_DOTGITONLY; static char *unset_environment_variables; int mingw_core_config(const char *var, const char *value, - const struct config_context *ctx, void *cb) + const struct config_context *ctx UNUSED, + void *cb UNUSED) { if (!strcmp(var, "core.hidedotfiles")) { if (value && !strcasecmp(value, "dotgitonly")) @@ -453,7 +454,7 @@ static int set_hidden_flag(const wchar_t *path, int set) return -1; } -int mingw_mkdir(const char *path, int mode) +int mingw_mkdir(const char *path, int mode UNUSED) { int ret; wchar_t wpath[MAX_PATH]; @@ -597,7 +598,7 @@ int mingw_open (const char *filename, int oflags, ...) return fd; } -static BOOL WINAPI ctrl_ignore(DWORD type) +static BOOL WINAPI ctrl_ignore(DWORD type UNUSED) { return TRUE; } @@ -1085,7 +1086,7 @@ int mkstemp(char *template) return git_mkstemp_mode(template, 0600); } -int gettimeofday(struct timeval *tv, void *tz) +int gettimeofday(struct timeval *tv, void *tz UNUSED) { FILETIME ft; long long hnsec; @@ -2252,7 +2253,7 @@ char *mingw_query_user_email(void) return get_extended_user_info(NameUserPrincipal); } -struct passwd *getpwuid(int uid) +struct passwd *getpwuid(int uid UNUSED) { static unsigned initialized; static char user_name[100]; @@ -2304,7 +2305,7 @@ static sig_handler_t timer_fn = SIG_DFL, sigint_fn = SIG_DFL; * length to call the signal handler. */ -static unsigned __stdcall ticktack(void *dummy) +static unsigned __stdcall ticktack(void *dummy UNUSED) { while (WaitForSingleObject(timer_event, timer_interval) == WAIT_TIMEOUT) { mingw_raise(SIGALRM); @@ -2352,7 +2353,7 @@ static inline int is_timeval_eq(const struct timeval *i1, const struct timeval * return i1->tv_sec == i2->tv_sec && i1->tv_usec == i2->tv_usec; } -int setitimer(int type, struct itimerval *in, struct itimerval *out) +int setitimer(int type UNUSED, struct itimerval *in, struct itimerval *out) { static const struct timeval zero; static int atexit_done; diff --git a/compat/mingw.h b/compat/mingw.h index 27b61284f4..ebfb8ba423 100644 --- a/compat/mingw.h +++ b/compat/mingw.h @@ -122,17 +122,17 @@ struct utsname { * trivial stubs */ -static inline int readlink(const char *path, char *buf, size_t bufsiz) +static inline int readlink(const char *path UNUSED, char *buf UNUSED, size_t bufsiz UNUSED) { errno = ENOSYS; return -1; } -static inline int symlink(const char *oldpath, const char *newpath) +static inline int symlink(const char *oldpath UNUSED, const char *newpath UNUSED) { errno = ENOSYS; return -1; } -static inline int fchmod(int fildes, mode_t mode) +static inline int fchmod(int fildes UNUSED, mode_t mode UNUSED) { errno = ENOSYS; return -1; } #ifndef __MINGW64_VERSION_MAJOR static inline pid_t fork(void) { errno = ENOSYS; return -1; } #endif -static inline unsigned int alarm(unsigned int seconds) +static inline unsigned int alarm(unsigned int seconds UNUSED) { return 0; } static inline int fsync(int fd) { return _commit(fd); } @@ -140,9 +140,9 @@ static inline void sync(void) {} static inline uid_t getuid(void) { return 1; } -static inline struct passwd *getpwnam(const char *name) +static inline struct passwd *getpwnam(const char *name UNUSED) { return NULL; } -static inline int fcntl(int fd, int cmd, ...) +static inline int fcntl(int fd UNUSED, int cmd, ...) { if (cmd == F_GETFD || cmd == F_SETFD) return 0; @@ -151,17 +151,17 @@ static inline int fcntl(int fd, int cmd, ...) } #define sigemptyset(x) (void)0 -static inline int sigaddset(sigset_t *set, int signum) +static inline int sigaddset(sigset_t *set UNUSED, int signum UNUSED) { return 0; } #define SIG_BLOCK 0 #define SIG_UNBLOCK 0 -static inline int sigprocmask(int how, const sigset_t *set, sigset_t *oldset) +static inline int sigprocmask(int how UNUSED, const sigset_t *set UNUSED, sigset_t *oldset UNUSED) { return 0; } static inline pid_t getppid(void) { return 1; } static inline pid_t getpgid(pid_t pid) { return pid == 0 ? getpid() : pid; } -static inline pid_t tcgetpgrp(int fd) +static inline pid_t tcgetpgrp(int fd UNUSED) { return getpid(); } /* diff --git a/compat/nedmalloc/nedmalloc.c b/compat/nedmalloc/nedmalloc.c index 2c0ace7075..145255da43 100644 --- a/compat/nedmalloc/nedmalloc.c +++ b/compat/nedmalloc/nedmalloc.c @@ -31,6 +31,8 @@ DEALINGS IN THE SOFTWARE. /*#pragma optimize("a", on)*/ #endif +#pragma GCC diagnostic ignored "-Wunused-parameter" + /*#define FULLSANITYCHECKS*/ #include "nedmalloc.h" diff --git a/compat/regex/regcomp.c b/compat/regex/regcomp.c index 6c5d455e92..8d93a9b93f 100644 --- a/compat/regex/regcomp.c +++ b/compat/regex/regcomp.c @@ -17,6 +17,8 @@ License along with the GNU C Library; if not, see <http://www.gnu.org/licenses/>. */ +#pragma GCC diagnostic ignored "-Wunused-parameter" + #if defined __TANDEM /* This is currently duplicated from git-compat-utils.h */ # ifdef NO_INTPTR_T diff --git a/compat/stub/procinfo.c b/compat/stub/procinfo.c index 12c0a23c9e..3168cd5714 100644 --- a/compat/stub/procinfo.c +++ b/compat/stub/procinfo.c @@ -6,6 +6,6 @@ * Stub. See sample implementations in compat/linux/procinfo.c and * compat/win32/trace2_win32_process_info.c. */ -void trace2_collect_process_info(enum trace2_process_info_reason reason) +void trace2_collect_process_info(enum trace2_process_info_reason reason UNUSED) { } diff --git a/compat/terminal.c b/compat/terminal.c index 0afda730f2..d54efa1c5d 100644 --- a/compat/terminal.c +++ b/compat/terminal.c @@ -594,7 +594,7 @@ void restore_term(void) { } -char *git_terminal_prompt(const char *prompt, int echo) +char *git_terminal_prompt(const char *prompt, int echo UNUSED) { return getpass(prompt); } diff --git a/compat/win32/headless.c b/compat/win32/headless.c index 8b00dfe3bd..11392a0b9a 100644 --- a/compat/win32/headless.c +++ b/compat/win32/headless.c @@ -11,6 +11,8 @@ #include <stdlib.h> #include <wchar.h> +#pragma GCC diagnostic ignored "-Wunused-parameter" + /* * If `dir` contains the path to a Git exec directory, extend `PATH` to * include the corresponding `bin/` directory (which is where all those diff --git a/compat/win32/pthread.c b/compat/win32/pthread.c index 85f8f7920c..58980a529c 100644 --- a/compat/win32/pthread.c +++ b/compat/win32/pthread.c @@ -21,7 +21,7 @@ static unsigned __stdcall win32_start_routine(void *arg) return 0; } -int pthread_create(pthread_t *thread, const void *unused, +int pthread_create(pthread_t *thread, const void *attr UNUSED, void *(*start_routine)(void *), void *arg) { thread->arg = arg; diff --git a/compat/win32/pthread.h b/compat/win32/pthread.h index cc3221cb2c..e2b5c4f64c 100644 --- a/compat/win32/pthread.h +++ b/compat/win32/pthread.h @@ -18,7 +18,7 @@ */ #define pthread_mutex_t CRITICAL_SECTION -static inline int return_0(int i) { +static inline int return_0(int i UNUSED) { return 0; } #define pthread_mutex_init(a,b) return_0((InitializeCriticalSection((a)), 0)) @@ -70,7 +70,7 @@ static inline void NORETURN pthread_exit(void *ret) } typedef DWORD pthread_key_t; -static inline int pthread_key_create(pthread_key_t *keyp, void (*destructor)(void *value)) +static inline int pthread_key_create(pthread_key_t *keyp, void (*destructor)(void *value) UNUSED) { return (*keyp = TlsAlloc()) == TLS_OUT_OF_INDEXES ? EAGAIN : 0; } diff --git a/compat/win32/syslog.c b/compat/win32/syslog.c index 0af18d8882..4e4794743a 100644 --- a/compat/win32/syslog.c +++ b/compat/win32/syslog.c @@ -2,7 +2,7 @@ static HANDLE ms_eventlog; -void openlog(const char *ident, int logopt, int facility) +void openlog(const char *ident, int logopt UNUSED, int facility UNUSED) { if (ms_eventlog) return; diff --git a/compat/win32mmap.c b/compat/win32mmap.c index 519d51f2b6..a4ab4cb939 100644 --- a/compat/win32mmap.c +++ b/compat/win32mmap.c @@ -40,7 +40,7 @@ void *git_mmap(void *start, size_t length, int prot, int flags, int fd, off_t of return MAP_FAILED; } -int git_munmap(void *start, size_t length) +int git_munmap(void *start, size_t length UNUSED) { return !UnmapViewOfFile(start); } diff --git a/compat/winansi.c b/compat/winansi.c index 575813bde8..1b3f916b9f 100644 --- a/compat/winansi.c +++ b/compat/winansi.c @@ -340,7 +340,7 @@ enum { TEXT = 0, ESCAPE = 033, BRACKET = '[' }; -static DWORD WINAPI console_thread(LPVOID unused) +static DWORD WINAPI console_thread(LPVOID data UNUSED) { unsigned char buffer[BUFFER_SIZE]; DWORD bytes; diff --git a/config.mak.dev b/config.mak.dev index 5229c35484..50026d1e0e 100644 --- a/config.mak.dev +++ b/config.mak.dev @@ -54,7 +54,6 @@ ifeq ($(filter extra-all,$(DEVOPTS)),) DEVELOPER_CFLAGS += -Wno-empty-body DEVELOPER_CFLAGS += -Wno-missing-field-initializers DEVELOPER_CFLAGS += -Wno-sign-compare -DEVELOPER_CFLAGS += -Wno-unused-parameter endif endif diff --git a/git-compat-util.h b/git-compat-util.h index 71b4d23f03..e4a306dd56 100644 --- a/git-compat-util.h +++ b/git-compat-util.h @@ -195,6 +195,19 @@ struct strbuf; #define _NETBSD_SOURCE 1 #define _SGI_SOURCE 1 +/* + * UNUSED marks a function parameter that is always unused. It also + * can be used to annotate a function, a variable, or a type that is + * always unused. + * + * A callback interface may dictate that a function accepts a + * parameter at that position, but the implementation of the function + * may not need to use the parameter. In such a case, mark the parameter + * with UNUSED. + * + * When a parameter may be used or unused, depending on conditional + * compilation, consider using MAYBE_UNUSED instead. + */ #if GIT_GNUC_PREREQ(4, 5) #define UNUSED __attribute__((unused)) \ __attribute__((deprecated ("parameter declared as UNUSED"))) @@ -649,6 +662,17 @@ static inline int git_has_dir_sep(const char *path) #define RESULT_MUST_BE_USED #endif +/* + * MAYBE_UNUSED marks a function parameter that may be unused, but + * whose use is not an error. It also can be used to annotate a + * function, a variable, or a type that may be unused. + * + * Depending on a configuration, all uses of such a thing may become + * #ifdef'ed away. Marking it with UNUSED would give a warning in a + * compilation where it is indeed used, and not marking it at all + * would give a warning in a compilation where it is unused. In such + * a case, MAYBE_UNUSED is the appropriate annotation to use. + */ #define MAYBE_UNUSED __attribute__((__unused__)) #include "compat/bswap.h" diff --git a/git-send-email.perl b/git-send-email.perl index cdcee1d0cf..c835d4c11a 100755 --- a/git-send-email.perl +++ b/git-send-email.perl @@ -47,6 +47,8 @@ git send-email --translate-aliases --compose-encoding <str> * Encoding to assume for introduction. --8bit-encoding <str> * Encoding to assume 8bit mails if undeclared --transfer-encoding <str> * Transfer encoding to use (quoted-printable, 8bit, base64) + --[no-]mailmap * Use mailmap file to map all email addresses to canonical + real names and email addresses. Sending: --envelope-sender <str> * Email envelope sender. @@ -278,12 +280,14 @@ my (@suppress_cc); my ($auto_8bit_encoding); my ($compose_encoding); my ($sendmail_cmd); +my ($mailmap_file, $mailmap_blob); # Variables with corresponding config settings & hardcoded defaults my ($debug_net_smtp) = 0; # Net::SMTP, see send_message() my $thread = 1; my $chain_reply_to = 0; my $use_xmailer = 1; my $validate = 1; +my $mailmap = 0; my $target_xfer_encoding = 'auto'; my $forbid_sendmail_variables = 1; @@ -300,6 +304,7 @@ my %config_bool_settings = ( "annotate" => \$annotate, "xmailer" => \$use_xmailer, "forbidsendmailvariables" => \$forbid_sendmail_variables, + "mailmap" => \$mailmap, ); my %config_settings = ( @@ -333,6 +338,8 @@ my %config_settings = ( my %config_path_settings = ( "aliasesfile" => \@alias_files, "smtpsslcertpath" => \$smtp_ssl_cert_path, + "mailmap.file" => \$mailmap_file, + "mailmap.blob" => \$mailmap_blob, ); # Handle Uncouth Termination @@ -533,6 +540,8 @@ my %options = ( "thread!" => \$thread, "validate!" => \$validate, "transfer-encoding=s" => \$target_xfer_encoding, + "mailmap!" => \$mailmap, + "use-mailmap!" => \$mailmap, "format-patch!" => \$format_patch, "8bit-encoding=s" => \$auto_8bit_encoding, "compose-encoding=s" => \$compose_encoding, @@ -1104,6 +1113,16 @@ if ($compose && $compose > 0) { our ($message_id, %mail, $subject, $in_reply_to, $references, $message, $needs_confirm, $message_num, $ask_default); +sub mailmap_address_list { + return @_ unless @_ and $mailmap; + my @options = (); + push(@options, "--mailmap-file=$mailmap_file") if $mailmap_file; + push(@options, "--mailmap-blob=$mailmap_blob") if $mailmap_blob; + my @addr_list = Git::command('check-mailmap', @options, @_); + s/^<(.*)>$/$1/ for @addr_list; + return @addr_list; +} + sub extract_valid_address { my $address = shift; my $local_part_regexp = qr/[^<>"\s@]+/; @@ -1313,6 +1332,7 @@ sub process_address_list { @addr_list = expand_aliases(@addr_list); @addr_list = sanitize_address_list(@addr_list); @addr_list = validate_address_list(@addr_list); + @addr_list = mailmap_address_list(@addr_list); return @addr_list; } @@ -245,7 +245,7 @@ static int is_fixed(const char *s, size_t len) #ifdef USE_LIBPCRE2 #define GREP_PCRE2_DEBUG_MALLOC 0 -static void *pcre2_malloc(PCRE2_SIZE size, MAYBE_UNUSED void *memory_data) +static void *pcre2_malloc(PCRE2_SIZE size, void *memory_data UNUSED) { void *pointer = malloc(size); #if GREP_PCRE2_DEBUG_MALLOC @@ -255,7 +255,7 @@ static void *pcre2_malloc(PCRE2_SIZE size, MAYBE_UNUSED void *memory_data) return pointer; } -static void pcre2_free(void *pointer, MAYBE_UNUSED void *memory_data) +static void pcre2_free(void *pointer, void *memory_data UNUSED) { #if GREP_PCRE2_DEBUG_MALLOC static int count = 1; diff --git a/mailinfo.c b/mailinfo.c index ce1455f943..d1f42bd7e3 100644 --- a/mailinfo.c +++ b/mailinfo.c @@ -348,9 +348,8 @@ static void cleanup_subject(struct mailinfo *mi, struct strbuf *subject) strbuf_trim(subject); } -#define MAX_HDR_PARSED 10 -static const char *header[MAX_HDR_PARSED] = { - "From","Subject","Date", +static const char * const header[] = { + "From", "Subject", "Date", }; static inline int skip_header(const struct strbuf *line, const char *hdr, @@ -585,7 +584,7 @@ static int check_header(struct mailinfo *mi, struct strbuf sb = STRBUF_INIT; /* search for the interesting parts */ - for (i = 0; header[i]; i++) { + for (i = 0; i < ARRAY_SIZE(header); i++) { if ((!hdr_data[i] || overwrite) && parse_header(line, header[i], mi, &sb)) { handle_header(&hdr_data[i], &sb); @@ -627,7 +626,7 @@ static int is_inbody_header(const struct mailinfo *mi, { int i; const char *val; - for (i = 0; header[i]; i++) + for (i = 0; i < ARRAY_SIZE(header); i++) if (!mi->s_hdr_data[i] && skip_header(line, header[i], &val)) return 1; return 0; @@ -774,7 +773,7 @@ static int check_inbody_header(struct mailinfo *mi, const struct strbuf *line) return is_format_patch_separator(line->buf + 1, line->len - 1); if (starts_with(line->buf, "[PATCH]") && isspace(line->buf[7])) { int i; - for (i = 0; header[i]; i++) + for (i = 0; i < ARRAY_SIZE(header); i++) if (!strcmp("Subject", header[i])) { handle_header(&mi->s_hdr_data[i], line); return 1; @@ -826,7 +825,7 @@ static int handle_commit_msg(struct mailinfo *mi, struct strbuf *line) * We may have already read "secondary headers"; purge * them to give ourselves a clean restart. */ - for (i = 0; header[i]; i++) { + for (i = 0; i < ARRAY_SIZE(header); i++) { if (mi->s_hdr_data[i]) strbuf_release(mi->s_hdr_data[i]); FREE_AND_NULL(mi->s_hdr_data[i]); @@ -1157,7 +1156,7 @@ static void handle_info(struct mailinfo *mi) struct strbuf *hdr; int i; - for (i = 0; header[i]; i++) { + for (i = 0; i < ARRAY_SIZE(header); i++) { /* only print inbody headers if we output a patch file */ if (mi->patch_lines && mi->s_hdr_data[i]) hdr = mi->s_hdr_data[i]; @@ -1208,8 +1207,8 @@ int mailinfo(struct mailinfo *mi, const char *msg, const char *patch) return -1; } - mi->p_hdr_data = xcalloc(MAX_HDR_PARSED, sizeof(*(mi->p_hdr_data))); - mi->s_hdr_data = xcalloc(MAX_HDR_PARSED, sizeof(*(mi->s_hdr_data))); + mi->p_hdr_data = xcalloc(ARRAY_SIZE(header), sizeof(*(mi->p_hdr_data))); + mi->s_hdr_data = xcalloc(ARRAY_SIZE(header), sizeof(*(mi->s_hdr_data))); do { peek = fgetc(mi->input); @@ -1292,7 +1291,7 @@ void clear_mailinfo(struct mailinfo *mi) strbuf_release(&mi->inbody_header_accum); free(mi->message_id); - for (size_t i = 0; header[i]; i++) { + for (size_t i = 0; i < ARRAY_SIZE(header); i++) { if (!mi->p_hdr_data[i]) continue; strbuf_release(mi->p_hdr_data[i]); @@ -1300,7 +1299,7 @@ void clear_mailinfo(struct mailinfo *mi) } free(mi->p_hdr_data); - for (size_t i = 0; header[i]; i++) { + for (size_t i = 0; i < ARRAY_SIZE(header); i++) { if (!mi->s_hdr_data[i]) continue; strbuf_release(mi->s_hdr_data[i]); @@ -142,11 +142,8 @@ static void read_mailmap_line(struct string_list *map, char *buffer) add_mapping(map, name1, email1, name2, email2); } -/* Flags for read_mailmap_file() */ -#define MAILMAP_NOFOLLOW (1<<0) - -static int read_mailmap_file(struct string_list *map, const char *filename, - unsigned flags) +int read_mailmap_file(struct string_list *map, const char *filename, + unsigned flags) { char buffer[1024]; FILE *f; @@ -186,7 +183,7 @@ static void read_mailmap_string(struct string_list *map, char *buf) } } -static int read_mailmap_blob(struct string_list *map, const char *name) +int read_mailmap_blob(struct string_list *map, const char *name) { struct object_id oid; char *buf; @@ -6,6 +6,13 @@ struct string_list; extern char *git_mailmap_file; extern char *git_mailmap_blob; +/* Flags for read_mailmap_file() */ +#define MAILMAP_NOFOLLOW (1<<0) + +int read_mailmap_file(struct string_list *map, const char *filename, + unsigned flags); +int read_mailmap_blob(struct string_list *map, const char *name); + int read_mailmap(struct string_list *map); void clear_mailmap(struct string_list *map); diff --git a/mergetools/vscode b/mergetools/vscode new file mode 100644 index 0000000000..3b39b458d6 --- /dev/null +++ b/mergetools/vscode @@ -0,0 +1,19 @@ +diff_cmd () { + "$merge_tool_path" --wait --diff "$LOCAL" "$REMOTE" +} + +diff_cmd_help () { + echo "Use Visual Studio Code (requires a graphical session)" +} + +merge_cmd () { + "$merge_tool_path" --wait --merge "$REMOTE" "$LOCAL" "$BASE" "$MERGED" +} + +merge_cmd_help () { + echo "Use Visual Studio Code (requires a graphical session)" +} + +translate_merge_tool_path () { + echo code +} @@ -496,6 +496,7 @@ int nth_bitmapped_pack(struct repository *r, struct multi_pack_index *m, MIDX_CHUNK_BITMAPPED_PACKS_WIDTH * local_pack_int_id + sizeof(uint32_t)); bp->pack_int_id = pack_int_id; + bp->from_midx = m; return 0; } diff --git a/pack-bitmap.c b/pack-bitmap.c index 2e657a2aa4..9d9b8c4bfb 100644 --- a/pack-bitmap.c +++ b/pack-bitmap.c @@ -2055,17 +2055,18 @@ static int try_partial_reuse(struct bitmap_index *bitmap_git, struct bitmapped_pack *pack, size_t bitmap_pos, uint32_t pack_pos, + off_t offset, struct bitmap *reuse, struct pack_window **w_curs) { - off_t offset, delta_obj_offset; + off_t delta_obj_offset; enum object_type type; unsigned long size; if (pack_pos >= pack->p->num_objects) return -1; /* not actually in the pack */ - offset = delta_obj_offset = pack_pos_to_offset(pack->p, pack_pos); + delta_obj_offset = offset; type = unpack_object_header(pack->p, w_curs, &offset, &size); if (type < 0) return -1; /* broken packfile, punt */ @@ -2184,6 +2185,7 @@ static void reuse_partial_packfile_from_bitmap_1(struct bitmap_index *bitmap_git for (offset = 0; offset < BITS_IN_EWORD; offset++) { size_t bit_pos; uint32_t pack_pos; + off_t ofs; if (word >> offset == 0) break; @@ -2198,7 +2200,6 @@ static void reuse_partial_packfile_from_bitmap_1(struct bitmap_index *bitmap_git if (bitmap_is_midx(bitmap_git)) { uint32_t midx_pos; - off_t ofs; midx_pos = pack_pos_to_midx(bitmap_git->midx, bit_pos); ofs = nth_midxed_offset(bitmap_git->midx, midx_pos); @@ -2213,10 +2214,12 @@ static void reuse_partial_packfile_from_bitmap_1(struct bitmap_index *bitmap_git BUG("advanced beyond the end of pack %s (%"PRIuMAX" > %"PRIu32")", pack_basename(pack->p), (uintmax_t)pack_pos, pack->p->num_objects); + + ofs = pack_pos_to_offset(pack->p, pack_pos); } if (try_partial_reuse(bitmap_git, pack, bit_pos, - pack_pos, reuse, &w_curs) < 0) { + pack_pos, ofs, reuse, &w_curs) < 0) { /* * try_partial_reuse indicated we couldn't reuse * any bits, so there is no point in trying more @@ -2322,6 +2325,7 @@ void reuse_partial_packfile_from_bitmap(struct bitmap_index *bitmap_git, packs[packs_nr].pack_int_id = pack_int_id; packs[packs_nr].bitmap_nr = pack->num_objects; packs[packs_nr].bitmap_pos = 0; + packs[packs_nr].from_midx = bitmap_git->midx; objects_nr = packs[packs_nr++].bitmap_nr; } diff --git a/pack-bitmap.h b/pack-bitmap.h index ff0fd815b8..d7f4b8b8e9 100644 --- a/pack-bitmap.h +++ b/pack-bitmap.h @@ -60,6 +60,7 @@ struct bitmapped_pack { uint32_t bitmap_pos; uint32_t bitmap_nr; + struct multi_pack_index *from_midx; /* MIDX only */ uint32_t pack_int_id; /* MIDX only */ }; diff --git a/refs/files-backend.c b/refs/files-backend.c index 1cff65f6ae..c7f3f4e591 100644 --- a/refs/files-backend.c +++ b/refs/files-backend.c @@ -1311,6 +1311,68 @@ static int should_pack_ref(struct files_ref_store *refs, return 0; } +static int should_pack_refs(struct files_ref_store *refs, + struct pack_refs_opts *opts) +{ + struct ref_iterator *iter; + size_t packed_size; + size_t refcount = 0; + size_t limit; + int ret; + + if (!(opts->flags & PACK_REFS_AUTO)) + return 1; + + ret = packed_refs_size(refs->packed_ref_store, &packed_size); + if (ret < 0) + die("cannot determine packed-refs size"); + + /* + * Packing loose references into the packed-refs file scales with the + * number of references we're about to write. We thus decide whether we + * repack refs by weighing the current size of the packed-refs file + * against the number of loose references. This is done such that we do + * not repack too often on repositories with a huge number of + * references, where we can expect a lot of churn in the number of + * references. + * + * As a heuristic, we repack if the number of loose references in the + * repository exceeds `log2(nr_packed_refs) * 5`, where we estimate + * `nr_packed_refs = packed_size / 100`, which scales as following: + * + * - 1kB ~ 10 packed refs: 16 refs + * - 10kB ~ 100 packed refs: 33 refs + * - 100kB ~ 1k packed refs: 49 refs + * - 1MB ~ 10k packed refs: 66 refs + * - 10MB ~ 100k packed refs: 82 refs + * - 100MB ~ 1m packed refs: 99 refs + * + * We thus allow roughly 16 additional loose refs per factor of ten of + * packed refs. This heuristic may be tweaked in the future, but should + * serve as a sufficiently good first iteration. + */ + limit = log2u(packed_size / 100) * 5; + if (limit < 16) + limit = 16; + + iter = cache_ref_iterator_begin(get_loose_ref_cache(refs, 0), NULL, + refs->base.repo, 0); + while ((ret = ref_iterator_advance(iter)) == ITER_OK) { + if (should_pack_ref(refs, iter->refname, iter->oid, + iter->flags, opts)) + refcount++; + if (refcount >= limit) { + ref_iterator_abort(iter); + return 1; + } + } + + if (ret != ITER_DONE) + die("error while iterating over references"); + + return 0; +} + static int files_pack_refs(struct ref_store *ref_store, struct pack_refs_opts *opts) { @@ -1323,6 +1385,9 @@ static int files_pack_refs(struct ref_store *ref_store, struct strbuf err = STRBUF_INIT; struct ref_transaction *transaction; + if (!should_pack_refs(refs, opts)) + return 0; + transaction = ref_store_transaction_begin(refs->packed_ref_store, &err); if (!transaction) return -1; @@ -1946,10 +2011,13 @@ static int commit_ref_update(struct files_ref_store *refs, return 0; } +#ifdef NO_SYMLINK_HEAD +#define create_ref_symlink(a, b) (-1) +#else static int create_ref_symlink(struct ref_lock *lock, const char *target) { int ret = -1; -#ifndef NO_SYMLINK_HEAD + char *ref_path = get_locked_file_path(&lock->lk); unlink(ref_path); ret = symlink(target, ref_path); @@ -1957,9 +2025,9 @@ static int create_ref_symlink(struct ref_lock *lock, const char *target) if (ret) fprintf(stderr, "no symlink - falling back to symbolic ref\n"); -#endif return ret; } +#endif static int create_symref_lock(struct ref_lock *lock, const char *target, struct strbuf *err) diff --git a/refs/packed-backend.c b/refs/packed-backend.c index 7a0a695ca2..07c57fd541 100644 --- a/refs/packed-backend.c +++ b/refs/packed-backend.c @@ -1250,6 +1250,24 @@ int packed_refs_is_locked(struct ref_store *ref_store) return is_lock_file_locked(&refs->lock); } +int packed_refs_size(struct ref_store *ref_store, + size_t *out) +{ + struct packed_ref_store *refs = packed_downcast(ref_store, REF_STORE_READ, + "packed_refs_size"); + struct stat st; + + if (stat(refs->path, &st) < 0) { + if (errno != ENOENT) + return -1; + *out = 0; + return 0; + } + + *out = st.st_size; + return 0; +} + /* * The packed-refs header line that we write out. Perhaps other traits * will be added later. diff --git a/refs/packed-backend.h b/refs/packed-backend.h index 09437ad13b..9481d5e7c2 100644 --- a/refs/packed-backend.h +++ b/refs/packed-backend.h @@ -28,6 +28,13 @@ void packed_refs_unlock(struct ref_store *ref_store); int packed_refs_is_locked(struct ref_store *ref_store); /* + * Obtain the size of the `packed-refs` file. Reports `0` as size in case there + * is no packed-refs file. Returns 0 on success, negative otherwise. + */ +int packed_refs_size(struct ref_store *ref_store, + size_t *out); + +/* * Return true if `transaction` really needs to be carried out against * the specified packed_ref_store, or false if it can be skipped * (i.e., because it is an obvious NOOP). `ref_store` must be locked diff --git a/revision.c b/revision.c index ac94f8d429..2d7ad2bddf 100644 --- a/revision.c +++ b/revision.c @@ -4407,6 +4407,7 @@ static struct commit *get_revision_internal(struct rev_info *revs) c = get_revision_1(revs); if (!c) break; + free_commit_buffer(revs->repo->parsed_objects, c); } } diff --git a/t/helper/test-oid-array.c b/t/helper/test-oid-array.c deleted file mode 100644 index 076b849cbf..0000000000 --- a/t/helper/test-oid-array.c +++ /dev/null @@ -1,49 +0,0 @@ -#define USE_THE_REPOSITORY_VARIABLE - -#include "test-tool.h" -#include "hex.h" -#include "oid-array.h" -#include "setup.h" -#include "strbuf.h" - -static int print_oid(const struct object_id *oid, void *data UNUSED) -{ - puts(oid_to_hex(oid)); - return 0; -} - -int cmd__oid_array(int argc UNUSED, const char **argv UNUSED) -{ - struct oid_array array = OID_ARRAY_INIT; - struct strbuf line = STRBUF_INIT; - int nongit_ok; - - setup_git_directory_gently(&nongit_ok); - if (nongit_ok) - repo_set_hash_algo(the_repository, GIT_HASH_SHA1); - - while (strbuf_getline(&line, stdin) != EOF) { - const char *arg; - struct object_id oid; - - if (skip_prefix(line.buf, "append ", &arg)) { - if (get_oid_hex(arg, &oid)) - die("not a hexadecimal oid: %s", arg); - oid_array_append(&array, &oid); - } else if (skip_prefix(line.buf, "lookup ", &arg)) { - if (get_oid_hex(arg, &oid)) - die("not a hexadecimal oid: %s", arg); - printf("%d\n", oid_array_lookup(&array, &oid)); - } else if (!strcmp(line.buf, "clear")) - oid_array_clear(&array); - else if (!strcmp(line.buf, "for_each_unique")) - oid_array_for_each_unique(&array, print_oid, NULL); - else - die("unknown command: %s", line.buf); - } - - strbuf_release(&line); - oid_array_clear(&array); - - return 0; -} diff --git a/t/helper/test-tool.c b/t/helper/test-tool.c index f8a67df7de..7005b7d0bf 100644 --- a/t/helper/test-tool.c +++ b/t/helper/test-tool.c @@ -43,7 +43,6 @@ static struct test_cmd cmds[] = { { "match-trees", cmd__match_trees }, { "mergesort", cmd__mergesort }, { "mktemp", cmd__mktemp }, - { "oid-array", cmd__oid_array }, { "online-cpus", cmd__online_cpus }, { "pack-mtimes", cmd__pack_mtimes }, { "parse-options", cmd__parse_options }, diff --git a/t/helper/test-tool.h b/t/helper/test-tool.h index e74bc0ffd4..b51f79e774 100644 --- a/t/helper/test-tool.h +++ b/t/helper/test-tool.h @@ -64,7 +64,6 @@ int cmd__scrap_cache_tree(int argc, const char **argv); int cmd__serve_v2(int argc, const char **argv); int cmd__sha1(int argc, const char **argv); int cmd__sha1_is_sha1dc(int argc, const char **argv); -int cmd__oid_array(int argc, const char **argv); int cmd__sha256(int argc, const char **argv); int cmd__sigchain(int argc, const char **argv); int cmd__simple_ipc(int argc, const char **argv); diff --git a/t/t0064-oid-array.sh b/t/t0064-oid-array.sh deleted file mode 100755 index de74b692d0..0000000000 --- a/t/t0064-oid-array.sh +++ /dev/null @@ -1,122 +0,0 @@ -#!/bin/sh - -test_description='basic tests for the oid array implementation' - -TEST_PASSES_SANITIZE_LEAK=true -. ./test-lib.sh - -echoid () { - prefix="${1:+$1 }" - shift - while test $# -gt 0 - do - echo "$prefix$ZERO_OID" | sed -e "s/00/$1/g" - shift - done -} - -test_expect_success 'without repository' ' - cat >expect <<-EOF && - 4444444444444444444444444444444444444444 - 5555555555555555555555555555555555555555 - 8888888888888888888888888888888888888888 - aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa - EOF - cat >input <<-EOF && - append 4444444444444444444444444444444444444444 - append 5555555555555555555555555555555555555555 - append 8888888888888888888888888888888888888888 - append aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa - for_each_unique - EOF - nongit test-tool oid-array <input >actual && - test_cmp expect actual -' - -test_expect_success 'ordered enumeration' ' - echoid "" 44 55 88 aa >expect && - { - echoid append 88 44 aa 55 && - echo for_each_unique - } | test-tool oid-array >actual && - test_cmp expect actual -' - -test_expect_success 'ordered enumeration with duplicate suppression' ' - echoid "" 44 55 88 aa >expect && - { - echoid append 88 44 aa 55 && - echoid append 88 44 aa 55 && - echoid append 88 44 aa 55 && - echo for_each_unique - } | test-tool oid-array >actual && - test_cmp expect actual -' - -test_expect_success 'lookup' ' - { - echoid append 88 44 aa 55 && - echoid lookup 55 - } | test-tool oid-array >actual && - n=$(cat actual) && - test "$n" -eq 1 -' - -test_expect_success 'lookup non-existing entry' ' - { - echoid append 88 44 aa 55 && - echoid lookup 33 - } | test-tool oid-array >actual && - n=$(cat actual) && - test "$n" -lt 0 -' - -test_expect_success 'lookup with duplicates' ' - { - echoid append 88 44 aa 55 && - echoid append 88 44 aa 55 && - echoid append 88 44 aa 55 && - echoid lookup 55 - } | test-tool oid-array >actual && - n=$(cat actual) && - test "$n" -ge 3 && - test "$n" -le 5 -' - -test_expect_success 'lookup non-existing entry with duplicates' ' - { - echoid append 88 44 aa 55 && - echoid append 88 44 aa 55 && - echoid append 88 44 aa 55 && - echoid lookup 66 - } | test-tool oid-array >actual && - n=$(cat actual) && - test "$n" -lt 0 -' - -test_expect_success 'lookup with almost duplicate values' ' - # n-1 5s - root=$(echoid "" 55) && - root=${root%5} && - { - id1="${root}5" && - id2="${root}f" && - echo "append $id1" && - echo "append $id2" && - echoid lookup 55 - } | test-tool oid-array >actual && - n=$(cat actual) && - test "$n" -eq 0 -' - -test_expect_success 'lookup with single duplicate value' ' - { - echoid append 55 55 && - echoid lookup 55 - } | test-tool oid-array >actual && - n=$(cat actual) && - test "$n" -ge 0 && - test "$n" -le 1 -' - -test_done diff --git a/t/t0601-reffiles-pack-refs.sh b/t/t0601-reffiles-pack-refs.sh index 60a544b8ee..d8cbd3f202 100755 --- a/t/t0601-reffiles-pack-refs.sh +++ b/t/t0601-reffiles-pack-refs.sh @@ -161,13 +161,6 @@ test_expect_success 'test --exclude takes precedence over --include' ' git pack-refs --include "refs/heads/pack*" --exclude "refs/heads/pack*" && test -f .git/refs/heads/dont_pack5' -test_expect_success '--auto packs and prunes refs as usual' ' - git branch auto && - test_path_is_file .git/refs/heads/auto && - git pack-refs --auto --all && - test_path_is_missing .git/refs/heads/auto -' - test_expect_success 'see if up-to-date packed refs are preserved' ' git branch q && git pack-refs --all --prune && @@ -367,14 +360,90 @@ test_expect_success 'pack-refs does not drop broken refs during deletion' ' test_cmp expect actual ' -test_expect_success 'maintenance --auto unconditionally packs loose refs' ' - git update-ref refs/heads/something HEAD && - test_path_is_file .git/refs/heads/something && - git rev-parse refs/heads/something >expect && - git maintenance run --task=pack-refs --auto && - test_path_is_missing .git/refs/heads/something && - git rev-parse refs/heads/something >actual && - test_cmp expect actual -' +for command in "git pack-refs --all --auto" "git maintenance run --task=pack-refs --auto" +do + test_expect_success "$command does not repack below 16 refs without packed-refs" ' + test_when_finished "rm -rf repo" && + git init repo && + ( + cd repo && + git config set maintenance.auto false && + git commit --allow-empty --message "initial" && + + # Create 14 additional references, which brings us to + # 15 together with the default branch. + printf "create refs/heads/loose-%d HEAD\n" $(test_seq 14) >stdin && + git update-ref --stdin <stdin && + test_path_is_missing .git/packed-refs && + git pack-refs --auto --all && + test_path_is_missing .git/packed-refs && + + # Create the 16th reference, which should cause us to repack. + git update-ref refs/heads/loose-15 HEAD && + git pack-refs --auto --all && + test_path_is_file .git/packed-refs + ) + ' + + test_expect_success "$command does not repack below 16 refs with small packed-refs" ' + test_when_finished "rm -rf repo" && + git init repo && + ( + cd repo && + git config set maintenance.auto false && + git commit --allow-empty --message "initial" && + + git pack-refs --all && + test_line_count = 2 .git/packed-refs && + + # Create 15 loose references. + printf "create refs/heads/loose-%d HEAD\n" $(test_seq 15) >stdin && + git update-ref --stdin <stdin && + git pack-refs --auto --all && + test_line_count = 2 .git/packed-refs && + + # Create the 16th loose reference, which should cause us to repack. + git update-ref refs/heads/loose-17 HEAD && + git pack-refs --auto --all && + test_line_count = 18 .git/packed-refs + ) + ' + + test_expect_success "$command scales with size of packed-refs" ' + test_when_finished "rm -rf repo" && + git init repo && + ( + cd repo && + git config set maintenance.auto false && + git commit --allow-empty --message "initial" && + + # Create 99 packed refs. This should cause the heuristic + # to require more than the minimum amount of loose refs. + test_seq 99 | + while read i + do + printf "create refs/heads/packed-%d HEAD\n" $i || return 1 + done >stdin && + git update-ref --stdin <stdin && + git pack-refs --all && + test_line_count = 101 .git/packed-refs && + + # Create 24 loose refs, which should not yet cause us to repack. + printf "create refs/heads/loose-%d HEAD\n" $(test_seq 24) >stdin && + git update-ref --stdin <stdin && + git pack-refs --auto --all && + test_line_count = 101 .git/packed-refs && + + # Create another handful of refs to cross the border. + # Note that we explicitly do not check for strict + # boundaries here, as this also depends on the size of + # the object hash. + printf "create refs/heads/addn-%d HEAD\n" $(test_seq 10) >stdin && + git update-ref --stdin <stdin && + git pack-refs --auto --all && + test_line_count = 135 .git/packed-refs + ) + ' +done test_done diff --git a/t/t4203-mailmap.sh b/t/t4203-mailmap.sh index 79e5f42760..2265ff8872 100755 --- a/t/t4203-mailmap.sh +++ b/t/t4203-mailmap.sh @@ -72,12 +72,46 @@ test_expect_success 'check-mailmap --stdin arguments: mapping' ' test_cmp expect actual ' -test_expect_success 'check-mailmap bogus contact' ' - test_must_fail git check-mailmap bogus +test_expect_success 'check-mailmap simple address: mapping' ' + test_when_finished "rm .mailmap" && + cat >.mailmap <<-EOF && + New Name <$GIT_AUTHOR_EMAIL> + EOF + cat .mailmap >expect && + git check-mailmap "$GIT_AUTHOR_EMAIL" >actual && + test_cmp expect actual +' + +test_expect_success 'check-mailmap --stdin simple address: mapping' ' + test_when_finished "rm .mailmap" && + cat >.mailmap <<-EOF && + New Name <$GIT_AUTHOR_EMAIL> + EOF + cat >stdin <<-EOF && + $GIT_AUTHOR_EMAIL + EOF + cat .mailmap >expect && + git check-mailmap --stdin <stdin >actual && + test_cmp expect actual +' + +test_expect_success 'check-mailmap simple address: no mapping' ' + cat >expect <<-EOF && + <bugs@company.xx> + EOF + git check-mailmap "bugs@company.xx" >actual && + test_cmp expect actual ' -test_expect_success 'check-mailmap bogus contact --stdin' ' - test_must_fail git check-mailmap --stdin bogus </dev/null +test_expect_success 'check-mailmap --stdin simple address: no mapping' ' + cat >expect <<-EOF && + <bugs@company.xx> + EOF + cat >stdin <<-EOF && + bugs@company.xx + EOF + git check-mailmap --stdin <stdin >actual && + test_cmp expect actual ' test_expect_success 'No mailmap' ' diff --git a/t/t5300-pack-object.sh b/t/t5300-pack-object.sh index 4ad023c846..3b9dae331a 100755 --- a/t/t5300-pack-object.sh +++ b/t/t5300-pack-object.sh @@ -635,4 +635,43 @@ test_expect_success 'negative window clamps to 0' ' check_deltas stderr = 0 ' +for hash in sha1 sha256 +do + test_expect_success "verify-pack with $hash packfile" ' + test_when_finished "rm -rf repo" && + git init --object-format=$hash repo && + test_commit -C repo initial && + git -C repo repack -ad && + git -C repo verify-pack "$(pwd)"/repo/.git/objects/pack/*.idx && + if test $hash = sha1 + then + nongit git verify-pack "$(pwd)"/repo/.git/objects/pack/*.idx + else + # We have no way to identify the hash used by packfiles + # or indices, so we always fall back to SHA1. + nongit test_must_fail git verify-pack "$(pwd)"/repo/.git/objects/pack/*.idx && + # But with an explicit object format we should succeed. + nongit git verify-pack --object-format=$hash "$(pwd)"/repo/.git/objects/pack/*.idx + fi + ' + + test_expect_success "index-pack outside of a $hash repository" ' + test_when_finished "rm -rf repo" && + git init --object-format=$hash repo && + test_commit -C repo initial && + git -C repo repack -ad && + git -C repo index-pack --verify "$(pwd)"/repo/.git/objects/pack/*.pack && + if test $hash = sha1 + then + nongit git index-pack --verify "$(pwd)"/repo/.git/objects/pack/*.pack + else + # We have no way to identify the hash used by packfiles + # or indices, so we always fall back to SHA1. + nongit test_must_fail git index-pack --verify "$(pwd)"/repo/.git/objects/pack/*.pack 2>err && + # But with an explicit object format we should succeed. + nongit git index-pack --object-format=$hash --verify "$(pwd)"/repo/.git/objects/pack/*.pack + fi + ' +done + test_done diff --git a/t/t5332-multi-pack-reuse.sh b/t/t5332-multi-pack-reuse.sh index 941e73d354..955ea42769 100755 --- a/t/t5332-multi-pack-reuse.sh +++ b/t/t5332-multi-pack-reuse.sh @@ -31,20 +31,24 @@ test_pack_objects_reused_all () { : >trace2.txt && GIT_TRACE2_EVENT="$PWD/trace2.txt" \ git pack-objects --stdout --revs --all --delta-base-offset \ - >/dev/null && + >got.pack && test_pack_reused "$1" <trace2.txt && - test_packs_reused "$2" <trace2.txt + test_packs_reused "$2" <trace2.txt && + + git index-pack --strict -o got.idx got.pack } # test_pack_objects_reused <pack-reused> <packs-reused> test_pack_objects_reused () { : >trace2.txt && GIT_TRACE2_EVENT="$PWD/trace2.txt" \ - git pack-objects --stdout --revs >/dev/null && + git pack-objects --stdout --revs >got.pack && test_pack_reused "$1" <trace2.txt && - test_packs_reused "$2" <trace2.txt + test_packs_reused "$2" <trace2.txt && + + git index-pack --strict -o got.idx got.pack } test_expect_success 'preferred pack is reused for single-pack reuse' ' @@ -232,4 +236,27 @@ test_expect_success 'non-omitted delta in MIDX preferred pack' ' test_pack_objects_reused_all $(wc -l <expect) 1 ' +test_expect_success 'duplicate objects' ' + git init duplicate-objects && + ( + cd duplicate-objects && + + git config pack.allowPackReuse multi && + + test_commit base && + + git repack -a && + + git rev-parse HEAD^{tree} >in && + p="$(git pack-objects $packdir/pack <in)" && + + git multi-pack-index write --bitmap --preferred-pack=pack-$p.idx && + + objects_nr="$(git rev-list --count --all --objects)" && + packs_nr="$(find $packdir -type f -name "pack-*.pack" | wc -l)" && + + test_pack_objects_reused_all $objects_nr $packs_nr + ) +' + test_done diff --git a/t/t9001-send-email.sh b/t/t9001-send-email.sh index c5e862694e..df5336bb7e 100755 --- a/t/t9001-send-email.sh +++ b/t/t9001-send-email.sh @@ -2485,6 +2485,128 @@ test_expect_success $PREREQ 'leading and trailing whitespaces are removed' ' test_cmp expected-list actual-list ' +test_expect_success $PREREQ 'mailmap support with --to' ' + clean_fake_sendmail && + test_config mailmap.file "mailmap.test" && + cat >mailmap.test <<-EOF && + Some Body <someone@example.com> <someone@example.org> + EOF + git format-patch --stdout -1 >a.patch && + git send-email \ + --from="Example <nobody@example.com>" \ + --smtp-server="$(pwd)/fake.sendmail" \ + --to=someone@example.org \ + --mailmap \ + a.patch \ + 2>errors >out && + grep "^!someone@example\.com!$" commandline1 +' + +test_expect_success $PREREQ 'sendemail.mailmap configuration' ' + clean_fake_sendmail && + test_config mailmap.file "mailmap.test" && + test_config sendemail.mailmap "true" && + cat >mailmap.test <<-EOF && + Some Body <someone@example.com> <someone@example.org> + EOF + git format-patch --stdout -1 >a.patch && + git send-email \ + --from="Example <nobody@example.com>" \ + --smtp-server="$(pwd)/fake.sendmail" \ + --to=someone@example.org \ + a.patch \ + 2>errors >out && + grep "^!someone@example\.com!$" commandline1 +' + +test_expect_success $PREREQ 'sendemail.mailmap.file configuration' ' + clean_fake_sendmail && + test_config sendemail.mailmap.file "mailmap.test" && + test_config sendemail.mailmap "true" && + cat >mailmap.test <<-EOF && + Some Body <someone@example.com> <someone@example.org> + EOF + git format-patch --stdout -1 >a.patch && + git send-email \ + --from="Example <nobody@example.com>" \ + --smtp-server="$(pwd)/fake.sendmail" \ + --to=someone@example.org \ + a.patch \ + 2>errors >out && + grep "^!someone@example\.com!$" commandline1 +' + +test_expect_success $PREREQ 'sendemail.mailmap identity overrides configuration' ' + clean_fake_sendmail && + test_config sendemail.cloud.mailmap.file "mailmap.test" && + test_config sendemail.mailmap "false" && + test_config sendemail.cloud.mailmap "true" && + cat >mailmap.test <<-EOF && + Some Body <someone@example.com> <someone@example.org> + EOF + git format-patch --stdout -1 >a.patch && + git send-email \ + --from="Example <nobody@example.com>" \ + --smtp-server="$(pwd)/fake.sendmail" \ + --identity=cloud \ + --to=someone@example.org \ + a.patch \ + 2>errors >out && + grep "^!someone@example\.com!$" commandline1 +' + +test_expect_success $PREREQ '--no-mailmap overrides configuration' ' + clean_fake_sendmail && + test_config sendemail.cloud.mailmap.file "mailmap.test" && + test_config sendemail.mailmap "false" && + test_config sendemail.cloud.mailmap "true" && + cat >mailmap.test <<-EOF && + Some Body <someone@example.com> <someone@example.org> + EOF + git format-patch --stdout -1 >a.patch && + git send-email \ + --from="Example <nobody@example.com>" \ + --smtp-server="$(pwd)/fake.sendmail" \ + --identity=cloud \ + --to=someone@example.org \ + --no-mailmap \ + a.patch \ + 2>errors >out && + grep "^!someone@example\.org!$" commandline1 +' + +test_expect_success $PREREQ 'mailmap support in To header' ' + clean_fake_sendmail && + test_config mailmap.file "mailmap.test" && + cat >mailmap.test <<-EOF && + <someone@example.com> <someone@example.org> + EOF + git format-patch --stdout -1 --to=someone@example.org >a.patch && + git send-email \ + --from="Example <nobody@example.com>" \ + --smtp-server="$(pwd)/fake.sendmail" \ + --mailmap \ + a.patch \ + 2>errors >out && + grep "^!someone@example\.com!$" commandline1 +' + +test_expect_success $PREREQ 'mailmap support in Cc header' ' + clean_fake_sendmail && + test_config mailmap.file "mailmap.test" && + cat >mailmap.test <<-EOF && + <someone@example.com> <someone@example.org> + EOF + git format-patch --stdout -1 --cc=someone@example.org >a.patch && + git send-email \ + --from="Example <nobody@example.com>" \ + --smtp-server="$(pwd)/fake.sendmail" \ + --mailmap \ + a.patch \ + 2>errors >out && + grep "^!someone@example\.com!$" commandline1 +' + test_expect_success $PREREQ 'test using command name with --sendmail-cmd' ' clean_fake_sendmail && PATH="$PWD:$PATH" \ diff --git a/t/unit-tests/lib-oid.c b/t/unit-tests/lib-oid.c index 37105f0a8f..8f0ccac532 100644 --- a/t/unit-tests/lib-oid.c +++ b/t/unit-tests/lib-oid.c @@ -3,7 +3,7 @@ #include "strbuf.h" #include "hex.h" -static int init_hash_algo(void) +int init_hash_algo(void) { static int algo = -1; diff --git a/t/unit-tests/lib-oid.h b/t/unit-tests/lib-oid.h index 8d2acca768..4e77c04bd2 100644 --- a/t/unit-tests/lib-oid.h +++ b/t/unit-tests/lib-oid.h @@ -13,5 +13,13 @@ * environment variable. */ int get_oid_arbitrary_hex(const char *s, struct object_id *oid); +/* + * Returns one of GIT_HASH_{SHA1, SHA256, UNKNOWN} based on the value of + * GIT_TEST_DEFAULT_HASH environment variable. The fallback value in the + * absence of GIT_TEST_DEFAULT_HASH is GIT_HASH_SHA1. It also uses + * check(algo != GIT_HASH_UNKNOWN) before returning to verify if the + * GIT_TEST_DEFAULT_HASH's value is valid or not. + */ +int init_hash_algo(void); #endif /* LIB_OID_H */ diff --git a/t/unit-tests/t-oid-array.c b/t/unit-tests/t-oid-array.c new file mode 100644 index 0000000000..45b59a2a51 --- /dev/null +++ b/t/unit-tests/t-oid-array.c @@ -0,0 +1,126 @@ +#define USE_THE_REPOSITORY_VARIABLE + +#include "test-lib.h" +#include "lib-oid.h" +#include "oid-array.h" +#include "hex.h" + +static int fill_array(struct oid_array *array, const char *hexes[], size_t n) +{ + for (size_t i = 0; i < n; i++) { + struct object_id oid; + + if (!check_int(get_oid_arbitrary_hex(hexes[i], &oid), ==, 0)) + return -1; + oid_array_append(array, &oid); + } + if (!check_uint(array->nr, ==, n)) + return -1; + return 0; +} + +static int add_to_oid_array(const struct object_id *oid, void *data) +{ + struct oid_array *array = data; + + oid_array_append(array, oid); + return 0; +} + +static void t_enumeration(const char **input_args, size_t input_sz, + const char **expect_args, size_t expect_sz) +{ + struct oid_array input = OID_ARRAY_INIT, expect = OID_ARRAY_INIT, + actual = OID_ARRAY_INIT; + size_t i; + + if (fill_array(&input, input_args, input_sz)) + return; + if (fill_array(&expect, expect_args, expect_sz)) + return; + + oid_array_for_each_unique(&input, add_to_oid_array, &actual); + if (!check_uint(actual.nr, ==, expect.nr)) + return; + + for (i = 0; i < actual.nr; i++) { + if (!check(oideq(&actual.oid[i], &expect.oid[i]))) + test_msg("expected: %s\n got: %s\n index: %" PRIuMAX, + oid_to_hex(&expect.oid[i]), oid_to_hex(&actual.oid[i]), + (uintmax_t)i); + } + + oid_array_clear(&actual); + oid_array_clear(&input); + oid_array_clear(&expect); +} + +#define TEST_ENUMERATION(input, expect, desc) \ + TEST(t_enumeration(input, ARRAY_SIZE(input), expect, ARRAY_SIZE(expect)), \ + desc " works") + +static void t_lookup(const char **input_hexes, size_t n, const char *query_hex, + int lower_bound, int upper_bound) +{ + struct oid_array array = OID_ARRAY_INIT; + struct object_id oid_query; + int ret; + + if (!check_int(get_oid_arbitrary_hex(query_hex, &oid_query), ==, 0)) + return; + if (fill_array(&array, input_hexes, n)) + return; + ret = oid_array_lookup(&array, &oid_query); + + if (!check_int(ret, <=, upper_bound) || + !check_int(ret, >=, lower_bound)) + test_msg("oid query for lookup: %s", oid_to_hex(&oid_query)); + + oid_array_clear(&array); +} + +#define TEST_LOOKUP(input_hexes, query, lower_bound, upper_bound, desc) \ + TEST(t_lookup(input_hexes, ARRAY_SIZE(input_hexes), query, \ + lower_bound, upper_bound), \ + desc " works") + +static void setup(void) +{ + /* The hash algo is used by oid_array_lookup() internally */ + int algo = init_hash_algo(); + if (check_int(algo, !=, GIT_HASH_UNKNOWN)) + repo_set_hash_algo(the_repository, algo); +} + +int cmd_main(int argc UNUSED, const char **argv UNUSED) +{ + const char *arr_input[] = { "88", "44", "aa", "55" }; + const char *arr_input_dup[] = { "88", "44", "aa", "55", + "88", "44", "aa", "55", + "88", "44", "aa", "55" }; + const char *res_sorted[] = { "44", "55", "88", "aa" }; + const char *nearly_55; + + if (!TEST(setup(), "setup")) + test_skip_all("hash algo initialization failed"); + + TEST_ENUMERATION(arr_input, res_sorted, "ordered enumeration"); + TEST_ENUMERATION(arr_input_dup, res_sorted, + "ordered enumeration with duplicate suppression"); + + TEST_LOOKUP(arr_input, "55", 1, 1, "lookup"); + TEST_LOOKUP(arr_input, "33", INT_MIN, -1, "lookup non-existent entry"); + TEST_LOOKUP(arr_input_dup, "55", 3, 5, "lookup with duplicates"); + TEST_LOOKUP(arr_input_dup, "66", INT_MIN, -1, + "lookup non-existent entry with duplicates"); + + nearly_55 = init_hash_algo() == GIT_HASH_SHA1 ? + "5500000000000000000000000000000000000001" : + "5500000000000000000000000000000000000000000000000000000000000001"; + TEST_LOOKUP(((const char *[]){ "55", nearly_55 }), "55", 0, 0, + "lookup with almost duplicate values"); + TEST_LOOKUP(((const char *[]){ "55", "55" }), "55", 0, 1, + "lookup with single duplicate value"); + + return test_done(); +} diff --git a/t/unit-tests/t-reftable-readwrite.c b/t/unit-tests/t-reftable-readwrite.c index b4d7e7e76b..82bfaf3287 100644 --- a/t/unit-tests/t-reftable-readwrite.c +++ b/t/unit-tests/t-reftable-readwrite.c @@ -26,7 +26,7 @@ static ssize_t strbuf_add_void(void *b, const void *data, size_t sz) return sz; } -static int noop_flush(void *arg) +static int noop_flush(void *arg UNUSED) { return 0; } @@ -140,4 +140,22 @@ int csprng_bytes(void *buf, size_t len); */ uint32_t git_rand(void); +/* Provide log2 of the given `size_t`. */ +static inline unsigned log2u(uintmax_t sz) +{ + unsigned l = 0; + + /* + * Technically this isn't required, but it helps the compiler optimize + * this to a `bsr` instruction. + */ + if (!sz) + return 0; + + for (; sz; sz >>= 1) + l++; + + return l - 1; +} + #endif /* WRAPPER_H */ |
