From: Shawn O. Pearce Date: Fri, 10 Oct 2008 15:39:20 +0000 (-0700) Subject: Merge branch 'maint' X-Git-Tag: v1.6.1-rc1~156 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/e782e12f89955dfb0be82098af3cfdd8dd0eaf80?ds=inline;hp=-c Merge branch 'maint' * maint: rebase -i: do not fail when there is no commit to cherry-pick test-lib: fix color reset in say_color() fix pread()'s short read in index-pack Conflicts: csum-file.c --- e782e12f89955dfb0be82098af3cfdd8dd0eaf80 diff --combined csum-file.c index 717d29fc03,cfc1ac42b9..2ddb12a0b7 --- a/csum-file.c +++ b/csum-file.c @@@ -11,8 -11,10 +11,8 @@@ #include "progress.h" #include "csum-file.h" - static void sha1flush(struct sha1file *f, void *buf, unsigned int count) -static void flush(struct sha1file *f, unsigned int count) ++static void flush(struct sha1file *f, void * buf, unsigned int count) { - void *buf = f->buffer; - for (;;) { int ret = xwrite(f->fd, buf, count); if (ret > 0) { @@@ -30,22 -32,28 +30,28 @@@ } } - int sha1close(struct sha1file *f, unsigned char *result, unsigned int flags) + void sha1flush(struct sha1file *f) { - int fd; unsigned offset = f->offset; if (offset) { - SHA1_Update(&f->ctx, f->buffer, offset); - flush(f, offset); + git_SHA1_Update(&f->ctx, f->buffer, offset); - sha1flush(f, f->buffer, offset); ++ flush(f, f->buffer, offset); f->offset = 0; } + } + + int sha1close(struct sha1file *f, unsigned char *result, unsigned int flags) + { + int fd; + + sha1flush(f); - SHA1_Final(f->buffer, &f->ctx); + git_SHA1_Final(f->buffer, &f->ctx); if (result) hashcpy(result, f->buffer); if (flags & (CSUM_CLOSE | CSUM_FSYNC)) { /* write checksum and close fd */ - sha1flush(f, f->buffer, 20); - flush(f, 20); ++ flush(f, f->buffer, 20); if (flags & CSUM_FSYNC) fsync_or_die(f->fd, f->name); if (close(f->fd)) @@@ -60,30 -68,21 +66,30 @@@ int sha1write(struct sha1file *f, void *buf, unsigned int count) { - if (f->do_crc) - f->crc32 = crc32(f->crc32, buf, count); while (count) { unsigned offset = f->offset; unsigned left = sizeof(f->buffer) - offset; unsigned nr = count > left ? left : count; + void *data; + + if (f->do_crc) + f->crc32 = crc32(f->crc32, buf, nr); + + if (nr == sizeof(f->buffer)) { + /* process full buffer directly without copy */ + data = buf; + } else { + memcpy(f->buffer + offset, buf, nr); + data = f->buffer; + } - memcpy(f->buffer + offset, buf, nr); count -= nr; offset += nr; buf = (char *) buf + nr; left -= nr; if (!left) { - SHA1_Update(&f->ctx, f->buffer, offset); - flush(f, offset); + git_SHA1_Update(&f->ctx, data, offset); - sha1flush(f, data, offset); ++ flush(f, data, offset); offset = 0; } f->offset = offset; @@@ -105,7 -104,7 +111,7 @@@ struct sha1file *sha1fd_throughput(int f->tp = tp; f->name = name; f->do_crc = 0; - SHA1_Init(&f->ctx); + git_SHA1_Init(&f->ctx); return f; } diff --combined csum-file.h index 9e13342eb3,01f13b5501..294add2a91 --- a/csum-file.h +++ b/csum-file.h @@@ -7,7 -7,7 +7,7 @@@ struct progress struct sha1file { int fd; unsigned int offset; - SHA_CTX ctx; + git_SHA_CTX ctx; off_t total; struct progress *tp; const char *name; @@@ -24,6 -24,7 +24,7 @@@ extern struct sha1file *sha1fd(int fd, extern struct sha1file *sha1fd_throughput(int fd, const char *name, struct progress *tp); extern int sha1close(struct sha1file *, unsigned char *, unsigned int); extern int sha1write(struct sha1file *, void *, unsigned int); + extern void sha1flush(struct sha1file *f); extern void crc32_begin(struct sha1file *); extern uint32_t crc32_end(struct sha1file *); diff --combined index-pack.c index 73860bf3da,2a366206a4..d3a4d31b4e --- a/index-pack.c +++ b/index-pack.c @@@ -67,7 -67,7 +67,7 @@@ static struct progress *progress static unsigned char input_buffer[4096]; static unsigned int input_offset, input_len; static off_t consumed_bytes; -static SHA_CTX input_ctx; +static git_SHA_CTX input_ctx; static uint32_t input_crc32; static int input_fd, output_fd, pack_fd; @@@ -119,7 -119,7 +119,7 @@@ static void flush(void if (input_offset) { if (output_fd >= 0) write_or_die(output_fd, input_buffer, input_offset); - SHA1_Update(&input_ctx, input_buffer, input_offset); + git_SHA1_Update(&input_ctx, input_buffer, input_offset); memmove(input_buffer, input_buffer + input_offset, input_len); input_offset = 0; } @@@ -188,7 -188,7 +188,7 @@@ static char *open_pack_file(char *pack_ output_fd = -1; pack_fd = input_fd; } - SHA1_Init(&input_ctx); + git_SHA1_Init(&input_ctx); return pack_name; } @@@ -591,7 -591,7 +591,7 @@@ static void parse_pack_objects(unsigne /* Check pack integrity */ flush(); - SHA1_Final(sha1, &input_ctx); + git_SHA1_Final(sha1, &input_ctx); if (hashcmp(fill(20), sha1)) die("pack is corrupted (SHA1 mismatch)"); use(20); @@@ -707,6 -707,7 +707,7 @@@ static struct object_entry *append_obj_ obj[1].idx.offset = obj[0].idx.offset + n; obj[1].idx.offset += write_compressed(f, buf, size); obj[0].idx.crc32 = crc32_end(f); + sha1flush(f); hashcpy(obj->idx.sha1, sha1); return obj; } diff --combined t/test-lib.sh index e2b106cb6a,35698361ba..fb89741125 --- a/t/test-lib.sh +++ b/t/test-lib.sh @@@ -112,8 -112,9 +112,9 @@@ if test -n "$color"; the *) test -n "$quiet" && return;; esac shift - echo "* $*" + printf "* $*" tput sgr0 + echo ) } else @@@ -406,7 -407,7 +407,7 @@@ test_create_repo () error "bug in the test script: not 1 parameter to test-create-repo" owd=`pwd` repo="$1" - mkdir "$repo" + mkdir -p "$repo" cd "$repo" || error "Cannot setup test environment" "$GIT_EXEC_PATH/git" init "--template=$GIT_EXEC_PATH/templates/blt/" >&3 2>&4 || error "cannot run git init -- have you built things yet?" @@@ -449,11 -450,6 +450,11 @@@ test_done () # we will leave things as they are. say_color pass "passed all $msg" + + test -d "$remove_trash" && + cd "$(dirname "$remove_trash")" && + rm -rf "$(basename "$remove_trash")" + exit 0 ;; *) @@@ -490,8 -486,7 +491,8 @@@ f . ../GIT-BUILD-OPTIONS # Test repository -test="trash directory" +test="trash directory.$(basename "$0" .sh)" +test ! -z "$debug" || remove_trash="$TEST_DIRECTORY/$test" rm -fr "$test" || { trap - exit echo >&5 "FATAL: Cannot prepare test area"