70 lines
1.7 KiB
C
70 lines
1.7 KiB
C
#include "git-compat-util.h"
|
|
#include "gettext.h"
|
|
#include "strbuf.h"
|
|
#include "repository.h"
|
|
#include "hash-ll.h"
|
|
#include "object.h"
|
|
#include "loose.h"
|
|
#include "object-file-convert.h"
|
|
|
|
int repo_oid_to_algop(struct repository *repo, const struct object_id *src,
|
|
const struct git_hash_algo *to, struct object_id *dest)
|
|
{
|
|
/*
|
|
* If the source algorithm is not set, then we're using the
|
|
* default hash algorithm for that object.
|
|
*/
|
|
const struct git_hash_algo *from =
|
|
src->algo ? &hash_algos[src->algo] : repo->hash_algo;
|
|
|
|
if (from == to) {
|
|
if (src != dest)
|
|
oidcpy(dest, src);
|
|
return 0;
|
|
}
|
|
if (repo_loose_object_map_oid(repo, src, to, dest)) {
|
|
/*
|
|
* We may have loaded the object map at repo initialization but
|
|
* another process (perhaps upstream of a pipe from us) may have
|
|
* written a new object into the map. If the object is missing,
|
|
* let's reload the map to see if the object has appeared.
|
|
*/
|
|
repo_read_loose_object_map(repo);
|
|
if (repo_loose_object_map_oid(repo, src, to, dest))
|
|
return -1;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
int convert_object_file(struct strbuf *outbuf,
|
|
const struct git_hash_algo *from,
|
|
const struct git_hash_algo *to,
|
|
const void *buf, size_t len,
|
|
enum object_type type,
|
|
int gentle)
|
|
{
|
|
int ret;
|
|
|
|
/* Don't call this function when no conversion is necessary */
|
|
if ((from == to) || (type == OBJ_BLOB))
|
|
BUG("Refusing noop object file conversion");
|
|
|
|
switch (type) {
|
|
case OBJ_COMMIT:
|
|
case OBJ_TREE:
|
|
case OBJ_TAG:
|
|
default:
|
|
/* Not implemented yet, so fail. */
|
|
ret = -1;
|
|
break;
|
|
}
|
|
if (!ret)
|
|
return 0;
|
|
if (gentle) {
|
|
strbuf_release(outbuf);
|
|
return ret;
|
|
}
|
|
die(_("Failed to convert object from %s to %s"),
|
|
from->name, to->name);
|
|
}
|