* [REGRESSION] Interrupted clone/fetch leaves .lock files around
@ 2006-06-06 18:51 Jonas Fonseca
2006-06-06 19:02 ` Jonas Fonseca
2006-06-06 19:09 ` Junio C Hamano
0 siblings, 2 replies; 4+ messages in thread
From: Jonas Fonseca @ 2006-06-06 18:51 UTC (permalink / raw)
To: git
Hi,
It used to be possible to continue an interrupted clone when using
cg-clone, by cding into the partial repo and run cg-fetch. However, it
seems that the recent changes in the ref locking code ends up leaving
.lock files around when interrupted.
$ cg clone http://elinks.cz/elinks.git
defaulting to local storage area
Fetching head...
Fetching objects...
...
Getting pack c0e265dab40fa34912c3ee6e02ba29686ab84a7b
which contains 16f85ec5043966c69e2142198c52e12494dcfc76
progress: 22 objects, 939754 bytes, now fetching c0e265dab40f... (657678 bytes)
cg-clone: interrupted
$ cd elinks
$ cg fetch
Recovering from a previously interrupted initial clone...
Fetching head...
Fetching objects...
error: Couldn't open lock file .git/refs/heads/origin.lock: File exists
error: Can't lock ref heads/origin
progress: 0 objects, 0 bytes
cg-fetch: objects fetch failed
Below is my feeble attempt at a (tested) fix.
diff --git a/fetch.c b/fetch.c
index e040ef9..861dc60 100644
--- a/fetch.c
+++ b/fetch.c
@@ -1,3 +1,5 @@
+#include <signal.h>
+
#include "fetch.h"
#include "cache.h"
@@ -214,9 +216,19 @@ static int mark_complete(const char *pat
return 0;
}
+static struct ref_lock *lock = NULL;
+
+static void remove_lockfile_on_signal(int signo)
+{
+ if (lock)
+ unlock_ref(lock);
+ lock = NULL;
+ signal(SIGINT, SIG_DFL);
+ raise(signo);
+}
+
int pull(char *target)
{
- struct ref_lock *lock = NULL;
unsigned char sha1[20];
char *msg;
int ret;
@@ -229,6 +241,7 @@ int pull(char *target)
error("Can't lock ref %s", write_ref);
return -1;
}
+ signal(SIGINT, remove_lockfile_on_signal);
}
if (!get_recover)
@@ -236,22 +249,11 @@ int pull(char *target)
if (interpret_target(target, sha1)) {
error("Could not interpret %s as something to pull", target);
- if (lock)
- unlock_ref(lock);
- return -1;
- }
- if (process(lookup_unknown_object(sha1))) {
- if (lock)
- unlock_ref(lock);
- return -1;
- }
- if (loop()) {
- if (lock)
- unlock_ref(lock);
- return -1;
- }
- if (write_ref) {
+ } else if (process(lookup_unknown_object(sha1)) || loop()) {
+ ; /* unlock */
+
+ } else if (write_ref) {
if (write_ref_log_details) {
msg = xmalloc(strlen(write_ref_log_details) + 12);
sprintf(msg, "fetch from %s", write_ref_log_details);
@@ -261,6 +263,10 @@ int pull(char *target)
if (msg)
free(msg);
return ret;
+ } else {
+ return 0;
}
- return 0;
+
+ remove_lockfile_on_signal(0);
+ return -1;
}
--
Jonas Fonseca
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [REGRESSION] Interrupted clone/fetch leaves .lock files around
2006-06-06 18:51 [REGRESSION] Interrupted clone/fetch leaves .lock files around Jonas Fonseca
@ 2006-06-06 19:02 ` Jonas Fonseca
2006-06-06 19:09 ` Junio C Hamano
1 sibling, 0 replies; 4+ messages in thread
From: Jonas Fonseca @ 2006-06-06 19:02 UTC (permalink / raw)
To: git
Jonas Fonseca <fonseca@diku.dk> wrote Tue, Jun 06, 2006:
> Below is my feeble attempt at a (tested) fix.
Ok, so maybe I didn't test it so well, other than continuously
interrupting the fetch. ;)
> diff --git a/fetch.c b/fetch.c
> index e040ef9..861dc60 100644
> --- a/fetch.c
> +++ b/fetch.c
> @@ -214,9 +216,19 @@ static int mark_complete(const char *pat
> return 0;
> }
>
> +static struct ref_lock *lock = NULL;
> +
> +static void remove_lockfile_on_signal(int signo)
> +{
> + if (lock)
> + unlock_ref(lock);
> + lock = NULL;
> + signal(SIGINT, SIG_DFL);
> + raise(signo);
> +}
> +
> int pull(char *target)
> {
> - struct ref_lock *lock = NULL;
> unsigned char sha1[20];
> char *msg;
> int ret;
...
> @@ -261,6 +263,10 @@ int pull(char *target)
> if (msg)
> free(msg);
> return ret;
> + } else {
> + return 0;
> }
> - return 0;
> +
> + remove_lockfile_on_signal(0);
This will end up calling raise().
> + return -1;
> }
--
Jonas Fonseca
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [REGRESSION] Interrupted clone/fetch leaves .lock files around
2006-06-06 18:51 [REGRESSION] Interrupted clone/fetch leaves .lock files around Jonas Fonseca
2006-06-06 19:02 ` Jonas Fonseca
@ 2006-06-06 19:09 ` Junio C Hamano
2006-06-06 21:58 ` Junio C Hamano
1 sibling, 1 reply; 4+ messages in thread
From: Junio C Hamano @ 2006-06-06 19:09 UTC (permalink / raw)
To: Jonas Fonseca; +Cc: git
Jonas Fonseca <fonseca@diku.dk> writes:
> Below is my feeble attempt at a (tested) fix.
>
> diff --git a/fetch.c b/fetch.c
> index e040ef9..861dc60 100644
> --- a/fetch.c
> +++ b/fetch.c
> @@ -1,3 +1,5 @@
> +#include <signal.h>
> +
> #include "fetch.h"
I suspect you could do something similar to what we already do
for index updates using atexit(). Let me take a look.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [REGRESSION] Interrupted clone/fetch leaves .lock files around
2006-06-06 19:09 ` Junio C Hamano
@ 2006-06-06 21:58 ` Junio C Hamano
0 siblings, 0 replies; 4+ messages in thread
From: Junio C Hamano @ 2006-06-06 21:58 UTC (permalink / raw)
To: Jonas Fonseca; +Cc: git, Shawn Pearce
Junio C Hamano <junkio@cox.net> writes:
> Jonas Fonseca <fonseca@diku.dk> writes:
>
>> Below is my feeble attempt at a (tested) fix.
>>
>> diff --git a/fetch.c b/fetch.c
>> index e040ef9..861dc60 100644
>> --- a/fetch.c
>> +++ b/fetch.c
>> @@ -1,3 +1,5 @@
>> +#include <signal.h>
>> +
>> #include "fetch.h"
>
> I suspect you could do something similar to what we already do
> for index updates using atexit(). Let me take a look.
Indeed it turns out that the signal work Pasky did in index.c is
exactly suitable for this. I've pushed out three patches in
"next" -- a few more eyeballs are appreciated on this one.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2006-06-06 21:59 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-06-06 18:51 [REGRESSION] Interrupted clone/fetch leaves .lock files around Jonas Fonseca
2006-06-06 19:02 ` Jonas Fonseca
2006-06-06 19:09 ` Junio C Hamano
2006-06-06 21:58 ` Junio C Hamano
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.