push: anonymize URL in status output
[gitweb.git] / transport.c
index 94fe8658f2bfa7775e667f7c28264c3dbe7f63b7..ff1b516943fd4069b9be247a8ec348b51df1ba29 100644 (file)
@@ -681,8 +681,11 @@ static void print_ok_ref_status(struct ref *ref, int porcelain)
 
 static int print_one_push_status(struct ref *ref, const char *dest, int count, int porcelain)
 {
-       if (!count)
-               fprintf(porcelain ? stdout : stderr, "To %s\n", dest);
+       if (!count) {
+               char *url = transport_anonymize_url(dest);
+               fprintf(porcelain ? stdout : stderr, "To %s\n", url);
+               free(url);
+       }
 
        switch(ref->status) {
        case REF_STATUS_NONE:
@@ -730,6 +733,10 @@ static int print_one_push_status(struct ref *ref, const char *dest, int count, i
                                                 ref->deletion ? NULL : ref->peer_ref,
                                                 "remote failed to report status", porcelain);
                break;
+       case REF_STATUS_ATOMIC_PUSH_FAILED:
+               print_ref_status('!', "[rejected]", ref, ref->peer_ref,
+                                                "atomic push failed", porcelain);
+               break;
        case REF_STATUS_OK:
                print_ok_ref_status(ref, porcelain);
                break;
@@ -828,6 +835,7 @@ static int git_transport_push(struct transport *transport, struct ref *remote_re
        args.dry_run = !!(flags & TRANSPORT_PUSH_DRY_RUN);
        args.porcelain = !!(flags & TRANSPORT_PUSH_PORCELAIN);
        args.push_cert = !!(flags & TRANSPORT_PUSH_CERT);
+       args.atomic = !!(flags & TRANSPORT_PUSH_ATOMIC);
        args.url = transport->url;
 
        ret = send_pack(&args, data->fd, data->conn, remote_refs,
@@ -909,18 +917,40 @@ static int external_specification_len(const char *url)
        return strchr(url, ':') - url;
 }
 
-void transport_check_allowed(const char *type)
+static const struct string_list *protocol_whitelist(void)
 {
-       struct string_list allowed = STRING_LIST_INIT_DUP;
-       const char *v = getenv("GIT_ALLOW_PROTOCOL");
+       static int enabled = -1;
+       static struct string_list allowed = STRING_LIST_INIT_DUP;
+
+       if (enabled < 0) {
+               const char *v = getenv("GIT_ALLOW_PROTOCOL");
+               if (v) {
+                       string_list_split(&allowed, v, ':', -1);
+                       string_list_sort(&allowed);
+                       enabled = 1;
+               } else {
+                       enabled = 0;
+               }
+       }
 
-       if (!v)
-               return;
+       return enabled ? &allowed : NULL;
+}
 
-       string_list_split(&allowed, v, ':', -1);
-       if (!unsorted_string_list_has_string(&allowed, type))
+int is_transport_allowed(const char *type)
+{
+       const struct string_list *allowed = protocol_whitelist();
+       return !allowed || string_list_has_string(allowed, type);
+}
+
+void transport_check_allowed(const char *type)
+{
+       if (!is_transport_allowed(type))
                die("transport '%s' not allowed", type);
-       string_list_clear(&allowed, 0);
+}
+
+int transport_restrict_protocols(void)
+{
+       return !!protocol_whitelist();
 }
 
 struct transport *transport_get(struct remote *remote, const char *url)