/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/diff-delta.c

Add bzrlib.pyutils, which has get_named_object, a wrapper around __import__.

This is used to replace various ad hoc implementations of the same logic,
notably the version used in registry's _LazyObjectGetter which had a bug when
getting a module without also getting a member.  And of course, this new
function has unit tests, unlike the replaced code.

This also adds a KnownHooksRegistry subclass to provide a more natural home for
some other logic.

I'm not thrilled about the name of the new module or the new functions, but it's
hard to think of good names for such generic functionality.

Show diffs side-by-side

added added

removed removed

Lines of Context:
853
853
    free(index);
854
854
}
855
855
 
856
 
unsigned long sizeof_delta_index(struct delta_index *index)
 
856
unsigned long
 
857
sizeof_delta_index(struct delta_index *index)
857
858
{
858
859
    if (index)
859
860
        return index->memsize;
872
873
             const void *trg_buf, unsigned long trg_size,
873
874
             unsigned long *delta_size, unsigned long max_size)
874
875
{
875
 
    unsigned int i, outpos, outsize, moff, msize, val;
 
876
    unsigned int i, outpos, outsize, moff, val;
 
877
    int msize;
876
878
    const struct source_info *msource;
877
879
    int inscnt;
878
880
    const unsigned char *ref_data, *ref_top, *data, *top;
943
945
                 entry++) {
944
946
                const unsigned char *ref;
945
947
                const unsigned char *src;
946
 
                unsigned int ref_size;
 
948
                int ref_size;
947
949
                if (entry->val != val)
948
950
                    continue;
949
951
                ref = entry->ptr;
956
958
                 * match more bytes with this location that we have already
957
959
                 * matched.
958
960
                 */
959
 
                if (ref_size > top - src)
 
961
                if (ref_size > (top - src))
960
962
                    ref_size = top - src;
961
963
                if (ref_size <= msize)
962
964
                    break;
963
965
                /* See how many bytes actually match at this location. */
964
966
                while (ref_size-- && *src++ == *ref)
965
967
                    ref++;
966
 
                if (msize < ref - entry->ptr) {
 
968
                if (msize < (ref - entry->ptr)) {
967
969
                    /* this is our best match so far */
968
970
                    msize = ref - entry->ptr;
969
971
                    msource = entry->src;