index 17cd0cef3c9819d70083554f99d8f09391171db1..98327d798375d2bc966f877af227a03070ce5d1b 100644 (file)
--- a/refs.c
+++ b/refs.c
if (lstat(path, &st) < 0) {
if (reading || errno != ENOENT)
return NULL;
if (lstat(path, &st) < 0) {
if (reading || errno != ENOENT)
return NULL;
- memset(sha1, 0, 20);
+ hashclr(sha1);
return path;
}
return path;
}
}
}
}
}
+ /* Is it a directory? */
+ if (S_ISDIR(st.st_mode)) {
+ errno = EISDIR;
+ return NULL;
+ }
+
/*
* Anything else, just open it and try to use it as
* a ref
/*
* Anything else, just open it and try to use it as
* a ref
}
lock->lk = xcalloc(1, sizeof(struct lock_file));
}
lock->lk = xcalloc(1, sizeof(struct lock_file));
- lock->ref_file = strdup(path);
- lock->log_file = strdup(git_path("logs/%s", lock->ref_file + plen));
+ lock->ref_file = xstrdup(path);
+ lock->log_file = xstrdup(git_path("logs/%s", lock->ref_file + plen));
lock->force_write = lstat(lock->ref_file, &st) && errno == ENOENT;
if (safe_create_leading_directories(lock->ref_file))
lock->force_write = lstat(lock->ref_file, &st) && errno == ENOENT;
if (safe_create_leading_directories(lock->ref_file))
if (lock->lk)
rollback_lock_file(lock->lk);
}
if (lock->lk)
rollback_lock_file(lock->lk);
}
- if (lock->ref_file)
- free(lock->ref_file);
- if (lock->log_file)
- free(lock->log_file);
+ free(lock->ref_file);
+ free(lock->log_file);
free(lock);
}
free(lock);
}