From cce91a2caef9296bd4a69e51e48f1d679935d868 Mon Sep 17 00:00:00 2001 From: Shawn Pearce Date: Fri, 19 May 2006 03:29:43 -0400 Subject: [PATCH] Change 'master@noon' syntax to 'master@{noon}'. Its ambiguous to parse "master@2006-05-17 18:30:foo" when foo is meant as a file name and ":30" is meant as 30 minutes past 6 pm. Therefore all date specifications in a sha1 expression must now appear within brackets and the ':' splitter used for the path name in a sha1 expression ignores ':' appearing within brackets. Signed-off-by: Shawn O. Pearce Signed-off-by: Junio C Hamano --- Documentation/git-rev-parse.txt | 11 ++++--- sha1_name.c | 27 ++++++++++------ t/t1400-update-ref.sh | 55 +++++++++++++++++++++++---------- 3 files changed, 62 insertions(+), 31 deletions(-) diff --git a/Documentation/git-rev-parse.txt b/Documentation/git-rev-parse.txt index df308c3f5..b89469436 100644 --- a/Documentation/git-rev-parse.txt +++ b/Documentation/git-rev-parse.txt @@ -124,11 +124,12 @@ syntax. happen to have both heads/master and tags/master, you can explicitly say 'heads/master' to tell git which one you mean. -* A suffix '@' followed by a date specification such as 'yesterday' - (24 hours ago) or '1 month 2 weeks 3 days 1 hour 1 second ago' - to specify the value of the ref at a prior point in time. - This suffix may only be used immediately following a ref name - and the ref must have an existing log ($GIT_DIR/logs/). +* A suffix '@' followed by a date specification enclosed in a brace + pair (e.g. '\{yesterday\}', '\{1 month 2 weeks 3 days 1 hour 1 + second ago\}' or '\{1979-02-26 18:30:00\}') to specify the value + of the ref at a prior point in time. This suffix may only be + used immediately following a ref name and the ref must have an + existing log ($GIT_DIR/logs/). * A suffix '{caret}' to a revision parameter means the first parent of that commit object. '{caret}' means the th parent (i.e. diff --git a/sha1_name.c b/sha1_name.c index 4376cb392..fbbde1cf7 100644 --- a/sha1_name.c +++ b/sha1_name.c @@ -249,7 +249,7 @@ static int get_sha1_basic(const char *str, int len, unsigned char *sha1) static const char *warning = "warning: refname '%.*s' is ambiguous.\n"; const char **p, *pathname; char *real_path = NULL; - int refs_found = 0, at_mark; + int refs_found = 0, am; unsigned long at_time = (unsigned long)-1; unsigned char *this_result; unsigned char sha1_from_ref[20]; @@ -257,16 +257,16 @@ static int get_sha1_basic(const char *str, int len, unsigned char *sha1) if (len == 40 && !get_sha1_hex(str, sha1)) return 0; - /* At a given period of time? "@2 hours ago" */ - for (at_mark = 1; at_mark < len; at_mark++) { - if (str[at_mark] == '@') { - int date_len = len - at_mark - 1; + /* At a given period of time? "@{2 hours ago}" */ + for (am = 1; am < len - 1; am++) { + if (str[am] == '@' && str[am+1] == '{' && str[len-1] == '}') { + int date_len = len - am - 3; char *date_spec = xmalloc(date_len + 1); - strncpy(date_spec, str + at_mark + 1, date_len); + strncpy(date_spec, str + am + 2, date_len); date_spec[date_len] = 0; at_time = approxidate(date_spec); free(date_spec); - len = at_mark; + len = am; break; } } @@ -482,7 +482,7 @@ static int get_sha1_1(const char *name, int len, unsigned char *sha1) */ int get_sha1(const char *name, unsigned char *sha1) { - int ret; + int ret, bracket_depth; unsigned unused; int namelen = strlen(name); const char *cp; @@ -528,8 +528,15 @@ int get_sha1(const char *name, unsigned char *sha1) } return -1; } - cp = strchr(name, ':'); - if (cp) { + for (cp = name, bracket_depth = 0; *cp; cp++) { + if (*cp == '{') + bracket_depth++; + else if (bracket_depth && *cp == '}') + bracket_depth--; + else if (!bracket_depth && *cp == ':') + break; + } + if (*cp == ':') { unsigned char tree_sha1[20]; if (!get_sha1_1(name, cp-name, tree_sha1)) return get_tree_entry(tree_sha1, cp+1, sha1, diff --git a/t/t1400-update-ref.sh b/t/t1400-update-ref.sh index 7858d86b9..f6b076baf 100755 --- a/t/t1400-update-ref.sh +++ b/t/t1400-update-ref.sh @@ -125,52 +125,75 @@ ed="Thu, 26 May 2005 18:32:00 -0500" gd="Thu, 26 May 2005 18:33:00 -0500" ld="Thu, 26 May 2005 18:43:00 -0500" test_expect_success \ - 'Query "master@May 25 2005" (before history)' \ + 'Query "master@{May 25 2005}" (before history)' \ 'rm -f o e - git-rev-parse --verify "master@May 25 2005" >o 2>e && + git-rev-parse --verify "master@{May 25 2005}" >o 2>e && test $C = $(cat o) && test "warning: Log .git/logs/$m only goes back to $ed." = "$(cat e)"' test_expect_success \ - "Query master@2005-05-25 (before history)" \ + "Query master@{2005-05-25} (before history)" \ 'rm -f o e - git-rev-parse --verify master@2005-05-25 >o 2>e && + git-rev-parse --verify master@{2005-05-25} >o 2>e && test $C = $(cat o) && echo test "warning: Log .git/logs/$m only goes back to $ed." = "$(cat e)"' test_expect_success \ - 'Query "master@May 26 2005 23:31:59" (1 second before history)' \ + 'Query "master@{May 26 2005 23:31:59}" (1 second before history)' \ 'rm -f o e - git-rev-parse --verify "master@May 26 2005 23:31:59" >o 2>e && + git-rev-parse --verify "master@{May 26 2005 23:31:59}" >o 2>e && test $C = $(cat o) && test "warning: Log .git/logs/$m only goes back to $ed." = "$(cat e)"' test_expect_success \ - 'Query "master@May 26 2005 23:32:00" (exactly history start)' \ + 'Query "master@{May 26 2005 23:32:00}" (exactly history start)' \ 'rm -f o e - git-rev-parse --verify "master@May 26 2005 23:32:00" >o 2>e && + git-rev-parse --verify "master@{May 26 2005 23:32:00}" >o 2>e && test $A = $(cat o) && test "" = "$(cat e)"' test_expect_success \ - 'Query "master@2005-05-26 23:33:01" (middle of history with gap)' \ + 'Query "master@{2005-05-26 23:33:01}" (middle of history with gap)' \ 'rm -f o e - git-rev-parse --verify "master@2005-05-26 23:33:01" >o 2>e && + git-rev-parse --verify "master@{2005-05-26 23:33:01}" >o 2>e && test $B = $(cat o) && test "warning: Log .git/logs/$m has gap after $gd." = "$(cat e)"' test_expect_success \ - 'Query "master@2005-05-26 23:33:01" (middle of history)' \ + 'Query "master@{2005-05-26 23:38:00}" (middle of history)' \ 'rm -f o e - git-rev-parse --verify "master@2005-05-26 23:38:00" >o 2>e && + git-rev-parse --verify "master@{2005-05-26 23:38:00}" >o 2>e && test $Z = $(cat o) && test "" = "$(cat e)"' test_expect_success \ - 'Query "master@2005-05-26 23:43:00" (exact end of history)' \ + 'Query "master@{2005-05-26 23:43:00}" (exact end of history)' \ 'rm -f o e - git-rev-parse --verify "master@2005-05-26 23:43:00" >o 2>e && + git-rev-parse --verify "master@{2005-05-26 23:43:00}" >o 2>e && test $E = $(cat o) && test "" = "$(cat e)"' test_expect_success \ - 'Query "master@2005-05-28" (past end of history)' \ + 'Query "master@{2005-05-28}" (past end of history)' \ 'rm -f o e - git-rev-parse --verify "master@2005-05-28" >o 2>e && + git-rev-parse --verify "master@{2005-05-28}" >o 2>e && test $D = $(cat o) && test "warning: Log .git/logs/$m unexpectedly ended on $ld." = "$(cat e)"' + +rm -f .git/$m .git/logs/$m expect + +test_expect_success \ + 'creating initial files' \ + 'cp ../../COPYING COPYING && + git-add COPYING && + GIT_COMMITTER_DATE="2005-05-26 23:30" git-commit -m add -a && + cp ../../Makefile COPYING && + GIT_COMMITTER_DATE="2005-05-26 23:41" git-commit -m change -a' + +test_expect_success \ + 'git-cat-file blob master:COPYING (expect Makefile)' \ + 'git-cat-file blob master:COPYING | diff - ../../Makefile' +test_expect_success \ + 'git-cat-file blob master@{2005-05-26 23:30}:COPYING (expect COPYING)' \ + 'git-cat-file blob "master@{2005-05-26 23:30}:COPYING" \ + | diff - ../../COPYING' +test_expect_success \ + 'git-cat-file blob master@{2005-05-26 23:42}:COPYING (expect Makefile)' \ + 'git-cat-file blob "master@{2005-05-26 23:42}:COPYING" \ + | diff - ../../Makefile' + test_done -- 2.26.2