Fix sparse warnings
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>
2011-03-22 10:51:05 +03:00
|
|
|
#include "builtin.h"
|
2007-03-13 02:00:21 +03:00
|
|
|
#include "run-command.h"
|
2005-04-18 06:52:54 +04:00
|
|
|
|
2006-08-15 21:23:48 +04:00
|
|
|
static const char *pgm;
|
2005-07-29 16:53:38 +04:00
|
|
|
static int one_shot, quiet;
|
2005-04-19 06:16:15 +04:00
|
|
|
static int err;
|
2005-04-18 06:52:54 +04:00
|
|
|
|
|
|
|
static int merge_entry(int pos, const char *path)
|
|
|
|
{
|
|
|
|
int found;
|
2009-06-09 00:34:29 +04:00
|
|
|
const char *arguments[] = { pgm, "", "", "", path, "", "", "", NULL };
|
2017-03-26 19:01:24 +03:00
|
|
|
char hexbuf[4][GIT_MAX_HEXSZ + 1];
|
2009-06-09 00:34:29 +04:00
|
|
|
char ownbuf[4][60];
|
2007-06-07 11:04:01 +04:00
|
|
|
|
2005-04-18 06:52:54 +04:00
|
|
|
if (pos >= active_nr)
|
2008-08-31 20:39:19 +04:00
|
|
|
die("git merge-index: %s not in the cache", path);
|
2005-04-18 06:52:54 +04:00
|
|
|
found = 0;
|
|
|
|
do {
|
Convert "struct cache_entry *" to "const ..." wherever possible
I attempted to make index_state->cache[] a "const struct cache_entry **"
to find out how existing entries in index are modified and where. The
question I have is what do we do if we really need to keep track of on-disk
changes in the index. The result is
- diff-lib.c: setting CE_UPTODATE
- name-hash.c: setting CE_HASHED
- preload-index.c, read-cache.c, unpack-trees.c and
builtin/update-index: obvious
- entry.c: write_entry() may refresh the checked out entry via
fill_stat_cache_info(). This causes "non-const struct cache_entry
*" in builtin/apply.c, builtin/checkout-index.c and
builtin/checkout.c
- builtin/ls-files.c: --with-tree changes stagemask and may set
CE_UPDATE
Of these, write_entry() and its call sites are probably most
interesting because it modifies on-disk info. But this is stat info
and can be retrieved via refresh, at least for porcelain
commands. Other just uses ce_flags for local purposes.
So, keeping track of "dirty" entries is just a matter of setting a
flag in index modification functions exposed by read-cache.c. Except
unpack-trees, the rest of the code base does not do anything funny
behind read-cache's back.
The actual patch is less valueable than the summary above. But if
anyone wants to re-identify the above sites. Applying this patch, then
this:
diff --git a/cache.h b/cache.h
index 430d021..1692891 100644
--- a/cache.h
+++ b/cache.h
@@ -267,7 +267,7 @@ static inline unsigned int canon_mode(unsigned int mode)
#define cache_entry_size(len) (offsetof(struct cache_entry,name) + (len) + 1)
struct index_state {
- struct cache_entry **cache;
+ const struct cache_entry **cache;
unsigned int version;
unsigned int cache_nr, cache_alloc, cache_changed;
struct string_list *resolve_undo;
will help quickly identify them without bogus warnings.
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-07-09 19:29:00 +04:00
|
|
|
const struct cache_entry *ce = active_cache[pos];
|
2005-04-18 06:52:54 +04:00
|
|
|
int stage = ce_stage(ce);
|
|
|
|
|
|
|
|
if (strcmp(ce->name, path))
|
|
|
|
break;
|
|
|
|
found++;
|
2017-01-29 01:03:03 +03:00
|
|
|
oid_to_hex_r(hexbuf[stage], &ce->oid);
|
2015-09-25 00:06:08 +03:00
|
|
|
xsnprintf(ownbuf[stage], sizeof(ownbuf[stage]), "%o", ce->ce_mode);
|
2005-04-19 01:17:58 +04:00
|
|
|
arguments[stage] = hexbuf[stage];
|
2005-04-24 07:50:10 +04:00
|
|
|
arguments[stage + 4] = ownbuf[stage];
|
2005-04-18 06:52:54 +04:00
|
|
|
} while (++pos < active_nr);
|
|
|
|
if (!found)
|
2008-08-31 20:39:19 +04:00
|
|
|
die("git merge-index: %s not in the cache", path);
|
2009-06-09 00:34:29 +04:00
|
|
|
|
|
|
|
if (run_command_v_opt(arguments, 0)) {
|
|
|
|
if (one_shot)
|
|
|
|
err++;
|
|
|
|
else {
|
|
|
|
if (!quiet)
|
|
|
|
die("merge program failed");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
2005-04-18 06:52:54 +04:00
|
|
|
return found;
|
|
|
|
}
|
|
|
|
|
2012-12-07 03:08:01 +04:00
|
|
|
static void merge_one_path(const char *path)
|
2005-04-18 06:52:54 +04:00
|
|
|
{
|
|
|
|
int pos = cache_name_pos(path, strlen(path));
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If it already exists in the cache as stage0, it's
|
|
|
|
* already merged and there is nothing to do.
|
|
|
|
*/
|
|
|
|
if (pos < 0)
|
|
|
|
merge_entry(-pos-1, path);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void merge_all(void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < active_nr; i++) {
|
Convert "struct cache_entry *" to "const ..." wherever possible
I attempted to make index_state->cache[] a "const struct cache_entry **"
to find out how existing entries in index are modified and where. The
question I have is what do we do if we really need to keep track of on-disk
changes in the index. The result is
- diff-lib.c: setting CE_UPTODATE
- name-hash.c: setting CE_HASHED
- preload-index.c, read-cache.c, unpack-trees.c and
builtin/update-index: obvious
- entry.c: write_entry() may refresh the checked out entry via
fill_stat_cache_info(). This causes "non-const struct cache_entry
*" in builtin/apply.c, builtin/checkout-index.c and
builtin/checkout.c
- builtin/ls-files.c: --with-tree changes stagemask and may set
CE_UPDATE
Of these, write_entry() and its call sites are probably most
interesting because it modifies on-disk info. But this is stat info
and can be retrieved via refresh, at least for porcelain
commands. Other just uses ce_flags for local purposes.
So, keeping track of "dirty" entries is just a matter of setting a
flag in index modification functions exposed by read-cache.c. Except
unpack-trees, the rest of the code base does not do anything funny
behind read-cache's back.
The actual patch is less valueable than the summary above. But if
anyone wants to re-identify the above sites. Applying this patch, then
this:
diff --git a/cache.h b/cache.h
index 430d021..1692891 100644
--- a/cache.h
+++ b/cache.h
@@ -267,7 +267,7 @@ static inline unsigned int canon_mode(unsigned int mode)
#define cache_entry_size(len) (offsetof(struct cache_entry,name) + (len) + 1)
struct index_state {
- struct cache_entry **cache;
+ const struct cache_entry **cache;
unsigned int version;
unsigned int cache_nr, cache_alloc, cache_changed;
struct string_list *resolve_undo;
will help quickly identify them without bogus warnings.
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-07-09 19:29:00 +04:00
|
|
|
const struct cache_entry *ce = active_cache[i];
|
2005-04-18 06:52:54 +04:00
|
|
|
if (!ce_stage(ce))
|
|
|
|
continue;
|
|
|
|
i += merge_entry(i, ce->name)-1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-22 18:29:21 +03:00
|
|
|
int cmd_merge_index(int argc, const char **argv, const char *prefix)
|
2005-04-18 06:52:54 +04:00
|
|
|
{
|
|
|
|
int i, force_file = 0;
|
|
|
|
|
2006-06-20 05:25:21 +04:00
|
|
|
/* Without this we cannot rely on waitpid() to tell
|
|
|
|
* what happened to our children.
|
|
|
|
*/
|
|
|
|
signal(SIGCHLD, SIG_DFL);
|
|
|
|
|
2005-04-18 06:52:54 +04:00
|
|
|
if (argc < 3)
|
2015-01-13 10:44:47 +03:00
|
|
|
usage("git merge-index [-o] [-q] <merge-program> (-a | [--] [<filename>...])");
|
2005-04-18 06:52:54 +04:00
|
|
|
|
|
|
|
read_cache();
|
|
|
|
|
2005-05-11 06:44:59 +04:00
|
|
|
i = 1;
|
2005-07-29 16:53:38 +04:00
|
|
|
if (!strcmp(argv[i], "-o")) {
|
2005-05-11 06:44:59 +04:00
|
|
|
one_shot = 1;
|
|
|
|
i++;
|
|
|
|
}
|
2005-07-29 16:53:38 +04:00
|
|
|
if (!strcmp(argv[i], "-q")) {
|
|
|
|
quiet = 1;
|
|
|
|
i++;
|
|
|
|
}
|
2005-05-11 06:44:59 +04:00
|
|
|
pgm = argv[i++];
|
|
|
|
for (; i < argc; i++) {
|
2010-01-22 18:29:21 +03:00
|
|
|
const char *arg = argv[i];
|
2005-04-18 06:52:54 +04:00
|
|
|
if (!force_file && *arg == '-') {
|
|
|
|
if (!strcmp(arg, "--")) {
|
|
|
|
force_file = 1;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (!strcmp(arg, "-a")) {
|
|
|
|
merge_all();
|
|
|
|
continue;
|
|
|
|
}
|
2008-08-31 20:39:19 +04:00
|
|
|
die("git merge-index: unknown option %s", arg);
|
2005-04-18 06:52:54 +04:00
|
|
|
}
|
2012-12-07 03:08:01 +04:00
|
|
|
merge_one_path(arg);
|
2005-04-18 06:52:54 +04:00
|
|
|
}
|
2005-08-05 02:31:12 +04:00
|
|
|
if (err && !quiet)
|
2005-04-19 06:16:15 +04:00
|
|
|
die("merge program failed");
|
2005-07-29 16:53:38 +04:00
|
|
|
return err;
|
2005-04-18 06:52:54 +04:00
|
|
|
}
|