/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/_patiencediff_c.c

  • Committer: John Arbash Meinel
  • Date: 2008-10-08 21:56:12 UTC
  • mto: This revision was merged to the branch mainline in revision 3773.
  • Revision ID: john@arbash-meinel.com-20081008215612-y9v94tqxreqoangx
Simplify the --raw mode.

I didn't realize, but the only node that is special cased is the 'root' node,
and to read it, you actually have to parse it directly, because the
compressed bytes start immediately after the end of the header, rather than
having any padding before the zlib bytes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 Copyright (C) 2007, 2010 Canonical Ltd
 
2
 Copyright (C) 2007 Canonical Ltd
3
3
 
4
4
 This program is free software; you can redistribute it and/or modify
5
5
 it under the terms of the GNU General Public License as published by
13
13
 
14
14
 You should have received a copy of the GNU General Public License
15
15
 along with this program; if not, write to the Free Software
16
 
 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
16
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
17
 
18
18
 Function equate_lines based on bdiff.c from Mercurial.
19
19
   Copyright (C) 2005, 2006 Matt Mackall <mpm@selenic.com>
46
46
#define SENTINEL -1
47
47
 
48
48
 
49
 
/* malloc returns NULL on some platforms if you try to allocate nothing,
50
 
 * causing <https://bugs.edge.launchpad.net/bzr/+bug/511267> and
51
 
 * <https://bugs.edge.launchpad.net/bzr/+bug/331095>.  On glibc it passes, but
52
 
 * let's make it fail to aid testing. */
53
 
#define guarded_malloc(x) ( (x) ? malloc(x) : NULL )
54
 
 
55
49
enum {
56
50
    OP_EQUAL = 0,
57
51
    OP_INSERT,
189
183
    while (hsize < bsize + 1)
190
184
        hsize *= 2;
191
185
 
192
 
    /* can't be 0 */
193
 
