@matheusbsbs / matheus-bagliano / commits / 1b018fd9be
Fork 0

git branch -D: give a better error message when lockfile creation fails

Previously the old error message just told the user that it was not possible to delete the ref from the packed-refs file. Give instructions on how to resolve the problem. Signed-off-by: Miklos Vajna <vmiklos@frugalware.org> Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>

Miklos Vajna committed Sep 27, 2009 at 01:15 UTC 1b018fd9be290fd6a70ce3093ab1dc1abce74e00
3 files changed +24 -7
cache.h
+1
@@ -489,6 +489,7 @@ struct lock_file {
489 };
490 #define LOCK_DIE_ON_ERROR 1
491 #define LOCK_NODEREF 2
492 +extern int unable_to_lock_error(const char *path, int err);
493 extern NORETURN void unable_to_lock_index_die(const char *path, int err);
494 extern int hold_lock_file_for_update(struct lock_file *, const char *path, int);
495 extern int hold_lock_file_for_append(struct lock_file *, const char *path, int);
lockfile.c
+20 -6
@@ -155,18 +155,32 @@ static int lock_file(struct lock_file *lk, const char *path, int flags)
155 return lk->fd;
156 }
157
158 -
159 -NORETURN void unable_to_lock_index_die(const char *path, int err)
158 +static char *unable_to_lock_message(const char *path, int err)
159 {
160 + struct strbuf buf = STRBUF_INIT;
161 +
162 if (err == EEXIST) {
162 - die("Unable to create '%s.lock': %s.\n\n"
163 + strbuf_addf(&buf, "Unable to create '%s.lock': %s.\n\n"
164 "If no other git process is currently running, this probably means a\n"
165 "git process crashed in this repository earlier. Make sure no other git\n"
166 "process is running and remove the file manually to continue.",
167 path, strerror(err));
167 - } else {
168 - die("Unable to create '%s.lock': %s", path, strerror(err));
169 - }
168 + } else
169 + strbuf_addf(&buf, "Unable to create '%s.lock': %s", path, strerror(err));
170 + return strbuf_detach(&buf, NULL);
171 +}
172 +
173 +int unable_to_lock_error(const char *path, int err)
174 +{
175 + char *msg = unable_to_lock_message(path, err);
176 + error("%s", msg);
177 + free(msg);
178 + return -1;
179 +}
180 +
181 +NORETURN void unable_to_lock_index_die(const char *path, int err)
182 +{
183 + die("%s", unable_to_lock_message(path, err));
184 }
185
186 int hold_lock_file_for_update(struct lock_file *lk, const char *path, int flags)
refs.c
+3 -1
@@ -972,8 +972,10 @@ static int repack_without_ref(const char *refname)
972 if (!found)
973 return 0;
974 fd = hold_lock_file_for_update(&packlock, git_path("packed-refs"), 0);
975 - if (fd < 0)
975 + if (fd < 0) {
976 + unable_to_lock_error(git_path("packed-refs"), errno);
977 return error("cannot delete '%s' from packed refs", refname);
978 + }
979
980 for (list = packed_ref_list; list; list = list->next) {
981 char line[PATH_MAX + 100];