MCPcopy Create free account
hub / github.com/git/git / trim_common_tail

Function trim_common_tail

xdiff-interface.c:98–117  ·  view source on GitHub ↗

* Trim down common substring at the end of the buffers, * but end on a complete line. */

Source from the content-addressed store, hash-verified

96 * but end on a complete line.
97 */
98static void trim_common_tail(mmfile_t *a, mmfile_t *b)
99{
100 const int blk = 1024;
101 long trimmed = 0, recovered = 0;
102 char *ap = a->size ? a->ptr + a->size : a->ptr;
103 char *bp = b->size ? b->ptr + b->size : b->ptr;
104 long smaller = (a->size < b->size) ? a->size : b->size;
105
106 while (blk + trimmed <= smaller && !memcmp(ap - blk, bp - blk, blk)) {
107 trimmed += blk;
108 ap -= blk;
109 bp -= blk;
110 }
111
112 while (recovered < trimmed)
113 if (ap[recovered++] == '\n')
114 break;
115 a->size -= trimmed - recovered;
116 b->size -= trimmed - recovered;
117}
118
119int xdi_diff(mmfile_t *mf1, mmfile_t *mf2, xpparam_t const *xpp, xdemitconf_t const *xecfg, xdemitcb_t *xecb)
120{

Callers 1

xdi_diffFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected