{"thread":{"id":"2","subject":"Various cleanups","startedAt":"2005-04-13T21:52:12Z","lastAt":"2005-04-14T23:13:18Z","messageCount":5,"participants":["Daniel Barkalow","Petr Baudis"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"11","messageId":"Pine.LNX.4.21.0504131556510.30848-100000@iabervon.org","threadId":"2","inReplyTo":"Pine.LNX.4.21.0504131547330.30848-100000@iabervon.org","subject":"Various cleanups","fromName":"Daniel Barkalow","fromEmail":"barkalow@iabervon.org","sentAt":"2005-04-13T21:52:12Z","receivedAt":"2005-04-13T21:52:12Z","isPatch":false,"sender":{"key":"barkalow@iabervon.org","avatar":"https://avatars.githubusercontent.com/u/55364219?v=4"},"body":"As it turns out, I ended up with two patches: one to set up the Makefile,\nand one to reorganize the common code. I'll do another one later to split\nstuff out of rev-tree/fsck-cache once merge-base is in.\n\nThe reorganization depends on the Makefile.\n\n\t-Daniel\n*This .sig left intentionally blank*\n\n"},{"id":"12","messageId":"Pine.LNX.4.21.0504131752410.30848-100000@iabervon.org","threadId":"2","inReplyTo":"Pine.LNX.4.21.0504131556510.30848-100000@iabervon.org","subject":"[PATCH] Clean up Makefile","fromName":"Daniel Barkalow","fromEmail":"barkalow@iabervon.org","sentAt":"2005-04-13T21:55:47Z","receivedAt":"2005-04-13T21:55:47Z","isPatch":true,"sender":{"key":"barkalow@iabervon.org","avatar":"https://avatars.githubusercontent.com/u/55364219?v=4"},"body":"Use a pattern rule for building executables, and a list of common objects\n(which could be made into a library).\n\nSigned-Off-By: Daniel Barkalow <barkalow@iabervon.org>\n\nIndex: Makefile\n===================================================================\n--- 833bb44b8e49daf0424f44cf300748da17945859/Makefile  (mode:100644 sha1:929aa49a3dbe683ad52094099797bc636a7949a6)\n+++ 783978eb212c1402ba2612bb32626e93af78b72d/Makefile  (mode:100644 sha1:2b626ec05b2e29016d26b5cb7b4f82ec5c4e79d6)\n@@ -20,6 +20,8 @@\n \tgitmerge.sh gitpull.sh gitrm.sh gittag.sh gittrack.sh gitexport.sh \\\n \tgitapply.sh\n \n+COMMON=\tread-cache.o\n+\n GEN_SCRIPT= gitversion.sh\n \n VERSION= VERSION\n@@ -31,46 +33,8 @@\n \n LIBS= -lssl -lz\n \n-init-db: init-db.o\n-\n-update-cache: update-cache.o read-cache.o\n-\t$(CC) $(CFLAGS) -o update-cache update-cache.o read-cache.o $(LIBS)\n-\n-show-diff: show-diff.o read-cache.o\n-\t$(CC) $(CFLAGS) -o show-diff show-diff.o read-cache.o $(LIBS)\n-\n-write-tree: write-tree.o read-cache.o\n-\t$(CC) $(CFLAGS) -o write-tree write-tree.o read-cache.o $(LIBS)\n-\n-read-tree: read-tree.o read-cache.o\n-\t$(CC) $(CFLAGS) -o read-tree read-tree.o read-cache.o $(LIBS)\n-\n-commit-tree: commit-tree.o read-cache.o\n-\t$(CC) $(CFLAGS) -o commit-tree commit-tree.o read-cache.o $(LIBS)\n-\n-cat-file: cat-file.o read-cache.o\n-\t$(CC) $(CFLAGS) -o cat-file cat-file.o read-cache.o $(LIBS)\n-\n-ls-tree: ls-tree.o read-cache.o\n-\t$(CC) $(CFLAGS) -o ls-tree ls-tree.o read-cache.o $(LIBS)\n-\n-checkout-cache: checkout-cache.o read-cache.o\n-\t$(CC) $(CFLAGS) -o checkout-cache checkout-cache.o read-cache.o $(LIBS)\n-\n-diff-tree: diff-tree.o read-cache.o\n-\t$(CC) $(CFLAGS) -o diff-tree diff-tree.o read-cache.o $(LIBS)\n-\n-fsck-cache: fsck-cache.o read-cache.o\n-\t$(CC) $(CFLAGS) -o fsck-cache fsck-cache.o read-cache.o $(LIBS)\n-\n-rev-tree: rev-tree.o read-cache.o\n-\t$(CC) $(CFLAGS) -o rev-tree rev-tree.o read-cache.o $(LIBS)\n-\n-show-files: show-files.o read-cache.o\n-\t$(CC) $(CFLAGS) -o show-files show-files.o read-cache.o $(LIBS)\n-\n-check-files: check-files.o read-cache.o\n-\t$(CC) $(CFLAGS) -o check-files check-files.o read-cache.o $(LIBS)\n+$(PROG):%: %.o $(COMMON)\n+\t$(CC) $(CFLAGS) -o $@ $^ $(LIBS)\n \n read-cache.o: cache.h\n show-diff.o: cache.h\n\n--\t-Daniel\n*This .sig left intentionally blank*\n\n"},{"id":"13","messageId":"Pine.LNX.4.21.0504131755550.30848-100000@iabervon.org","threadId":"2","inReplyTo":"Pine.LNX.4.21.0504131752410.30848-100000@iabervon.org","subject":"[PATCH] Reorganize common code","fromName":"Daniel Barkalow","fromEmail":"barkalow@iabervon.org","sentAt":"2005-04-13T22:00:25Z","receivedAt":"2005-04-13T22:00:25Z","isPatch":true,"sender":{"key":"barkalow@iabervon.org","avatar":"https://avatars.githubusercontent.com/u/55364219?v=4"},"body":"This splits read-cache.c into util.c, cache.c, and objects.c, based on\nwhat the code is used for; similarly, cache.h becomes util.h, cache.h, and\nobjects.h. For simplicity, cache.h includes the other two to give the\nprevious overall behavior.\n\nSigned-Off-By: Daniel Barkalow <barkalow@iabervon.org>\n\nIndex: Makefile\n===================================================================\n--- 783978eb212c1402ba2612bb32626e93af78b72d/Makefile  (mode:100644 sha1:2b626ec05b2e29016d26b5cb7b4f82ec5c4e79d6)\n+++ e8194c62bfc68725972a6847fa2c6d529ca64137/Makefile  (mode:100644 sha1:0b263fa693cb2addb2516a8f7af2ea05b95d3c8c)\n@@ -20,7 +20,7 @@\n \tgitmerge.sh gitpull.sh gitrm.sh gittag.sh gittrack.sh gitexport.sh \\\n \tgitapply.sh\n \n-COMMON=\tread-cache.o\n+COMMON=\tcache.o objects.o util.o\n \n GEN_SCRIPT= gitversion.sh\n \n@@ -36,7 +36,7 @@\n $(PROG):%: %.o $(COMMON)\n \t$(CC) $(CFLAGS) -o $@ $^ $(LIBS)\n \n-read-cache.o: cache.h\n+cache.o: cache.h\n show-diff.o: cache.h\n \n gitversion.sh: $(VERSION)\nIndex: cache.c\n===================================================================\n--- /dev/null  (tree:783978eb212c1402ba2612bb32626e93af78b72d)\n+++ e8194c62bfc68725972a6847fa2c6d529ca64137/cache.c  (mode:100644 sha1:fe61eae561e8ebaab9d9fe6d8f146ed7353b6a1c)\n@@ -0,0 +1,224 @@\n+/*\n+ * GIT - The information manager from hell\n+ *\n+ * Copyright (C) Linus Torvalds, 2005\n+ */\n+#include <stdarg.h>\n+#include \"cache.h\"\n+\n+const char *sha1_file_directory = NULL;\n+struct cache_entry **active_cache = NULL;\n+unsigned int active_nr = 0, active_alloc = 0;\n+\n+int cache_match_stat(struct cache_entry *ce, struct stat *st)\n+{\n+\tunsigned int changed = 0;\n+\n+\t/* nsec seems unreliable - not all filesystems support it, so\n+\t * as long as it is in the inode cache you get right nsec\n+\t * but after it gets flushed, you get zero nsec. */\n+\tif (ce->mtime.sec  != (unsigned int)st->st_mtim.tv_sec\n+#ifdef NSEC\n+\t    || ce->mtime.nsec != (unsigned int)st->st_mtim.tv_nsec\n+#endif\n+\t    )\n+\t\tchanged |= MTIME_CHANGED;\n+\tif (ce->ctime.sec  != (unsigned int)st->st_ctim.tv_sec\n+#ifdef NSEC\n+\t    || ce->ctime.nsec != (unsigned int)st->st_ctim.tv_nsec\n+#endif\n+\t    )\n+\t\tchanged |= CTIME_CHANGED;\n+\tif (ce->st_uid != (unsigned int)st->st_uid ||\n+\t    ce->st_gid != (unsigned int)st->st_gid)\n+\t\tchanged |= OWNER_CHANGED;\n+\tif (ce->st_mode != (unsigned int)st->st_mode)\n+\t\tchanged |= MODE_CHANGED;\n+\tif (ce->st_dev != (unsigned int)st->st_dev ||\n+\t    ce->st_ino != (unsigned int)st->st_ino)\n+\t\tchanged |= INODE_CHANGED;\n+\tif (ce->st_size != (unsigned int)st->st_size)\n+\t\tchanged |= DATA_CHANGED;\n+\treturn changed;\n+}\n+\n+int cache_name_compare(const char *name1, int len1, const char *name2, int len2)\n+{\n+\tint len = len1 < len2 ? len1 : len2;\n+\tint cmp;\n+\n+\tcmp = memcmp(name1, name2, len);\n+\tif (cmp)\n+\t\treturn cmp;\n+\tif (len1 < len2)\n+\t\treturn -1;\n+\tif (len1 > len2)\n+\t\treturn 1;\n+\treturn 0;\n+}\n+\n+int cache_name_pos(const char *name, int namelen)\n+{\n+\tint first, last;\n+\n+\tfirst = 0;\n+\tlast = active_nr;\n+\twhile (last > first) {\n+\t\tint next = (last + first) >> 1;\n+\t\tstruct cache_entry *ce = active_cache[next];\n+\t\tint cmp = cache_name_compare(name, namelen, ce->name, ce->namelen);\n+\t\tif (!cmp)\n+\t\t\treturn next;\n+\t\tif (cmp < 0) {\n+\t\t\tlast = next;\n+\t\t\tcontinue;\n+\t\t}\n+\t\tfirst = next+1;\n+\t}\n+\treturn -first-1;\n+}\n+\n+int remove_file_from_cache(char *path)\n+{\n+\tint pos = cache_name_pos(path, strlen(path));\n+\tif (pos >= 0) {\n+\t\tactive_nr--;\n+\t\tif (pos < active_nr)\n+\t\t\tmemmove(active_cache + pos, active_cache + pos + 1, (active_nr - pos) * sizeof(struct cache_entry *));\n+\t}\n+\treturn 0;\n+}\n+\n+int add_cache_entry(struct cache_entry *ce, int ok_to_add)\n+{\n+\tint pos;\n+\n+\tpos = cache_name_pos(ce->name, ce->namelen);\n+\n+\t/* existing match? Just replace it */\n+\tif (pos >= 0) {\n+\t\tactive_cache[pos] = ce;\n+\t\treturn 0;\n+\t}\n+\tpos = -pos-1;\n+\n+\tif (!ok_to_add)\n+\t\treturn -1;\n+\n+\t/* Make sure the array is big enough .. */\n+\tif (active_nr == active_alloc) {\n+\t\tactive_alloc = alloc_nr(active_alloc);\n+\t\tactive_cache = realloc(active_cache, active_alloc * sizeof(struct cache_entry *));\n+\t}\n+\n+\t/* Add it in.. */\n+\tactive_nr++;\n+\tif (active_nr > pos)\n+\t\tmemmove(active_cache + pos + 1, active_cache + pos, (active_nr - pos - 1) * sizeof(ce));\n+\tactive_cache[pos] = ce;\n+\treturn 0;\n+}\n+\n+static int verify_hdr(struct cache_header *hdr, unsigned long size)\n+{\n+\tSHA_CTX c;\n+\tunsigned char sha1[20];\n+\n+\tif (hdr->signature != CACHE_SIGNATURE)\n+\t\treturn error(\"bad signature\");\n+\tif (hdr->version != 1)\n+\t\treturn error(\"bad version\");\n+\tSHA1_Init(&c);\n+\tSHA1_Update(&c, hdr, offsetof(struct cache_header, sha1));\n+\tSHA1_Update(&c, hdr+1, size - sizeof(*hdr));\n+\tSHA1_Final(sha1, &c);\n+\tif (memcmp(sha1, hdr->sha1, 20))\n+\t\treturn error(\"bad header sha1\");\n+\treturn 0;\n+}\n+\n+int read_cache(void)\n+{\n+\tint fd, i;\n+\tstruct stat st;\n+\tunsigned long size, offset;\n+\tvoid *map;\n+\tstruct cache_header *hdr;\n+\n+\terrno = EBUSY;\n+\tif (active_cache)\n+\t\treturn error(\"more than one cachefile\");\n+\terrno = ENOENT;\n+\tsha1_file_directory = getenv(DB_ENVIRONMENT);\n+\tif (!sha1_file_directory)\n+\t\tsha1_file_directory = DEFAULT_DB_ENVIRONMENT;\n+\tif (access(sha1_file_directory, X_OK) < 0)\n+\t\treturn error(\"no access to SHA1 file directory\");\n+\tfd = open(\".git/index\", O_RDONLY);\n+\tif (fd < 0)\n+\t\treturn (errno == ENOENT) ? 0 : error(\"open failed\");\n+\n+\tsize = 0; // avoid gcc warning\n+\tmap = (void *)-1;\n+\tif (!fstat(fd, &st)) {\n+\t\tsize = st.st_size;\n+\t\terrno = EINVAL;\n+\t\tif (size >= sizeof(struct cache_header))\n+\t\t\tmap = mmap(NULL, size, PROT_READ, MAP_PRIVATE, fd, 0);\n+\t}\n+\tclose(fd);\n+\tif (-1 == (int)(long)map)\n+\t\treturn error(\"mmap failed\");\n+\n+\thdr = map;\n+\tif (verify_hdr(hdr, size) < 0)\n+\t\tgoto unmap;\n+\n+\tactive_nr = hdr->entries;\n+\tactive_alloc = alloc_nr(active_nr);\n+\tactive_cache = calloc(active_alloc, sizeof(struct cache_entry *));\n+\n+\toffset = sizeof(*hdr);\n+\tfor (i = 0; i < hdr->entries; i++) {\n+\t\tstruct cache_entry *ce = map + offset;\n+\t\toffset = offset + ce_size(ce);\n+\t\tactive_cache[i] = ce;\n+\t}\n+\treturn active_nr;\n+\n+unmap:\n+\tmunmap(map, size);\n+\terrno = EINVAL;\n+\treturn error(\"verify header failed\");\n+}\n+\n+int write_cache(int newfd, struct cache_entry **cache, int entries)\n+{\n+\tSHA_CTX c;\n+\tstruct cache_header hdr;\n+\tint i;\n+\n+\thdr.signature = CACHE_SIGNATURE;\n+\thdr.version = 1;\n+\thdr.entries = entries;\n+\n+\tSHA1_Init(&c);\n+\tSHA1_Update(&c, &hdr, offsetof(struct cache_header, sha1));\n+\tfor (i = 0; i < entries; i++) {\n+\t\tstruct cache_entry *ce = cache[i];\n+\t\tint size = ce_size(ce);\n+\t\tSHA1_Update(&c, ce, size);\n+\t}\n+\tSHA1_Final(hdr.sha1, &c);\n+\n+\tif (write(newfd, &hdr, sizeof(hdr)) != sizeof(hdr))\n+\t\treturn -1;\n+\n+\tfor (i = 0; i < entries; i++) {\n+\t\tstruct cache_entry *ce = cache[i];\n+\t\tint size = ce_size(ce);\n+\t\tif (write(newfd, ce, size) != size)\n+\t\t\treturn -1;\n+\t}\n+\treturn 0;\n+}\nIndex: cache.h\n===================================================================\n--- 783978eb212c1402ba2612bb32626e93af78b72d/cache.h  (mode:100644 sha1:d3e9a21b7d9a2ac32abacf5cc40ee1a4d83f9fe8)\n+++ e8194c62bfc68725972a6847fa2c6d529ca64137/cache.h  (mode:100644 sha1:e3302b454e5d55d4d7bd46bbfe870cb34733ce46)\n@@ -14,6 +14,9 @@\n #include <openssl/sha.h>\n #include <zlib.h>\n \n+#include \"util.h\"\n+#include \"objects.h\"\n+\n /*\n  * Basic data structures for the directory cache\n  *\n@@ -59,13 +62,9 @@\n \tchar name[0];\n };\n \n-const char *sha1_file_directory;\n struct cache_entry **active_cache;\n unsigned int active_nr, active_alloc;\n \n-#define DB_ENVIRONMENT \"SHA1_FILE_DIRECTORY\"\n-#define DEFAULT_DB_ENVIRONMENT \".git/objects\"\n-\n #define cache_entry_size(len) ((offsetof(struct cache_entry,name) + (len) + 8) & ~7)\n #define ce_size(ce) cache_entry_size((ce)->namelen)\n \n@@ -74,7 +73,10 @@\n /* Initialize and use the cache information */\n extern int read_cache(void);\n extern int write_cache(int newfd, struct cache_entry **cache, int entries);\n+\n+/* Returns the location of the given name in the cache. */\n extern int cache_name_pos(const char *name, int namelen);\n+\n extern int add_cache_entry(struct cache_entry *ce, int ok_to_add);\n extern int remove_file_from_cache(char *path);\n extern int cache_match_stat(struct cache_entry *ce, struct stat *st);\n@@ -86,28 +88,7 @@\n #define INODE_CHANGED   0x0010\n #define DATA_CHANGED    0x0020\n \n-/* Return a statically allocated filename matching the sha1 signature */\n-extern char *sha1_file_name(const unsigned char *sha1);\n-\n-/* Write a memory buffer out to the sha file */\n-extern int write_sha1_buffer(const unsigned char *sha1, void *buf, unsigned int size);\n-\n-/* Read and unpack a sha1 file into memory, write memory to a sha1 file */\n-extern void * map_sha1_file(const unsigned char *sha1, unsigned long *size);\n-extern void * unpack_sha1_file(void *map, unsigned long mapsize, char *type, unsigned long *size);\n-extern void * read_sha1_file(const unsigned char *sha1, char *type, unsigned long *size);\n-extern int write_sha1_file(char *buf, unsigned len, unsigned char *return_sha1);\n-extern int check_sha1_signature(const unsigned char *sha1, void *buf, unsigned long size);\n-\n-/* Convert to/from hex/sha1 representation */\n-extern int get_sha1_hex(const char *hex, unsigned char *sha1);\n-extern char *sha1_to_hex(const unsigned char *sha1);\t/* static buffer result! */\n-\n-/* General helper functions */\n-extern void usage(const char *err);\n-extern void die(const char *err, ...);\n-extern int error(const char *err, ...);\n-\n-extern int cache_name_compare(const char *name1, int len1, const char *name2, int len2);\n+extern int cache_name_compare(const char *name1, int len1, \n+\t\t\t      const char *name2, int len2);\n \n #endif /* CACHE_H */\nIndex: objects.c\n===================================================================\n--- /dev/null  (tree:783978eb212c1402ba2612bb32626e93af78b72d)\n+++ e8194c62bfc68725972a6847fa2c6d529ca64137/objects.c  (mode:100644 sha1:ee0aed670a76e0af9e4150c93915dad53a198ba5)\n@@ -0,0 +1,240 @@\n+/*\n+ * GIT - The information manager from hell\n+ *\n+ * Copyright (C) Linus Torvalds, 2005\n+ */\n+#include <stdarg.h>\n+#include \"cache.h\"\n+#include \"objects.h\"\n+#include <openssl/sha.h>\n+#include <stdio.h>\n+#include <sys/stat.h>\n+#include <fcntl.h>\n+#include <stddef.h>\n+#include <stdlib.h>\n+#include <stdarg.h>\n+#include <string.h>\n+#include <errno.h>\n+#include <sys/mman.h>\n+#include <zlib.h>\n+\n+\n+static unsigned hexval(char c)\n+{\n+\tif (c >= '0' && c <= '9')\n+\t\treturn c - '0';\n+\tif (c >= 'a' && c <= 'f')\n+\t\treturn c - 'a' + 10;\n+\tif (c >= 'A' && c <= 'F')\n+\t\treturn c - 'A' + 10;\n+\treturn ~0;\n+}\n+\n+int get_sha1_hex(const char *hex, unsigned char *sha1)\n+{\n+\tint i;\n+\tfor (i = 0; i < 20; i++) {\n+\t\tunsigned int val = (hexval(hex[0]) << 4) | hexval(hex[1]);\n+\t\tif (val & ~0xff)\n+\t\t\treturn -1;\n+\t\t*sha1++ = val;\n+\t\thex += 2;\n+\t}\n+\treturn 0;\n+}\n+\n+char * sha1_to_hex(const unsigned char *sha1)\n+{\n+\tstatic char buffer[50];\n+\tstatic const char hex[] = \"0123456789abcdef\";\n+\tchar *buf = buffer;\n+\tint i;\n+\n+\tfor (i = 0; i < 20; i++) {\n+\t\tunsigned int val = *sha1++;\n+\t\t*buf++ = hex[val >> 4];\n+\t\t*buf++ = hex[val & 0xf];\n+\t}\n+\treturn buffer;\n+}\n+\n+/*\n+ * NOTE! This returns a statically allocated buffer, so you have to be\n+ * careful about using it. Do a \"strdup()\" if you need to save the\n+ * filename.\n+ */\n+char *sha1_file_name(const unsigned char *sha1)\n+{\n+\tint i;\n+\tstatic char *name, *base;\n+\n+\tif (!base) {\n+\t\tchar *sha1_file_directory = getenv(DB_ENVIRONMENT) ? : DEFAULT_DB_ENVIRONMENT;\n+\t\tint len = strlen(sha1_file_directory);\n+\t\tbase = malloc(len + 60);\n+\t\tmemcpy(base, sha1_file_directory, len);\n+\t\tmemset(base+len, 0, 60);\n+\t\tbase[len] = '/';\n+\t\tbase[len+3] = '/';\n+\t\tname = base + len + 1;\n+\t}\n+\tfor (i = 0; i < 20; i++) {\n+\t\tstatic char hex[] = \"0123456789abcdef\";\n+\t\tunsigned int val = sha1[i];\n+\t\tchar *pos = name + i*2 + (i > 0);\n+\t\t*pos++ = hex[val >> 4];\n+\t\t*pos = hex[val & 0xf];\n+\t}\n+\treturn base;\n+}\n+\n+int check_sha1_signature(const unsigned char *sha1, void *map, unsigned long size)\n+{\n+\tunsigned char real_sha1[20];\n+\tSHA_CTX c;\n+\n+\tSHA1_Init(&c);\n+\tSHA1_Update(&c, map, size);\n+\tSHA1_Final(real_sha1, &c);\n+\treturn memcmp(sha1, real_sha1, 20) ? -1 : 0;\n+}\n+\n+void *map_sha1_file(const unsigned char *sha1, unsigned long *size)\n+{\n+\tchar *filename = sha1_file_name(sha1);\n+\tint fd = open(filename, O_RDONLY);\n+\tstruct stat st;\n+\tvoid *map;\n+\n+\tif (fd < 0) {\n+\t\tperror(filename);\n+\t\treturn NULL;\n+\t}\n+\tif (fstat(fd, &st) < 0) {\n+\t\tclose(fd);\n+\t\treturn NULL;\n+\t}\n+\tmap = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0);\n+\tclose(fd);\n+\tif (-1 == (int)(long)map)\n+\t\treturn NULL;\n+\t*size = st.st_size;\n+\treturn map;\n+}\n+\n+void * unpack_sha1_file(void *map, unsigned long mapsize, char *type, unsigned long *size)\n+{\n+\tint ret, bytes;\n+\tz_stream stream;\n+\tchar buffer[8192];\n+\tchar *buf;\n+\n+\t/* Get the data stream */\n+\tmemset(&stream, 0, sizeof(stream));\n+\tstream.next_in = map;\n+\tstream.avail_in = mapsize;\n+\tstream.next_out = buffer;\n+\tstream.avail_out = sizeof(buffer);\n+\n+\tinflateInit(&stream);\n+\tret = inflate(&stream, 0);\n+\tif (sscanf(buffer, \"%10s %lu\", type, size) != 2)\n+\t\treturn NULL;\n+\n+\tbytes = strlen(buffer) + 1;\n+\tbuf = malloc(*size);\n+\tif (!buf)\n+\t\treturn NULL;\n+\n+\tmemcpy(buf, buffer + bytes, stream.total_out - bytes);\n+\tbytes = stream.total_out - bytes;\n+\tif (bytes < *size && ret == Z_OK) {\n+\t\tstream.next_out = buf + bytes;\n+\t\tstream.avail_out = *size - bytes;\n+\t\twhile (inflate(&stream, Z_FINISH) == Z_OK)\n+\t\t\t/* nothing */;\n+\t}\n+\tinflateEnd(&stream);\n+\treturn buf;\n+}\n+\n+void * read_sha1_file(const unsigned char *sha1, char *type, unsigned long *size)\n+{\n+\tunsigned long mapsize;\n+\tvoid *map, *buf;\n+\n+\tmap = map_sha1_file(sha1, &mapsize);\n+\tif (map) {\n+\t\tbuf = unpack_sha1_file(map, mapsize, type, size);\n+\t\tmunmap(map, mapsize);\n+\t\treturn buf;\n+\t}\n+\treturn NULL;\n+}\n+\n+int write_sha1_file(char *buf, unsigned len, unsigned char *returnsha1)\n+{\n+\tint size;\n+\tchar *compressed;\n+\tz_stream stream;\n+\tunsigned char sha1[20];\n+\tSHA_CTX c;\n+\n+\t/* Set it up */\n+\tmemset(&stream, 0, sizeof(stream));\n+\tdeflateInit(&stream, Z_BEST_COMPRESSION);\n+\tsize = deflateBound(&stream, len);\n+\tcompressed = malloc(size);\n+\n+\t/* Compress it */\n+\tstream.next_in = buf;\n+\tstream.avail_in = len;\n+\tstream.next_out = compressed;\n+\tstream.avail_out = size;\n+\twhile (deflate(&stream, Z_FINISH) == Z_OK)\n+\t\t/* nothing */;\n+\tdeflateEnd(&stream);\n+\tsize = stream.total_out;\n+\n+\t/* Sha1.. */\n+\tSHA1_Init(&c);\n+\tSHA1_Update(&c, compressed, size);\n+\tSHA1_Final(sha1, &c);\n+\n+\tif (write_sha1_buffer(sha1, compressed, size) < 0)\n+\t\treturn -1;\n+\tif (returnsha1)\n+\t\tmemcpy(returnsha1, sha1, 20);\n+\treturn 0;\n+}\n+\n+int write_sha1_buffer(const unsigned char *sha1, void *buf, unsigned int size)\n+{\n+\tchar *filename = sha1_file_name(sha1);\n+\tint fd;\n+\n+\tfd = open(filename, O_WRONLY | O_CREAT | O_EXCL, 0666);\n+\tif (fd < 0) {\n+\t\tvoid *map;\n+\n+\t\tif (errno != EEXIST)\n+\t\t\treturn -1;\n+\t\t/* #define NO_COLLISION_CHECK to possibly speed things up,\n+\t\t * but the speedup should be really negligible. */\n+#ifndef NO_COLLISION_CHECK\n+\t\tfd = open(filename, O_RDONLY);\n+\t\tif (fd < 0)\n+\t\t\treturn -1;\n+\t\tmap = mmap(NULL, size, PROT_READ, MAP_PRIVATE, fd, 0);\n+\t\tif (map == MAP_FAILED)\n+\t\t\treturn -1;\n+\t\tif (memcmp(buf, map, size))\n+\t\t\treturn error(\"SHA1 collision detected!\"\n+\t\t\t\t\t\" This is bad, bad, BAD!\\a\\n\");\n+#endif\n+\t\treturn 0;\n+\t}\n+\twrite(fd, buf, size);\n+\tclose(fd);\n+\treturn 0;\n+}\nIndex: objects.h\n===================================================================\n--- /dev/null  (tree:783978eb212c1402ba2612bb32626e93af78b72d)\n+++ e8194c62bfc68725972a6847fa2c6d529ca64137/objects.h  (mode:100644 sha1:b6469e3e2ef191b36a23da23cbb8bf70ad54da0e)\n@@ -0,0 +1,43 @@\n+#ifndef OBJECTS_H\n+#define OBJECTS_H\n+\n+/* Operations on the object database. */\n+const char *sha1_file_directory;\n+\n+#define DB_ENVIRONMENT \"SHA1_FILE_DIRECTORY\"\n+#define DEFAULT_DB_ENVIRONMENT \".git/objects\"\n+\n+/* Takes a key and returns the contents, and sets *type to its type\n+ * and size to its size.  \n+ */\n+extern void * read_sha1_file(const unsigned char *sha1, char *type,\n+\t\t\t     unsigned long *size);\n+\n+/* Writes the given data and length to a file, and returns the key. */\n+extern int write_sha1_file(char *buf, unsigned len, \n+\t\t\t   unsigned char *return_sha1);\n+\n+/* mmap the given file, and put its size in *size. */\n+extern void * map_sha1_file(const unsigned char *sha1, unsigned long *size);\n+\n+/* Given a map, its size, and its expected type, return its contents and set\n+ * *size to the size of the contents. \n+ */\n+extern void * unpack_sha1_file(void *map, unsigned long mapsize, char *type,\n+\t\t\t       unsigned long *size);\n+\n+/* Return a statically allocated filename matching the sha1 signature */\n+extern char *sha1_file_name(const unsigned char *sha1);\n+\n+/* Write a memory buffer out to the sha file */\n+extern int write_sha1_buffer(const unsigned char *sha1, void *buf, \n+\t\t\t     unsigned int size);\n+/* compares the given buffer against its expected sha1 hash. */\n+extern int check_sha1_signature(const unsigned char *sha1, void *buf, \n+\t\t\t\tunsigned long size);\n+\n+/* Convert to/from hex/sha1 representation */\n+extern int get_sha1_hex(const char *hex, unsigned char *sha1);\n+extern char * sha1_to_hex(const unsigned char *sha1); /* static buffer ret! */\n+\n+#endif /* OBJECTS_H */\nIndex: read-cache.c\n===================================================================\n--- 783978eb212c1402ba2612bb32626e93af78b72d/read-cache.c  (mode:100644 sha1:7cdd0f82992789e64f6ea272e43ee4af8cdf7f2a)\n+++ /dev/null  (tree:e8194c62bfc68725972a6847fa2c6d529ca64137)\n@@ -1,478 +0,0 @@\n-/*\n- * GIT - The information manager from hell\n- *\n- * Copyright (C) Linus Torvalds, 2005\n- */\n-#include <stdarg.h>\n-#include \"cache.h\"\n-\n-const char *sha1_file_directory = NULL;\n-struct cache_entry **active_cache = NULL;\n-unsigned int active_nr = 0, active_alloc = 0;\n-\n-void usage(const char *err)\n-{\n-\tfprintf(stderr, \"usage: %s\\n\", err);\n-\texit(1);\n-}\n-\n-static void report(const char *prefix, const char *err, va_list params)\n-{\n-\tfputs(prefix, stderr);\n-\tvfprintf(stderr, err, params);\n-\tfputs(\"\\n\", stderr);\n-}\n-\n-void die(const char *err, ...)\n-{\n-\tva_list params;\n-\n-\tva_start(params, err);\n-\treport(\"fatal: \", err, params);\n-\tva_end(params);\n-\texit(1);\n-}\n-\n-int error(const char *err, ...)\n-{\n-\tva_list params;\n-\n-\tva_start(params, err);\n-\treport(\"error: \", err, params);\n-\tva_end(params);\n-\treturn -1;\n-}\n-\n-\n-static unsigned hexval(char c)\n-{\n-\tif (c >= '0' && c <= '9')\n-\t\treturn c - '0';\n-\tif (c >= 'a' && c <= 'f')\n-\t\treturn c - 'a' + 10;\n-\tif (c >= 'A' && c <= 'F')\n-\t\treturn c - 'A' + 10;\n-\treturn ~0;\n-}\n-\n-int get_sha1_hex(const char *hex, unsigned char *sha1)\n-{\n-\tint i;\n-\tfor (i = 0; i < 20; i++) {\n-\t\tunsigned int val = (hexval(hex[0]) << 4) | hexval(hex[1]);\n-\t\tif (val & ~0xff)\n-\t\t\treturn -1;\n-\t\t*sha1++ = val;\n-\t\thex += 2;\n-\t}\n-\treturn 0;\n-}\n-\n-char * sha1_to_hex(const unsigned char *sha1)\n-{\n-\tstatic char buffer[50];\n-\tstatic const char hex[] = \"0123456789abcdef\";\n-\tchar *buf = buffer;\n-\tint i;\n-\n-\tfor (i = 0; i < 20; i++) {\n-\t\tunsigned int val = *sha1++;\n-\t\t*buf++ = hex[val >> 4];\n-\t\t*buf++ = hex[val & 0xf];\n-\t}\n-\treturn buffer;\n-}\n-\n-/*\n- * NOTE! This returns a statically allocated buffer, so you have to be\n- * careful about using it. Do a \"strdup()\" if you need to save the\n- * filename.\n- */\n-char *sha1_file_name(const unsigned char *sha1)\n-{\n-\tint i;\n-\tstatic char *name, *base;\n-\n-\tif (!base) {\n-\t\tchar *sha1_file_directory = getenv(DB_ENVIRONMENT) ? : DEFAULT_DB_ENVIRONMENT;\n-\t\tint len = strlen(sha1_file_directory);\n-\t\tbase = malloc(len + 60);\n-\t\tmemcpy(base, sha1_file_directory, len);\n-\t\tmemset(base+len, 0, 60);\n-\t\tbase[len] = '/';\n-\t\tbase[len+3] = '/';\n-\t\tname = base + len + 1;\n-\t}\n-\tfor (i = 0; i < 20; i++) {\n-\t\tstatic char hex[] = \"0123456789abcdef\";\n-\t\tunsigned int val = sha1[i];\n-\t\tchar *pos = name + i*2 + (i > 0);\n-\t\t*pos++ = hex[val >> 4];\n-\t\t*pos = hex[val & 0xf];\n-\t}\n-\treturn base;\n-}\n-\n-int check_sha1_signature(const unsigned char *sha1, void *map, unsigned long size)\n-{\n-\tunsigned char real_sha1[20];\n-\tSHA_CTX c;\n-\n-\tSHA1_Init(&c);\n-\tSHA1_Update(&c, map, size);\n-\tSHA1_Final(real_sha1, &c);\n-\treturn memcmp(sha1, real_sha1, 20) ? -1 : 0;\n-}\n-\n-void *map_sha1_file(const unsigned char *sha1, unsigned long *size)\n-{\n-\tchar *filename = sha1_file_name(sha1);\n-\tint fd = open(filename, O_RDONLY);\n-\tstruct stat st;\n-\tvoid *map;\n-\n-\tif (fd < 0) {\n-\t\tperror(filename);\n-\t\treturn NULL;\n-\t}\n-\tif (fstat(fd, &st) < 0) {\n-\t\tclose(fd);\n-\t\treturn NULL;\n-\t}\n-\tmap = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0);\n-\tclose(fd);\n-\tif (-1 == (int)(long)map)\n-\t\treturn NULL;\n-\t*size = st.st_size;\n-\treturn map;\n-}\n-\n-void * unpack_sha1_file(void *map, unsigned long mapsize, char *type, unsigned long *size)\n-{\n-\tint ret, bytes;\n-\tz_stream stream;\n-\tchar buffer[8192];\n-\tchar *buf;\n-\n-\t/* Get the data stream */\n-\tmemset(&stream, 0, sizeof(stream));\n-\tstream.next_in = map;\n-\tstream.avail_in = mapsize;\n-\tstream.next_out = buffer;\n-\tstream.avail_out = sizeof(buffer);\n-\n-\tinflateInit(&stream);\n-\tret = inflate(&stream, 0);\n-\tif (sscanf(buffer, \"%10s %lu\", type, size) != 2)\n-\t\treturn NULL;\n-\n-\tbytes = strlen(buffer) + 1;\n-\tbuf = malloc(*size);\n-\tif (!buf)\n-\t\treturn NULL;\n-\n-\tmemcpy(buf, buffer + bytes, stream.total_out - bytes);\n-\tbytes = stream.total_out - bytes;\n-\tif (bytes < *size && ret == Z_OK) {\n-\t\tstream.next_out = buf + bytes;\n-\t\tstream.avail_out = *size - bytes;\n-\t\twhile (inflate(&stream, Z_FINISH) == Z_OK)\n-\t\t\t/* nothing */;\n-\t}\n-\tinflateEnd(&stream);\n-\treturn buf;\n-}\n-\n-void * read_sha1_file(const unsigned char *sha1, char *type, unsigned long *size)\n-{\n-\tunsigned long mapsize;\n-\tvoid *map, *buf;\n-\n-\tmap = map_sha1_file(sha1, &mapsize);\n-\tif (map) {\n-\t\tbuf = unpack_sha1_file(map, mapsize, type, size);\n-\t\tmunmap(map, mapsize);\n-\t\treturn buf;\n-\t}\n-\treturn NULL;\n-}\n-\n-int write_sha1_file(char *buf, unsigned len, unsigned char *returnsha1)\n-{\n-\tint size;\n-\tchar *compressed;\n-\tz_stream stream;\n-\tunsigned char sha1[20];\n-\tSHA_CTX c;\n-\n-\t/* Set it up */\n-\tmemset(&stream, 0, sizeof(stream));\n-\tdeflateInit(&stream, Z_BEST_COMPRESSION);\n-\tsize = deflateBound(&stream, len);\n-\tcompressed = malloc(size);\n-\n-\t/* Compress it */\n-\tstream.next_in = buf;\n-\tstream.avail_in = len;\n-\tstream.next_out = compressed;\n-\tstream.avail_out = size;\n-\twhile (deflate(&stream, Z_FINISH) == Z_OK)\n-\t\t/* nothing */;\n-\tdeflateEnd(&stream);\n-\tsize = stream.total_out;\n-\n-\t/* Sha1.. */\n-\tSHA1_Init(&c);\n-\tSHA1_Update(&c, compressed, size);\n-\tSHA1_Final(sha1, &c);\n-\n-\tif (write_sha1_buffer(sha1, compressed, size) < 0)\n-\t\treturn -1;\n-\tif (returnsha1)\n-\t\tmemcpy(returnsha1, sha1, 20);\n-\treturn 0;\n-}\n-\n-int write_sha1_buffer(const unsigned char *sha1, void *buf, unsigned int size)\n-{\n-\tchar *filename = sha1_file_name(sha1);\n-\tint fd;\n-\n-\tfd = open(filename, O_WRONLY | O_CREAT | O_EXCL, 0666);\n-\tif (fd < 0) {\n-\t\tvoid *map;\n-\n-\t\tif (errno != EEXIST)\n-\t\t\treturn -1;\n-\t\t/* #define NO_COLLISION_CHECK to possibly speed things up,\n-\t\t * but the speedup should be really negligible. */\n-#ifndef NO_COLLISION_CHECK\n-\t\tfd = open(filename, O_RDONLY);\n-\t\tif (fd < 0)\n-\t\t\treturn -1;\n-\t\tmap = mmap(NULL, size, PROT_READ, MAP_PRIVATE, fd, 0);\n-\t\tif (map == MAP_FAILED)\n-\t\t\treturn -1;\n-\t\tif (memcmp(buf, map, size))\n-\t\t\treturn error(\"SHA1 collision detected!\"\n-\t\t\t\t\t\" This is bad, bad, BAD!\\a\\n\");\n-#endif\n-\t\treturn 0;\n-\t}\n-\twrite(fd, buf, size);\n-\tclose(fd);\n-\treturn 0;\n-}\n-\n-int cache_match_stat(struct cache_entry *ce, struct stat *st)\n-{\n-\tunsigned int changed = 0;\n-\n-\t/* nsec seems unreliable - not all filesystems support it, so\n-\t * as long as it is in the inode cache you get right nsec\n-\t * but after it gets flushed, you get zero nsec. */\n-\tif (ce->mtime.sec  != (unsigned int)st->st_mtim.tv_sec\n-#ifdef NSEC\n-\t    || ce->mtime.nsec != (unsigned int)st->st_mtim.tv_nsec\n-#endif\n-\t    )\n-\t\tchanged |= MTIME_CHANGED;\n-\tif (ce->ctime.sec  != (unsigned int)st->st_ctim.tv_sec\n-#ifdef NSEC\n-\t    || ce->ctime.nsec != (unsigned int)st->st_ctim.tv_nsec\n-#endif\n-\t    )\n-\t\tchanged |= CTIME_CHANGED;\n-\tif (ce->st_uid != (unsigned int)st->st_uid ||\n-\t    ce->st_gid != (unsigned int)st->st_gid)\n-\t\tchanged |= OWNER_CHANGED;\n-\tif (ce->st_mode != (unsigned int)st->st_mode)\n-\t\tchanged |= MODE_CHANGED;\n-\tif (ce->st_dev != (unsigned int)st->st_dev ||\n-\t    ce->st_ino != (unsigned int)st->st_ino)\n-\t\tchanged |= INODE_CHANGED;\n-\tif (ce->st_size != (unsigned int)st->st_size)\n-\t\tchanged |= DATA_CHANGED;\n-\treturn changed;\n-}\n-\n-int cache_name_compare(const char *name1, int len1, const char *name2, int len2)\n-{\n-\tint len = len1 < len2 ? len1 : len2;\n-\tint cmp;\n-\n-\tcmp = memcmp(name1, name2, len);\n-\tif (cmp)\n-\t\treturn cmp;\n-\tif (len1 < len2)\n-\t\treturn -1;\n-\tif (len1 > len2)\n-\t\treturn 1;\n-\treturn 0;\n-}\n-\n-int cache_name_pos(const char *name, int namelen)\n-{\n-\tint first, last;\n-\n-\tfirst = 0;\n-\tlast = active_nr;\n-\twhile (last > first) {\n-\t\tint next = (last + first) >> 1;\n-\t\tstruct cache_entry *ce = active_cache[next];\n-\t\tint cmp = cache_name_compare(name, namelen, ce->name, ce->namelen);\n-\t\tif (!cmp)\n-\t\t\treturn next;\n-\t\tif (cmp < 0) {\n-\t\t\tlast = next;\n-\t\t\tcontinue;\n-\t\t}\n-\t\tfirst = next+1;\n-\t}\n-\treturn -first-1;\n-}\n-\n-int remove_file_from_cache(char *path)\n-{\n-\tint pos = cache_name_pos(path, strlen(path));\n-\tif (pos >= 0) {\n-\t\tactive_nr--;\n-\t\tif (pos < active_nr)\n-\t\t\tmemmove(active_cache + pos, active_cache + pos + 1, (active_nr - pos) * sizeof(struct cache_entry *));\n-\t}\n-\treturn 0;\n-}\n-\n-int add_cache_entry(struct cache_entry *ce, int ok_to_add)\n-{\n-\tint pos;\n-\n-\tpos = cache_name_pos(ce->name, ce->namelen);\n-\n-\t/* existing match? Just replace it */\n-\tif (pos >= 0) {\n-\t\tactive_cache[pos] = ce;\n-\t\treturn 0;\n-\t}\n-\tpos = -pos-1;\n-\n-\tif (!ok_to_add)\n-\t\treturn -1;\n-\n-\t/* Make sure the array is big enough .. */\n-\tif (active_nr == active_alloc) {\n-\t\tactive_alloc = alloc_nr(active_alloc);\n-\t\tactive_cache = realloc(active_cache, active_alloc * sizeof(struct cache_entry *));\n-\t}\n-\n-\t/* Add it in.. */\n-\tactive_nr++;\n-\tif (active_nr > pos)\n-\t\tmemmove(active_cache + pos + 1, active_cache + pos, (active_nr - pos - 1) * sizeof(ce));\n-\tactive_cache[pos] = ce;\n-\treturn 0;\n-}\n-\n-static int verify_hdr(struct cache_header *hdr, unsigned long size)\n-{\n-\tSHA_CTX c;\n-\tunsigned char sha1[20];\n-\n-\tif (hdr->signature != CACHE_SIGNATURE)\n-\t\treturn error(\"bad signature\");\n-\tif (hdr->version != 1)\n-\t\treturn error(\"bad version\");\n-\tSHA1_Init(&c);\n-\tSHA1_Update(&c, hdr, offsetof(struct cache_header, sha1));\n-\tSHA1_Update(&c, hdr+1, size - sizeof(*hdr));\n-\tSHA1_Final(sha1, &c);\n-\tif (memcmp(sha1, hdr->sha1, 20))\n-\t\treturn error(\"bad header sha1\");\n-\treturn 0;\n-}\n-\n-int read_cache(void)\n-{\n-\tint fd, i;\n-\tstruct stat st;\n-\tunsigned long size, offset;\n-\tvoid *map;\n-\tstruct cache_header *hdr;\n-\n-\terrno = EBUSY;\n-\tif (active_cache)\n-\t\treturn error(\"more than one cachefile\");\n-\terrno = ENOENT;\n-\tsha1_file_directory = getenv(DB_ENVIRONMENT);\n-\tif (!sha1_file_directory)\n-\t\tsha1_file_directory = DEFAULT_DB_ENVIRONMENT;\n-\tif (access(sha1_file_directory, X_OK) < 0)\n-\t\treturn error(\"no access to SHA1 file directory\");\n-\tfd = open(\".git/index\", O_RDONLY);\n-\tif (fd < 0)\n-\t\treturn (errno == ENOENT) ? 0 : error(\"open failed\");\n-\n-\tsize = 0; // avoid gcc warning\n-\tmap = (void *)-1;\n-\tif (!fstat(fd, &st)) {\n-\t\tsize = st.st_size;\n-\t\terrno = EINVAL;\n-\t\tif (size >= sizeof(struct cache_header))\n-\t\t\tmap = mmap(NULL, size, PROT_READ, MAP_PRIVATE, fd, 0);\n-\t}\n-\tclose(fd);\n-\tif (-1 == (int)(long)map)\n-\t\treturn error(\"mmap failed\");\n-\n-\thdr = map;\n-\tif (verify_hdr(hdr, size) < 0)\n-\t\tgoto unmap;\n-\n-\tactive_nr = hdr->entries;\n-\tactive_alloc = alloc_nr(active_nr);\n-\tactive_cache = calloc(active_alloc, sizeof(struct cache_entry *));\n-\n-\toffset = sizeof(*hdr);\n-\tfor (i = 0; i < hdr->entries; i++) {\n-\t\tstruct cache_entry *ce = map + offset;\n-\t\toffset = offset + ce_size(ce);\n-\t\tactive_cache[i] = ce;\n-\t}\n-\treturn active_nr;\n-\n-unmap:\n-\tmunmap(map, size);\n-\terrno = EINVAL;\n-\treturn error(\"verify header failed\");\n-}\n-\n-int write_cache(int newfd, struct cache_entry **cache, int entries)\n-{\n-\tSHA_CTX c;\n-\tstruct cache_header hdr;\n-\tint i;\n-\n-\thdr.signature = CACHE_SIGNATURE;\n-\thdr.version = 1;\n-\thdr.entries = entries;\n-\n-\tSHA1_Init(&c);\n-\tSHA1_Update(&c, &hdr, offsetof(struct cache_header, sha1));\n-\tfor (i = 0; i < entries; i++) {\n-\t\tstruct cache_entry *ce = cache[i];\n-\t\tint size = ce_size(ce);\n-\t\tSHA1_Update(&c, ce, size);\n-\t}\n-\tSHA1_Final(hdr.sha1, &c);\n-\n-\tif (write(newfd, &hdr, sizeof(hdr)) != sizeof(hdr))\n-\t\treturn -1;\n-\n-\tfor (i = 0; i < entries; i++) {\n-\t\tstruct cache_entry *ce = cache[i];\n-\t\tint size = ce_size(ce);\n-\t\tif (write(newfd, ce, size) != size)\n-\t\t\treturn -1;\n-\t}\n-\treturn 0;\n-}\nIndex: util.h\n===================================================================\n--- /dev/null  (tree:783978eb212c1402ba2612bb32626e93af78b72d)\n+++ e8194c62bfc68725972a6847fa2c6d529ca64137/util.h  (mode:100644 sha1:d81ccd0b3363ff2a883e8d9e543af043728fd32a)\n@@ -0,0 +1,9 @@\n+#ifndef UTIL_H\n+#define UTIL_H\n+\n+/* General helper functions */\n+extern void usage(const char *err);\n+extern void die(const char *err, ...);\n+extern int error(const char *err, ...);\n+\n+#endif\n\n"},{"id":"89","messageId":"Pine.LNX.4.21.0504141230310.30848-100000@iabervon.org","threadId":"2","inReplyTo":"Pine.LNX.4.21.0504131755550.30848-100000@iabervon.org","subject":"Re: [PATCH] Reorganize common code","fromName":"Daniel Barkalow","fromEmail":"barkalow@iabervon.org","sentAt":"2005-04-14T16:33:17Z","receivedAt":"2005-04-14T16:33:17Z","isPatch":true,"sender":{"key":"barkalow@iabervon.org","avatar":"https://avatars.githubusercontent.com/u/55364219?v=4"},"body":"I forgot to include util.c. On my to-do list is something to make this\nmore obvious.\n\nSigned-Off-By: Daniel Barkalow <barkalow@iabervon.org>\n\nIndex: util.c\n===================================================================\n--- /dev/null  (tree:e8194c62bfc68725972a6847fa2c6d529ca64137)\n+++ 420a52c504bf712cd898a11746a54ea4349a9386/util.c  (mode:100644 sha1:d1d497c6709503f71138e816b2599d5105cc4915)\n@@ -0,0 +1,37 @@\n+#include \"util.h\"\n+#include <stdarg.h>\n+#include <stdio.h>\n+#include <stdlib.h>\n+\n+void usage(const char *err)\n+{\n+\tfprintf(stderr, \"usage: %s\\n\", err);\n+\texit(1);\n+}\n+\n+static void report(const char *prefix, const char *err, va_list params)\n+{\n+\tfputs(prefix, stderr);\n+\tvfprintf(stderr, err, params);\n+\tfputs(\"\\n\", stderr);\n+}\n+\n+void die(const char *err, ...)\n+{\n+\tva_list params;\n+\n+\tva_start(params, err);\n+\treport(\"fatal: \", err, params);\n+\tva_end(params);\n+\texit(1);\n+}\n+\n+int error(const char *err, ...)\n+{\n+\tva_list params;\n+\n+\tva_start(params, err);\n+\treport(\"error: \", err, params);\n+\tva_end(params);\n+\treturn -1;\n+}\n\n"},{"id":"158","messageId":"20050414231318.GV22699@pasky.ji.cz","threadId":"2","inReplyTo":"Pine.LNX.4.21.0504131755550.30848-100000@iabervon.org","subject":"Re: Reorganize common code","fromName":"Petr Baudis","fromEmail":"pasky@ucw.cz","sentAt":"2005-04-14T23:13:18Z","receivedAt":"2005-04-14T23:13:18Z","isPatch":false,"sender":{"key":"pasky@ucw.cz","avatar":"https://avatars.githubusercontent.com/u/18439?v=4"},"body":"Dear diary, on Thu, Apr 14, 2005 at 12:00:25AM CEST, I got a letter\nwhere Daniel Barkalow <barkalow@iabervon.org> told me that...\n> This splits read-cache.c into util.c, cache.c, and objects.c, based on\n> what the code is used for; similarly, cache.h becomes util.h, cache.h, and\n> objects.h. For simplicity, cache.h includes the other two to give the\n> previous overall behavior.\n> \n> Signed-Off-By: Daniel Barkalow <barkalow@iabervon.org>\n\nFYI, given the scale of this change, I'm waiting for Linus to either ack\nit, pick it himself or reject it.\n\n-- \n\t\t\t\tPetr \"Pasky\" Baudis\nStuff: http://pasky.or.cz/\nC++: an octopus made by nailing extra legs onto a dog. -- Steve Taylor\n"}]}