X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=http-push.c;h=5b230380ccd33d8b04f8dfce24050237ae9206ad;hb=049a226fa14fb25c03d2146c2f8f184cfea5e5bf;hp=0beb7406c34a19403062a6a2e2aeeee35566a45f;hpb=923d44aeb7cb6d21eeb459fdc1b58137e37c2b1c;p=git.git diff --git a/http-push.c b/http-push.c index 0beb7406c..5b230380c 100644 --- a/http-push.c +++ b/http-push.c @@ -664,8 +664,7 @@ static void release_request(struct transfer_request *request) close(request->local_fileno); if (request->local_stream) fclose(request->local_stream); - if (request->url != NULL) - free(request->url); + free(request->url); free(request); } @@ -1283,10 +1282,8 @@ static struct remote_lock *lock_remote(const char *path, long timeout) strbuf_release(&in_buffer); if (lock->token == NULL || lock->timeout <= 0) { - if (lock->token != NULL) - free(lock->token); - if (lock->owner != NULL) - free(lock->owner); + free(lock->token); + free(lock->owner); free(url); free(lock); lock = NULL; @@ -1344,8 +1341,7 @@ static int unlock_remote(struct remote_lock *lock) prev->next = prev->next->next; } - if (lock->owner != NULL) - free(lock->owner); + free(lock->owner); free(lock->url); free(lock->token); free(lock); @@ -2035,8 +2031,7 @@ static void fetch_symref(const char *path, char **symref, unsigned char *sha1) } free(url); - if (*symref != NULL) - free(*symref); + free(*symref); *symref = NULL; hashclr(sha1); @@ -2138,6 +2133,8 @@ static int delete_remote_branch(char *pattern, int force) /* Send delete request */ fprintf(stderr, "Removing remote branch '%s'\n", remote_ref->name); + if (dry_run) + return 0; url = xmalloc(strlen(remote->url) + strlen(remote_ref->name) + 1); sprintf(url, "%s%s", remote->url, remote_ref->name); slot = get_active_slot(); @@ -2240,7 +2237,7 @@ int main(int argc, char **argv) memset(remote_dir_exists, -1, 256); - http_init(); + http_init(NULL); no_pragma_header = curl_slist_append(no_pragma_header, "Pragma:"); @@ -2311,6 +2308,16 @@ int main(int argc, char **argv) if (!ref->peer_ref) continue; + + if (is_zero_sha1(ref->peer_ref->new_sha1)) { + if (delete_remote_branch(ref->name, 1) == -1) { + error("Could not remove %s", ref->name); + rc = -4; + } + new_refs++; + continue; + } + if (!hashcmp(ref->old_sha1, ref->peer_ref->new_sha1)) { if (push_verbosely || 1) fprintf(stderr, "'%s': up-to-date\n", ref->name); @@ -2342,11 +2349,6 @@ int main(int argc, char **argv) } } hashcpy(ref->new_sha1, ref->peer_ref->new_sha1); - if (is_zero_sha1(ref->new_sha1)) { - error("cannot happen anymore"); - rc = -3; - continue; - } new_refs++; strcpy(old_hex, sha1_to_hex(ref->old_sha1)); new_hex = sha1_to_hex(ref->new_sha1); @@ -2435,8 +2437,7 @@ int main(int argc, char **argv) } cleanup: - if (rewritten_url) - free(rewritten_url); + free(rewritten_url); if (info_ref_lock) unlock_remote(info_ref_lock); free(remote);