Skip to content

Commit

Permalink
Merge branch 'ps/build-sign-compare'
Browse files Browse the repository at this point in the history
Start working to make the codebase buildable with -Wsign-compare.

* ps/build-sign-compare:
  t/helper: don't depend on implicit wraparound
  scalar: address -Wsign-compare warnings
  builtin/patch-id: fix type of `get_one_patchid()`
  builtin/blame: fix type of `length` variable when emitting object ID
  gpg-interface: address -Wsign-comparison warnings
  daemon: fix type of `max_connections`
  daemon: fix loops that have mismatching integer types
  global: trivial conversions to fix `-Wsign-compare` warnings
  pkt-line: fix -Wsign-compare warning on 32 bit platform
  csum-file: fix -Wsign-compare warning on 32-bit platform
  diff.h: fix index used to loop through unsigned integer
  config.mak.dev: drop `-Wno-sign-compare`
  global: mark code units that generate warnings with `-Wsign-compare`
  compat/win32: fix -Wsign-compare warning in "wWinMain()"
  compat/regex: explicitly ignore "-Wsign-compare" warnings
  git-compat-util: introduce macros to disable "-Wsign-compare" warnings
  • Loading branch information
gitster committed Dec 23, 2024
2 parents f7c607f + e03d2a9 commit 4156b6a
Show file tree
Hide file tree
Showing 266 changed files with 524 additions and 235 deletions.
1 change: 1 addition & 0 deletions add-interactive.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#define USE_THE_REPOSITORY_VARIABLE
#define DISABLE_SIGN_COMPARE_WARNINGS

#include "git-compat-util.h"
#include "add-interactive.h"
Expand Down
1 change: 1 addition & 0 deletions add-patch.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#define USE_THE_REPOSITORY_VARIABLE
#define DISABLE_SIGN_COMPARE_WARNINGS

