Merge branch 'maint'
authorShawn O. Pearce <spearce@spearce.org>
Fri, 10 Oct 2008 15:39:20 +0000 (08:39 -0700)
committerShawn O. Pearce <spearce@spearce.org>
Fri, 10 Oct 2008 15:39:20 +0000 (08:39 -0700)
* 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

1  2 
csum-file.c
csum-file.h
index-pack.c
t/test-lib.sh
diff --combined csum-file.c
index 717d29fc03ba0bf375efa58be8dc0f676d9ac5c4,cfc1ac42b9fc9489237cd0bcd1652fb4df243512..2ddb12a0b70da87afe6fa8a33dce08c6c8ae7f71
  #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) {
        }
  }
  
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;
        }
 -      SHA1_Final(f->buffer, &f->ctx);
+ }
+ int sha1close(struct sha1file *f, unsigned char *result, unsigned int flags)
+ {
+       int fd;
+       sha1flush(f);
 +      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))
  
  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 9e13342eb357d6427a208fc6777ea170eb55acb8,01f13b550118769ed7fbe35fce9bd8c91d87e42d..294add2a91496355b42ce02ecfe9c453d21b291a
@@@ -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 73860bf3da062d283c266f6b83fdf3f613af26e7,2a366206a4e830d0bb66d6ac708cd512a94d6d37..d3a4d31b4e92d69eb32d1a18ebb7be1f7470d1d1
@@@ -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 e2b106cb6a2337f873a7225670392b376f74c6e7,35698361bac232412d51f2b64c45c7ab5a5041d2..fb8974112598fa46f0eefb8d84be9bcf9a1eee09
@@@ -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"