csum-file interface updates: return resulting SHA1 · wolfpython/git@e180884 · GitHub
Skip to content

Commit e180884

Browse files
author
Linus Torvalds
committed
csum-file interface updates: return resulting SHA1
Also, make the writing of the SHA1 as a end-header be conditional: not every user will necessarily want to write the SHA1 to the file itself, even though current users do (but we migh end up using the same helper functions for the object files themselves, that don't do this). This also makes the packed index file contain the SHA1 of the packed data file at the end (just before its own SHA1). That way you can validate the pairing of the two if you want to.
1 parent c38138c commit e180884

4 files changed

Lines changed: 26 additions & 16 deletions

File tree

csum-file.c

Lines changed: 16 additions & 10 deletions

csum-file.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@
44
/* A SHA1-protected file */
55
struct sha1file {
66
int fd, error;
7-
unsigned long offset;
7+
unsigned int offset, namelen;
88
SHA_CTX ctx;
9+
char name[PATH_MAX];
910
unsigned char buffer[8192];
1011
};
1112

1213
extern struct sha1file *sha1create(const char *fmt, ...);
13-
extern int sha1close(struct sha1file *);
14+
extern int sha1close(struct sha1file *, unsigned char *, int);
1415
extern int sha1write(struct sha1file *, void *, unsigned int);
1516
extern int sha1write_compressed(struct sha1file *, void *, unsigned int);
1617

pack-objects.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ static struct object_entry **sorted_by_sha, **sorted_by_type;
2929
static struct object_entry *objects = NULL;
3030
static int nr_objects = 0, nr_alloc = 0;
3131
static const char *base_name;
32+
static unsigned char pack_file_sha1[20];
3233

3334
static void *delta_against(void *buf, unsigned long size, struct object_entry *entry)
3435
{
@@ -95,7 +96,7 @@ static void write_pack_file(void)
9596
entry->offset = offset;
9697
offset += write_object(f, entry);
9798
}
98-
sha1close(f);
99+
sha1close(f, pack_file_sha1, 1);
99100
mb = offset >> 20;
100101
offset &= 0xfffff;
101102
}
@@ -111,7 +112,7 @@ static void write_index_file(void)
111112
/*
112113
* Write the first-level table (the list is sorted,
113114
* but we use a 256-entry lookup to be able to avoid
114-
* having to do eight extra binary search iterations)
115+
* having to do eight extra binary search iterations).
115116
*/
116117
for (i = 0; i < 256; i++) {
117118
struct object_entry **next = list;
@@ -136,7 +137,8 @@ static void write_index_file(void)
136137
sha1write(f, &offset, 4);
137138
sha1write(f, entry->sha1, 20);
138139
}
139-
sha1close(f);
140+
sha1write(f, pack_file_sha1, 20);
141+
sha1close(f, NULL, 1);
140142
}
141143

142144
static void add_object_entry(unsigned char *sha1, unsigned int hash)

unpack-objects.c

Lines changed: 2 additions & 1 deletion

0 commit comments

Comments
 (0)