Skip to content

Commit 974e4a8

Browse files
bk2204gitster
authored andcommitted
cache: make oidcpy always copy GIT_MAX_RAWSZ bytes
There are some situations in which we want to store an object ID into struct object_id without the_hash_algo necessarily being set correctly. One such case is when cloning a repository, where we must read refs from the remote side without having a repository from which to read the preferred algorithm. In this cases, we may have the_hash_algo set to SHA-1, which is the default, but read refs into struct object_id that are SHA-256. When copying these values, we will want to copy them completely, not just the first 20 bytes. Consequently, make sure that oidcpy copies the maximum number of bytes at all times, regardless of the setting of the_hash_algo. Since oidcpy and hashcpy are no longer functionally identical, remove the Cocinelle object_id transformations that convert from one into the other. Signed-off-by: brian m. carlson <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ea82b2a commit 974e4a8

File tree

2 files changed

+1
-31
lines changed

2 files changed

+1
-31
lines changed

cache.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1072,7 +1072,7 @@ static inline void hashcpy(unsigned char *sha_dst, const unsigned char *sha_src)
10721072

10731073
static inline void oidcpy(struct object_id *dst, const struct object_id *src)
10741074
{
1075-
hashcpy(dst->hash, src->hash);
1075+
memcpy(dst->hash, src->hash, GIT_MAX_RAWSZ);
10761076
}
10771077

10781078
static inline struct object_id *oiddup(const struct object_id *src)

contrib/coccinelle/object_id.cocci

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -86,36 +86,6 @@ struct object_id OID;
8686
- hashcmp(OID.hash, OIDPTR->hash)
8787
+ oidcmp(&OID, OIDPTR)
8888

89-
@@
90-
struct object_id OID1, OID2;
91-
@@
92-
- hashcpy(OID1.hash, OID2.hash)
93-
+ oidcpy(&OID1, &OID2)
94-
95-
@@
96-
identifier f != oidcpy;
97-
struct object_id *OIDPTR1;
98-
struct object_id *OIDPTR2;
99-
@@
100-
f(...) {<...
101-
- hashcpy(OIDPTR1->hash, OIDPTR2->hash)
102-
+ oidcpy(OIDPTR1, OIDPTR2)
103-
...>}
104-
105-
@@
106-
struct object_id *OIDPTR;
107-
struct object_id OID;
108-
@@
109-
- hashcpy(OIDPTR->hash, OID.hash)
110-
+ oidcpy(OIDPTR, &OID)
111-
112-
@@
113-
struct object_id *OIDPTR;
114-
struct object_id OID;
115-
@@
116-
- hashcpy(OID.hash, OIDPTR->hash)
117-
+ oidcpy(&OID, OIDPTR)
118-
11989
@@
12090
struct object_id *OIDPTR1;
12191
struct object_id *OIDPTR2;

0 commit comments

Comments
 (0)