object: add repository argument to object_as_type
[gitweb.git] / upload-pack.c
index 87b4d32a6e23aed2416a9bb752dfa56b916b141c..45e3a94788f387b9068b4b20f7175a70edf94394 100644 (file)
@@ -3,6 +3,8 @@
 #include "refs.h"
 #include "pkt-line.h"
 #include "sideband.h"
+#include "repository.h"
+#include "object-store.h"
 #include "tag.h"
 #include "object.h"
 #include "commit.h"
@@ -310,7 +312,7 @@ static int got_oid(const char *hex, struct object_id *oid)
        if (!has_object_file(oid))
                return -1;
 
-       o = parse_object(oid);
+       o = parse_object(the_repository, oid);
        if (!o)
                die("oops (%s)", oid_to_hex(oid));
        if (o->type == OBJ_COMMIT) {
@@ -348,7 +350,7 @@ static int reachable(struct commit *want)
                        break;
                }
                if (!commit->object.parsed)
-                       parse_object(&commit->object.oid);
+                       parse_object(the_repository, &commit->object.oid);
                if (commit->object.flags & REACHABLE)
                        continue;
                commit->object.flags |= REACHABLE;
@@ -444,7 +446,7 @@ static int get_common_commits(void)
                                break;
                        default:
                                got_common = 1;
-                               memcpy(last_hex, oid_to_hex(&oid), 41);
+                               oid_to_hex_r(last_hex, &oid);
                                if (multi_ack == 2)
                                        packet_write_fmt(1, "ACK %s common\n", last_hex);
                                else if (multi_ack)
@@ -486,7 +488,7 @@ static int do_reachable_revlist(struct child_process *cmd,
                "rev-list", "--stdin", NULL,
        };
        struct object *o;
-       char namebuf[42]; /* ^ + SHA-1 + LF */
+       char namebuf[GIT_MAX_HEXSZ + 2]; /* ^ + hash + LF */
        int i;
 
        cmd->argv = argv;
