Skip to content

Commit 1002f28

Browse files
committed
Merge branch 'eb/hash-transition'
Work to support a repository that work with both SHA-1 and SHA-256 hash algorithms has started. * eb/hash-transition: (30 commits) t1016-compatObjectFormat: add tests to verify the conversion between objects t1006: test oid compatibility with cat-file t1006: rename sha1 to oid test-lib: compute the compatibility hash so tests may use it builtin/ls-tree: let the oid determine the output algorithm object-file: handle compat objects in check_object_signature tree-walk: init_tree_desc take an oid to get the hash algorithm builtin/cat-file: let the oid determine the output algorithm rev-parse: add an --output-object-format parameter repository: implement extensions.compatObjectFormat object-file: update object_info_extended to reencode objects object-file-convert: convert commits that embed signed tags object-file-convert: convert commit objects when writing object-file-convert: don't leak when converting tag objects object-file-convert: convert tag objects when writing object-file-convert: add a function to convert trees between algorithms object: factor out parse_mode out of fast-import and tree-walk into in object.h cache: add a function to read an OID of a specific algorithm tag: sign both hashes commit: export add_header_signature to support handling signatures on tags ...
2 parents c75fd8d + 7673ecd commit 1002f28

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+1844
-349
lines changed

Documentation/config/extensions.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,18 @@ Note that this setting should only be set by linkgit:git-init[1] or
77
linkgit:git-clone[1]. Trying to change it after initialization will not
88
work and will produce hard-to-diagnose issues.
99

10+
extensions.compatObjectFormat::
11+
12+
Specify a compatitbility hash algorithm to use. The acceptable values
13+
are `sha1` and `sha256`. The value specified must be different from the
14+
value of extensions.objectFormat. This allows client level
15+
interoperability between git repositories whose objectFormat matches
16+
this compatObjectFormat. In particular when fully implemented the
17+
pushes and pulls from a repository in whose objectFormat matches
18+
compatObjectFormat. As well as being able to use oids encoded in
19+
compatObjectFormat in addition to oids encoded with objectFormat to
20+
locally specify objects.
21+
1022
extensions.refStorage::
1123
Specify the ref storage format to use. The acceptable values are:
1224
+

Documentation/git-rev-parse.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,18 @@ for another option.
159159
unfortunately named tag "master"), and shows them as full
160160
refnames (e.g. "refs/heads/master").
161161

162+
--output-object-format=(sha1|sha256|storage)::
163+
164+
Allow oids to be input from any object format that the current
165+
repository supports.
166+
167+
Specifying "sha1" translates if necessary and returns a sha1 oid.
168+
169+
Specifying "sha256" translates if necessary and returns a sha256 oid.
170+
171+
Specifying "storage" translates if necessary and returns an oid in
172+
encoded in the storage hash algorithm.
173+
162174
Options for Objects
163175
~~~~~~~~~~~~~~~~~~~
164176

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -797,6 +797,7 @@ TEST_BUILTINS_OBJS += test-config.o
797797
TEST_BUILTINS_OBJS += test-crontab.o
798798
TEST_BUILTINS_OBJS += test-csprng.o
799799
TEST_BUILTINS_OBJS += test-date.o
800+
TEST_BUILTINS_OBJS += test-delete-gpgsig.o
800801
TEST_BUILTINS_OBJS += test-delta.o
801802
TEST_BUILTINS_OBJS += test-dir-iterator.o
802803
TEST_BUILTINS_OBJS += test-drop-caches.o
@@ -1060,6 +1061,7 @@ LIB_OBJS += list-objects-filter.o
10601061
LIB_OBJS += list-objects.o
10611062
LIB_OBJS += lockfile.o
10621063
LIB_OBJS += log-tree.o
1064+
LIB_OBJS += loose.o
10631065
LIB_OBJS += ls-refs.o
10641066
LIB_OBJS += mailinfo.o
10651067
LIB_OBJS += mailmap.o
@@ -1080,6 +1082,7 @@ LIB_OBJS += notes-cache.o
10801082
LIB_OBJS += notes-merge.o
10811083
LIB_OBJS += notes-utils.o
10821084
LIB_OBJS += notes.o
1085+
LIB_OBJS += object-file-convert.o
10831086
LIB_OBJS += object-file.o
10841087
LIB_OBJS += object-name.o
10851088
LIB_OBJS += object.o