#include "git-compat-util.h"
#include "add-interactive.h"
Expand Down
7 changes: 2 additions & 5 deletions advice.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@ void advise_if_enabled(enum advice_type type, const char *advice, ...)
int git_default_advice_config(const char *var, const char *value)
{
const char *k, *slot_name;
int i;

if (!strcmp(var, "color.advice")) {
advice_use_color = git_config_colorbool(var, value);
Expand All @@ -180,7 +179,7 @@ int git_default_advice_config(const char *var, const char *value)
if (!skip_prefix(var, "advice.", &k))
return 0;

for (i = 0; i < ARRAY_SIZE(advice_setting); i++) {
for (size_t i = 0; i < ARRAY_SIZE(advice_setting); i++) {
if (strcasecmp(k, advice_setting[i].key))
continue;
advice_setting[i].level = git_config_bool(var, value)
Expand All @@ -194,9 +193,7 @@ int git_default_advice_config(const char *var, const char *value)

void list_config_advices(struct string_list *list, const char *prefix)
{
int i;

for (i = 0; i < ARRAY_SIZE(advice_setting); i++)
for (size_t i = 0; i < ARRAY_SIZE(advice_setting); i++)
list_config_item(list, prefix, advice_setting[i].key);
}

Expand Down
1 change: 1 addition & 0 deletions apply.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/

#define USE_THE_REPOSITORY_VARIABLE
#define DISABLE_SIGN_COMPARE_WARNINGS

#include "git-compat-util.h"
#include "abspath.h"
Expand Down
1 change: 1 addition & 0 deletions archive.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#define USE_THE_REPOSITORY_VARIABLE
#define DISABLE_SIGN_COMPARE_WARNINGS

#include "git-compat-util.h"
#include "abspath.h"
Expand Down
1 change: 1 addition & 0 deletions attr.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/

#define USE_THE_REPOSITORY_VARIABLE
#define DISABLE_SIGN_COMPARE_WARNINGS

#include "git-compat-util.h"
#include "config.h"
Expand Down
3 changes: 1 addition & 2 deletions base85.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,9 @@ static const char en85[] = {
static char de85[256];
static void prep_base85(void)
{
int i;
if (de85['Z'])
return;
for (i = 0; i < ARRAY_SIZE(en85); i++) {
for (size_t i = 0; i < ARRAY_SIZE(en85); i++) {
int ch = en85[i];
de85[ch] = i + 1;
}
Expand Down
1 change: 1 addition & 0 deletions bisect.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#define USE_THE_REPOSITORY_VARIABLE
#define DISABLE_SIGN_COMPARE_WARNINGS

#include "git-compat-util.h"
#include "config.h"
Expand Down
1 change: 1 addition & 0 deletions blame.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#define USE_THE_REPOSITORY_VARIABLE
#define DISABLE_SIGN_COMPARE_WARNINGS

#include "git-compat-util.h"
#include "refs.h"
Expand Down
2 changes: 2 additions & 0 deletions bloom.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#define DISABLE_SIGN_COMPARE_WARNINGS

#include "git-compat-util.h"
#include "bloom.h"
#include "diff.h"
Expand Down
9 changes: 5 additions & 4 deletions builtin/add.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*
* Copyright (C) 2006 Linus Torvalds
*/

#include "builtin.h"
#include "advice.h"
#include "config.h"
Expand Down Expand Up @@ -39,9 +40,9 @@ static int chmod_pathspec(struct repository *repo,
char flip,
int show_only)
{
int i, ret = 0;
int ret = 0;

for (i = 0; i < repo->index->cache_nr; i++) {
for (size_t i = 0; i < repo->index->cache_nr; i++) {
struct cache_entry *ce = repo->index->cache[i];
int err;

Expand Down Expand Up @@ -69,9 +70,9 @@ static int renormalize_tracked_files(struct repository *repo,
const struct pathspec *pathspec,
int flags)
{
int i, retval = 0;
int retval = 0;

for (i = 0; i < repo->index->cache_nr; i++) {
for (size_t i = 0; i < repo->index->cache_nr; i++) {
struct cache_entry *ce = repo->index->cache[i];

if (!include_sparse &&
Expand Down
1 change: 1 addition & 0 deletions builtin/am.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/

#define USE_THE_REPOSITORY_VARIABLE

#include "builtin.h"
#include "abspath.h"
#include "advice.h"
Expand Down
2 changes: 2 additions & 0 deletions builtin/bisect.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#define USE_THE_REPOSITORY_VARIABLE
#define DISABLE_SIGN_COMPARE_WARNINGS

#include "builtin.h"
#include "copy.h"
#include "environment.h"
Expand Down
11 changes: 9 additions & 2 deletions builtin/blame.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
* Copyright (c) 2006, 2014 by its authors
* See COPYING for licensing conditions
*/

#define USE_THE_REPOSITORY_VARIABLE

#include "builtin.h"
#include "config.h"
#include "color.h"
Expand Down Expand Up @@ -465,9 +467,14 @@ static void emit_other(struct blame_scoreboard *sb, struct blame_entry *ent, int
reset = GIT_COLOR_RESET;
}

if (abbrev < MINIMUM_ABBREV)
BUG("abbreviation is smaller than minimum length: %d < %d",
abbrev, MINIMUM_ABBREV);

for (cnt = 0; cnt < ent->num_lines; cnt++) {
char ch;
int length = (opt & OUTPUT_LONG_OBJECT_NAME) ? the_hash_algo->hexsz : abbrev;
size_t length = (opt & OUTPUT_LONG_OBJECT_NAME) ?
the_hash_algo->hexsz : (size_t) abbrev;

if (opt & OUTPUT_COLOR_LINE) {
if (cnt > 0) {
Expand Down Expand Up @@ -498,7 +505,7 @@ static void emit_other(struct blame_scoreboard *sb, struct blame_entry *ent, int
length--;
putchar('?');
}
printf("%.*s", length, hex);
fwrite(hex, 1, length, stdout);
if (opt & OUTPUT_ANNOTATE_COMPAT) {
const char *name;
if (opt & OUTPUT_SHOW_EMAIL)
Expand Down
2 changes: 2 additions & 0 deletions builtin/branch.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
* Copyright (c) 2006 Kristian Høgsberg <[email protected]>
* Based on git-branch.sh by Junio C Hamano.
*/

#define USE_THE_REPOSITORY_VARIABLE

#include "builtin.h"
#include "config.h"
#include "color.h"
Expand Down
3 changes: 3 additions & 0 deletions builtin/cat-file.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
*
* Copyright (C) Linus Torvalds, 2005
*/

#define USE_THE_REPOSITORY_VARIABLE
#define DISABLE_SIGN_COMPARE_WARNINGS

#include "builtin.h"
#include "config.h"
#include "convert.h"
Expand Down
2 changes: 2 additions & 0 deletions builtin/checkout--worker.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#define USE_THE_REPOSITORY_VARIABLE
#define DISABLE_SIGN_COMPARE_WARNINGS

#include "builtin.h"
#include "config.h"
#include "entry.h"
Expand Down
3 changes: 3 additions & 0 deletions builtin/checkout-index.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
* Copyright (C) 2005 Linus Torvalds
*
*/

#define USE_THE_REPOSITORY_VARIABLE
#define DISABLE_SIGN_COMPARE_WARNINGS

#include "builtin.h"
#include "config.h"
#include "gettext.h"
Expand Down
2 changes: 2 additions & 0 deletions builtin/checkout.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#define USE_THE_REPOSITORY_VARIABLE
#define DISABLE_SIGN_COMPARE_WARNINGS

#include "builtin.h"
#include "advice.h"
#include "branch.h"
Expand Down
3 changes: 3 additions & 0 deletions builtin/clean.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
*
* Based on git-clean.sh by Pavel Roskin
*/

#define USE_THE_REPOSITORY_VARIABLE
#define DISABLE_SIGN_COMPARE_WARNINGS

#include "builtin.h"
#include "abspath.h"
#include "config.h"
Expand Down
3 changes: 3 additions & 0 deletions builtin/clone.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
*
* Clone a repository into a different directory that does not yet exist.
*/

#define USE_THE_REPOSITORY_VARIABLE
#define DISABLE_SIGN_COMPARE_WARNINGS

#include "builtin.h"

#include "abspath.h"
Expand Down
3 changes: 3 additions & 0 deletions builtin/commit.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
* Copyright (c) 2007 Kristian Høgsberg <[email protected]>
* Based on git-commit.sh by Junio C Hamano and Linus Torvalds
*/

#define USE_THE_REPOSITORY_VARIABLE
#define DISABLE_SIGN_COMPARE_WARNINGS

#include "builtin.h"
#include "advice.h"
#include "config.h"
Expand Down
2 changes: 2 additions & 0 deletions builtin/describe.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#define USE_THE_REPOSITORY_VARIABLE
#define DISABLE_SIGN_COMPARE_WARNINGS

#include "builtin.h"
#include "config.h"
#include "environment.h"
Expand Down
3 changes: 3 additions & 0 deletions builtin/diff-files.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
*
* Copyright (C) Linus Torvalds, 2005
*/

#define USE_THE_REPOSITORY_VARIABLE
#define DISABLE_SIGN_COMPARE_WARNINGS

#include "builtin.h"
#include "config.h"
#include "diff.h"
Expand Down
2 changes: 2 additions & 0 deletions builtin/diff-index.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#define USE_THE_REPOSITORY_VARIABLE
#define DISABLE_SIGN_COMPARE_WARNINGS

#include "builtin.h"
#include "config.h"
#include "diff.h"
Expand Down
1 change: 1 addition & 0 deletions builtin/diff-tree.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#define USE_THE_REPOSITORY_VARIABLE

#include "builtin.h"
#include "config.h"
#include "diff.h"
Expand Down
3 changes: 3 additions & 0 deletions builtin/diff.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
*
* Copyright (c) 2006 Junio C Hamano
*/

#define USE_THE_REPOSITORY_VARIABLE
#define DISABLE_SIGN_COMPARE_WARNINGS

#include "builtin.h"
#include "config.h"
#include "ewah/ewok.h"
Expand Down
5 changes: 4 additions & 1 deletion builtin/difftool.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
*
* Copyright (C) 2016 Johannes Schindelin
*/

#define USE_THE_REPOSITORY_VARIABLE

#include "builtin.h"

#include "abspath.h"
Expand Down Expand Up @@ -364,7 +366,8 @@ static int run_dir_diff(const char *extcmd, int symlinks, const char *prefix,
char *lbase_dir = NULL, *rbase_dir = NULL;
size_t ldir_len, rdir_len, wtdir_len;
const char *workdir, *tmp;
int ret = 0, i;
int ret = 0;
size_t i;
FILE *fp = NULL;
struct hashmap working_tree_dups = HASHMAP_INIT(working_tree_entry_cmp,
NULL);
Expand Down
3 changes: 3 additions & 0 deletions builtin/fast-export.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
*
* Copyright (C) 2007 Johannes E. Schindelin
*/

#define USE_THE_REPOSITORY_VARIABLE
#define DISABLE_SIGN_COMPARE_WARNINGS

#include "builtin.h"
#include "config.h"
#include "gettext.h"
Expand Down
2 changes: 2 additions & 0 deletions builtin/fast-import.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#define USE_THE_REPOSITORY_VARIABLE
#define DISABLE_SIGN_COMPARE_WARNINGS

#include "builtin.h"
#include "abspath.h"
#include "environment.h"
Expand Down
2 changes: 2 additions & 0 deletions builtin/fetch-pack.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#define USE_THE_REPOSITORY_VARIABLE
#define DISABLE_SIGN_COMPARE_WARNINGS

#include "builtin.h"
#include "gettext.h"
#include "hex.h"
Expand Down
3 changes: 3 additions & 0 deletions builtin/fetch.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
/*
* "git fetch"
*/

#define USE_THE_REPOSITORY_VARIABLE
#define DISABLE_SIGN_COMPARE_WARNINGS

#include "builtin.h"
#include "advice.h"
#include "config.h"
Expand Down
5 changes: 3 additions & 2 deletions builtin/for-each-repo.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#define USE_THE_REPOSITORY_VARIABLE

#include "builtin.h"
#include "config.h"
#include "gettext.h"
Expand Down Expand Up @@ -36,7 +37,7 @@ int cmd_for_each_repo(int argc,
{
static const char *config_key = NULL;
int keep_going = 0;
int i, result = 0;
int result = 0;
const struct string_list *values;
int err;

Expand All @@ -61,7 +62,7 @@ int cmd_for_each_repo(int argc,
else if (err)
return 0;

for (i = 0; i < values->nr; i++) {
for (size_t i = 0; i < values->nr; i++) {
int ret = run_command_on_repo(values->items[i].string, argc, argv);
if (ret) {
if (!keep_going)
Expand Down
2 changes: 2 additions & 0 deletions builtin/fsmonitor--daemon.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#define USE_THE_REPOSITORY_VARIABLE
#define DISABLE_SIGN_COMPARE_WARNINGS

#include "builtin.h"
#include "abspath.h"
#include "config.h"
Expand Down
3 changes: 3 additions & 0 deletions builtin/gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
*
* Copyright (c) 2006 Shawn O. Pearce
*/

#define USE_THE_REPOSITORY_VARIABLE
#define DISABLE_SIGN_COMPARE_WARNINGS

#include "builtin.h"
#include "abspath.h"
#include "date.h"
Expand Down
Loading

0 comments on commit 4156b6a

Please sign in to comment.