- int ret;
- /* try the @{-N} syntax for n-th checkout */
- ret = interpret_branch_name(str, &buf);
- if (ret > 0)
- /* substitute this branch name and restart */
- return get_sha1_1(buf.buf, buf.len, sha1, 0);
- else if (ret == 0)
- return -1;
+ int detached;
+
+ if (interpret_nth_prior_checkout(str, &buf) > 0) {
+ detached = (buf.len == 40 && !get_sha1_hex(buf.buf, sha1));
+ strbuf_release(&buf);
+ if (detached)
+ return 0;
+ }
+ }
+
+ if (!len && reflog_len)