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 <spearce@spearce.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
Shawn Pearce committed
May 19, 2006 at 03:29 UTC
cce91a2caef9296bd4a69e51e48f1d679935d868
3 files changed
+62
-31
Documentation/git-rev-parse.txt
+6
-5
@@ -124,11 +124,12 @@ syntax.
124
happen to have both heads/master and tags/master, you can
125
explicitly say 'heads/master' to tell git which one you mean.
126
127
-* A suffix '@' followed by a date specification such as 'yesterday'
128
- (24 hours ago) or '1 month 2 weeks 3 days 1 hour 1 second ago'
129
- to specify the value of the ref at a prior point in time.
130
- This suffix may only be used immediately following a ref name
131
- and the ref must have an existing log ($GIT_DIR/logs/<ref>).
127
+* A suffix '@' followed by a date specification enclosed in a brace
128
+ pair (e.g. '\{yesterday\}', '\{1 month 2 weeks 3 days 1 hour 1
129
+ second ago\}' or '\{1979-02-26 18:30:00\}') to specify the value
130
+ of the ref at a prior point in time. This suffix may only be
131
+ used immediately following a ref name and the ref must have an
132
+ existing log ($GIT_DIR/logs/<ref>).
133
134
* A suffix '{caret}' to a revision parameter means the first parent of
135
that commit object. '{caret}<n>' means the <n>th parent (i.e.
sha1_name.c
+17
-10
@@ -249,7 +249,7 @@ static int get_sha1_basic(const char *str, int len, unsigned char *sha1)
249
static const char *warning = "warning: refname '%.*s' is ambiguous.\n";
250
const char **p, *pathname;
251
char *real_path = NULL;
252
- int refs_found = 0, at_mark;
252
+ int refs_found = 0, am;
253
unsigned long at_time = (unsigned long)-1;
254
unsigned char *this_result;
255
unsigned char sha1_from_ref[20];
@@ -257,16 +257,16 @@ static int get_sha1_basic(const char *str, int len, unsigned char *sha1)
257
if (len == 40 && !get_sha1_hex(str, sha1))
258
return 0;
259
260
- /* At a given period of time? "@2 hours ago" */
261
- for (at_mark = 1; at_mark < len; at_mark++) {
262
- if (str[at_mark] == '@') {
263
- int date_len = len - at_mark - 1;
260
+ /* At a given period of time? "@{2 hours ago}" */
261
+ for (am = 1; am < len - 1; am++) {
262
+ if (str[am] == '@' && str[am+1] == '{' && str[len-1] == '}') {
263
+ int date_len = len - am - 3;
264
char *date_spec = xmalloc(date_len + 1);
265
- strncpy(date_spec, str + at_mark + 1, date_len);
265
+ strncpy(date_spec, str + am + 2, date_len);
266
date_spec[date_len] = 0;
267
at_time = approxidate(date_spec);
268
free(date_spec);
269
- len = at_mark;
269
+ len = am;
270
break;
271
}
272
}
@@ -482,7 +482,7 @@ static int get_sha1_1(const char *name, int len, unsigned char *sha1)
482
*/
483
int get_sha1(const char *name, unsigned char *sha1)
484
{
485
- int ret;
485
+ int ret, bracket_depth;
486
unsigned unused;
487
int namelen = strlen(name);
488
const char *cp;
@@ -528,8 +528,15 @@ int get_sha1(const char *name, unsigned char *sha1)
528
}
529
return -1;
530
}
531
- cp = strchr(name, ':');
532
- if (cp) {
531
+ for (cp = name, bracket_depth = 0; *cp; cp++) {
532
+ if (*cp == '{')
533
+ bracket_depth++;
534
+ else if (bracket_depth && *cp == '}')
535
+ bracket_depth--;
536
+ else if (!bracket_depth && *cp == ':')
537
+ break;
538
+ }
539
+ if (*cp == ':') {
540
unsigned char tree_sha1[20];
541
if (!get_sha1_1(name, cp-name, tree_sha1))
542
return get_tree_entry(tree_sha1, cp+1, sha1,
t/t1400-update-ref.sh
+39
-16
@@ -125,52 +125,75 @@ ed="Thu, 26 May 2005 18:32:00 -0500"
125
gd="Thu, 26 May 2005 18:33:00 -0500"
126
ld="Thu, 26 May 2005 18:43:00 -0500"
127
test_expect_success \
128
- 'Query "master@May 25 2005" (before history)' \
128
+ 'Query "master@{May 25 2005}" (before history)' \
129
'rm -f o e
130
- git-rev-parse --verify "master@May 25 2005" >o 2>e &&
130
+ git-rev-parse --verify "master@{May 25 2005}" >o 2>e &&
131
test $C = $(cat o) &&
132
test "warning: Log .git/logs/$m only goes back to $ed." = "$(cat e)"'
133
test_expect_success \
134
- "Query master@2005-05-25 (before history)" \
134
+ "Query master@{2005-05-25} (before history)" \
135
'rm -f o e
136
- git-rev-parse --verify master@2005-05-25 >o 2>e &&
136
+ git-rev-parse --verify master@{2005-05-25} >o 2>e &&
137
test $C = $(cat o) &&
138
echo test "warning: Log .git/logs/$m only goes back to $ed." = "$(cat e)"'
139
test_expect_success \
140
- 'Query "master@May 26 2005 23:31:59" (1 second before history)' \
140
+ 'Query "master@{May 26 2005 23:31:59}" (1 second before history)' \
141
'rm -f o e
142
- git-rev-parse --verify "master@May 26 2005 23:31:59" >o 2>e &&
142
+ git-rev-parse --verify "master@{May 26 2005 23:31:59}" >o 2>e &&
143
test $C = $(cat o) &&
144
test "warning: Log .git/logs/$m only goes back to $ed." = "$(cat e)"'
145
test_expect_success \
146
- 'Query "master@May 26 2005 23:32:00" (exactly history start)' \
146
+ 'Query "master@{May 26 2005 23:32:00}" (exactly history start)' \
147
'rm -f o e
148
- git-rev-parse --verify "master@May 26 2005 23:32:00" >o 2>e &&
148
+ git-rev-parse --verify "master@{May 26 2005 23:32:00}" >o 2>e &&
149
test $A = $(cat o) &&
150
test "" = "$(cat e)"'
151
test_expect_success \
152
- 'Query "master@2005-05-26 23:33:01" (middle of history with gap)' \
152
+ 'Query "master@{2005-05-26 23:33:01}" (middle of history with gap)' \
153
'rm -f o e
154
- git-rev-parse --verify "master@2005-05-26 23:33:01" >o 2>e &&
154
+ git-rev-parse --verify "master@{2005-05-26 23:33:01}" >o 2>e &&
155
test $B = $(cat o) &&
156
test "warning: Log .git/logs/$m has gap after $gd." = "$(cat e)"'
157
test_expect_success \
158
- 'Query "master@2005-05-26 23:33:01" (middle of history)' \
158
+ 'Query "master@{2005-05-26 23:38:00}" (middle of history)' \
159
'rm -f o e
160
- git-rev-parse --verify "master@2005-05-26 23:38:00" >o 2>e &&
160
+ git-rev-parse --verify "master@{2005-05-26 23:38:00}" >o 2>e &&
161
test $Z = $(cat o) &&
162
test "" = "$(cat e)"'
163
test_expect_success \
164
- 'Query "master@2005-05-26 23:43:00" (exact end of history)' \
164
+ 'Query "master@{2005-05-26 23:43:00}" (exact end of history)' \
165
'rm -f o e
166
- git-rev-parse --verify "master@2005-05-26 23:43:00" >o 2>e &&
166
+ git-rev-parse --verify "master@{2005-05-26 23:43:00}" >o 2>e &&
167
test $E = $(cat o) &&
168
test "" = "$(cat e)"'
169
test_expect_success \
170
- 'Query "master@2005-05-28" (past end of history)' \
170
+ 'Query "master@{2005-05-28}" (past end of history)' \
171
'rm -f o e
172
- git-rev-parse --verify "master@2005-05-28" >o 2>e &&
172
+ git-rev-parse --verify "master@{2005-05-28}" >o 2>e &&
173
test $D = $(cat o) &&
174
test "warning: Log .git/logs/$m unexpectedly ended on $ld." = "$(cat e)"'
175
176
+
177
+rm -f .git/$m .git/logs/$m expect
178
+
179
+test_expect_success \
180
+ 'creating initial files' \
181
+ 'cp ../../COPYING COPYING &&
182
+ git-add COPYING &&
183
+ GIT_COMMITTER_DATE="2005-05-26 23:30" git-commit -m add -a &&
184
+ cp ../../Makefile COPYING &&
185
+ GIT_COMMITTER_DATE="2005-05-26 23:41" git-commit -m change -a'
186
+
187
+test_expect_success \
188
+ 'git-cat-file blob master:COPYING (expect Makefile)' \
189
+ 'git-cat-file blob master:COPYING | diff - ../../Makefile'
190
+test_expect_success \
191
+ 'git-cat-file blob master@{2005-05-26 23:30}:COPYING (expect COPYING)' \
192
+ 'git-cat-file blob "master@{2005-05-26 23:30}:COPYING" \
193
+ | diff - ../../COPYING'
194
+test_expect_success \
195
+ 'git-cat-file blob master@{2005-05-26 23:42}:COPYING (expect Makefile)' \
196
+ 'git-cat-file blob "master@{2005-05-26 23:42}:COPYING" \
197
+ | diff - ../../Makefile'
198
+
199
test_done