    hashtable = (struct bucket *) guarded_malloc(sizeof(struct bucket) * hsize);
 
186
    hashtable = (struct bucket *)malloc(sizeof(struct bucket) * hsize);
194
187
    if (hashtable == NULL) {
195
188
        PyErr_NoMemory();
196
189
        return 0;
305
298
        apos = SENTINEL;
306
299
        /* loop through all lines in the linked list */
307
300
        for (i = h[equiv].a_pos; i != SENTINEL; i = lines_a[i].next) {
308
 
            /* the index is lower than alo, continue to the next line */
 
301
            /* the index is lower than alo, the the next line */
309
302
            if (i < alo) {
310
303
                h[equiv].a_pos = i;
311
304
                continue;
326
319
        /* check for duplicates of this line in lines_b[blo:bhi] */
327
320
        /* loop through all lines in the linked list */
328
321
        for (i = h[equiv].b_pos; i != SENTINEL; i = lines_b[i].next) {
329
 
            /* the index is lower than blo, continue to the next line */
 
322
            /* the index is lower than blo, the the next line */
330
323
            if (i < blo) {
331
324
                h[equiv].b_pos = i;
332
325
                continue;
467
460
    last_a_pos = alo - 1;
468
461
    last_b_pos = blo - 1;
469
462
 
470
 
    lcs = (struct matching_line *)guarded_malloc(sizeof(struct matching_line) * (bhi - blo));
 
463
    lcs = (struct matching_line *)malloc(sizeof(struct matching_line) * (bhi - blo));
471
464
    if (lcs == NULL)
472
465
        return 0;
473
466
 
627
620
    if (!equate_lines(&hashtable, a, b, asize, bsize))
628
621
        goto error;
629
622
 
630
 
    if (bsize > 0) {
631
 
        matches = (struct matching_line *)guarded_malloc(sizeof(struct matching_line) * bsize);
632
 
        if (matches == NULL)
633
 
            goto error;
 
623
    matches = (struct matching_line *)malloc(sizeof(struct matching_line) * bsize);
 
624
    if (matches == NULL)
 
625
        goto error;
634
626
 
635
 
        backpointers = (Py_ssize_t *)guarded_malloc(sizeof(Py_ssize_t) * bsize * 4);
636
 
        if (backpointers == NULL)
637
 
            goto error;
638
 
    }
 
627
    backpointers = (Py_ssize_t *)malloc(sizeof(Py_ssize_t) * bsize * 4);
 
628
    if (backpointers == NULL)
 
629
        goto error;
639
630
 
640
631
    nmatches = unique_lcs(matches, &hashtable, backpointers, a, b, 0, 0, asize, bsize);
641
632
 
701
692
        goto error;
702
693
 
703
694
    matches.count = 0;
704
 
 
705
 
    if (bsize > 0) {
706
 
        matches.matches = (struct matching_block *)guarded_malloc(sizeof(struct matching_block) * bsize);
707
 
        if (matches.matches == NULL)
708
 
            goto error;
709
 
 
710
 
        backpointers = (Py_ssize_t *)guarded_malloc(sizeof(Py_ssize_t) * bsize * 4);
711
 
        if (backpointers == NULL)
712
 
            goto error;
713
 
    } else {
714
 
        matches.matches = NULL;
715
 
        backpointers = NULL;
716
 
    }
 
695
    matches.matches = (struct matching_block *)malloc(sizeof(struct matching_block) * bsize);
 
696
    if (matches.matches == NULL)
 
697
        goto error;
 
698
 
 
699
    backpointers = (Py_ssize_t *)malloc(sizeof(Py_ssize_t) * bsize * 4);
 
700
    if (backpointers == NULL)
 
701
        goto error;
717
702
 
718
703
    res = recurse_matches(&matches, &hashtable, backpointers,
719
704
                          a, b, alo, blo, ahi, bhi, maxrecursion);
780
765
            return NULL;
781
766
        }
782
767
 
783
 
        if (self->bsize > 0) {
784
 
            self->backpointers = (Py_ssize_t *)guarded_malloc(sizeof(Py_ssize_t) * self->bsize * 4);
785
 
            if (self->backpointers == NULL) {
786
 
                Py_DECREF(self);
787
 
                PyErr_NoMemory();
788
 
                return NULL;
789
 
            }
790
 
        } else {
791
 
            self->backpointers = NULL;
 
768
        self->backpointers = (Py_ssize_t *)malloc(sizeof(Py_ssize_t) * self->bsize * 4);
 
769
        if (self->backpointers == NULL) {
 
770
            Py_DECREF(self);
 
771
            return NULL;
792
772
        }
793
773
 
794
774
    }
831
811
    struct matching_blocks matches;
832
812
 
833
813
    matches.count = 0;
834
 
    if (self->bsize > 0) {
835
 
        matches.matches = (struct matching_block *)
836
 
            guarded_malloc(sizeof(struct matching_block) * self->bsize);
837
 
        if (matches.matches == NULL)
838
 
            return PyErr_NoMemory();
839
 
    } else
840
 
        matches.matches = NULL;
 
814
    matches.matches = (struct matching_block *)malloc(sizeof(struct matching_block) * self->bsize);
 
815
    if (matches.matches == NULL)
 
816
        return PyErr_NoMemory();
841
817
 
842
818
    res = recurse_matches(&matches, &self->hashtable, self->backpointers,
843
819
                          self->a, self->b, 0, 0,
923
899
    struct matching_blocks matches;
924
900
 
925
901
    matches.count = 0;
926
 
    matches.matches = (struct matching_block *)guarded_malloc(sizeof(struct matching_block) * (self->bsize + 1));
 
902
    matches.matches = (struct matching_block *)malloc(sizeof(struct matching_block) * (self->bsize + 1));
927
903
    if (matches.matches == NULL)
928
904
        return PyErr_NoMemory();
929
905
 
1036
1012
        return NULL;
1037
1013
 
1038
1014
    matches.count = 0;
1039
 
    matches.matches = (struct matching_block *)guarded_malloc(sizeof(struct matching_block) * (self->bsize + 1));
 
1015
    matches.matches = (struct matching_block *)malloc(sizeof(struct matching_block) * (self->bsize + 1));
1040
1016
    if (matches.matches == NULL)
1041
1017
        return PyErr_NoMemory();
1042
1018
 
1054
1030
    matches.count++;
1055
1031
 
1056
1032
    ncodes = 0;
1057
 
    codes = (struct opcode *)guarded_malloc(sizeof(struct opcode) * matches.count * 2);
 
1033
    codes = (struct opcode *)malloc(sizeof(struct opcode) * matches.count * 2);
1058
1034
    if (codes == NULL) {
1059
1035
        free(matches.matches);
1060
1036
        return PyErr_NoMemory();
1275
1251
    PyModule_AddObject(m, "PatienceSequenceMatcher_c",
1276
1252
                       (PyObject *)&PatienceSequenceMatcherType);
1277
1253
}
1278
 
 
1279
 
 
1280
 
/* vim: sw=4 et 
1281
 
 */