summaryrefslogtreecommitdiff
path: root/sha1_name.c
diff options
context:
space:
mode:
authorJunio C Hamano <junkio@cox.net>2006-11-01 08:48:50 -0800
committerJunio C Hamano <junkio@cox.net>2006-11-01 08:48:50 -0800
commit58a1e0e83bcdbf063fb708ee9a8a563c0aa14f87 (patch)
treee3534fae05b865abb5d686c191cdbde9b9cbf3d0 /sha1_name.c
parentec1e46897329317d7a9996264d7e999f9a68e307 (diff)
parent2e6d8f181dd77d40a1148549d4f33cdf2877fb19 (diff)
downloadgit-58a1e0e83bcdbf063fb708ee9a8a563c0aa14f87.tar.gz
Merge branch 'lj/refs'
* lj/refs: (63 commits) Fix show-ref usagestring t3200: git-branch testsuite update sha1_name.c: avoid compilation warnings. Make git-branch a builtin ref-log: fix D/F conflict coming from deleted refs. git-revert with conflicts to behave as git-merge with conflicts core.logallrefupdates thinko-fix git-pack-refs --all core.logallrefupdates create new log file only for branch heads. Remove bashism from t3210-pack-refs.sh ref-log: allow ref@{count} syntax. pack-refs: call fflush before fsync. pack-refs: use lockfile as everybody else does. git-fetch: do not look into $GIT_DIR/refs to see if a tag exists. lock_ref_sha1_basic does not remove empty directories on BSD Do not create tag leading directories since git update-ref does it. Check that a tag exists using show-ref instead of looking for the ref file. Use git-update-ref to delete a tag instead of rm()ing the ref file. Fix refs.c;:repack_without_ref() clean-up path Clean up "git-branch.sh" and add remove recursive dir test cases. ...
Diffstat (limited to 'sha1_name.c')
-rw-r--r--sha1_name.c56
1 files changed, 33 insertions, 23 deletions
diff --git a/sha1_name.c b/sha1_name.c
index 6ffee22081..6d7cd78381 100644
--- a/sha1_name.c
+++ b/sha1_name.c
@@ -247,26 +247,25 @@ static int get_sha1_basic(const char *str, int len, unsigned char *sha1)
NULL
};
static const char *warning = "warning: refname '%.*s' is ambiguous.\n";
- const char **p, *pathname;
- char *real_path = NULL;
- int refs_found = 0, am;
- unsigned long at_time = (unsigned long)-1;
+ const char **p, *ref;
+ char *real_ref = NULL;
+ int refs_found = 0;
+ int at, reflog_len;
unsigned char *this_result;
unsigned char sha1_from_ref[20];
if (len == 40 && !get_sha1_hex(str, sha1))
return 0;
- /* 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);
- strlcpy(date_spec, str + am + 2, date_len + 1);
- at_time = approxidate(date_spec);
- free(date_spec);
- len = am;
- break;
+ /* basic@{time or number} format to query ref-log */
+ reflog_len = at = 0;
+ if (str[len-1] == '}') {
+ for (at = 1; at < len - 1; at++) {
+ if (str[at] == '@' && str[at+1] == '{') {
+ reflog_len = (len-1) - (at+2);
+ len = at;
+ break;
+ }
}
}
@@ -276,10 +275,10 @@ static int get_sha1_basic(const char *str, int len, unsigned char *sha1)
for (p = fmt; *p; p++) {
this_result = refs_found ? sha1_from_ref : sha1;
- pathname = resolve_ref(git_path(*p, len, str), this_result, 1);
- if (pathname) {
+ ref = resolve_ref(mkpath(*p, len, str), this_result, 1, NULL);
+ if (ref) {
if (!refs_found++)
- real_path = xstrdup(pathname);
+ real_ref = xstrdup(ref);
if (!warn_ambiguous_refs)
break;
}
@@ -291,14 +290,25 @@ static int get_sha1_basic(const char *str, int len, unsigned char *sha1)
if (warn_ambiguous_refs && refs_found > 1)
fprintf(stderr, warning, len, str);
- if (at_time != (unsigned long)-1) {
- read_ref_at(
- real_path + strlen(git_path(".")) - 1,
- at_time,
- sha1);
+ if (reflog_len) {
+ /* Is it asking for N-th entry, or approxidate? */
+ int nth, i;
+ unsigned long at_time;
+ for (i = nth = 0; 0 <= nth && i < reflog_len; i++) {
+ char ch = str[at+2+i];
+ if ('0' <= ch && ch <= '9')
+ nth = nth * 10 + ch - '0';
+ else
+ nth = -1;
+ }
+ if (0 <= nth)
+ at_time = 0;
+ else
+ at_time = approxidate(str + at + 2);
+ read_ref_at(real_ref, at_time, nth, sha1);
}
- free(real_path);
+ free(real_ref);
return 0;
}