]> git.ipfire.org Git - thirdparty/git.git/blobdiff - transport.c
replace {pre,suf}fixcmp() with {starts,ends}_with()
[thirdparty/git.git] / transport.c
index de255880a41248857990380d7622512fd18160b0..8023956696d0d00bbc4b65c148eade97906a2729 100644 (file)
@@ -3,6 +3,8 @@
 #include "run-command.h"
 #include "pkt-line.h"
 #include "fetch-pack.h"
+#include "remote.h"
+#include "connect.h"
 #include "send-pack.h"
 #include "walker.h"
 #include "bundle.h"
@@ -167,13 +169,13 @@ static void set_upstreams(struct transport *transport, struct ref *refs,
                remotename = ref->name;
                tmp = resolve_ref_unsafe(localname, sha, 1, &flag);
                if (tmp && flag & REF_ISSYMREF &&
-                       !prefixcmp(tmp, "refs/heads/"))
+                       starts_with(tmp, "refs/heads/"))
                        localname = tmp;
 
                /* Both source and destination must be local branches. */
-               if (!localname || prefixcmp(localname, "refs/heads/"))
+               if (!localname || !starts_with(localname, "refs/heads/"))
                        continue;
-               if (!remotename || prefixcmp(remotename, "refs/heads/"))
+               if (!remotename || !starts_with(remotename, "refs/heads/"))
                        continue;
 
                if (!pretend)
@@ -189,7 +191,7 @@ static void set_upstreams(struct transport *transport, struct ref *refs,
 
 static const char *rsync_url(const char *url)
 {
-       return prefixcmp(url, "rsync://") ? skip_prefix(url, "rsync:") : url;
+       return !starts_with(url, "rsync://") ? skip_prefix(url, "rsync:") : url;
 }
 
 static struct ref *get_refs_via_rsync(struct transport *transport, int for_push)
@@ -294,8 +296,8 @@ static int write_one_ref(const char *name, const unsigned char *sha1,
        FILE *f;
 
        /* when called via for_each_ref(), flags is non-zero */
-       if (flags && prefixcmp(name, "refs/heads/") &&
-                       prefixcmp(name, "refs/tags/"))
+       if (flags && !starts_with(name, "refs/heads/") &&
+                       !starts_with(name, "refs/tags/"))
                return 0;
 
        strbuf_addstr(buf, name);
@@ -650,7 +652,7 @@ static void print_ok_ref_status(struct ref *ref, int porcelain)
                print_ref_status('-', "[deleted]", ref, NULL, NULL, porcelain);
        else if (is_null_sha1(ref->old_sha1))
                print_ref_status('*',
-                       (!prefixcmp(ref->name, "refs/tags/") ? "[new tag]" :
+                       (starts_with(ref->name, "refs/tags/") ? "[new tag]" :
                        "[new branch]"),
                        ref, ref->peer_ref, NULL, porcelain);
        else {
@@ -707,6 +709,10 @@ static int print_one_push_status(struct ref *ref, const char *dest, int count, i
                print_ref_status('!', "[rejected]", ref, ref->peer_ref,
                                                 "needs force", porcelain);
                break;
+       case REF_STATUS_REJECT_STALE:
+               print_ref_status('!', "[rejected]", ref, ref->peer_ref,
+                                                "stale info", porcelain);
+               break;
        case REF_STATUS_REMOTE_REJECT:
                print_ref_status('!', "[remote rejected]", ref,
                                                 ref->deletion ? NULL : ref->peer_ref,
@@ -924,13 +930,13 @@ struct transport *transport_get(struct remote *remote, const char *url)
 
                while (is_urlschemechar(p == url, *p))
                        p++;
-               if (!prefixcmp(p, "::"))
+               if (starts_with(p, "::"))
                        helper = xstrndup(url, p - url);
        }
 
        if (helper) {
                transport_helper_init(ret, helper);
-       } else if (!prefixcmp(url, "rsync:")) {
+       } else if (starts_with(url, "rsync:")) {
                ret->get_refs_list = get_refs_via_rsync;
                ret->fetch = fetch_objs_via_rsync;
                ret->push = rsync_transport_push;
@@ -943,11 +949,11 @@ struct transport *transport_get(struct remote *remote, const char *url)
                ret->disconnect = close_bundle;
                ret->smart_options = NULL;
        } else if (!is_url(url)
-               || !prefixcmp(url, "file://")
-               || !prefixcmp(url, "git://")
-               || !prefixcmp(url, "ssh://")
-               || !prefixcmp(url, "git+ssh://")
-               || !prefixcmp(url, "ssh+git://")) {
+               || starts_with(url, "file://")
+               || starts_with(url, "git://")
+               || starts_with(url, "ssh://")
+               || starts_with(url, "git+ssh://")
+               || starts_with(url, "ssh+git://")) {
                /* These are builtin smart transports. */
                struct git_transport_data *data = xcalloc(1, sizeof(*data));
                ret->data = data;
@@ -1078,6 +1084,7 @@ static int run_pre_push_hook(struct transport *transport,
        for (r = remote_refs; r; r = r->next) {
                if (!r->peer_ref) continue;
                if (r->status == REF_STATUS_REJECT_NONFASTFORWARD) continue;
+               if (r->status == REF_STATUS_REJECT_STALE) continue;
                if (r->status == REF_STATUS_UPTODATE) continue;
 
                strbuf_reset(&buf);
@@ -1142,6 +1149,12 @@ int transport_push(struct transport *transport,
                        return -1;
                }
 
+               if (transport->smart_options &&
+                   transport->smart_options->cas &&
+                   !is_empty_cas(transport->smart_options->cas))
+                       apply_push_cas(transport->smart_options->cas,
+                                      transport->remote, remote_refs);
+
                set_ref_status_for_push(remote_refs,
                        flags & TRANSPORT_PUSH_MIRROR,
                        flags & TRANSPORT_PUSH_FORCE);