* name is a proper prefix of our refname.
*/
if (missing &&
- !is_refname_available(ref, NULL, get_packed_refs(), 0))
+ !is_refname_available(ref, NULL, get_packed_refs(), 0)) {
+ last_errno = ENOTDIR;
goto error_return;
+ }
lock->lk = xcalloc(1, sizeof(struct lock_file));
} else {
path = git_path("%s", refname);
}
- err = unlink(path);
- if (err && errno != ENOENT) {
+ err = unlink_or_warn(path);
+ if (err && errno != ENOENT)
ret = 1;
- error("unlink(%s) failed: %s",
- path, strerror(errno));
- }
+
if (!(delopt & REF_NODEREF))
lock->lk->filename[i] = '.';
}
*/
ret |= repack_without_ref(refname);
- err = unlink(git_path("logs/%s", lock->ref_name));
- if (err && errno != ENOENT)
- warning("unlink(%s) failed: %s",
- git_path("logs/%s", lock->ref_name), strerror(errno));
+ unlink_or_warn(git_path("logs/%s", lock->ref_name));
invalidate_cached_refs();
unlock_ref(lock);
return ret;
if (adjust_shared_perm(git_HEAD)) {
error("Unable to fix permissions on %s", lockpath);
error_unlink_return:
- unlink(lockpath);
+ unlink_or_warn(lockpath);
error_free_return:
free(git_HEAD);
return -1;
return;
}
-char *shorten_unambiguous_ref(const char *ref)
+char *shorten_unambiguous_ref(const char *ref, int strict)
{
int i;
static char **scanf_fmts;
/* skip first rule, it will always match */
for (i = nr_rules - 1; i > 0 ; --i) {
int j;
+ int rules_to_fail = i;
int short_name_len;
if (1 != sscanf(ref, scanf_fmts[i], short_name))
short_name_len = strlen(short_name);
+ /*
+ * in strict mode, all (except the matched one) rules
+ * must fail to resolve to a valid non-ambiguous ref
+ */
+ if (strict)
+ rules_to_fail = nr_rules;
+
/*
* check if the short name resolves to a valid ref,
* but use only rules prior to the matched one
*/
- for (j = 0; j < i; j++) {
+ for (j = 0; j < rules_to_fail; j++) {
const char *rule = ref_rev_parse_rules[j];
unsigned char short_objectname[20];
char refname[PATH_MAX];
+ /* skip matched rule */
+ if (i == j)
+ continue;
+
/*
* the short name is ambiguous, if it resolves
* (with this previous rule) to a valid ref
* short name is non-ambiguous if all previous rules
* haven't resolved to a valid ref
*/
- if (j == i)
+ if (j == rules_to_fail)
return short_name;
}