Merge branch 'pb/config'
[gitweb.git] / xdiff / xutils.c
index afaada1edf72c8797d3d7bbd24303638accd6c24..f91b4034751df72996afbe6b4b04a9f05638d322 100644 (file)
 
 
 
+long xdl_bogosqrt(long n) {
+       long i;
+
+       /*
+        * Classical integer square root approximation using shifts.
+        */
+       for (i = 1; n > 0; n >>= 2)
+               i <<= 1;
+
+       return i;
+}
+
+
 int xdl_emit_diffrec(char const *rec, long size, char const *pre, long psize,
                     xdemitcb_t *ecb) {
+       int i = 2;
        mmbuffer_t mb[3];
-       int i;
 
        mb[0].ptr = (char *) pre;
        mb[0].size = psize;
        mb[1].ptr = (char *) rec;
        mb[1].size = size;
-       i = 2;
-
-       if (!size || rec[size-1] != '\n') {
-               mb[2].ptr = "\n\\ No newline at end of file\n";
+       if (size > 0 && rec[size - 1] != '\n') {
+               mb[2].ptr = (char *) "\n\\ No newline at end of file\n";
                mb[2].size = strlen(mb[2].ptr);
-               i = 3;
+               i++;
        }
-
        if (ecb->outf(ecb->priv, mb, i) < 0) {
 
                return -1;
@@ -244,7 +254,7 @@ int xdl_emit_hunk_hdr(long s1, long c1, long s2, long c2,
        memcpy(buf, "@@ -", 4);
        nb += 4;
 
-       nb += xdl_num_out(buf + nb, c1 ? s1: 0);
+       nb += xdl_num_out(buf + nb, c1 ? s1: s1 - 1);
 
        if (c1 != 1) {
                memcpy(buf + nb, ",", 1);
@@ -256,7 +266,7 @@ int xdl_emit_hunk_hdr(long s1, long c1, long s2, long c2,
        memcpy(buf + nb, " +", 2);
        nb += 2;
 
-       nb += xdl_num_out(buf + nb, c2 ? s2: 0);
+       nb += xdl_num_out(buf + nb, c2 ? s2: s2 - 1);
 
        if (c2 != 1) {
                memcpy(buf + nb, ",", 1);