Code

gitweb: Lift any characters restriction on searched strings
[git.git] / diff-delta.c
index 3a737da68c8cadb900ffe5b44973d9193fbca83f..0dde2f2dc032863b154509f5b966cfafb01dd722 100644 (file)
@@ -1,21 +1,14 @@
 /*
  * diff-delta.c: generate a delta between two buffers
  *
- *  Many parts of this file have been lifted from LibXDiff version 0.10.
- *  http://www.xmailserver.org/xdiff-lib.html
+ * This code was greatly inspired by parts of LibXDiff from Davide Libenzi
+ * http://www.xmailserver.org/xdiff-lib.html
  *
- *  LibXDiff was written by Davide Libenzi <davidel@xmailserver.org>
- *  Copyright (C) 2003 Davide Libenzi
+ * Rewritten for GIT by Nicolas Pitre <nico@cam.org>, (C) 2005-2007
  *
- *  Many mods for GIT usage by Nicolas Pitre <nico@cam.org>, (C) 2005.
- *
- *  This file is free software; you can redistribute it and/or
- *  modify it under the terms of the GNU Lesser General Public
- *  License as published by the Free Software Foundation; either
- *  version 2.1 of the License, or (at your option) any later version.
- *
- *  Use of this within git automatically means that the LGPL
- *  licensing gets turned into GPLv2 within this project.
+ * This code is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
  */
 
 #include "git-compat-util.h"
@@ -126,6 +119,7 @@ struct index_entry {
 };
 
 struct delta_index {
+       unsigned long memsize;
        const void *src_buf;
        unsigned long src_size;
        unsigned int hash_mask;
@@ -166,6 +160,7 @@ struct delta_index * create_delta_index(const void *buf, unsigned long bufsize)
        mem = hash + hsize;
        entry = mem;
 
+       index->memsize = memsize;
        index->src_buf = buf;
        index->src_size = bufsize;
        index->hash_mask = hmask;
@@ -218,7 +213,7 @@ struct delta_index * create_delta_index(const void *buf, unsigned long bufsize)
                entry = hash[i];
                do {
                        struct index_entry *keep = entry;
-                       int skip = hash_count[i] / HASH_LIMIT / 2;
+                       int skip = hash_count[i] / HASH_LIMIT;
                        do {
                                entry = entry->next;
                        } while(--skip && entry);
@@ -235,6 +230,14 @@ void free_delta_index(struct delta_index *index)
        free(index);
 }
 
+unsigned long sizeof_delta_index(struct delta_index *index)
+{
+       if (index)
+               return index->memsize;
+       else
+               return 0;
+}
+
 /*
  * The maximum size for any opcode sequence, including the initial header
  * plus Rabin window plus biggest copy.
@@ -395,7 +398,7 @@ create_delta(const struct delta_index *index,
                                outsize = max_size + MAX_OP_SIZE + 1;
                        if (max_size && outpos > max_size)
                                break;
-                       out = xrealloc(out, outsize);
+                       out = realloc(out, outsize);
                        if (!out) {
                                free(tmp);
                                return NULL;