| 111 | } |
| 112 | |
| 113 | void hashwrite(struct hashfile *f, const void *buf, uint32_t count) |
| 114 | { |
| 115 | while (count) { |
| 116 | unsigned left = f->buffer_len - f->offset; |
| 117 | unsigned nr = count > left ? left : count; |
| 118 | |
| 119 | if (f->do_crc) |
| 120 | f->crc32 = crc32(f->crc32, buf, nr); |
| 121 | |
| 122 | if (nr == f->buffer_len) { |
| 123 | /* |
| 124 | * Flush a full batch worth of data directly |
| 125 | * from the input, skipping the memcpy() to |
| 126 | * the hashfile's buffer. In this block, |
| 127 | * f->offset is necessarily zero. |
| 128 | */ |
| 129 | if (!f->skip_hash) |
| 130 | git_hash_update(&f->ctx, buf, nr); |
| 131 | flush(f, buf, nr); |
| 132 | } else { |
| 133 | /* |
| 134 | * Copy to the hashfile's buffer, flushing only |
| 135 | * if it became full. |
| 136 | */ |
| 137 | memcpy(f->buffer + f->offset, buf, nr); |
| 138 | f->offset += nr; |
| 139 | left -= nr; |
| 140 | if (!left) |
| 141 | hashflush(f); |
| 142 | } |
| 143 | |
| 144 | count -= nr; |
| 145 | buf = (char *) buf + nr; |
| 146 | } |
| 147 | } |
| 148 | |
| 149 | struct hashfile *hashfd_check(const struct git_hash_algo *algop, |
| 150 | const char *name) |