From: Bryan Larsen <bryan.larsen@gmail.com>
To: git@vger.kernel.org
Subject: [PATCH] 2/7 Prepare for the next two patches
Date: Fri, 08 Jul 2005 06:54:14 -0400 [thread overview]
Message-ID: <42CE5B56.5090602@gmail.com> (raw)
Prepare for the next two patches. This patch makes the first half of
write_sha1_file() and index_fd() externally visible. The first half of
these two functions is basically just an SHA1 calculation, so there is
probably a better way to do this. However, doing things this way makes
this patch and the subsequent patches minimally intrusive.
Signed-off-by: Bryan Larsen <bryan.larsen@gmail.com>
---
cache.h | 3 ++-
sha1_file.c | 13 +++++++++----
update-cache.c | 2 +-
write-blob.c | 2 +-
4 files changed, 13 insertions(+), 7 deletions(-)
diff --git a/cache.h b/cache.h
--- a/cache.h
+++ b/cache.h
@@ -139,7 +139,7 @@ extern int remove_cache_entry_at(int pos
extern int remove_file_from_cache(char *path);
extern int ce_same_name(struct cache_entry *a, struct cache_entry *b);
extern int ce_match_stat(struct cache_entry *ce, struct stat *st);
-extern int index_fd(unsigned char *sha1, int fd, struct stat *st);
+extern int index_fd(unsigned char *sha1, int fd, struct stat *st, int
info_only);
extern void fill_stat_cache_info(struct cache_entry *ce, struct stat *st);
struct cache_file {
@@ -169,6 +169,7 @@ extern int sha1_object_info(const unsign
extern void * unpack_sha1_file(void *map, unsigned long mapsize, char
*type, unsigned long *size);
extern void * read_sha1_file(const unsigned char *sha1, char *type,
unsigned long *size);
extern int write_sha1_file(void *buf, unsigned long len, const char
*type, unsigned char *return_sha1);
+extern char *write_sha1_file_prepare(void *buf, unsigned long len,
const char *type, unsigned char *sha1, unsigned char *hdr, int *hdrlen);
extern int check_sha1_signature(const unsigned char *sha1, void *buf,
unsigned long size, const char *type);
diff --git a/sha1_file.c b/sha1_file.c
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -1084,7 +1084,7 @@ void *read_object_with_reference(const u
}
}
-static char *write_sha1_file_prepare(void *buf,
+char *write_sha1_file_prepare(void *buf,
unsigned long len,
const char *type,
unsigned char *sha1,
@@ -1283,12 +1283,14 @@ int has_sha1_file(const unsigned char *s
return find_pack_entry(sha1, &e);
}
-int index_fd(unsigned char *sha1, int fd, struct stat *st)
+int index_fd(unsigned char *sha1, int fd, struct stat *st, int info_only)
{
unsigned long size = st->st_size;
void *buf;
int ret;
-
+ unsigned char hdr[50];
+ int hdrlen;
+
buf = "";
if (size)
buf = mmap(NULL, size, PROT_READ, MAP_PRIVATE, fd, 0);
@@ -1296,7 +1298,10 @@ int index_fd(unsigned char *sha1, int fd
if ((int)(long)buf == -1)
return -1;
- ret = write_sha1_file(buf, size, "blob", sha1);
+ if (info_only) {
+ (void) write_sha1_file_prepare(buf, size, "blob", sha1, hdr, &hdrlen);
+ ret = 0;
+ } else ret = write_sha1_file(buf, size, "blob", sha1);
if (size)
munmap(buf, size);
return ret;
diff --git a/update-cache.c b/update-cache.c
--- a/update-cache.c
+++ b/update-cache.c
@@ -68,7 +68,7 @@ static int add_file_to_cache(char *path)
fd = open(path, O_RDONLY);
if (fd < 0)
return -1;
- if (index_fd(ce->sha1, fd, &st) < 0)
+ if (index_fd(ce->sha1, fd, &st, 0) < 0)
return -1;
break;
case S_IFLNK:
diff --git a/write-blob.c b/write-blob.c
--- a/write-blob.c
+++ b/write-blob.c
@@ -17,7 +17,7 @@ int main(int argc, char **argv)
fd = open(path, O_RDONLY);
if (fd < 0 ||
fstat(fd, &st) < 0 ||
- index_fd(sha1, fd, &st) < 0)
+ index_fd(sha1, fd, &st, 0) < 0)
die("Unable to add blob %s to database", path);
printf("%s\n", sha1_to_hex(sha1));
}
\f
reply other threads:[~2005-07-08 11:08 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=42CE5B56.5090602@gmail.com \
--to=bryan.larsen@gmail.com \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).