/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

  • Committer: Martin
  • Date: 2011-03-20 18:08:45 UTC
  • mto: This revision was merged to the branch mainline in revision 5731.
  • Revision ID: gzlist@googlemail.com-20110320180845-fh11c1z8libkzflw
Switch approach to delta function interfaces and use a return code and outparam

Show diffs side-by-side

added added

removed removed

Lines of Context:
373
373
}
374
374
 
375
375
 
376
 
struct delta_index *
 
376
delta_result
377
377
create_delta_index(const struct source_info *src,
378
 
                   struct delta_index *old)
 
378
                   struct delta_index *old,
 
379
                   struct delta_index **fresh)
379
380
{
380
381
    unsigned int i, hsize, hmask, num_entries, prev_val, *hash_count;
381
382
    unsigned int total_num_entries;
386
387
    unsigned long memsize;
387
388
 
388
389
    if (!src->buf || !src->size)
389
 
        return NULL;
 
390
        return DELTA_SOURCE_EMPTY;
390
391
    buffer = src->buf;
391
392
 
392
393
    /* Determine index hash size.  Note that indexing skips the
411
412
          sizeof(*entry) * total_num_entries;
412
413
    mem = malloc(memsize);
413
414
    if (!mem)
414
 
        return NULL;
 
415
        return DELTA_OUT_OF_MEMORY;
415
416
    hash = mem;
416
417
    mem = hash + hsize;
417
418
    entry = mem;
422
423
    hash_count = calloc(hsize, sizeof(*hash_count));
423
424
    if (!hash_count) {
424
425
        free(hash);
425
 
        return NULL;
 
426
        return DELTA_OUT_OF_MEMORY;
426
427
    }
427
428
 
428
429
    /* then populate the index for the new data */
455
456
    free(hash_count);
456
457
    index = pack_delta_index(hash, hsize, total_num_entries, old);
457
458
    free(hash);
 
459
    /* pack_delta_index only returns NULL on malloc failure */
458
460
    if (!index) {
459
 
        return NULL;
 
461
        return DELTA_OUT_OF_MEMORY;
460
462
    }
461
463
    index->last_src = src;
462
 
    return index;
 
464
    *fresh = index;
 
465
    return DELTA_OK;
463
466
}
464
467
 
465
468
/* Take some entries, and put them into a custom hash.
679
682
    }
680
683
}
681
684
 
682
 
struct delta_index *
 
685
delta_result
683
686
create_delta_index_from_delta(const struct source_info *src,
684
 
                              struct delta_index *old_index)
 
687
                              struct delta_index *old_index,
 
688
                              struct delta_index **fresh)
685
689
{
686
690
    unsigned int i, num_entries, max_num_entries, prev_val, num_inserted;
687
691
    unsigned int hash_offset;
690
694
    struct delta_index *new_index;
691
695
    struct index_entry *entry, *entries;
692
696
 
693
 
    assert(old_index != NULL);
 
697
    if (!old_index)
 
698
        return DELTA_INDEX_NEEDED;
694
699
    if (!src->buf || !src->size)
695
 
        return NULL;
 
700
        return DELTA_SOURCE_EMPTY;
696
701
    buffer = src->buf;
697
702
    top = buffer + src->size;
698
703
 
708
713
    /* allocate an array to hold whatever entries we find */
709
714
    entries = malloc(sizeof(*entry) * max_num_entries);
710
715
    if (!entries) /* malloc failure */
711
 
        return NULL;
 
716
        return DELTA_OUT_OF_MEMORY;
712
717
 
713
718
    /* then populate the index for the new data */
714
719
    prev_val = ~0;
774
779
            break;
775
780
        }
776
781
    }
777
 
    /* GZ 2011-03-04: What is 'something' exactly? If this an unrecoverable
778
 
                      error perhaps it should be an assert? */
779
782
    if (data != top) {
780
 
        /* Something was wrong with this delta */
 
783
        /* The source_info data passed was corrupted or otherwise invalid */
781
784
        free(entries);
782
 
        return old_index;
 
785
        return DELTA_SOURCE_BAD;
783
786
    }
784
787
    if (num_entries == 0) {
785
788
        /** Nothing to index **/
786
789
        free(entries);
787
 
        return old_index;
 
790
        *fresh = old_index;
 
791
        return DELTA_OK;
788
792
    }
789
793
    old_index->last_src = src;
790
794
    /* See if we can fill in these values into the holes in the array */
842
846
        // fprintf(stderr, "inserted %d before resize\n", num_inserted);
843
847
        new_index = create_index_from_old_and_new_entries(old_index,
844
848
            entry, num_entries);
 
849
        
845
850
    } else {
846
851
        new_index = old_index;
847
852
        // fprintf(stderr, "inserted %d without resizing\n", num_inserted);
848
853
    }
849
854
    free(entries);
850
 
    return new_index;
 
855
    /* create_index_from_old_and_new_entries returns NULL on malloc failure */
 
856
    if (!new_index)
 
857
        return DELTA_OUT_OF_MEMORY;
 
858
    *fresh = new_index;
 
859
    return DELTA_OK;
851
860
}
852
861
 
853
862
void free_delta_index(struct delta_index *index)