Skip to content

Commit

Permalink
Merge branch 'jc/date' into next
Browse files Browse the repository at this point in the history
* jc/date:
  date parsing: be friendlier to our European friends.
  Tweaks to make asciidoc play nice.
  git-commit: document --amend
  Avoid a crash if realloc returns a different pointer.
  Avoid a divide by zero if there's no messages to send.
  [PATCH] Provide configurable UI font for gitk
  [PATCH] gitk: Use git wrapper to run git-ls-remote.
  [PATCH] gitk: add key bindings for selecting first and last commit
  gitk: Add a help menu item to display key bindings
  [PATCH] gitk: allow goto heads
  gitk: replace parent and children arrays with lists
  • Loading branch information
Junio C Hamano committed Apr 5, 2006
2 parents 1b83ace + 38035cf commit 9cda21d
Show file tree
Hide file tree
Showing 4 changed files with 312 additions and 129 deletions.
25 changes: 24 additions & 1 deletion Documentation/git-commit.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ SYNOPSIS
--------
[verse]
'git-commit' [-a] [-s] [-v] [(-c | -C) <commit> | -F <file> | -m <msg>]
[-e] [--author <author>] [--] [[-i | -o ]<file>...]
[--no-verify] [--amend] [-e] [--author <author>]
[--] [[-i | -o ]<file>...]

DESCRIPTION
-----------
Expand Down Expand Up @@ -71,6 +72,28 @@ OPTIONS
commit log message unmodified. This option lets you
further edit the message taken from these sources.

--amend::

Used to amend the tip of the current branch. Prepare the tree
object you would want to replace the latest commit as usual
(this includes the usual -i/-o and explicit paths), and the
commit log editor is seeded with the commit message from the
tip of the current branch. The commit you create replaces the
current tip -- if it was a merge, it will have the parents of
the current tip as parents -- so the current top commit is
discarded.
+
--
It is a rough equivalent for:
------
$ git reset --soft HEAD^
$ ... do something else to come up with the right tree ...
$ git commit -c ORIG_HEAD

------
but can be used to amend a merge commit.
--

-i|--include::
Instead of committing only the files specified on the
command line, update them in the index file and then
Expand Down
77 changes: 56 additions & 21 deletions date.c
Original file line number Diff line number Diff line change
Expand Up @@ -197,33 +197,53 @@ static int match_alpha(const char *date, struct tm *tm, int *offset)
return skip_alpha(date);
}

static int is_date(int year, int month, int day, struct tm *tm)
static int is_date(int year, int month, int day, struct tm *now_tm, time_t now, struct tm *tm)
{
if (month > 0 && month < 13 && day > 0 && day < 32) {
struct tm check = *tm;
struct tm *r = (now_tm ? &check : tm);
time_t specified;

r->tm_mon = month - 1;
r->tm_mday = day;
if (year == -1) {
tm->tm_mon = month-1;
tm->tm_mday = day;
return 1;
if (!now_tm)
return 1;
r->tm_year = now_tm->tm_year;
}
if (year >= 1970 && year < 2100) {
year -= 1900;
} else if (year > 70 && year < 100) {
/* ok */
} else if (year < 38) {
year += 100;
} else
else if (year >= 1970 && year < 2100)
r->tm_year = year - 1900;
else if (year > 70 && year < 100)
r->tm_year = year;
else if (year < 38)
r->tm_year = year + 100;
else
return 0;
if (!now_tm)
return 1;

specified = my_mktime(r);

tm->tm_mon = month-1;
tm->tm_mday = day;
tm->tm_year = year;
/* Be it commit time or author time, it does not make
* sense to specify timestamp way into the future. Make
* sure it is not later than ten days from now...
*/
if (now + 10*24*3600 < specified)
return 0;
tm->tm_mon = r->tm_mon;
tm->tm_mday = r->tm_mday;
if (year != -1)
tm->tm_year = r->tm_year;
return 1;
}
return 0;
}

static int match_multi_number(unsigned long num, char c, const char *date, char *end, struct tm *tm)
{
time_t now;
struct tm now_tm;
struct tm *refuse_future;
long num2, num3;

num2 = strtol(end+1, &end, 10);
Expand All @@ -246,19 +266,33 @@ static int match_multi_number(unsigned long num, char c, const char *date, char

case '-':
case '/':
case '.':
now = time(NULL);
refuse_future = NULL;
if (gmtime_r(&now, &now_tm))
refuse_future = &now_tm;

if (num > 70) {
/* yyyy-mm-dd? */
if (is_date(num, num2, num3, tm))
if (is_date(num, num2, num3, refuse_future, now, tm))
break;
/* yyyy-dd-mm? */
if (is_date(num, num3, num2, tm))
if (is_date(num, num3, num2, refuse_future, now, tm))
break;
}
/* mm/dd/yy ? */
if (is_date(num3, num, num2, tm))
/* Our eastern European friends say dd.mm.yy[yy]
* is the norm there, so giving precedence to
* mm/dd/yy[yy] form only when separator is not '.'
*/
if (c != '.' &&
is_date(num3, num, num2, refuse_future, now, tm))
break;
/* European dd.mm.yy[yy] or funny US dd/mm/yy[yy] */
if (is_date(num3, num2, num, refuse_future, now, tm))
break;
/* dd/mm/yy ? */
if (is_date(num3, num2, num, tm))
/* Funny European mm.dd.yy */
if (c == '.' &&
is_date(num3, num, num2, refuse_future, now, tm))
break;
return 0;
}
Expand Down Expand Up @@ -288,10 +322,11 @@ static int match_digit(const char *date, struct tm *tm, int *offset, int *tm_gmt
}

/*
* Check for special formats: num[:-/]num[same]num
* Check for special formats: num[-.:/]num[same]num
*/
switch (*end) {
case ':':
case '.':
case '/':
case '-':
if (isdigit(end[1])) {
Expand Down
Loading

0 comments on commit 9cda21d

Please sign in to comment.