~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/diff-delta.c

  • Committer: John Arbash Meinel
  • Date: 2009-03-27 22:29:55 UTC
  • mto: (3735.39.2 clean)
  • mto: This revision was merged to the branch mainline in revision 4280.
  • Revision ID: john@arbash-meinel.com-20090327222955-utifmfm888zerixt
Implement apply_delta_to_source which doesn't have to malloc another string.

Show diffs side-by-side

added added

removed removed

Lines of Context:
7
7
 * Rewritten for GIT by Nicolas Pitre <nico@cam.org>, (C) 2005-2007
8
8
 * Adapted for Bazaar by John Arbash Meinel <john@arbash-meinel.com> (C) 2009
9
9
 *
10
 
 * This program is free software; you can redistribute it and/or modify
11
 
 * it under the terms of the GNU General Public License as published by
12
 
 * the Free Software Foundation; either version 2 of the License, or
13
 
 * (at your option) any later version.
14
 
 *
15
 
 * NB: The version in GIT is 'version 2 of the Licence only', however Nicolas
16
 
 * has granted permission for use under 'version 2 or later' in private email
17
 
 * to Robert Collins and Karl Fogel on the 6th April 2009.
 
10
 * This code is free software; you can redistribute it and/or modify
 
11
 * it under the terms of the GNU General Public License version 2 as
 
12
 * published by the Free Software Foundation.
18
13
 */
19
14
 
20
15
#include <stdio.h>
688
683
    const unsigned char *data, *buffer, *top;
689
684
    unsigned char cmd;
690
685
    struct delta_index *new_index;
691
 
    struct index_entry *entry, *entries;
 
686
    struct index_entry *entry, *entries, *old_entry;
692
687
 
693
688
    if (!src->buf || !src->size)
694
689
        return NULL;
713
708
    prev_val = ~0;
714
709
    data = buffer;
715
710
    /* target size */
716
 
    /* get_delta_hdr_size doesn't mutate the content, just moves the
717
 
     * start-of-data pointer, so it is safe to do the cast.
718
 
     */
719
 
    get_delta_hdr_size((unsigned char**)&data, top);
 
711
    get_delta_hdr_size(&data, top);
720
712
    entry = entries; /* start at the first slot */
721
713
    num_entries = 0; /* calculate the real number of entries */
722
714
    while (data < top) {
789
781
    entry = entries;
790
782
    num_inserted = 0;
791
783
    for (; num_entries > 0; --num_entries, ++entry) {
792
 
        struct index_entry *next_bucket_entry, *cur_entry, *bucket_first_entry;
793
784
        hash_offset = (entry->val & old_index->hash_mask);
794
785
        /* The basic structure is a hash => packed_entries that fit in that
795
786
         * hash bucket. Things are structured such that the hash-pointers are
798
789
         * forward. If there are no NULL targets, then we know because
799
790
         * entry->ptr will not be NULL.
800
791
         */
801
 
        // The start of the next bucket, this may point past the end of the
802
 
        // entry table if hash_offset is the last bucket.
803
 
        next_bucket_entry = old_index->hash[hash_offset + 1];
804
 
        // First entry in this bucket
805
 
        bucket_first_entry = old_index->hash[hash_offset];
806
 
        cur_entry = next_bucket_entry - 1;
807
 
        while (cur_entry->ptr == NULL && cur_entry >= bucket_first_entry) {
808
 
            cur_entry--;
 
792
        old_entry = old_index->hash[hash_offset + 1];
 
793
        old_entry--;
 
794
        while (old_entry->ptr == NULL
 
795
               && old_entry >= old_index->hash[hash_offset]) {
 
796
            old_entry--;
809
797
        }
810
 
        // cur_entry now either points at the first NULL, or it points to
811
 
        // next_bucket_entry if there were no blank spots.
812
 
        cur_entry++;
813
 
        if (cur_entry >= next_bucket_entry || cur_entry->ptr != NULL) {
 
798
        old_entry++;
 
799
        if (old_entry->ptr != NULL
 
800
            || old_entry >= old_index->hash[hash_offset + 1]) {
814
801
            /* There is no room for this entry, we have to resize */
815
802
            // char buff[128];
816
803
            // get_text(buff, entry->ptr);
827
814
            break;
828
815
        }
829
816
        num_inserted++;
830
 
        *cur_entry = *entry;
 
817
        *old_entry = *entry;
831
818
        /* For entries which we *do* manage to insert into old_index, we don't
832
819
         * want them double copied into the final output.
833
820
         */