lockfile.c: add a new public function unable_to_lock_message
Introducing a new unable_to_lock_message helper, which has nicer semantics than unable_to_lock_error and cleans up lockfile.c a little. Signed-off-by: Ronnie Sahlberg <sahlberg@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com> Acked-by: Michael Haggerty <mhagger@alum.mit.edu>
This commit is contained in:
parent
995f8746bc
commit
6af926e8bc
2
cache.h
2
cache.h
@ -559,6 +559,8 @@ struct lock_file {
|
|||||||
#define LOCK_DIE_ON_ERROR 1
|
#define LOCK_DIE_ON_ERROR 1
|
||||||
#define LOCK_NODEREF 2
|
#define LOCK_NODEREF 2
|
||||||
extern int unable_to_lock_error(const char *path, int err);
|
extern int unable_to_lock_error(const char *path, int err);
|
||||||
|
extern void unable_to_lock_message(const char *path, int err,
|
||||||
|
struct strbuf *buf);
|
||||||
extern NORETURN void unable_to_lock_index_die(const char *path, int err);
|
extern NORETURN void unable_to_lock_index_die(const char *path, int err);
|
||||||
extern int hold_lock_file_for_update(struct lock_file *, const char *path, int);
|
extern int hold_lock_file_for_update(struct lock_file *, const char *path, int);
|
||||||
extern int hold_lock_file_for_append(struct lock_file *, const char *path, int);
|
extern int hold_lock_file_for_append(struct lock_file *, const char *path, int);
|
||||||
|
22
lockfile.c
22
lockfile.c
@ -157,33 +157,35 @@ static int lock_file(struct lock_file *lk, const char *path, int flags)
|
|||||||
return lk->fd;
|
return lk->fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *unable_to_lock_message(const char *path, int err)
|
void unable_to_lock_message(const char *path, int err, struct strbuf *buf)
|
||||||
{
|
{
|
||||||
struct strbuf buf = STRBUF_INIT;
|
|
||||||
|
|
||||||
if (err == EEXIST) {
|
if (err == EEXIST) {
|
||||||
strbuf_addf(&buf, "Unable to create '%s.lock': %s.\n\n"
|
strbuf_addf(buf, "Unable to create '%s.lock': %s.\n\n"
|
||||||
"If no other git process is currently running, this probably means a\n"
|
"If no other git process is currently running, this probably means a\n"
|
||||||
"git process crashed in this repository earlier. Make sure no other git\n"
|
"git process crashed in this repository earlier. Make sure no other git\n"
|
||||||
"process is running and remove the file manually to continue.",
|
"process is running and remove the file manually to continue.",
|
||||||
absolute_path(path), strerror(err));
|
absolute_path(path), strerror(err));
|
||||||
} else
|
} else
|
||||||
strbuf_addf(&buf, "Unable to create '%s.lock': %s",
|
strbuf_addf(buf, "Unable to create '%s.lock': %s",
|
||||||
absolute_path(path), strerror(err));
|
absolute_path(path), strerror(err));
|
||||||
return strbuf_detach(&buf, NULL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int unable_to_lock_error(const char *path, int err)
|
int unable_to_lock_error(const char *path, int err)
|
||||||
{
|
{
|
||||||
char *msg = unable_to_lock_message(path, err);
|
struct strbuf buf = STRBUF_INIT;
|
||||||
error("%s", msg);
|
|
||||||
free(msg);
|
unable_to_lock_message(path, err, &buf);
|
||||||
|
error("%s", buf.buf);
|
||||||
|
strbuf_release(&buf);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
NORETURN void unable_to_lock_index_die(const char *path, int err)
|
NORETURN void unable_to_lock_index_die(const char *path, int err)
|
||||||
{
|
{
|
||||||
die("%s", unable_to_lock_message(path, err));
|
struct strbuf buf = STRBUF_INIT;
|
||||||
|
|
||||||
|
unable_to_lock_message(path, err, &buf);
|
||||||
|
die("%s", buf.buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
int hold_lock_file_for_update(struct lock_file *lk, const char *path, int flags)
|
int hold_lock_file_for_update(struct lock_file *lk, const char *path, int flags)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user