#include "cache.h"
+#include "repository.h"
#include "commit.h"
#include "tag.h"
#include "blob.h"
#include "refs.h"
#include "diff.h"
#include "revision.h"
-#include "exec_cmd.h"
+#include "exec-cmd.h"
#include "remote.h"
#include "list-objects.h"
#include "sigchain.h"
#include "argv-array.h"
#include "packfile.h"
+#include "object-store.h"
+#include "commit-reach.h"
#ifdef EXPAT_NEEDS_XMLPARSE_H
#include <xmlparse.h>
char *url;
char *owner;
char *token;
- char tmpfile_suffix[41];
+ char tmpfile_suffix[GIT_MAX_HEXSZ + 1];
time_t start_time;
long timeout;
int refreshing;
struct active_request_slot *slot;
struct http_object_request *obj_req;
- obj_req = new_http_object_request(repo->url, request->obj->oid.hash);
+ obj_req = new_http_object_request(repo->url, &request->obj->oid);
if (obj_req == NULL) {
request->state = ABORTED;
return;
return;
}
- fprintf(stderr, "Fetching pack %s\n", sha1_to_hex(target->sha1));
+ fprintf(stderr, "Fetching pack %s\n",
+ hash_to_hex(target->hash));
fprintf(stderr, " which contains %s\n", oid_to_hex(&request->obj->oid));
preq = new_http_pack_request(target, repo->url);
ssize_t size;
git_zstream stream;
- unpacked = read_sha1_file(request->obj->oid.hash, &type, &len);
- hdrlen = xsnprintf(hdr, sizeof(hdr), "%s %lu", type_name(type), len) + 1;
+ unpacked = read_object_file(&request->obj->oid, &type, &len);
+ hdrlen = xsnprintf(hdr, sizeof(hdr), "%s %"PRIuMAX , type_name(type), (uintmax_t)len) + 1;
/* Set it up */
git_deflate_init(&stream, zlib_compression_level);
request->dest = strbuf_detach(&buf, NULL);
append_remote_object_url(&buf, repo->url, hex, 0);
- strbuf_add(&buf, request->lock->tmpfile_suffix, 41);
+ strbuf_add(&buf, request->lock->tmpfile_suffix, the_hash_algo->hexsz + 1);
request->url = strbuf_detach(&buf, NULL);
slot = get_active_slot();
if (request->headers != NULL)
curl_slist_free_all(request->headers);
- /* URL is reused for MOVE after PUT */
- if (request->state != RUN_PUT) {
+ /* URL is reused for MOVE after PUT and used during FETCH */
+ if (request->state != RUN_PUT && request->state != RUN_FETCH_PACKED) {
FREE_AND_NULL(request->url);
}
{
struct object *obj;
- obj = lookup_object(oid->hash);
+ obj = lookup_object(the_repository, oid->hash);
if (!obj)
- obj = parse_object(oid);
+ obj = parse_object(the_repository, oid);
/* Ignore remote objects that don't exist locally */
if (!obj)
static void handle_new_lock_ctx(struct xml_ctx *ctx, int tag_closed)
{
struct remote_lock *lock = (struct remote_lock *)ctx->userData;
- git_SHA_CTX sha_ctx;
- unsigned char lock_token_sha1[20];
+ git_hash_ctx hash_ctx;
+ unsigned char lock_token_hash[GIT_MAX_RAWSZ];
if (tag_closed && ctx->cdata) {
if (!strcmp(ctx->name, DAV_ACTIVELOCK_OWNER)) {
} else if (!strcmp(ctx->name, DAV_ACTIVELOCK_TOKEN)) {
lock->token = xstrdup(ctx->cdata);
- git_SHA1_Init(&sha_ctx);
- git_SHA1_Update(&sha_ctx, lock->token, strlen(lock->token));
- git_SHA1_Final(lock_token_sha1, &sha_ctx);
+ the_hash_algo->init_fn(&hash_ctx);
+ the_hash_algo->update_fn(&hash_ctx, lock->token, strlen(lock->token));
+ the_hash_algo->final_fn(lock_token_hash, &hash_ctx);
lock->tmpfile_suffix[0] = '_';
- memcpy(lock->tmpfile_suffix + 1, sha1_to_hex(lock_token_sha1), 40);
+ memcpy(lock->tmpfile_suffix + 1, hash_to_hex(lock_token_hash), the_hash_algo->hexsz);
}
}
}
/* extract hex from sharded "xx/x{38}" filename */
static int get_oid_hex_from_objpath(const char *path, struct object_id *oid)
{
- if (strlen(path) != GIT_SHA1_HEXSZ + 1)
+ if (strlen(path) != the_hash_algo->hexsz + 1)
return -1;
if (hex_to_bytes(oid->hash, path, 1))
path += 2;
path++; /* skip '/' */
- return hex_to_bytes(oid->hash + 1, path, GIT_SHA1_RAWSZ - 1);
+ return hex_to_bytes(oid->hash + 1, path, the_hash_algo->rawsz - 1);
}
static void process_ls_object(struct remote_ls_ctx *ls)
while (tree_entry(&desc, &entry))
switch (object_type(entry.mode)) {
case OBJ_TREE:
- p = process_tree(lookup_tree(entry.oid), p);
+ p = process_tree(lookup_tree(the_repository, &entry.oid),
+ p);
break;
case OBJ_BLOB:
- p = process_blob(lookup_blob(entry.oid), p);
+ p = process_blob(lookup_blob(the_repository, &entry.oid),
+ p);
break;
default:
/* Subproject commit - not in this repository */
int count = 0;
while ((commit = get_revision(revs)) != NULL) {
- p = process_tree(commit->tree, p);
+ p = process_tree(get_commit_tree(commit), p);
commit->object.flags |= LOCAL;
if (!(commit->object.flags & UNINTERESTING))
count += add_send_request(&commit->object, lock);
return count;
}
-static int update_remote(unsigned char *sha1, struct remote_lock *lock)
+static int update_remote(const struct object_id *oid, struct remote_lock *lock)
{
struct active_request_slot *slot;
struct slot_results results;
dav_headers = get_dav_token_headers(lock, DAV_HEADER_IF);
- strbuf_addf(&out_buffer.buf, "%s\n", sha1_to_hex(sha1));
+ strbuf_addf(&out_buffer.buf, "%s\n", oid_to_hex(oid));
slot = get_active_slot();
slot->results = &results;
return;
}
- o = parse_object(&ref->old_oid);
+ o = parse_object(the_repository, &ref->old_oid);
if (!o) {
fprintf(stderr,
"Unable to parse object %s for remote ref %s\n",
oid_to_hex(&ref->old_oid), ls->dentry_name);
if (o->type == OBJ_TAG) {
- o = deref_tag(o, ls->dentry_name, 0);
+ o = deref_tag(the_repository, o, ls->dentry_name, 0);
if (o)
strbuf_addf(buf, "%s\t%s^{}\n",
oid_to_hex(&o->oid), ls->dentry_name);
{
struct transfer_request *request;
struct transfer_request *next_request;
- int nr_refspec = 0;
- const char **refspec = NULL;
+ struct refspec rs = REFSPEC_INIT_PUSH;
struct remote_lock *ref_lock = NULL;
struct remote_lock *info_ref_lock = NULL;
struct rev_info revs;
}
continue;
}
- refspec = argv;
- nr_refspec = argc - i;
+ refspec_appendn(&rs, argv, argc - i);
break;
}
if (!repo->url)
usage(http_push_usage);
- if (delete_branch && nr_refspec != 1)
+ if (delete_branch && rs.nr != 1)
die("You must specify only one branch name when deleting a remote branch");
setup_git_directory();
/* Remove a remote branch if -d or -D was specified */
if (delete_branch) {
- if (delete_remote_branch(refspec[0], force_delete) == -1) {
+ const char *branch = rs.items[i].src;
+ if (delete_remote_branch(branch, force_delete) == -1) {
fprintf(stderr, "Unable to delete remote branch %s\n",
- refspec[0]);
+ branch);
if (helper_status)
- printf("error %s cannot remove\n", refspec[0]);
+ printf("error %s cannot remove\n", branch);
}
goto cleanup;
}
/* match them up */
- if (match_push_refs(local_refs, &remote_refs,
- nr_refspec, (const char **) refspec, push_all)) {
+ if (match_push_refs(local_refs, &remote_refs, &rs, push_all)) {
rc = -1;
goto cleanup;
}
continue;
}
- if (!oidcmp(&ref->old_oid, &ref->peer_ref->new_oid)) {
+ if (oideq(&ref->old_oid, &ref->peer_ref->new_oid)) {
if (push_verbosely)
fprintf(stderr, "'%s': up-to-date\n", ref->name);
if (helper_status)
if (!push_all && !is_null_oid(&ref->old_oid))
argv_array_pushf(&commit_argv, "^%s",
oid_to_hex(&ref->old_oid));
- init_revisions(&revs, setup_git_directory());
+ repo_init_revisions(the_repository, &revs, setup_git_directory());
setup_revisions(commit_argv.argc, commit_argv.argv, &revs, NULL);
revs.edge_hint = 0; /* just in case */
pushing = 0;
if (prepare_revision_walk(&revs))
die("revision walk setup failed");
- mark_edges_uninteresting(&revs, NULL);
+ mark_edges_uninteresting(&revs, NULL, 0);
objects_to_send = get_delta(&revs, ref_lock);
finish_all_active_slots();
run_request_queue();
/* Update the remote branch if all went well */
- if (aborted || !update_remote(ref->new_oid.hash, ref_lock))
+ if (aborted || !update_remote(&ref->new_oid, ref_lock))
rc = 1;
if (!rc)