Code

builtin-fetch.c (store_updated_refs): Honor update_local_ref() return value
[git.git] / http-push.c
index 939a76460232f9097b20e43d71b35efbdad97b52..f173dcd64f73bddc891808c96c43407533aac1f5 100644 (file)
@@ -1349,6 +1349,24 @@ static int unlock_remote(struct remote_lock *lock)
        return rc;
 }
 
+static void remove_locks(void)
+{
+       struct remote_lock *lock = remote->locks;
+
+       fprintf(stderr, "Removing remote locks...\n");
+       while (lock) {
+               unlock_remote(lock);
+               lock = lock->next;
+       }
+}
+
+static void remove_locks_on_signal(int signo)
+{
+       remove_locks();
+       signal(signo, SIG_DFL);
+       raise(signo);
+}
+
 static void remote_ls(const char *path, int flags,
                      void (*userFunc)(struct remote_ls_ctx *ls),
                      void *userData);
@@ -1761,8 +1779,7 @@ static void one_remote_ref(char *refname)
        struct ref *ref;
        struct object *obj;
 
-       ref = alloc_ref(strlen(refname) + 1);
-       strcpy(ref->name, refname);
+       ref = alloc_ref_from_str(refname);
 
        if (http_fetch_ref(remote->url, ref) != 0) {
                fprintf(stderr,
@@ -1894,8 +1911,7 @@ static void add_remote_info_ref(struct remote_ls_ctx *ls)
        char *ref_info;
        struct ref *ref;
 
-       ref = alloc_ref(strlen(ls->dentry_name) + 1);
-       strcpy(ref->name, ls->dentry_name);
+       ref = alloc_ref_from_str(ls->dentry_name);
 
        if (http_fetch_ref(remote->url, ref) != 0) {
                fprintf(stderr,
@@ -2258,6 +2274,10 @@ int main(int argc, char **argv)
                goto cleanup;
        }
 
+       signal(SIGINT, remove_locks_on_signal);
+       signal(SIGHUP, remove_locks_on_signal);
+       signal(SIGQUIT, remove_locks_on_signal);
+
        /* Check whether the remote has server info files */
        remote->can_update_info_refs = 0;
        remote->has_info_refs = remote_exists("info/refs");