mirror of
https://github.com/git/git
synced 2024-08-27 11:39:22 +00:00
Merge branch 'sg/name-rev-cutoff-underflow-fix'
Integer arithmetic fix. * sg/name-rev-cutoff-underflow-fix: name-rev: avoid cutoff timestamp underflow
This commit is contained in:
commit
0b4fae553c
|
@ -9,7 +9,11 @@
|
|||
#include "sha1-lookup.h"
|
||||
#include "commit-slab.h"
|
||||
|
||||
#define CUTOFF_DATE_SLOP 86400 /* one day */
|
||||
/*
|
||||
* One day. See the 'name a rev shortly after epoch' test in t6120 when
|
||||
* changing this value
|
||||
*/
|
||||
#define CUTOFF_DATE_SLOP 86400
|
||||
|
||||
typedef struct rev_name {
|
||||
const char *tip_name;
|
||||
|
@ -481,8 +485,13 @@ int cmd_name_rev(int argc, const char **argv, const char *prefix)
|
|||
add_object_array(object, *argv, &revs);
|
||||
}
|
||||
|
||||
if (cutoff)
|
||||
cutoff = cutoff - CUTOFF_DATE_SLOP;
|
||||
if (cutoff) {
|
||||
/* check for undeflow */
|
||||
if (cutoff > TIME_MIN + CUTOFF_DATE_SLOP)
|
||||
cutoff = cutoff - CUTOFF_DATE_SLOP;
|
||||
else
|
||||
cutoff = TIME_MIN;
|
||||
}
|
||||
for_each_ref(name_ref, &data);
|
||||
|
||||
if (transform_stdin) {
|
||||
|
|
|
@ -344,6 +344,7 @@ typedef uintmax_t timestamp_t;
|
|||
#define PRItime PRIuMAX
|
||||
#define parse_timestamp strtoumax
|
||||
#define TIME_MAX UINTMAX_MAX
|
||||
#define TIME_MIN 0
|
||||
|
||||
#ifndef PATH_SEP
|
||||
#define PATH_SEP ':'
|
||||
|
|
|
@ -424,4 +424,19 @@ test_expect_success 'describe complains about missing object' '
|
|||
test_must_fail git describe $ZERO_OID
|
||||
'
|
||||
|
||||
test_expect_success 'name-rev a rev shortly after epoch' '
|
||||
test_when_finished "git checkout master" &&
|
||||
|
||||
git checkout --orphan no-timestamp-underflow &&
|
||||
# Any date closer to epoch than the CUTOFF_DATE_SLOP constant
|
||||
# in builtin/name-rev.c.
|
||||
GIT_COMMITTER_DATE="@1234 +0000" \
|
||||
git commit -m "committer date shortly after epoch" &&
|
||||
old_commit_oid=$(git rev-parse HEAD) &&
|
||||
|
||||
echo "$old_commit_oid no-timestamp-underflow" >expect &&
|
||||
git name-rev $old_commit_oid >actual &&
|
||||
test_cmp expect actual
|
||||
'
|
||||
|
||||
test_done
|
||||
|
|
Loading…
Reference in a new issue