@@ -555,18 +557,20 @@ static int get_reachable_list(struct object_array *src,
        struct child_process cmd = CHILD_PROCESS_INIT;
        int i;
        struct object *o;
-       char namebuf[42]; /* ^ + SHA-1 + LF */
+       char namebuf[GIT_MAX_HEXSZ + 2]; /* ^ + hash + LF */
+       const unsigned hexsz = the_hash_algo->hexsz;
 
        if (do_reachable_revlist(&cmd, src, reachable) < 0)
                return -1;
 
-       while ((i = read_in_full(cmd.out, namebuf, 41)) == 41) {
+       while ((i = read_in_full(cmd.out, namebuf, hexsz + 1)) == hexsz + 1) {
                struct object_id sha1;
+               const char *p;
 
-               if (namebuf[40] != '\n' || get_oid_hex(namebuf, &sha1))
+               if (parse_oid_hex(namebuf, &sha1, &p) || *p != '\n')
                        break;
 
-               o = lookup_object(sha1.hash);
+               o = lookup_object(the_repository, sha1.hash);
                if (o && o->type == OBJ_COMMIT) {
                        o->flags &= ~TMP_MARK;
                }
@@ -656,7 +660,7 @@ static void send_shallow(struct commit_list *result)
                if (!(object->flags & (CLIENT_SHALLOW|NOT_SHALLOW))) {
                        packet_write_fmt(1, "shallow %s",
                                         oid_to_hex(&object->oid));
-                       register_shallow(&object->oid);
+                       register_shallow(the_repository, &object->oid);
                        shallow_nr++;
                }
                result = result->next;
@@ -693,14 +697,14 @@ static void send_unshallow(const struct object_array *shallows)
                        add_object_array(object, NULL, &extra_edge_obj);
                }
                /* make sure commit traversal conforms to client */
-               register_shallow(&object->oid);
+               register_shallow(the_repository, &object->oid);
        }
 }
 
 static void deepen(int depth, int deepen_relative,
                   struct object_array *shallows)
 {
-       if (depth == INFINITE_DEPTH && !is_repository_shallow()) {
+       if (depth == INFINITE_DEPTH && !is_repository_shallow(the_repository)) {
                int i;
 
                for (i = 0; i < shallows->nr; i++) {
@@ -780,7 +784,8 @@ static int send_shallow_list(int depth, int deepen_rev_list,
                if (shallows->nr > 0) {
                        int i;
                        for (i = 0; i < shallows->nr; i++)
-                               register_shallow(&shallows->objects[i].item->oid);
+                               register_shallow(the_repository,
+                                                &shallows->objects[i].item->oid);
                }
        }
 
@@ -796,7 +801,7 @@ static int process_shallow(const char *line, struct object_array *shallows)
                struct object *object;
                if (get_oid_hex(arg, &oid))
                        die("invalid shallow line: %s", line);
-               object = parse_object(&oid);
+               object = parse_object(the_repository, &oid);
                if (!object)
                        return 1;
                if (object->type != OBJ_COMMIT)
@@ -895,11 +900,9 @@ static void receive_needs(void)
                }
 
                if (!skip_prefix(line, "want ", &arg) ||
-                   get_oid_hex(arg, &oid_buf))
+                   parse_oid_hex(arg, &oid_buf, &features))
                        die("git upload-pack: protocol error, "
-                           "expected to get sha, not '%s'", line);
-
-               features = arg + 40;
+                           "expected to get object ID, not '%s'", line);
 
                if (parse_feature_request(features, "deepen-relative"))
                        deepen_relative = 1;
@@ -924,7 +927,7 @@ static void receive_needs(void)
                if (allow_filter && parse_feature_request(features, "filter"))
                        filter_capability_requested = 1;
 
-               o = parse_object(&oid_buf);
+               o = parse_object(the_repository, &oid_buf);
                if (!o) {
                        packet_write_fmt(1,
                                         "ERR upload-pack: not our ref %s",
@@ -1165,7 +1168,7 @@ static int parse_want(const char *line)
                        die("git upload-pack: protocol error, "
                            "expected to get oid, not '%s'", line);
 
-               o = parse_object(&oid);
+               o = parse_object(the_repository, &oid);
                if (!o) {
                        packet_write_fmt(1,
                                         "ERR upload-pack: not our ref %s",
@@ -1205,6 +1208,7 @@ static void process_args(struct packet_reader *request,
 {
        while (packet_reader_read(request) != PACKET_READ_FLUSH) {
                const char *arg = request->line;
+               const char *p;
 
                /* process want */
                if (parse_want(arg))
@@ -1251,8 +1255,13 @@ static void process_args(struct packet_reader *request,
                        continue;
                }
 
+               if (allow_filter && skip_prefix(arg, "filter ", &p)) {
+                       parse_list_objects_filter(&filter_options, p);
+                       continue;
+               }
+
                /* ignore unknown lines maybe? */
-               die("unexpect line: '%s'", arg);
+               die("unexpected line: '%s'", arg);
        }
 }
 
@@ -1271,7 +1280,7 @@ static int process_haves(struct oid_array *haves, struct oid_array *common)
 
                oid_array_append(common, oid);
 
-               o = parse_object(oid);
+               o = parse_object(the_repository, oid);
                if (!o)
                        die("oops (%s)", oid_to_hex(oid));
                if (o->type == OBJ_COMMIT) {
@@ -1350,14 +1359,15 @@ static void send_shallow_info(struct upload_pack_data *data)
 {
        /* No shallow info needs to be sent */
        if (!data->depth && !data->deepen_rev_list && !data->shallows.nr &&
-           !is_repository_shallow())
+           !is_repository_shallow(the_repository))
                return;
 
        packet_write_fmt(1, "shallow-info\n");
 
        if (!send_shallow_list(data->depth, data->deepen_rev_list,
                               data->deepen_since, &data->deepen_not,
-                              &data->shallows) && is_repository_shallow())
+                              &data->shallows) &&
+           is_repository_shallow(the_repository))
                deepen(INFINITE_DEPTH, data->deepen_relative, &data->shallows);
 
        packet_delim(1);
@@ -1376,6 +1386,8 @@ int upload_pack_v2(struct repository *r, struct argv_array *keys,
        enum fetch_state state = FETCH_PROCESS_ARGS;
        struct upload_pack_data data;
 
+       git_config(upload_pack_config, NULL);
+
        upload_pack_data_init(&data);
        use_sideband = LARGE_PACKET_MAX;
 
@@ -1428,7 +1440,14 @@ int upload_pack_v2(struct repository *r, struct argv_array *keys,
 int upload_pack_advertise(struct repository *r,
                          struct strbuf *value)
 {
-       if (value)
+       if (value) {
+               int allow_filter_value;
                strbuf_addstr(value, "shallow");
+               if (!repo_config_get_bool(the_repository,
+                                        "uploadpack.allowfilter",
+                                        &allow_filter_value) &&
+                   allow_filter_value)
+                       strbuf_addstr(value, " filter");
+       }
        return 1;
 }