Merge branch 'jk/misc-unused-fixes'

Assorted fixes for bugs found while auditing -Wunused-parameter
warnings.

* jk/misc-unused-fixes:
  approxidate: fix NULL dereference in date_time()
  pathspec: handle non-terminated strings with :(attr)
  approxidate: handle pending number for "specials"
  rev-list: handle flags for --indexed-objects
This commit is contained in:
Junio C Hamano 2018-11-13 22:37:26 +09:00
commit f22838aa7a
5 changed files with 59 additions and 34 deletions

62
date.c
View file

@ -887,20 +887,49 @@ static time_t update_tm(struct tm *tm, struct tm *now, time_t sec)
return n; return n;
} }
/*
* Do we have a pending number at the end, or when
* we see a new one? Let's assume it's a month day,
* as in "Dec 6, 1992"
*/
static void pending_number(struct tm *tm, int *num)
{
int number = *num;
if (number) {
*num = 0;
if (tm->tm_mday < 0 && number < 32)
tm->tm_mday = number;
else if (tm->tm_mon < 0 && number < 13)
tm->tm_mon = number-1;
else if (tm->tm_year < 0) {
if (number > 1969 && number < 2100)
tm->tm_year = number - 1900;
else if (number > 69 && number < 100)
tm->tm_year = number;
else if (number < 38)
tm->tm_year = 100 + number;
/* We screw up for number = 00 ? */
}
}
}
static void date_now(struct tm *tm, struct tm *now, int *num) static void date_now(struct tm *tm, struct tm *now, int *num)
{ {
*num = 0;
update_tm(tm, now, 0); update_tm(tm, now, 0);
} }
static void date_yesterday(struct tm *tm, struct tm *now, int *num) static void date_yesterday(struct tm *tm, struct tm *now, int *num)
{ {
*num = 0;
update_tm(tm, now, 24*60*60); update_tm(tm, now, 24*60*60);
} }
static void date_time(struct tm *tm, struct tm *now, int hour) static void date_time(struct tm *tm, struct tm *now, int hour)
{ {
if (tm->tm_hour < hour) if (tm->tm_hour < hour)
date_yesterday(tm, now, NULL); update_tm(tm, now, 24*60*60);
tm->tm_hour = hour; tm->tm_hour = hour;
tm->tm_min = 0; tm->tm_min = 0;
tm->tm_sec = 0; tm->tm_sec = 0;
@ -908,16 +937,19 @@ static void date_time(struct tm *tm, struct tm *now, int hour)
static void date_midnight(struct tm *tm, struct tm *now, int *num) static void date_midnight(struct tm *tm, struct tm *now, int *num)
{ {
pending_number(tm, num);
date_time(tm, now, 0); date_time(tm, now, 0);
} }
static void date_noon(struct tm *tm, struct tm *now, int *num) static void date_noon(struct tm *tm, struct tm *now, int *num)
{ {
pending_number(tm, num);
date_time(tm, now, 12); date_time(tm, now, 12);
} }
static void date_tea(struct tm *tm, struct tm *now, int *num) static void date_tea(struct tm *tm, struct tm *now, int *num)
{ {
pending_number(tm, num);
date_time(tm, now, 17); date_time(tm, now, 17);
} }
@ -953,6 +985,7 @@ static void date_never(struct tm *tm, struct tm *now, int *num)
{ {
time_t n = 0; time_t n = 0;
localtime_r(&n, tm); localtime_r(&n, tm);
*num = 0;
} }
static const struct special { static const struct special {
@ -1110,33 +1143,6 @@ static const char *approxidate_digit(const char *date, struct tm *tm, int *num,
return end; return end;
} }
/*
* Do we have a pending number at the end, or when
* we see a new one? Let's assume it's a month day,
* as in "Dec 6, 1992"
*/
static void pending_number(struct tm *tm, int *num)
{
int number = *num;
if (number) {
*num = 0;
if (tm->tm_mday < 0 && number < 32)
tm->tm_mday = number;
else if (tm->tm_mon < 0 && number < 13)
tm->tm_mon = number-1;
else if (tm->tm_year < 0) {
if (number > 1969 && number < 2100)
tm->tm_year = number - 1900;
else if (number > 69 && number < 100)
tm->tm_year = number;
else if (number < 38)
tm->tm_year = 100 + number;
/* We screw up for number = 00 ? */
}
}
}
static timestamp_t approxidate_str(const char *date, static timestamp_t approxidate_str(const char *date,
const struct timeval *tv, const struct timeval *tv,
int *error_ret) int *error_ret)

7
dir.c
View file

@ -281,8 +281,15 @@ static int match_attrs(const struct index_state *istate,
const struct pathspec_item *item) const struct pathspec_item *item)
{ {
int i; int i;
char *to_free = NULL;
if (name[namelen])
name = to_free = xmemdupz(name, namelen);
git_check_attr(istate, name, item->attr_check); git_check_attr(istate, name, item->attr_check);
free(to_free);
for (i = 0; i < item->attr_match_nr; i++) { for (i = 0; i < item->attr_match_nr; i++) {
const char *value; const char *value;
int matched; int matched;

View file

@ -1327,13 +1327,14 @@ void add_reflogs_to_pending(struct rev_info *revs, unsigned flags)
} }
static void add_cache_tree(struct cache_tree *it, struct rev_info *revs, static void add_cache_tree(struct cache_tree *it, struct rev_info *revs,
struct strbuf *path) struct strbuf *path, unsigned int flags)
{ {
size_t baselen = path->len; size_t baselen = path->len;
int i; int i;
if (it->entry_count >= 0) { if (it->entry_count >= 0) {
struct tree *tree = lookup_tree(revs->repo, &it->oid); struct tree *tree = lookup_tree(revs->repo, &it->oid);
tree->object.flags |= flags;
add_pending_object_with_path(revs, &tree->object, "", add_pending_object_with_path(revs, &tree->object, "",
040000, path->buf); 040000, path->buf);
} }
@ -1341,14 +1342,15 @@ static void add_cache_tree(struct cache_tree *it, struct rev_info *revs,
for (i = 0; i < it->subtree_nr; i++) { for (i = 0; i < it->subtree_nr; i++) {
struct cache_tree_sub *sub = it->down[i]; struct cache_tree_sub *sub = it->down[i];
strbuf_addf(path, "%s%s", baselen ? "/" : "", sub->name); strbuf_addf(path, "%s%s", baselen ? "/" : "", sub->name);
add_cache_tree(sub->cache_tree, revs, path); add_cache_tree(sub->cache_tree, revs, path, flags);
strbuf_setlen(path, baselen); strbuf_setlen(path, baselen);
} }
} }
static void do_add_index_objects_to_pending(struct rev_info *revs, static void do_add_index_objects_to_pending(struct rev_info *revs,
struct index_state *istate) struct index_state *istate,
unsigned int flags)
{ {
int i; int i;
@ -1362,13 +1364,14 @@ static void do_add_index_objects_to_pending(struct rev_info *revs,
blob = lookup_blob(revs->repo, &ce->oid); blob = lookup_blob(revs->repo, &ce->oid);
if (!blob) if (!blob)
die("unable to add index blob to traversal"); die("unable to add index blob to traversal");
blob->object.flags |= flags;
add_pending_object_with_path(revs, &blob->object, "", add_pending_object_with_path(revs, &blob->object, "",
ce->ce_mode, ce->name); ce->ce_mode, ce->name);
} }
if (istate->cache_tree) { if (istate->cache_tree) {
struct strbuf path = STRBUF_INIT; struct strbuf path = STRBUF_INIT;
add_cache_tree(istate->cache_tree, revs, &path); add_cache_tree(istate->cache_tree, revs, &path, flags);
strbuf_release(&path); strbuf_release(&path);
} }
} }
@ -1378,7 +1381,7 @@ void add_index_objects_to_pending(struct rev_info *revs, unsigned int flags)
struct worktree **worktrees, **p; struct worktree **worktrees, **p;
read_index(revs->repo->index); read_index(revs->repo->index);
do_add_index_objects_to_pending(revs, revs->repo->index); do_add_index_objects_to_pending(revs, revs->repo->index, flags);
if (revs->single_worktree) if (revs->single_worktree)
return; return;
@ -1394,7 +1397,7 @@ void add_index_objects_to_pending(struct rev_info *revs, unsigned int flags)
if (read_index_from(&istate, if (read_index_from(&istate,
worktree_git_path(wt, "index"), worktree_git_path(wt, "index"),
get_worktree_git_dir(wt)) > 0) get_worktree_git_dir(wt)) > 0)
do_add_index_objects_to_pending(revs, &istate); do_add_index_objects_to_pending(revs, &istate, flags);
discard_index(&istate); discard_index(&istate);
} }
free_worktrees(worktrees); free_worktrees(worktrees);

View file

@ -113,6 +113,8 @@ check_approxidate '3:00' '2009-08-30 03:00:00'
check_approxidate '15:00' '2009-08-30 15:00:00' check_approxidate '15:00' '2009-08-30 15:00:00'
check_approxidate 'noon today' '2009-08-30 12:00:00' check_approxidate 'noon today' '2009-08-30 12:00:00'
check_approxidate 'noon yesterday' '2009-08-29 12:00:00' check_approxidate 'noon yesterday' '2009-08-29 12:00:00'
check_approxidate 'January 5th noon pm' '2009-01-05 12:00:00'
check_approxidate '10am noon' '2009-08-29 12:00:00'
check_approxidate 'last tuesday' '2009-08-25 19:20:00' check_approxidate 'last tuesday' '2009-08-25 19:20:00'
check_approxidate 'July 5th' '2009-07-05 19:20:00' check_approxidate 'July 5th' '2009-07-05 19:20:00'

View file

@ -90,11 +90,18 @@ test_expect_success 'rev-list can show index objects' '
9200b628cf9dc883a85a7abc8d6e6730baee589c two 9200b628cf9dc883a85a7abc8d6e6730baee589c two
EOF EOF
echo only-in-index >only-in-index && echo only-in-index >only-in-index &&
test_when_finished "git reset --hard" &&
git add only-in-index && git add only-in-index &&
git rev-list --objects --indexed-objects >actual && git rev-list --objects --indexed-objects >actual &&
test_cmp expect actual test_cmp expect actual
' '
test_expect_success 'rev-list can negate index objects' '
git rev-parse HEAD >expect &&
git rev-list -1 --objects HEAD --not --indexed-objects >actual &&
test_cmp expect actual
'
test_expect_success '--bisect and --first-parent can not be combined' ' test_expect_success '--bisect and --first-parent can not be combined' '
test_must_fail git rev-list --bisect --first-parent HEAD test_must_fail git rev-list --bisect --first-parent HEAD
' '