Skip to contentSkip to conversation

Change 'master@noon' syntax to 'master@{noon}'.

PATCH In review Shawn Pearce 1 participant 1 message Jun 15, 2016 Documentation

lore
Share & tools
lore
#0 lore raw

PATCH 5/5 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.

---

 Documentation/git-rev-parse.txt |   11 ++++----
 sha1_name.c                     |   27 ++++++++++++-------
 t/t1400-update-ref.sh           |   55 ++++++++++++++++++++++++++++-----------
 3 files changed, 62 insertions(+), 31 deletions(-)

eea4ae092b92129ef09e9caf6f6f2b523cd193cb

Documentation/git-rev-parse.txt +6 -5
index df308c3..b894694 100644
@@ -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/<ref>).
+* 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/<ref>).
 
 * A suffix '{caret}' to a revision parameter means the first parent of
   that commit object.  '{caret}<n>' means the <n>th parent (i.e.
sha1_name.c +17 -10
index 4376cb3..fbbde1c 100644
@@ -249,7 +249,7 @@ static int get_sha1_basic(const char *st
 	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 *st
 	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 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 
 		}
 		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,
t/t1400-update-ref.sh +39 -16

91 lines not on this page · raw message

Signature · 1 line
1.3.2.g7278