Mercurial > public > mercurial-scm > hg
annotate mercurial/thirdparty/xdiff/xutils.c @ 36763:90f8fe72446c
xdiff: remove xemit related logic
xemit handles "diff formatting and output" with options like context lines,
whether show function names, etc. That is handled more cleanly at a higher
level in hg.
Removing context line parameters would also make the trimming logic (D2686)
cleaner and more confident. See [1].
[1]: https://github.com/git/git/commit/d2f82950a9226ae1102a7a97f03440a4bf8c6c09
Differential Revision: https://phab.mercurial-scm.org/D2705
author | Jun Wu <quark@fb.com> |
---|---|
date | Tue, 06 Mar 2018 18:41:08 -0800 |
parents | b5bb0f99064d |
children | 882657a9f768 |
rev | line source |
---|---|
36671 | 1 /* |
2 * LibXDiff by Davide Libenzi ( File Differential Library ) | |
3 * Copyright (C) 2003 Davide Libenzi | |
4 * | |
5 * This library is free software; you can redistribute it and/or | |
6 * modify it under the terms of the GNU Lesser General Public | |
7 * License as published by the Free Software Foundation; either | |
8 * version 2.1 of the License, or (at your option) any later version. | |
9 * | |
10 * This library is distributed in the hope that it will be useful, | |
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 * Lesser General Public License for more details. | |
14 * | |
15 * You should have received a copy of the GNU Lesser General Public | |
16 * License along with this library; if not, see | |
17 * <http://www.gnu.org/licenses/>. | |
18 * | |
19 * Davide Libenzi <davidel@xmailserver.org> | |
20 * | |
21 */ | |
22 | |
23 #include <limits.h> | |
24 #include <assert.h> | |
25 #include "xinclude.h" | |
26 | |
27 | |
28 | |
29 | |
30 long xdl_bogosqrt(long n) { | |
31 long i; | |
32 | |
33 /* | |
34 * Classical integer square root approximation using shifts. | |
35 */ | |
36 for (i = 1; n > 0; n >>= 2) | |
37 i <<= 1; | |
38 | |
39 return i; | |
40 } | |
41 | |
42 | |
43 void *xdl_mmfile_first(mmfile_t *mmf, long *size) | |
44 { | |
45 *size = mmf->size; | |
46 return mmf->ptr; | |
47 } | |
48 | |
49 | |
50 long xdl_mmfile_size(mmfile_t *mmf) | |
51 { | |
52 return mmf->size; | |
53 } | |
54 | |
55 | |
56 int xdl_cha_init(chastore_t *cha, long isize, long icount) { | |
57 | |
58 cha->head = cha->tail = NULL; | |
59 cha->isize = isize; | |
60 cha->nsize = icount * isize; | |
61 cha->ancur = cha->sncur = NULL; | |
62 cha->scurr = 0; | |
63 | |
64 return 0; | |
65 } | |
66 | |
67 | |
68 void xdl_cha_free(chastore_t *cha) { | |
69 chanode_t *cur, *tmp; | |
70 | |
71 for (cur = cha->head; (tmp = cur) != NULL;) { | |
72 cur = cur->next; | |
73 xdl_free(tmp); | |
74 } | |
75 } | |
76 | |
77 | |
78 void *xdl_cha_alloc(chastore_t *cha) { | |
79 chanode_t *ancur; | |
80 void *data; | |
81 | |
82 if (!(ancur = cha->ancur) || ancur->icurr == cha->nsize) { | |
83 if (!(ancur = (chanode_t *) xdl_malloc(sizeof(chanode_t) + cha->nsize))) { | |
84 | |
85 return NULL; | |
86 } | |
87 ancur->icurr = 0; | |
88 ancur->next = NULL; | |
89 if (cha->tail) | |
90 cha->tail->next = ancur; | |
91 if (!cha->head) | |
92 cha->head = ancur; | |
93 cha->tail = ancur; | |
94 cha->ancur = ancur; | |
95 } | |
96 | |
97 data = (char *) ancur + sizeof(chanode_t) + ancur->icurr; | |
98 ancur->icurr += cha->isize; | |
99 | |
100 return data; | |
101 } | |
102 | |
103 long xdl_guess_lines(mmfile_t *mf, long sample) { | |
104 long nl = 0, size, tsize = 0; | |
105 char const *data, *cur, *top; | |
106 | |
107 if ((cur = data = xdl_mmfile_first(mf, &size)) != NULL) { | |
108 for (top = data + size; nl < sample && cur < top; ) { | |
109 nl++; | |
110 if (!(cur = memchr(cur, '\n', top - cur))) | |
111 cur = top; | |
112 else | |
113 cur++; | |
114 } | |
115 tsize += (long) (cur - data); | |
116 } | |
117 | |
118 if (nl && tsize) | |
119 nl = xdl_mmfile_size(mf) / (tsize / nl); | |
120 | |
121 return nl + 1; | |
122 } | |
123 | |
124 int xdl_recmatch(const char *l1, long s1, const char *l2, long s2, long flags) | |
125 { | |
126 if (s1 == s2 && !memcmp(l1, l2, s1)) | |
127 return 1; | |
36761
09f320067591
xdiff: remove whitespace related feature
Jun Wu <quark@fb.com>
parents:
36671
diff
changeset
|
128 return 0; |
36671 | 129 } |
130 | |
131 unsigned long xdl_hash_record(char const **data, char const *top, long flags) { | |
132 unsigned long ha = 5381; | |
133 char const *ptr = *data; | |
134 | |
135 for (; ptr < top && *ptr != '\n'; ptr++) { | |
136 ha += (ha << 5); | |
137 ha ^= (unsigned long) *ptr; | |
138 } | |
139 *data = ptr < top ? ptr + 1: ptr; | |
140 | |
141 return ha; | |
142 } | |
143 | |
144 unsigned int xdl_hashbits(unsigned int size) { | |
145 unsigned int val = 1, bits = 0; | |
146 | |
147 for (; val < size && bits < CHAR_BIT * sizeof(unsigned int); val <<= 1, bits++); | |
148 return bits ? bits: 1; | |
149 } |