Skip to content
Navigation Menu
Toggle navigation
Sign in
In this repository
All GitHub Enterprise
↵
Jump to
↵
No suggested jump to results
In this repository
All GitHub Enterprise
↵
Jump to
↵
In this organization
All GitHub Enterprise
↵
Jump to
↵
In this repository
All GitHub Enterprise
↵
Jump to
↵
Sign in
Reseting focus
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
git-mirror
/
git
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Issues
0
Pull requests
0
Actions
Projects
0
Security
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security
Insights
Files
8b5157e
Documentation
arm
compat
contrib
gitweb
mozilla-sha1
perl
ppc
t
templates
xdiff
.gitignore
.mailmap
COPYING
GIT-VERSION-GEN
INSTALL
Makefile
README
alloc.c
archive-tar.c
archive-zip.c
archive.h
base85.c
blob.c
blob.h
builtin-add.c
builtin-annotate.c
builtin-apply.c
builtin-archive.c
builtin-blame.c
builtin-branch.c
builtin-cat-file.c
builtin-check-ref-format.c
builtin-checkout-index.c
builtin-commit-tree.c
builtin-count-objects.c
builtin-describe.c
builtin-diff-files.c
builtin-diff-index.c
builtin-diff-stages.c
builtin-diff-tree.c
builtin-diff.c
builtin-fmt-merge-msg.c
builtin-for-each-ref.c
builtin-grep.c
builtin-init-db.c
builtin-log.c
builtin-ls-files.c
builtin-ls-tree.c
builtin-mailinfo.c
builtin-mailsplit.c
builtin-merge-file.c
builtin-mv.c
builtin-name-rev.c
builtin-pack-objects.c
builtin-pack-refs.c
builtin-prune-packed.c
builtin-prune.c
builtin-push.c
builtin-read-tree.c
builtin-reflog.c
builtin-repo-config.c
builtin-rerere.c
builtin-rev-list.c
builtin-rev-parse.c
builtin-rm.c
builtin-runstatus.c
builtin-shortlog.c
builtin-show-branch.c
builtin-show-ref.c
builtin-stripspace.c
builtin-symbolic-ref.c
builtin-tar-tree.c
builtin-unpack-objects.c
builtin-update-index.c
builtin-update-ref.c
builtin-upload-archive.c
builtin-verify-pack.c
builtin-write-tree.c
builtin.h
cache-tree.c
cache-tree.h
cache.h
check-builtins.sh
check-racy.c
color.c
color.h
combine-diff.c
commit.c
commit.h
config.c
config.mak.in
configure.ac
connect.c
convert-objects.c
copy.c
csum-file.c
csum-file.h
ctype.c
daemon.c
date.c
delta.h
diff-delta.c
diff-lib.c
diff.c
diff.h
diffcore-break.c
diffcore-delta.c
diffcore-order.c
diffcore-pickaxe.c
diffcore-rename.c
diffcore.h
dir.c
dir.h
dump-cache-tree.c
entry.c
environment.c
exec_cmd.c
exec_cmd.h
fetch-pack.c
fetch.c
fetch.h
fsck-objects.c
generate-cmdlist.sh
git-add--interactive.perl
git-am.sh
git-applymbox.sh
git-applypatch.sh
git-archimport.perl
git-bisect.sh
git-checkout.sh
git-clean.sh
git-clone.sh
git-commit.sh
git-compat-util.h
git-cvsexportcommit.perl
git-cvsimport.perl
git-cvsserver.perl
git-fetch.sh
git-gc.sh
git-instaweb.sh
git-lost-found.sh
git-ls-remote.sh
git-merge-octopus.sh
git-merge-one-file.sh
git-merge-ours.sh
git-merge-resolve.sh
git-merge-stupid.sh
git-merge.sh
git-p4import.py
git-parse-remote.sh
git-pull.sh
git-quiltimport.sh
git-rebase.sh
git-relink.perl
git-remote.perl
git-repack.sh
git-request-pull.sh
git-reset.sh
git-resolve.sh
git-revert.sh
git-send-email.perl
git-sh-setup.sh
git-svn.perl
git-svnimport.perl
git-tag.sh
git-verify-tag.sh
git.c
git.spec.in
gitk
grep.c
grep.h
hash-object.c
help.c
http-fetch.c
http-push.c
http.c
http.h
ident.c
imap-send.c
index-pack.c
interpolate.c
interpolate.h
list-objects.c
list-objects.h
local-fetch.c
lockfile.c
log-tree.c
log-tree.h
merge-base.c
merge-file.c
merge-index.c
merge-recursive.c
merge-tree.c
mktag.c
mktree.c
object-refs.c
object.c
object.h
pack-check.c
pack-redundant.c
pack.h
pager.c
patch-delta.c
patch-id.c
path-list.c
path-list.h
path.c
peek-remote.c
pkt-line.c
pkt-line.h
quote.c
quote.h
reachable.c
reachable.h
read-cache.c
receive-pack.c
reflog-walk.c
reflog-walk.h
refs.c
refs.h
revision.c
revision.h
rsh.c
rsh.h
run-command.c
run-command.h
send-pack.c
server-info.c
setup.c
sha1_file.c
sha1_name.c
shallow.c
shell.c
show-index.c
sideband.c
sideband.h
ssh-fetch.c
ssh-pull.c
ssh-push.c
ssh-upload.c
strbuf.c
strbuf.h
tag.c
tag.h
tar.h
test-date.c
test-delta.c
test-sha1.c
test-sha1.sh
trace.c
tree-diff.c
tree-walk.c
tree-walk.h
tree.c
tree.h
unpack-file.c
unpack-trees.c
unpack-trees.h
update-server-info.c
upload-pack.c
usage.c
utf8.c
utf8.h
var.c
write_or_die.c
wt-status.c
wt-status.h
xdiff-interface.c
xdiff-interface.h
Breadcrumbs
git
/
diffcore-delta.c
Blame
Blame
Latest commit
History
History
213 lines (196 loc) · 5.15 KB
Breadcrumbs
git
/
diffcore-delta.c
Top
File metadata and controls
Code
Blame
213 lines (196 loc) · 5.15 KB
Raw
#include "cache.h" #include "diff.h" #include "diffcore.h" /* * Idea here is very simple. * * We have total of (sz-N+1) N-byte overlapping sequences in buf whose * size is sz. If the same N-byte sequence appears in both source and * destination, we say the byte that starts that sequence is shared * between them (i.e. copied from source to destination). * * For each possible N-byte sequence, if the source buffer has more * instances of it than the destination buffer, that means the * difference are the number of bytes not copied from source to * destination. If the counts are the same, everything was copied * from source to destination. If the destination has more, * everything was copied, and destination added more. * * We are doing an approximation so we do not really have to waste * memory by actually storing the sequence. We just hash them into * somewhere around 2^16 hashbuckets and count the occurrences. * * The length of the sequence is arbitrarily set to 8 for now. */ /* Wild guess at the initial hash size */ #define INITIAL_HASH_SIZE 9 /* We leave more room in smaller hash but do not let it * grow to have unused hole too much. */ #define INITIAL_FREE(sz_log2) ((1<<(sz_log2))*(sz_log2-3)/(sz_log2)) /* A prime rather carefully chosen between 2^16..2^17, so that * HASHBASE < INITIAL_FREE(17). We want to keep the maximum hashtable * size under the current 2<<17 maximum, which can hold this many * different values before overflowing to hashtable of size 2<<18. */ #define HASHBASE 107927 struct spanhash { unsigned int hashval; unsigned int cnt; }; struct spanhash_top { int alloc_log2; int free; struct spanhash data[FLEX_ARRAY]; }; static struct spanhash *spanhash_find(struct spanhash_top *top, unsigned int hashval) { int sz = 1 << top->alloc_log2; int bucket = hashval & (sz - 1); while (1) { struct spanhash *h = &(top->data[bucket++]); if (!h->cnt) return NULL; if (h->hashval == hashval) return h; if (sz <= bucket) bucket = 0; } } static struct spanhash_top *spanhash_rehash(struct spanhash_top *orig) { struct spanhash_top *new; int i; int osz = 1 << orig->alloc_log2; int sz = osz << 1; new = xmalloc(sizeof(*orig) + sizeof(struct spanhash) * sz); new->alloc_log2 = orig->alloc_log2 + 1; new->free = INITIAL_FREE(new->alloc_log2); memset(new->data, 0, sizeof(struct spanhash) * sz); for (i = 0; i < osz; i++) { struct spanhash *o = &(orig->data[i]); int bucket; if (!o->cnt) continue; bucket = o->hashval & (sz - 1); while (1) { struct spanhash *h = &(new->data[bucket++]); if (!h->cnt) { h->hashval = o->hashval; h->cnt = o->cnt; new->free--; break; } if (sz <= bucket) bucket = 0; } } free(orig); return new; } static struct spanhash_top *add_spanhash(struct spanhash_top *top, unsigned int hashval, int cnt) { int bucket, lim; struct spanhash *h; lim = (1 << top->alloc_log2); bucket = hashval & (lim - 1); while (1) { h = &(top->data[bucket++]); if (!h->cnt) { h->hashval = hashval; h->cnt = cnt; top->free--; if (top->free < 0) return spanhash_rehash(top); return top; } if (h->hashval == hashval) { h->cnt += cnt; return top; } if (lim <= bucket) bucket = 0; } } static struct spanhash_top *hash_chars(unsigned char *buf, unsigned int sz) { int i, n; unsigned int accum1, accum2, hashval; struct spanhash_top *hash; i = INITIAL_HASH_SIZE; hash = xmalloc(sizeof(*hash) + sizeof(struct spanhash) * (1<<i)); hash->alloc_log2 = i; hash->free = INITIAL_FREE(i); memset(hash->data, 0, sizeof(struct spanhash) * (1<<i)); n = 0; accum1 = accum2 = 0; while (sz) { unsigned int c = *buf++; unsigned int old_1 = accum1; sz--; accum1 = (accum1 << 7) ^ (accum2 >> 25); accum2 = (accum2 << 7) ^ (old_1 >> 25); accum1 += c; if (++n < 64 && c != '\n') continue; hashval = (accum1 + accum2 * 0x61) % HASHBASE; hash = add_spanhash(hash, hashval, n); n = 0; accum1 = accum2 = 0; } return hash; } int diffcore_count_changes(void *src, unsigned long src_size, void *dst, unsigned long dst_size, void **src_count_p, void **dst_count_p, unsigned long delta_limit, unsigned long *src_copied, unsigned long *literal_added) { int i, ssz; struct spanhash_top *src_count, *dst_count; unsigned long sc, la; src_count = dst_count = NULL; if (src_count_p) src_count = *src_count_p; if (!src_count) { src_count = hash_chars(src, src_size); if (src_count_p) *src_count_p = src_count; } if (dst_count_p) dst_count = *dst_count_p; if (!dst_count) { dst_count = hash_chars(dst, dst_size); if (dst_count_p) *dst_count_p = dst_count; } sc = la = 0; ssz = 1 << src_count->alloc_log2; for (i = 0; i < ssz; i++) { struct spanhash *s = &(src_count->data[i]); struct spanhash *d; unsigned dst_cnt, src_cnt; if (!s->cnt) continue; src_cnt = s->cnt; d = spanhash_find(dst_count, s->hashval); dst_cnt = d ? d->cnt : 0; if (src_cnt < dst_cnt) { la += dst_cnt - src_cnt; sc += src_cnt; } else sc += dst_cnt; } if (!src_count_p) free(src_count); if (!dst_count_p) free(dst_count); *src_copied = sc; *literal_added = la; return 0; }
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
You can’t perform that action at this time.