archive.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,8 @@ int write_archive_entries(struct archiver_args *args,
339339
opts.src_index = args->repo->index;
340340
opts.dst_index = args->repo->index;
341341
opts.fn = oneway_merge;
342-
init_tree_desc(&t, args->tree->buffer, args->tree->size);
342+
init_tree_desc(&t, &args->tree->object.oid,
343+
args->tree->buffer, args->tree->size);
343344
if (unpack_trees(1, &t, &opts))
344345
return -1;
345346
git_attr_set_direction(GIT_ATTR_INDEX);

builtin/am.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1994,8 +1994,8 @@ static int fast_forward_to(struct tree *head, struct tree *remote, int reset)
19941994
opts.reset = reset ? UNPACK_RESET_PROTECT_UNTRACKED : 0;
19951995
opts.preserve_ignored = 0; /* FIXME: !overwrite_ignore */
19961996
opts.fn = twoway_merge;
1997-
init_tree_desc(&t[0], head->buffer, head->size);
1998-
init_tree_desc(&t[1], remote->buffer, remote->size);
1997+
init_tree_desc(&t[0], &head->object.oid, head->buffer, head->size);
1998+
init_tree_desc(&t[1], &remote->object.oid, remote->buffer, remote->size);
19991999

20002000
if (unpack_trees(2, t, &opts)) {
20012001
rollback_lock_file(&lock_file);
@@ -2029,7 +2029,7 @@ static int merge_tree(struct tree *tree)
20292029
opts.dst_index = &the_index;
20302030
opts.merge = 1;
20312031
opts.fn = oneway_merge;
2032-
init_tree_desc(&t[0], tree->buffer, tree->size);
2032+
init_tree_desc(&t[0], &tree->object.oid, tree->buffer, tree->size);
20332033

20342034
if (unpack_trees(1, t, &opts)) {
20352035
rollback_lock_file(&lock_file);

builtin/cat-file.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,10 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
106106
struct object_info oi = OBJECT_INFO_INIT;
107107
struct strbuf sb = STRBUF_INIT;
108108
unsigned flags = OBJECT_INFO_LOOKUP_REPLACE;
109-
unsigned get_oid_flags = GET_OID_RECORD_PATH | GET_OID_ONLY_TO_DIE;
109+
unsigned get_oid_flags =
110+
GET_OID_RECORD_PATH |
111+
GET_OID_ONLY_TO_DIE |
112+
GET_OID_HASH_ANY;
110113
const char *path = force_path;
111114
const int opt_cw = (opt == 'c' || opt == 'w');
112115
if (!path && opt_cw)
@@ -226,7 +229,8 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
226229
die(_("unable to read %s"), oid_to_hex(&oid));
227230

228231
if (!skip_prefix(buffer, "object ", &target) ||
229-
get_oid_hex(target, &blob_oid))
232+
get_oid_hex_algop(target, &blob_oid,
233+
&hash_algos[oid.algo]))
230234
die("%s not a valid tag", oid_to_hex(&oid));
231235
free(buffer);
232236
} else
@@ -517,7 +521,9 @@ static void batch_one_object(const char *obj_name,
517521
struct expand_data *data)
518522
{
519523
struct object_context ctx;
520-
int flags = opt->follow_symlinks ? GET_OID_FOLLOW_SYMLINKS : 0;
524+
int flags =
525+
GET_OID_HASH_ANY |
526+
(opt->follow_symlinks ? GET_OID_FOLLOW_SYMLINKS : 0);
521527
enum get_oid_result result;
522528

523529
result = get_oid_with_context(the_repository, obj_name,

builtin/checkout.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -706,7 +706,7 @@ static int reset_tree(struct tree *tree, const struct checkout_opts *o,
706706
NULL);
707707
if (parse_tree(tree) < 0)
708708
return 128;
709-
init_tree_desc(&tree_desc, tree->buffer, tree->size);
709+
init_tree_desc(&tree_desc, &tree->object.oid, tree->buffer, tree->size);
710710
switch (unpack_trees(1, &tree_desc, &opts)) {
711711
case -2:
712712
*writeout_error = 1;
@@ -826,11 +826,13 @@ static int merge_working_tree(const struct checkout_opts *opts,
826826
die(_("unable to parse commit %s"),
827827
oid_to_hex(old_commit_oid));
828828

829-
init_tree_desc(&trees[0], tree->buffer, tree->size);
829+
init_tree_desc(&trees[0], &tree->object.oid,
830+
tree->buffer, tree->size);
830831
if (parse_tree(new_tree) < 0)
831832
exit(128);
832833
tree = new_tree;
833-
init_tree_desc(&trees[1], tree->buffer, tree->size);
834+
init_tree_desc(&trees[1], &tree->object.oid,
835+
tree->buffer, tree->size);
834836

835837
ret = unpack_trees(2, trees, &topts);
836838
clear_unpack_trees_porcelain(&topts);

builtin/clone.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -740,7 +740,7 @@ static int checkout(int submodule_progress, int filter_submodules)
740740
die(_("unable to parse commit %s"), oid_to_hex(&oid));
741741
if (parse_tree(tree) < 0)
742742
exit(128);
743-
init_tree_desc(&t, tree->buffer, tree->size);
743+
init_tree_desc(&t, &tree->object.oid, tree->buffer, tree->size);
744744
if (unpack_trees(1, &t, &opts) < 0)
745745
die(_("unable to checkout working tree"));
746746

builtin/commit.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ static void create_base_index(const struct commit *current_head)
333333
die(_("failed to unpack HEAD tree object"));
334334
if (parse_tree(tree) < 0)
335335
exit(128);
336-
init_tree_desc(&t, tree->buffer, tree->size);
336+
init_tree_desc(&t, &tree->object.oid, tree->buffer, tree->size);
337337
if (unpack_trees(1, &t, &opts))
338338
exit(128); /* We've already reported the error, finish dying */
339339
}

builtin/fast-import.c

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1236,20 +1236,6 @@ static void *gfi_unpack_entry(
12361236
return unpack_entry(the_repository, p, oe->idx.offset, &type, sizep);
12371237
}
12381238

1239-
static const char *get_mode(const char *str, uint16_t *modep)
1240-
{
1241-
unsigned char c;
1242-
uint16_t mode = 0;
1243-
1244-
while ((c = *str++) != ' ') {
1245-
if (c < '0' || c > '7')
1246-
return NULL;
1247-
mode = (mode << 3) + (c - '0');
1248-
}
1249-
*modep = mode;
1250-
return str;
1251-
}
1252-
12531239
static void load_tree(struct tree_entry *root)
12541240
{
12551241
struct object_id *oid = &root->versions[1].oid;
@@ -1287,7 +1273,7 @@ static void load_tree(struct tree_entry *root)
12871273
t->entries[t->entry_count++] = e;
12881274

12891275
e->tree = NULL;
1290-
c = get_mode(c, &e->versions[1].mode);
1276+
c = parse_mode(c, &e->versions[1].mode);
12911277
if (!c)
12921278
die("Corrupt mode in %s", oid_to_hex(oid));
12931279
e->versions[0].mode = e->versions[1].mode;
@@ -2280,7 +2266,7 @@ static void file_change_m(const char *p, struct branch *b)
22802266
struct object_id oid;
22812267
uint16_t mode, inline_data = 0;
22822268

2283-
p = get_mode(p, &mode);
2269+
p = parse_mode(p, &mode);
22842270
if (!p)
22852271
die("Corrupt mode: %s", command_buf.buf);
22862272
switch (mode) {

0 commit comments

Comments
 (0)