Skip to content

Commit

Permalink
Fix sparse warnings
Browse files Browse the repository at this point in the history
Fix warnings from 'make check'.

 - These files don't include 'builtin.h' causing sparse to complain that
   cmd_* isn't declared:

   builtin/clone.c:364, builtin/fetch-pack.c:797,
   builtin/fmt-merge-msg.c:34, builtin/hash-object.c:78,
   builtin/merge-index.c:69, builtin/merge-recursive.c:22
   builtin/merge-tree.c:341, builtin/mktag.c:156, builtin/notes.c:426
   builtin/notes.c:822, builtin/pack-redundant.c:596,
   builtin/pack-refs.c:10, builtin/patch-id.c:60, builtin/patch-id.c:149,
   builtin/remote.c:1512, builtin/remote-ext.c:240,
   builtin/remote-fd.c:53, builtin/reset.c:236, builtin/send-pack.c:384,
   builtin/unpack-file.c:25, builtin/var.c:75

 - These files have symbols which should be marked static since they're
   only file scope:

   submodule.c:12, diff.c:631, replace_object.c:92, submodule.c:13,
   submodule.c:14, trace.c:78, transport.c:195, transport-helper.c:79,
   unpack-trees.c:19, url.c:3, url.c:18, url.c:104, url.c:117, url.c:123,
   url.c:129, url.c:136, thread-utils.c:21, thread-utils.c:48

 - These files redeclare symbols to be different types:

   builtin/index-pack.c:210, parse-options.c:564, parse-options.c:571,
   usage.c:49, usage.c:58, usage.c:63, usage.c:72

 - These files use a literal integer 0 when they really should use a NULL
   pointer:

   daemon.c:663, fast-import.c:2942, imap-send.c:1072, notes-merge.c:362

While we're in the area, clean up some unused #includes in builtin files
(mostly exec_cmd.h).

Signed-off-by: Stephen Boyd <bebarino@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
bebarino authored and gitster committed Mar 22, 2011
1 parent 08c8d55 commit c2e86ad
Show file tree
Hide file tree
Showing 35 changed files with 43 additions and 48 deletions.
2 changes: 1 addition & 1 deletion builtin/clone.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* Clone a repository into a different directory that does not yet exist.
*/

#include "cache.h"
#include "builtin.h"
#include "parse-options.h"
#include "fetch-pack.h"
#include "refs.h"
Expand Down
2 changes: 1 addition & 1 deletion builtin/fetch-pack.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "cache.h"
#include "builtin.h"
#include "refs.h"
#include "pkt-line.h"
#include "commit.h"
Expand Down
2 changes: 1 addition & 1 deletion builtin/fmt-merge-msg.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ struct src_data {
int head_status;
};

void init_src_data(struct src_data *data)
static void init_src_data(struct src_data *data)
{
data->branch.strdup_strings = 1;
data->tag.strdup_strings = 1;
Expand Down
2 changes: 1 addition & 1 deletion builtin/hash-object.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Copyright (C) Linus Torvalds, 2005
* Copyright (C) Junio C Hamano, 2005
*/
#include "cache.h"
#include "builtin.h"
#include "blob.h"
#include "quote.h"
#include "parse-options.h"
Expand Down
2 changes: 1 addition & 1 deletion builtin/index-pack.c
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ static void parse_pack_header(void)
static NORETURN void bad_object(unsigned long offset, const char *format,
...) __attribute__((format (printf, 2, 3)));

static void bad_object(unsigned long offset, const char *format, ...)
static NORETURN void bad_object(unsigned long offset, const char *format, ...)
{
va_list params;
char buf[1024];
Expand Down
3 changes: 1 addition & 2 deletions builtin/merge-index.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "cache.h"
#include "builtin.h"
#include "run-command.h"
#include "exec_cmd.h"

static const char *pgm;
static int one_shot, quiet;
Expand Down
2 changes: 1 addition & 1 deletion builtin/merge-recursive.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "cache.h"
#include "builtin.h"
#include "commit.h"
#include "tag.h"
#include "merge-recursive.h"
Expand Down
2 changes: 1 addition & 1 deletion builtin/merge-tree.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "cache.h"
#include "builtin.h"
#include "tree-walk.h"
#include "xdiff-interface.h"
#include "blob.h"
Expand Down
3 changes: 1 addition & 2 deletions builtin/mktag.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "cache.h"
#include "builtin.h"
#include "tag.h"
#include "exec_cmd.h"

/*
* A signature file has a very simple fixed format: four lines
Expand Down
4 changes: 2 additions & 2 deletions builtin/notes.c
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ void finish_copy_notes_for_rewrite(struct notes_rewrite_cfg *c)
free(c);
}

int notes_copy_from_stdin(int force, const char *rewrite_cmd)
static int notes_copy_from_stdin(int force, const char *rewrite_cmd)
{
struct strbuf buf = STRBUF_INIT;
struct notes_rewrite_cfg *c = NULL;
Expand Down Expand Up @@ -819,7 +819,7 @@ static int merge_commit(struct notes_merge_options *o)
t = xcalloc(1, sizeof(struct notes_tree));
init_notes(t, "NOTES_MERGE_PARTIAL", combine_notes_overwrite, 0);

o->local_ref = resolve_ref("NOTES_MERGE_REF", sha1, 0, 0);
o->local_ref = resolve_ref("NOTES_MERGE_REF", sha1, 0, NULL);
if (!o->local_ref)
die("Failed to resolve NOTES_MERGE_REF");

Expand Down
3 changes: 1 addition & 2 deletions builtin/pack-redundant.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
*
*/

#include "cache.h"
#include "exec_cmd.h"
#include "builtin.h"

#define BLKSIZE 512

Expand Down
2 changes: 1 addition & 1 deletion builtin/pack-refs.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "cache.h"
#include "builtin.h"
#include "parse-options.h"
#include "pack-refs.h"

Expand Down
5 changes: 2 additions & 3 deletions builtin/patch-id.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include "cache.h"
#include "exec_cmd.h"
#include "builtin.h"

static void flush_current_id(int patchlen, unsigned char *id, git_SHA_CTX *c)
{
Expand Down Expand Up @@ -57,7 +56,7 @@ static int scan_hunk_header(const char *p, int *p_before, int *p_after)
return 1;
}

int get_one_patchid(unsigned char *next_sha1, git_SHA_CTX *ctx)
static int get_one_patchid(unsigned char *next_sha1, git_SHA_CTX *ctx)
{
static char line[1000];
int patchlen = 0, found_next = 0;
Expand Down
2 changes: 1 addition & 1 deletion builtin/remote-ext.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "git-compat-util.h"
#include "builtin.h"
#include "transport.h"
#include "run-command.h"

Expand Down
2 changes: 1 addition & 1 deletion builtin/remote-fd.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "git-compat-util.h"
#include "builtin.h"
#include "transport.h"

/*
Expand Down
2 changes: 1 addition & 1 deletion builtin/remote.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "cache.h"
#include "builtin.h"
#include "parse-options.h"
#include "transport.h"
#include "remote.h"
Expand Down
2 changes: 1 addition & 1 deletion builtin/reset.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*
* Copyright (c) 2005, 2006 Linus Torvalds and Junio C Hamano
*/
#include "cache.h"
#include "builtin.h"
#include "tag.h"
#include "object.h"
#include "commit.h"
Expand Down
2 changes: 1 addition & 1 deletion builtin/send-pack.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "cache.h"
#include "builtin.h"
#include "commit.h"
#include "refs.h"
#include "pkt-line.h"
Expand Down
4 changes: 1 addition & 3 deletions builtin/unpack-file.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#include "cache.h"
#include "blob.h"
#include "exec_cmd.h"
#include "builtin.h"

static char *create_temp_file(unsigned char *sha1)
{
Expand Down
3 changes: 1 addition & 2 deletions builtin/var.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
*
* Copyright (C) Eric Biederman, 2005
*/
#include "cache.h"
#include "exec_cmd.h"
#include "builtin.h"

static const char var_usage[] = "git var (-l | <variable>)";

Expand Down
2 changes: 1 addition & 1 deletion daemon.c
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,7 @@ static void check_dead_children(void)
static char **cld_argv;
static void handle(int incoming, struct sockaddr *addr, socklen_t addrlen)
{
struct child_process cld = { 0 };
struct child_process cld = { NULL };
char addrbuf[300] = "REMOTE_ADDR=", portbuf[300];
char *env[] = { addrbuf, portbuf, NULL };

Expand Down
2 changes: 1 addition & 1 deletion diff.c
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,7 @@ struct diff_words_style {
const char *newline;
};

struct diff_words_style diff_words_styles[] = {
static struct diff_words_style diff_words_styles[] = {
{ DIFF_WORDS_PORCELAIN, {"+", "\n"}, {"-", "\n"}, {" ", "\n"}, "~\n" },
{ DIFF_WORDS_PLAIN, {"{+", "+}"}, {"[-", "-]"}, {"", ""}, "\n" },
{ DIFF_WORDS_COLOR, {"", ""}, {"", ""}, {"", ""}, "\n" }
Expand Down
2 changes: 1 addition & 1 deletion fast-import.c
Original file line number Diff line number Diff line change
Expand Up @@ -2939,7 +2939,7 @@ static void parse_ls(struct branch *b)
{
const char *p;
struct tree_entry *root = NULL;
struct tree_entry leaf = {0};
struct tree_entry leaf = {NULL};

/* ls SP (<treeish> SP)? <path> */
p = command_buf.buf + strlen("ls ");
Expand Down
2 changes: 1 addition & 1 deletion imap-send.c
Original file line number Diff line number Diff line change
Expand Up @@ -1069,7 +1069,7 @@ static struct store *imap_open_store(struct imap_server_conf *srvc)

if (srvc->tunnel) {
const char *argv[] = { srvc->tunnel, NULL };
struct child_process tunnel = {0};
struct child_process tunnel = {NULL};

imap_info("Starting tunnel '%s'... ", srvc->tunnel);

Expand Down
2 changes: 1 addition & 1 deletion notes-merge.c
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ static int ll_merge_in_worktree(struct notes_merge_options *o,
read_mmblob(&remote, p->remote);

status = ll_merge(&result_buf, sha1_to_hex(p->obj), &base, NULL,
&local, o->local_ref, &remote, o->remote_ref, 0);
&local, o->local_ref, &remote, o->remote_ref, NULL);

free(base.ptr);
free(local.ptr);
Expand Down
4 changes: 2 additions & 2 deletions parse-options.c
Original file line number Diff line number Diff line change
Expand Up @@ -561,14 +561,14 @@ static int usage_with_options_internal(struct parse_opt_ctx_t *ctx,
return PARSE_OPT_HELP;
}

void usage_with_options(const char * const *usagestr,
void NORETURN usage_with_options(const char * const *usagestr,
const struct option *opts)
{
usage_with_options_internal(NULL, usagestr, opts, 0, 1);
exit(129);
}

void usage_msg_opt(const char *msg,
void NORETURN usage_msg_opt(const char *msg,
const char * const *usagestr,
const struct option *options)
{
Expand Down
1 change: 1 addition & 0 deletions replace_object.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "cache.h"
#include "sha1-lookup.h"
#include "refs.h"
#include "commit.h"

static struct replace_object {
unsigned char sha1[2][20];
Expand Down
6 changes: 3 additions & 3 deletions submodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
#include "refs.h"
#include "string-list.h"

struct string_list config_name_for_path;
struct string_list config_fetch_recurse_submodules_for_name;
struct string_list config_ignore_for_name;
static struct string_list config_name_for_path;
static struct string_list config_fetch_recurse_submodules_for_name;
static struct string_list config_ignore_for_name;
static int config_fetch_recurse_submodules;

static int add_submodule_odb(const char *path)
Expand Down
2 changes: 1 addition & 1 deletion thread-utils.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "cache.h"
#include <pthread.h>
#include "thread-utils.h"

#if defined(hpux) || defined(__hpux) || defined(_hpux)
# include <sys/pstat.h>
Expand Down
2 changes: 1 addition & 1 deletion trace.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ void trace_vprintf(const char *key, const char *fmt, va_list ap)
strbuf_release(&buf);
}

void trace_printf_key(const char *key, const char *fmt, ...)
static void trace_printf_key(const char *key, const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
Expand Down
2 changes: 1 addition & 1 deletion transport-helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ static void write_constant(int fd, const char *str)
die_errno("Full write to remote helper failed");
}

const char *remove_ext_force(const char *url)
static const char *remove_ext_force(const char *url)
{
if (url) {
const char *colon = strchr(url, ':');
Expand Down
2 changes: 1 addition & 1 deletion transport.c
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ static const char *rsync_url(const char *url)
static struct ref *get_refs_via_rsync(struct transport *transport, int for_push)
{
struct strbuf buf = STRBUF_INIT, temp_dir = STRBUF_INIT;
struct ref dummy = {0}, *tail = &dummy;
struct ref dummy = {NULL}, *tail = &dummy;
struct child_process rsync;
const char *args[5];
int temp_dir_len;
Expand Down
2 changes: 1 addition & 1 deletion unpack-trees.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* situation better. See how "git checkout" and "git merge" replaces
* them using setup_unpack_trees_porcelain(), for example.
*/
const char *unpack_plumbing_errors[NB_UNPACK_TREES_ERROR_TYPES] = {
static const char *unpack_plumbing_errors[NB_UNPACK_TREES_ERROR_TYPES] = {
/* ERROR_WOULD_OVERWRITE */
"Entry '%s' would be overwritten by merge. Cannot merge.",

Expand Down
1 change: 1 addition & 0 deletions url.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "cache.h"
#include "url.h"

int is_urlschemechar(int first_flag, int ch)
{
Expand Down
8 changes: 4 additions & 4 deletions usage.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ void set_die_routine(NORETURN_PTR void (*routine)(const char *err, va_list param
die_routine = routine;
}

void usagef(const char *err, ...)
void NORETURN usagef(const char *err, ...)
{
va_list params;

Expand All @@ -55,12 +55,12 @@ void usagef(const char *err, ...)
va_end(params);
}

void usage(const char *err)
void NORETURN usage(const char *err)
{
usagef("%s", err);
}

void die(const char *err, ...)
void NORETURN die(const char *err, ...)
{
va_list params;

Expand All @@ -69,7 +69,7 @@ void die(const char *err, ...)
va_end(params);
}

void die_errno(const char *fmt, ...)
void NORETURN die_errno(const char *fmt, ...)
{
va_list params;
char fmt_with_err[1024];
Expand Down

0 comments on commit c2e86ad

Please sign in to comment.