/* Generated by Pyrex 0.9.8.5 on Thu Nov 25 16:59:21 2010 */

#define PY_SSIZE_T_CLEAN
#include "Python.h"
#include "structmember.h"
#ifndef PY_LONG_LONG
  #define PY_LONG_LONG LONG_LONG
#endif
#if PY_VERSION_HEX < 0x02050000
  typedef int Py_ssize_t;
  #define PY_SSIZE_T_MAX INT_MAX
  #define PY_SSIZE_T_MIN INT_MIN
  #define PyInt_FromSsize_t(z) PyInt_FromLong(z)
  #define PyInt_AsSsize_t(o)	PyInt_AsLong(o)
#endif
#if !defined(WIN32) && !defined(MS_WINDOWS)
  #ifndef __stdcall
    #define __stdcall
  #endif
  #ifndef __cdecl
    #define __cdecl
  #endif
#endif
#ifdef __cplusplus
#define __PYX_EXTERN_C extern "C"
#else
#define __PYX_EXTERN_C extern
#endif
#include <math.h>
#include "python-compat.h"
#include "delta.h"


typedef struct {PyObject **p; int i; char *s; long n;} __Pyx_StringTabEntry; /*proto*/

static PyObject *__pyx_m;
static PyObject *__pyx_b;
static int __pyx_lineno;
static char *__pyx_filename;
static char **__pyx_f;

static char __pyx_mdoc[] = "Compiled extensions for doing compression.";

static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb); /*proto*/

static int __Pyx_InitStrings(__Pyx_StringTabEntry *t); /*proto*/

static int __Pyx_SetVtable(PyObject *dict, void *vtable); /*proto*/

static void __Pyx_AddTraceback(char *funcname); /*proto*/

/* Declarations from bzrlib._groupcompress_pyx */


/* Declarations from implementation of bzrlib._groupcompress_pyx */

struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex {
  PyObject_HEAD
  struct __pyx_vtabstruct_6bzrlib_18_groupcompress_pyx_DeltaIndex *__pyx_vtab;
  PyObject *_sources;
  struct source_info *_source_infos;
  struct delta_index *_index;
  unsigned int _max_num_sources;
  unsigned long _source_offset;
};


struct __pyx_vtabstruct_6bzrlib_18_groupcompress_pyx_DeltaIndex {
  PyObject *(*_populate_first_index)(struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *);
  PyObject *(*_expand_sources)(struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *);
};
static struct __pyx_vtabstruct_6bzrlib_18_groupcompress_pyx_DeltaIndex *__pyx_vtabptr_6bzrlib_18_groupcompress_pyx_DeltaIndex;

static PyTypeObject *__pyx_ptype_6bzrlib_18_groupcompress_pyx_DeltaIndex = 0;
static void *__pyx_f_6bzrlib_18_groupcompress_pyx_safe_malloc(size_t); /*proto*/
static void *__pyx_f_6bzrlib_18_groupcompress_pyx_safe_realloc(void *,size_t); /*proto*/
static int __pyx_f_6bzrlib_18_groupcompress_pyx_safe_free(void **); /*proto*/
static unsigned char *__pyx_f_6bzrlib_18_groupcompress_pyx__decode_copy_instruction(unsigned char *,unsigned char,unsigned int *,unsigned int *); /*proto*/
static PyObject *__pyx_f_6bzrlib_18_groupcompress_pyx__apply_delta(char *,Py_ssize_t,char *,Py_ssize_t); /*proto*/

static char __pyx_k1[] = "Failed to allocate %d bytes of memory";
static char __pyx_k2[] = "Failed to reallocate to %d bytes of memory";
static char __pyx_k3[] = "add_source";
static char __pyx_k4[] = "%s(%d, %d)";
static char __pyx_k5[] = "__class__";
static char __pyx_k6[] = "__name__";
static char __pyx_k7[] = "delta is not a str";
static char __pyx_k8[] = "append";
static char __pyx_k9[] = "source is not a str";
static char __pyx_k10[] = "_populate_first_index should only be called when we have a single source and no index yet";
static char __pyx_k11[] = "if we move self._source_infos, then we need to change all of the index pointers as well.";
static char __pyx_k12[] = "target is not a str";
static char __pyx_k13[] = "make_delta";
static char __pyx_k14[] = "delta_size %d smaller than min delta size %d";
static char __pyx_k15[] = "Something wrong with: cp_off = %s, cp_size = %s source_size = %s, size = %s";
static char __pyx_k16[] = "Got delta opcode: 0, not supported";
static char __pyx_k17[] = "Insert instruction longer than remaining bytes: %d > %d";
static char __pyx_k18[] = "Did not extract the number of bytes we expected we were left with %d bytes in \"size\", and top - data = %d";
static char __pyx_k19[] = "Number of bytes extracted did not match the size encoded in the delta header.";
static char __pyx_k20[] = "delta starts after source";
static char __pyx_k21[] = "delta ends after source";
static char __pyx_k22[] = "delta starts after it ends";
static char __pyx_k23[] = "encode_base128_int overflowed the buffer";
static char __pyx_k24[] = "bytes is not a string";
static char __pyx_k25[] = "Data not properly formatted, we ran out of bytes before 0x80 stopped being set.";

static PyObject *__pyx_n___class__;
static PyObject *__pyx_n___name__;
static PyObject *__pyx_n_add_source;
static PyObject *__pyx_n_append;
static PyObject *__pyx_n_make_delta;

static PyObject *__pyx_k1p;
static PyObject *__pyx_k2p;
static PyObject *__pyx_k4p;
static PyObject *__pyx_k7p;
static PyObject *__pyx_k9p;
static PyObject *__pyx_k10p;
static PyObject *__pyx_k11p;
static PyObject *__pyx_k12p;
static PyObject *__pyx_k14p;
static PyObject *__pyx_k15p;
static PyObject *__pyx_k16p;
static PyObject *__pyx_k17p;
static PyObject *__pyx_k18p;
static PyObject *__pyx_k19p;
static PyObject *__pyx_k20p;
static PyObject *__pyx_k21p;
static PyObject *__pyx_k22p;
static PyObject *__pyx_k23p;
static PyObject *__pyx_k24p;
static PyObject *__pyx_k25p;

static __Pyx_StringTabEntry __pyx_string_tab[] = {
  {&__pyx_n___class__, 1, __pyx_k5, sizeof(__pyx_k5)},
  {&__pyx_n___name__, 1, __pyx_k6, sizeof(__pyx_k6)},
  {&__pyx_n_add_source, 1, __pyx_k3, sizeof(__pyx_k3)},
  {&__pyx_n_append, 1, __pyx_k8, sizeof(__pyx_k8)},
  {&__pyx_n_make_delta, 1, __pyx_k13, sizeof(__pyx_k13)},
  {&__pyx_k1p, 0, __pyx_k1, sizeof(__pyx_k1)},
  {&__pyx_k2p, 0, __pyx_k2, sizeof(__pyx_k2)},
  {&__pyx_k4p, 0, __pyx_k4, sizeof(__pyx_k4)},
  {&__pyx_k7p, 0, __pyx_k7, sizeof(__pyx_k7)},
  {&__pyx_k9p, 0, __pyx_k9, sizeof(__pyx_k9)},
  {&__pyx_k10p, 0, __pyx_k10, sizeof(__pyx_k10)},
  {&__pyx_k11p, 0, __pyx_k11, sizeof(__pyx_k11)},
  {&__pyx_k12p, 0, __pyx_k12, sizeof(__pyx_k12)},
  {&__pyx_k14p, 0, __pyx_k14, sizeof(__pyx_k14)},
  {&__pyx_k15p, 0, __pyx_k15, sizeof(__pyx_k15)},
  {&__pyx_k16p, 0, __pyx_k16, sizeof(__pyx_k16)},
  {&__pyx_k17p, 0, __pyx_k17, sizeof(__pyx_k17)},
  {&__pyx_k18p, 0, __pyx_k18, sizeof(__pyx_k18)},
  {&__pyx_k19p, 0, __pyx_k19, sizeof(__pyx_k19)},
  {&__pyx_k20p, 0, __pyx_k20, sizeof(__pyx_k20)},
  {&__pyx_k21p, 0, __pyx_k21, sizeof(__pyx_k21)},
  {&__pyx_k22p, 0, __pyx_k22, sizeof(__pyx_k22)},
  {&__pyx_k23p, 0, __pyx_k23, sizeof(__pyx_k23)},
  {&__pyx_k24p, 0, __pyx_k24, sizeof(__pyx_k24)},
  {&__pyx_k25p, 0, __pyx_k25, sizeof(__pyx_k25)},
  {0, 0, 0, 0}
};

static PyObject *__pyx_d1;
static PyObject *__pyx_d2;


/* Implementation of bzrlib._groupcompress_pyx */

static void *__pyx_f_6bzrlib_18_groupcompress_pyx_safe_malloc(size_t __pyx_v_count) {
  void *__pyx_v_result;
  void *__pyx_r;
  int __pyx_1;
  PyObject *__pyx_2 = 0;
  PyObject *__pyx_3 = 0;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":61 */
  __pyx_v_result = malloc(__pyx_v_count);

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":62 */
  __pyx_1 = (__pyx_v_result == NULL);
  if (__pyx_1) {
    __pyx_2 = PyLong_FromUnsignedLong(__pyx_v_count); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; goto __pyx_L1;}
    __pyx_3 = PyTuple_New(1); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; goto __pyx_L1;}
    PyTuple_SET_ITEM(__pyx_3, 0, __pyx_2);
    __pyx_2 = 0;
    __pyx_2 = PyNumber_Remainder(__pyx_k1p, __pyx_3); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; goto __pyx_L1;}
    Py_DECREF(__pyx_3); __pyx_3 = 0;
    __pyx_3 = PyTuple_New(1); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; goto __pyx_L1;}
    PyTuple_SET_ITEM(__pyx_3, 0, __pyx_2);
    __pyx_2 = 0;
    __pyx_2 = PyObject_CallObject(PyExc_MemoryError, __pyx_3); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; goto __pyx_L1;}
    Py_DECREF(__pyx_3); __pyx_3 = 0;
    __Pyx_Raise(__pyx_2, 0, 0);
    Py_DECREF(__pyx_2); __pyx_2 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; goto __pyx_L1;}
    goto __pyx_L2;
  }
  __pyx_L2:;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":64 */
  __pyx_r = __pyx_v_result;
  goto __pyx_L0;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_2);
  Py_XDECREF(__pyx_3);
  __Pyx_AddTraceback("bzrlib._groupcompress_pyx.safe_malloc");
  __pyx_r = NULL;
  __pyx_L0:;
  return __pyx_r;
}

static void *__pyx_f_6bzrlib_18_groupcompress_pyx_safe_realloc(void *__pyx_v_old,size_t __pyx_v_count) {
  void *__pyx_v_result;
  void *__pyx_r;
  int __pyx_1;
  PyObject *__pyx_2 = 0;
  PyObject *__pyx_3 = 0;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":69 */
  __pyx_v_result = realloc(__pyx_v_old,__pyx_v_count);

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":70 */
  __pyx_1 = (__pyx_v_result == NULL);
  if (__pyx_1) {
    __pyx_2 = PyLong_FromUnsignedLong(__pyx_v_count); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 72; goto __pyx_L1;}
    __pyx_3 = PyTuple_New(1); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 72; goto __pyx_L1;}
    PyTuple_SET_ITEM(__pyx_3, 0, __pyx_2);
    __pyx_2 = 0;
    __pyx_2 = PyNumber_Remainder(__pyx_k2p, __pyx_3); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 72; goto __pyx_L1;}
    Py_DECREF(__pyx_3); __pyx_3 = 0;
    __pyx_3 = PyTuple_New(1); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 71; goto __pyx_L1;}
    PyTuple_SET_ITEM(__pyx_3, 0, __pyx_2);
    __pyx_2 = 0;
    __pyx_2 = PyObject_CallObject(PyExc_MemoryError, __pyx_3); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 71; goto __pyx_L1;}
    Py_DECREF(__pyx_3); __pyx_3 = 0;
    __Pyx_Raise(__pyx_2, 0, 0);
    Py_DECREF(__pyx_2); __pyx_2 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 71; goto __pyx_L1;}
    goto __pyx_L2;
  }
  __pyx_L2:;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":73 */
  __pyx_r = __pyx_v_result;
  goto __pyx_L0;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_2);
  Py_XDECREF(__pyx_3);
  __Pyx_AddTraceback("bzrlib._groupcompress_pyx.safe_realloc");
  __pyx_r = NULL;
  __pyx_L0:;
  return __pyx_r;
}

static int __pyx_f_6bzrlib_18_groupcompress_pyx_safe_free(void **__pyx_v_val) {
  int __pyx_r;
  int __pyx_1;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":77 */
  #ifndef PYREX_WITHOUT_ASSERTIONS
  if (!(__pyx_v_val != NULL)) {
    PyErr_SetNone(PyExc_AssertionError);
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 77; goto __pyx_L1;}
  }
  #endif

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":78 */
  __pyx_1 = ((__pyx_v_val[0]) != NULL);
  if (__pyx_1) {

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":79 */
    free((__pyx_v_val[0]));

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":80 */
    (__pyx_v_val[0]) = NULL;
    goto __pyx_L2;
  }
  __pyx_L2:;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1:;
  __Pyx_AddTraceback("bzrlib._groupcompress_pyx.safe_free");
  __pyx_r = (-1);
  __pyx_L0:;
  return __pyx_r;
}

static PyObject *__pyx_f_6bzrlib_18_groupcompress_pyx_make_delta_index(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_f_6bzrlib_18_groupcompress_pyx_make_delta_index(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_source = 0;
  PyObject *__pyx_r;
  PyObject *__pyx_1 = 0;
  PyObject *__pyx_2 = 0;
  static char *__pyx_argnames[] = {"source",0};
  if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "O", __pyx_argnames, &__pyx_v_source)) return 0;
  Py_INCREF(__pyx_v_source);
  __pyx_1 = PyTuple_New(1); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 83; goto __pyx_L1;}
  Py_INCREF(__pyx_v_source);
  PyTuple_SET_ITEM(__pyx_1, 0, __pyx_v_source);
  __pyx_2 = PyObject_CallObject(((PyObject *)__pyx_ptype_6bzrlib_18_groupcompress_pyx_DeltaIndex), __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 83; goto __pyx_L1;}
  Py_DECREF(__pyx_1); __pyx_1 = 0;
  __pyx_r = __pyx_2;
  __pyx_2 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; Py_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_1);
  Py_XDECREF(__pyx_2);
  __Pyx_AddTraceback("bzrlib._groupcompress_pyx.make_delta_index");
  __pyx_r = 0;
  __pyx_L0:;
  Py_DECREF(__pyx_v_source);
  return __pyx_r;
}

static int __pyx_f_6bzrlib_18_groupcompress_pyx_10DeltaIndex___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_f_6bzrlib_18_groupcompress_pyx_10DeltaIndex___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_source = 0;
  int __pyx_r;
  PyObject *__pyx_1 = 0;
  void *__pyx_2;
  int __pyx_3;
  PyObject *__pyx_4 = 0;
  PyObject *__pyx_5 = 0;
  static char *__pyx_argnames[] = {"source",0};
  __pyx_v_source = __pyx_d1;
  if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "|O", __pyx_argnames, &__pyx_v_source)) return -1;
  Py_INCREF(__pyx_v_self);
  Py_INCREF(__pyx_v_source);

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":98 */
  __pyx_1 = PyList_New(0); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 98; goto __pyx_L1;}
  Py_DECREF(((struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *)__pyx_v_self)->_sources);
  ((struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *)__pyx_v_self)->_sources = __pyx_1;
  __pyx_1 = 0;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":99 */
  ((struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *)__pyx_v_self)->_index = NULL;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":100 */
  ((struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *)__pyx_v_self)->_max_num_sources = 65000;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":101 */
  __pyx_2 = __pyx_f_6bzrlib_18_groupcompress_pyx_safe_malloc(((sizeof(struct source_info)) * ((struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *)__pyx_v_self)->_max_num_sources)); if (__pyx_2 == NULL) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 101; goto __pyx_L1;}
  ((struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *)__pyx_v_self)->_source_infos = ((struct source_info *)__pyx_2);

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":103 */
  ((struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *)__pyx_v_self)->_source_offset = 0;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":105 */
  __pyx_3 = __pyx_v_source != Py_None;
  if (__pyx_3) {
    __pyx_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_add_source); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 106; goto __pyx_L1;}
    __pyx_4 = PyInt_FromLong(0); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 106; goto __pyx_L1;}
    __pyx_5 = PyTuple_New(2); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 106; goto __pyx_L1;}
    Py_INCREF(__pyx_v_source);
    PyTuple_SET_ITEM(__pyx_5, 0, __pyx_v_source);
    PyTuple_SET_ITEM(__pyx_5, 1, __pyx_4);
    __pyx_4 = 0;
    __pyx_4 = PyObject_CallObject(__pyx_1, __pyx_5); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 106; goto __pyx_L1;}
    Py_DECREF(__pyx_1); __pyx_1 = 0;
    Py_DECREF(__pyx_5); __pyx_5 = 0;
    Py_DECREF(__pyx_4); __pyx_4 = 0;
    goto __pyx_L2;
  }
  __pyx_L2:;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_1);
  Py_XDECREF(__pyx_4);
  Py_XDECREF(__pyx_5);
  __Pyx_AddTraceback("bzrlib._groupcompress_pyx.DeltaIndex.__init__");
  __pyx_r = -1;
  __pyx_L0:;
  Py_DECREF(__pyx_v_self);
  Py_DECREF(__pyx_v_source);
  return __pyx_r;
}

static PyObject *__pyx_f_6bzrlib_18_groupcompress_pyx_10DeltaIndex___repr__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_f_6bzrlib_18_groupcompress_pyx_10DeltaIndex___repr__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r;
  PyObject *__pyx_1 = 0;
  PyObject *__pyx_2 = 0;
  Py_ssize_t __pyx_3;
  PyObject *__pyx_4 = 0;
  PyObject *__pyx_5 = 0;
  Py_INCREF(__pyx_v_self);
  __pyx_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n___class__); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 109; goto __pyx_L1;}
  __pyx_2 = PyObject_GetAttr(__pyx_1, __pyx_n___name__); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 109; goto __pyx_L1;}
  Py_DECREF(__pyx_1); __pyx_1 = 0;
  __pyx_3 = PyObject_Length(((struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *)__pyx_v_self)->_sources); if (__pyx_3 == -1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 110; goto __pyx_L1;}
  __pyx_1 = PyInt_FromSsize_t(__pyx_3); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 110; goto __pyx_L1;}
  __pyx_4 = PyLong_FromUnsignedLong(((struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *)__pyx_v_self)->_source_offset); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 110; goto __pyx_L1;}
  __pyx_5 = PyTuple_New(3); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 109; goto __pyx_L1;}
  PyTuple_SET_ITEM(__pyx_5, 0, __pyx_2);
  PyTuple_SET_ITEM(__pyx_5, 1, __pyx_1);
  PyTuple_SET_ITEM(__pyx_5, 2, __pyx_4);
  __pyx_2 = 0;
  __pyx_1 = 0;
  __pyx_4 = 0;
  __pyx_2 = PyNumber_Remainder(__pyx_k4p, __pyx_5); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 109; goto __pyx_L1;}
  Py_DECREF(__pyx_5); __pyx_5 = 0;
  __pyx_r = __pyx_2;
  __pyx_2 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; Py_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_1);
  Py_XDECREF(__pyx_2);
  Py_XDECREF(__pyx_4);
  Py_XDECREF(__pyx_5);
  __Pyx_AddTraceback("bzrlib._groupcompress_pyx.DeltaIndex.__repr__");
  __pyx_r = 0;
  __pyx_L0:;
  Py_DECREF(__pyx_v_self);
  return __pyx_r;
}

static void __pyx_f_6bzrlib_18_groupcompress_pyx_10DeltaIndex___dealloc__(PyObject *__pyx_v_self); /*proto*/
static void __pyx_f_6bzrlib_18_groupcompress_pyx_10DeltaIndex___dealloc__(PyObject *__pyx_v_self) {
  int __pyx_1;
  Py_INCREF(__pyx_v_self);

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":113 */
  __pyx_1 = (((struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *)__pyx_v_self)->_index != NULL);
  if (__pyx_1) {

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":114 */
    free_delta_index(((struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *)__pyx_v_self)->_index);

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":115 */
    ((struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *)__pyx_v_self)->_index = NULL;
    goto __pyx_L2;
  }
  __pyx_L2:;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":116 */
  __pyx_1 = __pyx_f_6bzrlib_18_groupcompress_pyx_safe_free(((void **)(&((struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *)__pyx_v_self)->_source_infos))); if (__pyx_1 == (-1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 116; goto __pyx_L1;}

  goto __pyx_L0;
  __pyx_L1:;
  __Pyx_AddTraceback("bzrlib._groupcompress_pyx.DeltaIndex.__dealloc__");
  __pyx_L0:;
  Py_DECREF(__pyx_v_self);
}

static PyObject *__pyx_f_6bzrlib_18_groupcompress_pyx_10DeltaIndex__has_index(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_f_6bzrlib_18_groupcompress_pyx_10DeltaIndex__has_index(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_r;
  PyObject *__pyx_1 = 0;
  static char *__pyx_argnames[] = {0};
  if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "", __pyx_argnames)) return 0;
  Py_INCREF(__pyx_v_self);
  __pyx_1 = PyInt_FromLong((((struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *)__pyx_v_self)->_index != NULL)); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 119; goto __pyx_L1;}
  __pyx_r = __pyx_1;
  __pyx_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; Py_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_1);
  __Pyx_AddTraceback("bzrlib._groupcompress_pyx.DeltaIndex._has_index");
  __pyx_r = 0;
  __pyx_L0:;
  Py_DECREF(__pyx_v_self);
  return __pyx_r;
}

static PyObject *__pyx_f_6bzrlib_18_groupcompress_pyx_10DeltaIndex_add_delta_source(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_6bzrlib_18_groupcompress_pyx_10DeltaIndex_add_delta_source[] = "Add a new delta to the source texts.\n\n        :param delta: The text of the delta, this must be a byte string.\n        :param unadded_bytes: Number of bytes that were added to the source\n            that were not indexed.\n        ";
static PyObject *__pyx_f_6bzrlib_18_groupcompress_pyx_10DeltaIndex_add_delta_source(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_delta = 0;
  PyObject *__pyx_v_unadded_bytes = 0;
  char *__pyx_v_c_delta;
  Py_ssize_t __pyx_v_c_delta_size;
  struct delta_index *__pyx_v_index;
  unsigned int __pyx_v_source_location;
  struct source_info *__pyx_v_src;
  PyObject *__pyx_r;
  int __pyx_1;
  PyObject *__pyx_2 = 0;
  PyObject *__pyx_3 = 0;
  Py_ssize_t __pyx_4;
  PyObject *__pyx_5 = 0;
  unsigned long __pyx_6;
  static char *__pyx_argnames[] = {"delta","unadded_bytes",0};
  if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "OO", __pyx_argnames, &__pyx_v_delta, &__pyx_v_unadded_bytes)) return 0;
  Py_INCREF(__pyx_v_self);
  Py_INCREF(__pyx_v_delta);
  Py_INCREF(__pyx_v_unadded_bytes);

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":135 */
  __pyx_1 = (!PyString_CheckExact(__pyx_v_delta));
  if (__pyx_1) {
    __pyx_2 = PyTuple_New(1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 136; goto __pyx_L1;}
    Py_INCREF(__pyx_k7p);
    PyTuple_SET_ITEM(__pyx_2, 0, __pyx_k7p);
    __pyx_3 = PyObject_CallObject(PyExc_TypeError, __pyx_2); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 136; goto __pyx_L1;}
    Py_DECREF(__pyx_2); __pyx_2 = 0;
    __Pyx_Raise(__pyx_3, 0, 0);
    Py_DECREF(__pyx_3); __pyx_3 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 136; goto __pyx_L1;}
    goto __pyx_L2;
  }
  __pyx_L2:;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":138 */
  __pyx_4 = PyObject_Length(((struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *)__pyx_v_self)->_sources); if (__pyx_4 == -1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 138; goto __pyx_L1;}
  __pyx_v_source_location = __pyx_4;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":139 */
  __pyx_1 = (__pyx_v_source_location >= ((struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *)__pyx_v_self)->_max_num_sources);
  if (__pyx_1) {
    __pyx_2 = ((struct __pyx_vtabstruct_6bzrlib_18_groupcompress_pyx_DeltaIndex *)((struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *)__pyx_v_self)->__pyx_vtab)->_expand_sources(((struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *)__pyx_v_self)); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 140; goto __pyx_L1;}
    Py_DECREF(__pyx_2); __pyx_2 = 0;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":141 */
  __pyx_3 = PyObject_GetAttr(((struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *)__pyx_v_self)->_sources, __pyx_n_append); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 141; goto __pyx_L1;}
  __pyx_2 = PyTuple_New(1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 141; goto __pyx_L1;}
  Py_INCREF(__pyx_v_delta);
  PyTuple_SET_ITEM(__pyx_2, 0, __pyx_v_delta);
  __pyx_5 = PyObject_CallObject(__pyx_3, __pyx_2); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 141; goto __pyx_L1;}
  Py_DECREF(__pyx_3); __pyx_3 = 0;
  Py_DECREF(__pyx_2); __pyx_2 = 0;
  Py_DECREF(__pyx_5); __pyx_5 = 0;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":142 */
  __pyx_v_c_delta = PyString_AS_STRING(__pyx_v_delta);

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":143 */
  __pyx_v_c_delta_size = PyString_GET_SIZE(__pyx_v_delta);

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":144 */
  __pyx_v_src = (((struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *)__pyx_v_self)->_source_infos + __pyx_v_source_location);

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":145 */
  __pyx_v_src->buf = __pyx_v_c_delta;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":146 */
  __pyx_v_src->size = __pyx_v_c_delta_size;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":147 */
  __pyx_3 = PyLong_FromUnsignedLong(((struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *)__pyx_v_self)->_source_offset); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 147; goto __pyx_L1;}
  __pyx_2 = PyNumber_Add(__pyx_3, __pyx_v_unadded_bytes); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 147; goto __pyx_L1;}
  Py_DECREF(__pyx_3); __pyx_3 = 0;
  __pyx_6 = PyInt_AsUnsignedLongMask(__pyx_2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 147; goto __pyx_L1;}
  Py_DECREF(__pyx_2); __pyx_2 = 0;
  __pyx_v_src->agg_offset = __pyx_6;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":148 */
  /*with nogil:*/ {
    PyThreadState *_save;
    Py_UNBLOCK_THREADS
    /*try:*/ {
      __pyx_v_index = create_delta_index_from_delta(__pyx_v_src,((struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *)__pyx_v_self)->_index);
    }
    /*finally:*/ {
      Py_BLOCK_THREADS
    }
  }

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":150 */
  ((struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *)__pyx_v_self)->_source_offset = (__pyx_v_src->agg_offset + __pyx_v_src->size);

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":151 */
  __pyx_1 = (__pyx_v_index != NULL);
  if (__pyx_1) {

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":152 */
    free_delta_index(((struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *)__pyx_v_self)->_index);

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":153 */
    ((struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *)__pyx_v_self)->_index = __pyx_v_index;
    goto __pyx_L7;
  }
  __pyx_L7:;

  __pyx_r = Py_None; Py_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_2);
  Py_XDECREF(__pyx_3);
  Py_XDECREF(__pyx_5);
  __Pyx_AddTraceback("bzrlib._groupcompress_pyx.DeltaIndex.add_delta_source");
  __pyx_r = 0;
  __pyx_L0:;
  Py_DECREF(__pyx_v_self);
  Py_DECREF(__pyx_v_delta);
  Py_DECREF(__pyx_v_unadded_bytes);
  return __pyx_r;
}

static PyObject *__pyx_f_6bzrlib_18_groupcompress_pyx_10DeltaIndex_add_source(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_6bzrlib_18_groupcompress_pyx_10DeltaIndex_add_source[] = "Add a new bit of source text to the delta indexes.\n\n        :param source: The text in question, this must be a byte string\n        :param unadded_bytes: Assume there are this many bytes that didn\'t get\n            added between this source and the end of the previous source.\n        ";
static PyObject *__pyx_f_6bzrlib_18_groupcompress_pyx_10DeltaIndex_add_source(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_source = 0;
  PyObject *__pyx_v_unadded_bytes = 0;
  char *__pyx_v_c_source;
  Py_ssize_t __pyx_v_c_source_size;
  struct delta_index *__pyx_v_index;
  unsigned int __pyx_v_source_location;
  struct source_info *__pyx_v_src;
  PyObject *__pyx_r;
  int __pyx_1;
  PyObject *__pyx_2 = 0;
  PyObject *__pyx_3 = 0;
  Py_ssize_t __pyx_4;
  PyObject *__pyx_5 = 0;
  unsigned long __pyx_6;
  static char *__pyx_argnames[] = {"source","unadded_bytes",0};
  if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "OO", __pyx_argnames, &__pyx_v_source, &__pyx_v_unadded_bytes)) return 0;
  Py_INCREF(__pyx_v_self);
  Py_INCREF(__pyx_v_source);
  Py_INCREF(__pyx_v_unadded_bytes);

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":169 */
  __pyx_1 = (!PyString_CheckExact(__pyx_v_source));
  if (__pyx_1) {
    __pyx_2 = PyTuple_New(1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 170; goto __pyx_L1;}
    Py_INCREF(__pyx_k9p);
    PyTuple_SET_ITEM(__pyx_2, 0, __pyx_k9p);
    __pyx_3 = PyObject_CallObject(PyExc_TypeError, __pyx_2); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 170; goto __pyx_L1;}
    Py_DECREF(__pyx_2); __pyx_2 = 0;
    __Pyx_Raise(__pyx_3, 0, 0);
    Py_DECREF(__pyx_3); __pyx_3 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 170; goto __pyx_L1;}
    goto __pyx_L2;
  }
  __pyx_L2:;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":172 */
  __pyx_4 = PyObject_Length(((struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *)__pyx_v_self)->_sources); if (__pyx_4 == -1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 172; goto __pyx_L1;}
  __pyx_v_source_location = __pyx_4;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":173 */
  __pyx_1 = (__pyx_v_source_location >= ((struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *)__pyx_v_self)->_max_num_sources);
  if (__pyx_1) {
    __pyx_2 = ((struct __pyx_vtabstruct_6bzrlib_18_groupcompress_pyx_DeltaIndex *)((struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *)__pyx_v_self)->__pyx_vtab)->_expand_sources(((struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *)__pyx_v_self)); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 174; goto __pyx_L1;}
    Py_DECREF(__pyx_2); __pyx_2 = 0;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":175 */
  __pyx_1 = (__pyx_v_source_location != 0);
  if (__pyx_1) {
    __pyx_1 = (((struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *)__pyx_v_self)->_index == NULL);
  }
  if (__pyx_1) {
    __pyx_3 = ((struct __pyx_vtabstruct_6bzrlib_18_groupcompress_pyx_DeltaIndex *)((struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *)__pyx_v_self)->__pyx_vtab)->_populate_first_index(((struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *)__pyx_v_self)); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 177; goto __pyx_L1;}
    Py_DECREF(__pyx_3); __pyx_3 = 0;
    goto __pyx_L4;
  }
  __pyx_L4:;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":178 */
  __pyx_2 = PyObject_GetAttr(((struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *)__pyx_v_self)->_sources, __pyx_n_append); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 178; goto __pyx_L1;}
  __pyx_3 = PyTuple_New(1); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 178; goto __pyx_L1;}
  Py_INCREF(__pyx_v_source);
  PyTuple_SET_ITEM(__pyx_3, 0, __pyx_v_source);
  __pyx_5 = PyObject_CallObject(__pyx_2, __pyx_3); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 178; goto __pyx_L1;}
  Py_DECREF(__pyx_2); __pyx_2 = 0;
  Py_DECREF(__pyx_3); __pyx_3 = 0;
  Py_DECREF(__pyx_5); __pyx_5 = 0;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":179 */
  __pyx_v_c_source = PyString_AS_STRING(__pyx_v_source);

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":180 */
  __pyx_v_c_source_size = PyString_GET_SIZE(__pyx_v_source);

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":181 */
  __pyx_v_src = (((struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *)__pyx_v_self)->_source_infos + __pyx_v_source_location);

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":182 */
  __pyx_v_src->buf = __pyx_v_c_source;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":183 */
  __pyx_v_src->size = __pyx_v_c_source_size;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":185 */
  __pyx_2 = PyLong_FromUnsignedLong(((struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *)__pyx_v_self)->_source_offset); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 185; goto __pyx_L1;}
  __pyx_3 = PyNumber_Add(__pyx_2, __pyx_v_unadded_bytes); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 185; goto __pyx_L1;}
  Py_DECREF(__pyx_2); __pyx_2 = 0;
  __pyx_6 = PyInt_AsUnsignedLongMask(__pyx_3); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 185; goto __pyx_L1;}
  Py_DECREF(__pyx_3); __pyx_3 = 0;
  __pyx_v_src->agg_offset = __pyx_6;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":186 */
  ((struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *)__pyx_v_self)->_source_offset = (__pyx_v_src->agg_offset + __pyx_v_src->size);

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":188 */
  __pyx_1 = (__pyx_v_source_location != 0);
  if (__pyx_1) {

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":189 */
    /*with nogil:*/ {
      PyThreadState *_save;
      Py_UNBLOCK_THREADS
      /*try:*/ {
        __pyx_v_index = create_delta_index(__pyx_v_src,((struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *)__pyx_v_self)->_index);
      }
      /*finally:*/ {
        Py_BLOCK_THREADS
      }
    }

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":191 */
    __pyx_1 = (__pyx_v_index != NULL);
    if (__pyx_1) {

      /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":192 */
      free_delta_index(((struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *)__pyx_v_self)->_index);

      /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":193 */
      ((struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *)__pyx_v_self)->_index = __pyx_v_index;
      goto __pyx_L9;
    }
    __pyx_L9:;
    goto __pyx_L5;
  }
  __pyx_L5:;

  __pyx_r = Py_None; Py_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_2);
  Py_XDECREF(__pyx_3);
  Py_XDECREF(__pyx_5);
  __Pyx_AddTraceback("bzrlib._groupcompress_pyx.DeltaIndex.add_source");
  __pyx_r = 0;
  __pyx_L0:;
  Py_DECREF(__pyx_v_self);
  Py_DECREF(__pyx_v_source);
  Py_DECREF(__pyx_v_unadded_bytes);
  return __pyx_r;
}

static PyObject *__pyx_f_6bzrlib_18_groupcompress_pyx_10DeltaIndex__populate_first_index(struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *__pyx_v_self) {
  PyObject *__pyx_r;
  int __pyx_1;
  Py_ssize_t __pyx_2;
  PyObject *__pyx_3 = 0;
  PyObject *__pyx_4 = 0;
  Py_INCREF(__pyx_v_self);

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":197 */
  __pyx_2 = PyObject_Length(__pyx_v_self->_sources); if (__pyx_2 == -1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 197; goto __pyx_L1;}
  __pyx_1 = (__pyx_2 != 1);
  if (!__pyx_1) {
    __pyx_1 = (__pyx_v_self->_index != NULL);
  }
  if (__pyx_1) {
    __pyx_3 = PyTuple_New(1); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 198; goto __pyx_L1;}
    Py_INCREF(__pyx_k10p);
    PyTuple_SET_ITEM(__pyx_3, 0, __pyx_k10p);
    __pyx_4 = PyObject_CallObject(PyExc_AssertionError, __pyx_3); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 198; goto __pyx_L1;}
    Py_DECREF(__pyx_3); __pyx_3 = 0;
    __Pyx_Raise(__pyx_4, 0, 0);
    Py_DECREF(__pyx_4); __pyx_4 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 198; goto __pyx_L1;}
    goto __pyx_L2;
  }
  __pyx_L2:;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":203 */
  /*with nogil:*/ {
    PyThreadState *_save;
    Py_UNBLOCK_THREADS
    /*try:*/ {
      __pyx_v_self->_index = create_delta_index((&(__pyx_v_self->_source_infos[0])),NULL);
    }
    /*finally:*/ {
      Py_BLOCK_THREADS
    }
  }

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":205 */
  #ifndef PYREX_WITHOUT_ASSERTIONS
  if (!(__pyx_v_self->_index != NULL)) {
    PyErr_SetNone(PyExc_AssertionError);
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 205; goto __pyx_L1;}
  }
  #endif

  __pyx_r = Py_None; Py_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_3);
  Py_XDECREF(__pyx_4);
  __Pyx_AddTraceback("bzrlib._groupcompress_pyx.DeltaIndex._populate_first_index");
  __pyx_r = 0;
  __pyx_L0:;
  Py_DECREF(__pyx_v_self);
  return __pyx_r;
}

static PyObject *__pyx_f_6bzrlib_18_groupcompress_pyx_10DeltaIndex__expand_sources(struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *__pyx_v_self) {
  PyObject *__pyx_r;
  PyObject *__pyx_1 = 0;
  PyObject *__pyx_2 = 0;
  void *__pyx_3;
  Py_INCREF(__pyx_v_self);

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":208 */
  __pyx_1 = PyTuple_New(1); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 208; goto __pyx_L1;}
  Py_INCREF(__pyx_k11p);
  PyTuple_SET_ITEM(__pyx_1, 0, __pyx_k11p);
  __pyx_2 = PyObject_CallObject(PyExc_RuntimeError, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 208; goto __pyx_L1;}
  Py_DECREF(__pyx_1); __pyx_1 = 0;
  __Pyx_Raise(__pyx_2, 0, 0);
  Py_DECREF(__pyx_2); __pyx_2 = 0;
  {__pyx_filename = __pyx_f[0]; __pyx_lineno = 208; goto __pyx_L1;}

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":210 */
  __pyx_v_self->_max_num_sources = (__pyx_v_self->_max_num_sources * 2);

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":211 */
  __pyx_3 = __pyx_f_6bzrlib_18_groupcompress_pyx_safe_realloc(__pyx_v_self->_source_infos,((sizeof(struct source_info)) * __pyx_v_self->_max_num_sources)); if (__pyx_3 == NULL) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 211; goto __pyx_L1;}
  __pyx_v_self->_source_infos = ((struct source_info *)__pyx_3);

  __pyx_r = Py_None; Py_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_1);
  Py_XDECREF(__pyx_2);
  __Pyx_AddTraceback("bzrlib._groupcompress_pyx.DeltaIndex._expand_sources");
  __pyx_r = 0;
  __pyx_L0:;
  Py_DECREF(__pyx_v_self);
  return __pyx_r;
}

static PyObject *__pyx_f_6bzrlib_18_groupcompress_pyx_10DeltaIndex_make_delta(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_6bzrlib_18_groupcompress_pyx_10DeltaIndex_make_delta[] = "Create a delta from the current source to the target bytes.";
static PyObject *__pyx_f_6bzrlib_18_groupcompress_pyx_10DeltaIndex_make_delta(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_target_bytes = 0;
  PyObject *__pyx_v_max_delta_size = 0;
  char *__pyx_v_target;
  Py_ssize_t __pyx_v_target_size;
  void *__pyx_v_delta;
  unsigned long __pyx_v_delta_size;
  unsigned long __pyx_v_c_max_delta_size;
  PyObject *__pyx_v_result;
  PyObject *__pyx_r;
  int __pyx_1;
  Py_ssize_t __pyx_2;
  PyObject *__pyx_3 = 0;
  PyObject *__pyx_4 = 0;
  unsigned long __pyx_5;
  static char *__pyx_argnames[] = {"target_bytes","max_delta_size",0};
  __pyx_v_max_delta_size = __pyx_d2;
  if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "O|O", __pyx_argnames, &__pyx_v_target_bytes, &__pyx_v_max_delta_size)) return 0;
  Py_INCREF(__pyx_v_self);
  Py_INCREF(__pyx_v_target_bytes);
  Py_INCREF(__pyx_v_max_delta_size);
  __pyx_v_result = Py_None; Py_INCREF(Py_None);

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":223 */
  __pyx_1 = (((struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *)__pyx_v_self)->_index == NULL);
  if (__pyx_1) {

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":224 */
    __pyx_2 = PyObject_Length(((struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *)__pyx_v_self)->_sources); if (__pyx_2 == -1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 224; goto __pyx_L1;}
    __pyx_1 = (__pyx_2 == 0);
    if (__pyx_1) {
      Py_INCREF(Py_None);
      __pyx_r = Py_None;
      goto __pyx_L0;
      goto __pyx_L3;
    }
    __pyx_L3:;

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":227 */
    __pyx_3 = ((struct __pyx_vtabstruct_6bzrlib_18_groupcompress_pyx_DeltaIndex *)((struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *)__pyx_v_self)->__pyx_vtab)->_populate_first_index(((struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *)__pyx_v_self)); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 227; goto __pyx_L1;}
    Py_DECREF(__pyx_3); __pyx_3 = 0;
    goto __pyx_L2;
  }
  __pyx_L2:;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":229 */
  __pyx_1 = (!PyString_CheckExact(__pyx_v_target_bytes));
  if (__pyx_1) {
    __pyx_3 = PyTuple_New(1); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 230; goto __pyx_L1;}
    Py_INCREF(__pyx_k12p);
    PyTuple_SET_ITEM(__pyx_3, 0, __pyx_k12p);
    __pyx_4 = PyObject_CallObject(PyExc_TypeError, __pyx_3); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 230; goto __pyx_L1;}
    Py_DECREF(__pyx_3); __pyx_3 = 0;
    __Pyx_Raise(__pyx_4, 0, 0);
    Py_DECREF(__pyx_4); __pyx_4 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 230; goto __pyx_L1;}
    goto __pyx_L4;
  }
  __pyx_L4:;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":232 */
  __pyx_v_target = PyString_AS_STRING(__pyx_v_target_bytes);

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":233 */
  __pyx_v_target_size = PyString_GET_SIZE(__pyx_v_target_bytes);

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":238 */
  __pyx_5 = PyInt_AsUnsignedLongMask(__pyx_v_max_delta_size); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 238; goto __pyx_L1;}
  __pyx_v_c_max_delta_size = __pyx_5;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":239 */
  /*with nogil:*/ {
    PyThreadState *_save;
    Py_UNBLOCK_THREADS
    /*try:*/ {
      __pyx_v_delta = create_delta(((struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *)__pyx_v_self)->_index,__pyx_v_target,__pyx_v_target_size,(&__pyx_v_delta_size),__pyx_v_c_max_delta_size);
    }
    /*finally:*/ {
      Py_BLOCK_THREADS
    }
  }

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":243 */
  Py_INCREF(Py_None);
  Py_DECREF(__pyx_v_result);
  __pyx_v_result = Py_None;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":244 */
  __pyx_1 = (__pyx_v_delta != 0);
  if (__pyx_1) {

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":245 */
    __pyx_3 = PyString_FromStringAndSize(((char *)__pyx_v_delta),__pyx_v_delta_size); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 245; goto __pyx_L1;}
    Py_DECREF(__pyx_v_result);
    __pyx_v_result = __pyx_3;
    __pyx_3 = 0;

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":246 */
    free(__pyx_v_delta);
    goto __pyx_L8;
  }
  __pyx_L8:;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":247 */
  Py_INCREF(__pyx_v_result);
  __pyx_r = __pyx_v_result;
  goto __pyx_L0;

  __pyx_r = Py_None; Py_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_3);
  Py_XDECREF(__pyx_4);
  __Pyx_AddTraceback("bzrlib._groupcompress_pyx.DeltaIndex.make_delta");
  __pyx_r = 0;
  __pyx_L0:;
  Py_DECREF(__pyx_v_result);
  Py_DECREF(__pyx_v_self);
  Py_DECREF(__pyx_v_target_bytes);
  Py_DECREF(__pyx_v_max_delta_size);
  return __pyx_r;
}

static PyObject *__pyx_f_6bzrlib_18_groupcompress_pyx_make_delta(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_6bzrlib_18_groupcompress_pyx_make_delta[] = "Create a delta, this is a wrapper around DeltaIndex.make_delta.";
static PyObject *__pyx_f_6bzrlib_18_groupcompress_pyx_make_delta(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_source_bytes = 0;
  PyObject *__pyx_v_target_bytes = 0;
  PyObject *__pyx_v_di;
  PyObject *__pyx_r;
  PyObject *__pyx_1 = 0;
  PyObject *__pyx_2 = 0;
  PyObject *__pyx_3 = 0;
  static char *__pyx_argnames[] = {"source_bytes","target_bytes",0};
  if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "OO", __pyx_argnames, &__pyx_v_source_bytes, &__pyx_v_target_bytes)) return 0;
  Py_INCREF(__pyx_v_source_bytes);
  Py_INCREF(__pyx_v_target_bytes);
  __pyx_v_di = Py_None; Py_INCREF(Py_None);

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":252 */
  __pyx_1 = PyTuple_New(1); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 252; goto __pyx_L1;}
  Py_INCREF(__pyx_v_source_bytes);
  PyTuple_SET_ITEM(__pyx_1, 0, __pyx_v_source_bytes);
  __pyx_2 = PyObject_CallObject(((PyObject *)__pyx_ptype_6bzrlib_18_groupcompress_pyx_DeltaIndex), __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 252; goto __pyx_L1;}
  Py_DECREF(__pyx_1); __pyx_1 = 0;
  Py_DECREF(__pyx_v_di);
  __pyx_v_di = __pyx_2;
  __pyx_2 = 0;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":253 */
  __pyx_1 = PyObject_GetAttr(__pyx_v_di, __pyx_n_make_delta); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 253; goto __pyx_L1;}
  __pyx_2 = PyTuple_New(1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 253; goto __pyx_L1;}
  Py_INCREF(__pyx_v_target_bytes);
  PyTuple_SET_ITEM(__pyx_2, 0, __pyx_v_target_bytes);
  __pyx_3 = PyObject_CallObject(__pyx_1, __pyx_2); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 253; goto __pyx_L1;}
  Py_DECREF(__pyx_1); __pyx_1 = 0;
  Py_DECREF(__pyx_2); __pyx_2 = 0;
  __pyx_r = __pyx_3;
  __pyx_3 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; Py_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_1);
  Py_XDECREF(__pyx_2);
  Py_XDECREF(__pyx_3);
  __Pyx_AddTraceback("bzrlib._groupcompress_pyx.make_delta");
  __pyx_r = 0;
  __pyx_L0:;
  Py_DECREF(__pyx_v_di);
  Py_DECREF(__pyx_v_source_bytes);
  Py_DECREF(__pyx_v_target_bytes);
  return __pyx_r;
}

static PyObject *__pyx_f_6bzrlib_18_groupcompress_pyx_apply_delta(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_6bzrlib_18_groupcompress_pyx_apply_delta[] = "Apply a delta generated by make_delta to source_bytes.";
static PyObject *__pyx_f_6bzrlib_18_groupcompress_pyx_apply_delta(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_source_bytes = 0;
  PyObject *__pyx_v_delta_bytes = 0;
  char *__pyx_v_source;
  Py_ssize_t __pyx_v_source_size;
  char *__pyx_v_delta;
  Py_ssize_t __pyx_v_delta_size;
  PyObject *__pyx_r;
  int __pyx_1;
  PyObject *__pyx_2 = 0;
  PyObject *__pyx_3 = 0;
  PyObject *__pyx_4 = 0;
  static char *__pyx_argnames[] = {"source_bytes","delta_bytes",0};
  if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "OO", __pyx_argnames, &__pyx_v_source_bytes, &__pyx_v_delta_bytes)) return 0;
  Py_INCREF(__pyx_v_source_bytes);
  Py_INCREF(__pyx_v_delta_bytes);

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":263 */
  __pyx_1 = (!PyString_CheckExact(__pyx_v_source_bytes));
  if (__pyx_1) {
    __pyx_2 = PyTuple_New(1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 264; goto __pyx_L1;}
    Py_INCREF(__pyx_k9p);
    PyTuple_SET_ITEM(__pyx_2, 0, __pyx_k9p);
    __pyx_3 = PyObject_CallObject(PyExc_TypeError, __pyx_2); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 264; goto __pyx_L1;}
    Py_DECREF(__pyx_2); __pyx_2 = 0;
    __Pyx_Raise(__pyx_3, 0, 0);
    Py_DECREF(__pyx_3); __pyx_3 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 264; goto __pyx_L1;}
    goto __pyx_L2;
  }
  __pyx_L2:;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":265 */
  __pyx_1 = (!PyString_CheckExact(__pyx_v_delta_bytes));
  if (__pyx_1) {
    __pyx_2 = PyTuple_New(1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 266; goto __pyx_L1;}
    Py_INCREF(__pyx_k7p);
    PyTuple_SET_ITEM(__pyx_2, 0, __pyx_k7p);
    __pyx_3 = PyObject_CallObject(PyExc_TypeError, __pyx_2); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 266; goto __pyx_L1;}
    Py_DECREF(__pyx_2); __pyx_2 = 0;
    __Pyx_Raise(__pyx_3, 0, 0);
    Py_DECREF(__pyx_3); __pyx_3 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 266; goto __pyx_L1;}
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":267 */
  __pyx_v_source = PyString_AS_STRING(__pyx_v_source_bytes);

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":268 */
  __pyx_v_source_size = PyString_GET_SIZE(__pyx_v_source_bytes);

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":269 */
  __pyx_v_delta = PyString_AS_STRING(__pyx_v_delta_bytes);

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":270 */
  __pyx_v_delta_size = PyString_GET_SIZE(__pyx_v_delta_bytes);

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":273 */
  __pyx_1 = (__pyx_v_delta_size < DELTA_SIZE_MIN);
  if (__pyx_1) {
    __pyx_2 = PyInt_FromSsize_t(__pyx_v_delta_size); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 276; goto __pyx_L1;}
    __pyx_3 = PyInt_FromSsize_t(DELTA_SIZE_MIN); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 276; goto __pyx_L1;}
    __pyx_4 = PyTuple_New(2); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 276; goto __pyx_L1;}
    PyTuple_SET_ITEM(__pyx_4, 0, __pyx_2);
    PyTuple_SET_ITEM(__pyx_4, 1, __pyx_3);
    __pyx_2 = 0;
    __pyx_3 = 0;
    __pyx_2 = PyNumber_Remainder(__pyx_k14p, __pyx_4); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 276; goto __pyx_L1;}
    Py_DECREF(__pyx_4); __pyx_4 = 0;
    __pyx_3 = PyTuple_New(1); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 275; goto __pyx_L1;}
    PyTuple_SET_ITEM(__pyx_3, 0, __pyx_2);
    __pyx_2 = 0;
    __pyx_4 = PyObject_CallObject(PyExc_RuntimeError, __pyx_3); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 275; goto __pyx_L1;}
    Py_DECREF(__pyx_3); __pyx_3 = 0;
    __Pyx_Raise(__pyx_4, 0, 0);
    Py_DECREF(__pyx_4); __pyx_4 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 275; goto __pyx_L1;}
    goto __pyx_L4;
  }
  __pyx_L4:;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":278 */
  __pyx_2 = __pyx_f_6bzrlib_18_groupcompress_pyx__apply_delta(__pyx_v_source,__pyx_v_source_size,__pyx_v_delta,__pyx_v_delta_size); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 278; goto __pyx_L1;}
  __pyx_r = __pyx_2;
  __pyx_2 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; Py_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_2);
  Py_XDECREF(__pyx_3);
  Py_XDECREF(__pyx_4);
  __Pyx_AddTraceback("bzrlib._groupcompress_pyx.apply_delta");
  __pyx_r = 0;
  __pyx_L0:;
  Py_DECREF(__pyx_v_source_bytes);
  Py_DECREF(__pyx_v_delta_bytes);
  return __pyx_r;
}

static unsigned char *__pyx_f_6bzrlib_18_groupcompress_pyx__decode_copy_instruction(unsigned char *__pyx_v_bytes,unsigned char __pyx_v_cmd,unsigned int *__pyx_v_offset,unsigned int *__pyx_v_length) {
  unsigned int __pyx_v_off;
  unsigned int __pyx_v_size;
  unsigned int __pyx_v_count;
  unsigned char *__pyx_r;
  long __pyx_1;
  int __pyx_2;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":295 */
  __pyx_v_off = 0;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":296 */
  __pyx_v_size = 0;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":297 */
  __pyx_v_count = 0;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":298 */
  __pyx_1 = (__pyx_v_cmd & 0x01);
  if (__pyx_1) {

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":299 */
    __pyx_v_off = (__pyx_v_bytes[__pyx_v_count]);

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":300 */
    __pyx_v_count = (__pyx_v_count + 1);
    goto __pyx_L2;
  }
  __pyx_L2:;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":301 */
  __pyx_1 = (__pyx_v_cmd & 0x02);
  if (__pyx_1) {

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":302 */
    __pyx_v_off = (__pyx_v_off | ((__pyx_v_bytes[__pyx_v_count]) << 8));

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":303 */
    __pyx_v_count = (__pyx_v_count + 1);
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":304 */
  __pyx_1 = (__pyx_v_cmd & 0x04);
  if (__pyx_1) {

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":305 */
    __pyx_v_off = (__pyx_v_off | ((__pyx_v_bytes[__pyx_v_count]) << 16));

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":306 */
    __pyx_v_count = (__pyx_v_count + 1);
    goto __pyx_L4;
  }
  __pyx_L4:;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":307 */
  __pyx_1 = (__pyx_v_cmd & 0x08);
  if (__pyx_1) {

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":308 */
    __pyx_v_off = (__pyx_v_off | ((__pyx_v_bytes[__pyx_v_count]) << 24));

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":309 */
    __pyx_v_count = (__pyx_v_count + 1);
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":310 */
  __pyx_1 = (__pyx_v_cmd & 0x10);
  if (__pyx_1) {

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":311 */
    __pyx_v_size = (__pyx_v_bytes[__pyx_v_count]);

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":312 */
    __pyx_v_count = (__pyx_v_count + 1);
    goto __pyx_L6;
  }
  __pyx_L6:;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":313 */
  __pyx_1 = (__pyx_v_cmd & 0x20);
  if (__pyx_1) {

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":314 */
    __pyx_v_size = (__pyx_v_size | ((__pyx_v_bytes[__pyx_v_count]) << 8));

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":315 */
    __pyx_v_count = (__pyx_v_count + 1);
    goto __pyx_L7;
  }
  __pyx_L7:;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":316 */
  __pyx_1 = (__pyx_v_cmd & 0x40);
  if (__pyx_1) {

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":317 */
    __pyx_v_size = (__pyx_v_size | ((__pyx_v_bytes[__pyx_v_count]) << 16));

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":318 */
    __pyx_v_count = (__pyx_v_count + 1);
    goto __pyx_L8;
  }
  __pyx_L8:;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":319 */
  __pyx_2 = (__pyx_v_size == 0);
  if (__pyx_2) {
    __pyx_v_size = 0x10000;
    goto __pyx_L9;
  }
  __pyx_L9:;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":321 */
  (__pyx_v_offset[0]) = __pyx_v_off;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":322 */
  (__pyx_v_length[0]) = __pyx_v_size;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":323 */
  __pyx_r = (__pyx_v_bytes + __pyx_v_count);
  goto __pyx_L0;

  __pyx_r = 0;
  __pyx_L0:;
  return __pyx_r;
}

static PyObject *__pyx_f_6bzrlib_18_groupcompress_pyx__apply_delta(char *__pyx_v_source,Py_ssize_t __pyx_v_source_size,char *__pyx_v_delta,Py_ssize_t __pyx_v_delta_size) {
  unsigned char *__pyx_v_data;
  unsigned char *__pyx_v_top;
  unsigned char *__pyx_v_dst_buf;
  unsigned char *__pyx_v_out;
  unsigned char __pyx_v_cmd;
  Py_ssize_t __pyx_v_size;
  unsigned int __pyx_v_cp_off;
  unsigned int __pyx_v_cp_size;
  int __pyx_v_failed;
  PyObject *__pyx_v_result;
  PyObject *__pyx_r;
  PyObject *__pyx_1 = 0;
  int __pyx_2;
  long __pyx_3;
  PyObject *__pyx_4 = 0;
  PyObject *__pyx_5 = 0;
  PyObject *__pyx_6 = 0;
  PyObject *__pyx_7 = 0;
  __pyx_v_result = Py_None; Py_INCREF(Py_None);

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":335 */
  __pyx_v_data = ((unsigned char *)__pyx_v_delta);

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":336 */
  __pyx_v_top = (__pyx_v_data + __pyx_v_delta_size);

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":339 */
  __pyx_v_size = get_delta_hdr_size((&__pyx_v_data),__pyx_v_top);

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":340 */
  __pyx_1 = PyString_FromStringAndSize(NULL,__pyx_v_size); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 340; goto __pyx_L1;}
  Py_DECREF(__pyx_v_result);
  __pyx_v_result = __pyx_1;
  __pyx_1 = 0;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":341 */
  __pyx_v_dst_buf = ((unsigned char *)PyString_AS_STRING(__pyx_v_result));

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":343 */
  __pyx_v_failed = 0;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":344 */
  /*with nogil:*/ {
    PyThreadState *_save;
    Py_UNBLOCK_THREADS
    /*try:*/ {

      /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":345 */
      __pyx_v_out = __pyx_v_dst_buf;

      /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":346 */
      while (1) {
        __pyx_2 = (__pyx_v_data < __pyx_v_top);
        if (!__pyx_2) break;

        /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":347 */
        __pyx_v_cmd = (__pyx_v_data[0]);

        /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":348 */
        __pyx_v_data = (__pyx_v_data + 1);

        /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":349 */
        __pyx_3 = (__pyx_v_cmd & 0x80);
        if (__pyx_3) {

          /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":351 */
          __pyx_v_data = __pyx_f_6bzrlib_18_groupcompress_pyx__decode_copy_instruction(__pyx_v_data,__pyx_v_cmd,(&__pyx_v_cp_off),(&__pyx_v_cp_size));

          /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":352 */
          __pyx_2 = ((__pyx_v_cp_off + __pyx_v_cp_size) < __pyx_v_cp_size);
          if (!__pyx_2) {
            __pyx_2 = ((__pyx_v_cp_off + __pyx_v_cp_size) > __pyx_v_source_size);
            if (!__pyx_2) {
              __pyx_2 = (__pyx_v_cp_size > __pyx_v_size);
            }
          }
          if (__pyx_2) {

            /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":355 */
            __pyx_v_failed = 1;

            /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":356 */
            goto __pyx_L6;
            goto __pyx_L8;
          }
          __pyx_L8:;

          /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":357 */
          memcpy(__pyx_v_out,(__pyx_v_source + __pyx_v_cp_off),__pyx_v_cp_size);

          /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":358 */
          __pyx_v_out = (__pyx_v_out + __pyx_v_cp_size);

          /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":359 */
          __pyx_v_size = (__pyx_v_size - __pyx_v_cp_size);
          goto __pyx_L7;
        }
        /*else*/ {

          /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":362 */
          __pyx_2 = (__pyx_v_cmd == 0);
          if (__pyx_2) {

            /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":366 */
            __pyx_v_failed = 2;

            /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":367 */
            goto __pyx_L6;
            goto __pyx_L9;
          }
          __pyx_L9:;

          /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":368 */
          __pyx_2 = (__pyx_v_cmd > __pyx_v_size);
          if (__pyx_2) {

            /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":369 */
            __pyx_v_failed = 3;

            /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":370 */
            goto __pyx_L6;
            goto __pyx_L10;
          }
          __pyx_L10:;

          /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":371 */
          memcpy(__pyx_v_out,__pyx_v_data,__pyx_v_cmd);

          /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":372 */
          __pyx_v_out = (__pyx_v_out + __pyx_v_cmd);

          /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":373 */
          __pyx_v_data = (__pyx_v_data + __pyx_v_cmd);

          /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":374 */
          __pyx_v_size = (__pyx_v_size - __pyx_v_cmd);
        }
        __pyx_L7:;
      }
      __pyx_L6:;
    }
    /*finally:*/ {
      Py_BLOCK_THREADS
    }
  }

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":375 */
  __pyx_2 = __pyx_v_failed;
  if (__pyx_2) {
    __pyx_2 = (__pyx_v_failed == 1);
    if (__pyx_2) {
      __pyx_1 = PyLong_FromUnsignedLong(__pyx_v_cp_off); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 380; goto __pyx_L1;}
      __pyx_4 = PyLong_FromUnsignedLong(__pyx_v_cp_size); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 380; goto __pyx_L1;}
      __pyx_5 = PyInt_FromSsize_t(__pyx_v_source_size); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 380; goto __pyx_L1;}
      __pyx_6 = PyInt_FromSsize_t(__pyx_v_size); if (!__pyx_6) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 380; goto __pyx_L1;}
      __pyx_7 = PyTuple_New(4); if (!__pyx_7) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 380; goto __pyx_L1;}
      PyTuple_SET_ITEM(__pyx_7, 0, __pyx_1);
      PyTuple_SET_ITEM(__pyx_7, 1, __pyx_4);
      PyTuple_SET_ITEM(__pyx_7, 2, __pyx_5);
      PyTuple_SET_ITEM(__pyx_7, 3, __pyx_6);
      __pyx_1 = 0;
      __pyx_4 = 0;
      __pyx_5 = 0;
      __pyx_6 = 0;
      __pyx_1 = PyNumber_Remainder(__pyx_k15p, __pyx_7); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 380; goto __pyx_L1;}
      Py_DECREF(__pyx_7); __pyx_7 = 0;
      __pyx_4 = PyTuple_New(1); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 377; goto __pyx_L1;}
      PyTuple_SET_ITEM(__pyx_4, 0, __pyx_1);
      __pyx_1 = 0;
      __pyx_5 = PyObject_CallObject(PyExc_ValueError, __pyx_4); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 377; goto __pyx_L1;}
      Py_DECREF(__pyx_4); __pyx_4 = 0;
      __Pyx_Raise(__pyx_5, 0, 0);
      Py_DECREF(__pyx_5); __pyx_5 = 0;
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 377; goto __pyx_L1;}
      goto __pyx_L12;
    }
    __pyx_2 = (__pyx_v_failed == 2);
    if (__pyx_2) {
      __pyx_6 = PyTuple_New(1); if (!__pyx_6) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 382; goto __pyx_L1;}
      Py_INCREF(__pyx_k16p);
      PyTuple_SET_ITEM(__pyx_6, 0, __pyx_k16p);
      __pyx_7 = PyObject_CallObject(PyExc_ValueError, __pyx_6); if (!__pyx_7) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 382; goto __pyx_L1;}
      Py_DECREF(__pyx_6); __pyx_6 = 0;
      __Pyx_Raise(__pyx_7, 0, 0);
      Py_DECREF(__pyx_7); __pyx_7 = 0;
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 382; goto __pyx_L1;}
      goto __pyx_L12;
    }
    __pyx_2 = (__pyx_v_failed == 3);
    if (__pyx_2) {
      __pyx_1 = PyInt_FromLong(__pyx_v_cmd); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 385; goto __pyx_L1;}
      __pyx_4 = PyInt_FromSsize_t(__pyx_v_size); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 385; goto __pyx_L1;}
      __pyx_5 = PyTuple_New(2); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 385; goto __pyx_L1;}
      PyTuple_SET_ITEM(__pyx_5, 0, __pyx_1);
      PyTuple_SET_ITEM(__pyx_5, 1, __pyx_4);
      __pyx_1 = 0;
      __pyx_4 = 0;
      __pyx_6 = PyNumber_Remainder(__pyx_k17p, __pyx_5); if (!__pyx_6) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 385; goto __pyx_L1;}
      Py_DECREF(__pyx_5); __pyx_5 = 0;
      __pyx_7 = PyTuple_New(1); if (!__pyx_7) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 384; goto __pyx_L1;}
      PyTuple_SET_ITEM(__pyx_7, 0, __pyx_6);
      __pyx_6 = 0;
      __pyx_1 = PyObject_CallObject(PyExc_ValueError, __pyx_7); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 384; goto __pyx_L1;}
      Py_DECREF(__pyx_7); __pyx_7 = 0;
      __Pyx_Raise(__pyx_1, 0, 0);
      Py_DECREF(__pyx_1); __pyx_1 = 0;
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 384; goto __pyx_L1;}
      goto __pyx_L12;
    }
    __pyx_L12:;
    goto __pyx_L11;
  }
  __pyx_L11:;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":388 */
  __pyx_2 = (__pyx_v_data != __pyx_v_top);
  if (!__pyx_2) {
    __pyx_2 = (__pyx_v_size != 0);
  }
  if (__pyx_2) {

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":389 */
    __pyx_4 = PyInt_FromSsize_t(__pyx_v_size); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 391; goto __pyx_L1;}
    __pyx_5 = PyInt_FromLong(((int)(__pyx_v_top - __pyx_v_data))); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 391; goto __pyx_L1;}
    __pyx_6 = PyTuple_New(2); if (!__pyx_6) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 391; goto __pyx_L1;}
    PyTuple_SET_ITEM(__pyx_6, 0, __pyx_4);
    PyTuple_SET_ITEM(__pyx_6, 1, __pyx_5);
    __pyx_4 = 0;
    __pyx_5 = 0;
    __pyx_7 = PyNumber_Remainder(__pyx_k18p, __pyx_6); if (!__pyx_7) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 391; goto __pyx_L1;}
    Py_DECREF(__pyx_6); __pyx_6 = 0;
    __pyx_1 = PyTuple_New(1); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 389; goto __pyx_L1;}
    PyTuple_SET_ITEM(__pyx_1, 0, __pyx_7);
    __pyx_7 = 0;
    __pyx_4 = PyObject_CallObject(PyExc_RuntimeError, __pyx_1); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 389; goto __pyx_L1;}
    Py_DECREF(__pyx_1); __pyx_1 = 0;
    __Pyx_Raise(__pyx_4, 0, 0);
    Py_DECREF(__pyx_4); __pyx_4 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 389; goto __pyx_L1;}

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":392 */
    Py_INCREF(Py_None);
    __pyx_r = Py_None;
    goto __pyx_L0;
    goto __pyx_L13;
  }
  __pyx_L13:;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":395 */
  __pyx_2 = ((__pyx_v_out - __pyx_v_dst_buf) != PyString_GET_SIZE(__pyx_v_result));
  if (__pyx_2) {
    __pyx_5 = PyTuple_New(1); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 396; goto __pyx_L1;}
    Py_INCREF(__pyx_k19p);
    PyTuple_SET_ITEM(__pyx_5, 0, __pyx_k19p);
    __pyx_6 = PyObject_CallObject(PyExc_RuntimeError, __pyx_5); if (!__pyx_6) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 396; goto __pyx_L1;}
    Py_DECREF(__pyx_5); __pyx_5 = 0;
    __Pyx_Raise(__pyx_6, 0, 0);
    Py_DECREF(__pyx_6); __pyx_6 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 396; goto __pyx_L1;}
    goto __pyx_L14;
  }
  __pyx_L14:;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":398 */
  Py_INCREF(__pyx_v_result);
  __pyx_r = __pyx_v_result;
  goto __pyx_L0;

  __pyx_r = Py_None; Py_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_1);
  Py_XDECREF(__pyx_4);
  Py_XDECREF(__pyx_5);
  Py_XDECREF(__pyx_6);
  Py_XDECREF(__pyx_7);
  __Pyx_AddTraceback("bzrlib._groupcompress_pyx._apply_delta");
  __pyx_r = 0;
  __pyx_L0:;
  Py_DECREF(__pyx_v_result);
  return __pyx_r;
}

static PyObject *__pyx_f_6bzrlib_18_groupcompress_pyx_apply_delta_to_source(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_6bzrlib_18_groupcompress_pyx_apply_delta_to_source[] = "Extract a delta from source bytes, and apply it.";
static PyObject *__pyx_f_6bzrlib_18_groupcompress_pyx_apply_delta_to_source(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_source = 0;
  PyObject *__pyx_v_delta_start = 0;
  PyObject *__pyx_v_delta_end = 0;
  char *__pyx_v_c_source;
  Py_ssize_t __pyx_v_c_source_size;
  char *__pyx_v_c_delta;
  Py_ssize_t __pyx_v_c_delta_size;
  Py_ssize_t __pyx_v_c_delta_start;
  Py_ssize_t __pyx_v_c_delta_end;
  PyObject *__pyx_r;
  int __pyx_1;
  PyObject *__pyx_2 = 0;
  PyObject *__pyx_3 = 0;
  Py_ssize_t __pyx_4;
  static char *__pyx_argnames[] = {"source","delta_start","delta_end",0};
  if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "OOO", __pyx_argnames, &__pyx_v_source, &__pyx_v_delta_start, &__pyx_v_delta_end)) return 0;
  Py_INCREF(__pyx_v_source);
  Py_INCREF(__pyx_v_delta_start);
  Py_INCREF(__pyx_v_delta_end);

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":409 */
  __pyx_1 = (!PyString_CheckExact(__pyx_v_source));
  if (__pyx_1) {
    __pyx_2 = PyTuple_New(1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 410; goto __pyx_L1;}
    Py_INCREF(__pyx_k9p);
    PyTuple_SET_ITEM(__pyx_2, 0, __pyx_k9p);
    __pyx_3 = PyObject_CallObject(PyExc_TypeError, __pyx_2); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 410; goto __pyx_L1;}
    Py_DECREF(__pyx_2); __pyx_2 = 0;
    __Pyx_Raise(__pyx_3, 0, 0);
    Py_DECREF(__pyx_3); __pyx_3 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 410; goto __pyx_L1;}
    goto __pyx_L2;
  }
  __pyx_L2:;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":411 */
  __pyx_v_c_source_size = PyString_GET_SIZE(__pyx_v_source);

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":412 */
  __pyx_4 = PyInt_AsSsize_t(__pyx_v_delta_start); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 412; goto __pyx_L1;}
  __pyx_v_c_delta_start = __pyx_4;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":413 */
  __pyx_4 = PyInt_AsSsize_t(__pyx_v_delta_end); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 413; goto __pyx_L1;}
  __pyx_v_c_delta_end = __pyx_4;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":414 */
  __pyx_1 = (__pyx_v_c_delta_start >= __pyx_v_c_source_size);
  if (__pyx_1) {
    __pyx_2 = PyTuple_New(1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 415; goto __pyx_L1;}
    Py_INCREF(__pyx_k20p);
    PyTuple_SET_ITEM(__pyx_2, 0, __pyx_k20p);
    __pyx_3 = PyObject_CallObject(PyExc_ValueError, __pyx_2); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 415; goto __pyx_L1;}
    Py_DECREF(__pyx_2); __pyx_2 = 0;
    __Pyx_Raise(__pyx_3, 0, 0);
    Py_DECREF(__pyx_3); __pyx_3 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 415; goto __pyx_L1;}
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":416 */
  __pyx_1 = (__pyx_v_c_delta_end > __pyx_v_c_source_size);
  if (__pyx_1) {
    __pyx_2 = PyTuple_New(1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 417; goto __pyx_L1;}
    Py_INCREF(__pyx_k21p);
    PyTuple_SET_ITEM(__pyx_2, 0, __pyx_k21p);
    __pyx_3 = PyObject_CallObject(PyExc_ValueError, __pyx_2); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 417; goto __pyx_L1;}
    Py_DECREF(__pyx_2); __pyx_2 = 0;
    __Pyx_Raise(__pyx_3, 0, 0);
    Py_DECREF(__pyx_3); __pyx_3 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 417; goto __pyx_L1;}
    goto __pyx_L4;
  }
  __pyx_L4:;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":418 */
  __pyx_1 = (__pyx_v_c_delta_start >= __pyx_v_c_delta_end);
  if (__pyx_1) {
    __pyx_2 = PyTuple_New(1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 419; goto __pyx_L1;}
    Py_INCREF(__pyx_k22p);
    PyTuple_SET_ITEM(__pyx_2, 0, __pyx_k22p);
    __pyx_3 = PyObject_CallObject(PyExc_ValueError, __pyx_2); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 419; goto __pyx_L1;}
    Py_DECREF(__pyx_2); __pyx_2 = 0;
    __Pyx_Raise(__pyx_3, 0, 0);
    Py_DECREF(__pyx_3); __pyx_3 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 419; goto __pyx_L1;}
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":421 */
  __pyx_v_c_delta_size = (__pyx_v_c_delta_end - __pyx_v_c_delta_start);

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":422 */
  __pyx_v_c_source = PyString_AS_STRING(__pyx_v_source);

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":423 */
  __pyx_v_c_delta = (__pyx_v_c_source + __pyx_v_c_delta_start);

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":426 */
  __pyx_2 = __pyx_f_6bzrlib_18_groupcompress_pyx__apply_delta(__pyx_v_c_source,__pyx_v_c_delta_start,__pyx_v_c_delta,__pyx_v_c_delta_size); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 426; goto __pyx_L1;}
  __pyx_r = __pyx_2;
  __pyx_2 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; Py_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_2);
  Py_XDECREF(__pyx_3);
  __Pyx_AddTraceback("bzrlib._groupcompress_pyx.apply_delta_to_source");
  __pyx_r = 0;
  __pyx_L0:;
  Py_DECREF(__pyx_v_source);
  Py_DECREF(__pyx_v_delta_start);
  Py_DECREF(__pyx_v_delta_end);
  return __pyx_r;
}

static PyObject *__pyx_f_6bzrlib_18_groupcompress_pyx_encode_base128_int(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_6bzrlib_18_groupcompress_pyx_encode_base128_int[] = "Convert an integer into a 7-bit lsb encoding.";
static PyObject *__pyx_f_6bzrlib_18_groupcompress_pyx_encode_base128_int(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_val = 0;
  unsigned int __pyx_v_c_val;
  Py_ssize_t __pyx_v_count;
  unsigned char __pyx_v_c_bytes[8];
  PyObject *__pyx_r;
  unsigned int __pyx_1;
  int __pyx_2;
  PyObject *__pyx_3 = 0;
  PyObject *__pyx_4 = 0;
  static char *__pyx_argnames[] = {"val",0};
  if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "O", __pyx_argnames, &__pyx_v_val)) return 0;
  Py_INCREF(__pyx_v_val);

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":436 */
  __pyx_1 = PyInt_AsUnsignedLongMask(__pyx_v_val); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 436; goto __pyx_L1;}
  __pyx_v_c_val = __pyx_1;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":437 */
  __pyx_v_count = 0;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":438 */
  while (1) {
    __pyx_2 = (__pyx_v_c_val >= 0x80);
    if (__pyx_2) {
      __pyx_2 = (__pyx_v_count < 8);
    }
    if (!__pyx_2) break;

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":439 */
    (__pyx_v_c_bytes[__pyx_v_count]) = ((unsigned char)((__pyx_v_c_val | 0x80) & 0xFF));

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":440 */
    __pyx_v_c_val = (__pyx_v_c_val >> 7);

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":441 */
    __pyx_v_count = (__pyx_v_count + 1);
  }

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":442 */
  __pyx_2 = (__pyx_v_count >= 8);
  if (!__pyx_2) {
    __pyx_2 = (__pyx_v_c_val >= 0x80);
  }
  if (__pyx_2) {
    __pyx_3 = PyTuple_New(1); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 443; goto __pyx_L1;}
    Py_INCREF(__pyx_k23p);
    PyTuple_SET_ITEM(__pyx_3, 0, __pyx_k23p);
    __pyx_4 = PyObject_CallObject(PyExc_ValueError, __pyx_3); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 443; goto __pyx_L1;}
    Py_DECREF(__pyx_3); __pyx_3 = 0;
    __Pyx_Raise(__pyx_4, 0, 0);
    Py_DECREF(__pyx_4); __pyx_4 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 443; goto __pyx_L1;}
    goto __pyx_L4;
  }
  __pyx_L4:;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":444 */
  (__pyx_v_c_bytes[__pyx_v_count]) = ((unsigned char)(__pyx_v_c_val & 0xFF));

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":445 */
  __pyx_v_count = (__pyx_v_count + 1);

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":446 */
  __pyx_3 = PyString_FromStringAndSize(((char *)__pyx_v_c_bytes),__pyx_v_count); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 446; goto __pyx_L1;}
  __pyx_r = __pyx_3;
  __pyx_3 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; Py_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_3);
  Py_XDECREF(__pyx_4);
  __Pyx_AddTraceback("bzrlib._groupcompress_pyx.encode_base128_int");
  __pyx_r = 0;
  __pyx_L0:;
  Py_DECREF(__pyx_v_val);
  return __pyx_r;
}

static PyObject *__pyx_f_6bzrlib_18_groupcompress_pyx_decode_base128_int(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_6bzrlib_18_groupcompress_pyx_decode_base128_int[] = "Decode an integer from a 7-bit lsb encoding.";
static PyObject *__pyx_f_6bzrlib_18_groupcompress_pyx_decode_base128_int(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_bytes = 0;
  int __pyx_v_offset;
  int __pyx_v_val;
  unsigned int __pyx_v_uval;
  int __pyx_v_shift;
  Py_ssize_t __pyx_v_num_low_bytes;
  unsigned char *__pyx_v_c_bytes;
  PyObject *__pyx_r;
  int __pyx_1;
  PyObject *__pyx_2 = 0;
  PyObject *__pyx_3 = 0;
  long __pyx_4;
  PyObject *__pyx_5 = 0;
  static char *__pyx_argnames[] = {"bytes",0};
  if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "O", __pyx_argnames, &__pyx_v_bytes)) return 0;
  Py_INCREF(__pyx_v_bytes);

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":458 */
  __pyx_v_offset = 0;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":459 */
  __pyx_v_val = 0;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":460 */
  __pyx_v_shift = 0;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":461 */
  __pyx_1 = (!PyString_CheckExact(__pyx_v_bytes));
  if (__pyx_1) {
    __pyx_2 = PyTuple_New(1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 462; goto __pyx_L1;}
    Py_INCREF(__pyx_k24p);
    PyTuple_SET_ITEM(__pyx_2, 0, __pyx_k24p);
    __pyx_3 = PyObject_CallObject(PyExc_TypeError, __pyx_2); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 462; goto __pyx_L1;}
    Py_DECREF(__pyx_2); __pyx_2 = 0;
    __Pyx_Raise(__pyx_3, 0, 0);
    Py_DECREF(__pyx_3); __pyx_3 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 462; goto __pyx_L1;}
    goto __pyx_L2;
  }
  __pyx_L2:;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":463 */
  __pyx_v_c_bytes = ((unsigned char *)PyString_AS_STRING(__pyx_v_bytes));

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":465 */
  __pyx_v_num_low_bytes = (PyString_GET_SIZE(__pyx_v_bytes) - 1);

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":466 */
  while (1) {
    __pyx_1 = ((__pyx_v_c_bytes[__pyx_v_offset]) & 0x80);
    if (__pyx_1) {
      __pyx_1 = (__pyx_v_offset < __pyx_v_num_low_bytes);
    }
    if (!__pyx_1) break;

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":467 */
    __pyx_v_val = (__pyx_v_val | (((__pyx_v_c_bytes[__pyx_v_offset]) & 0x7F) << __pyx_v_shift));

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":468 */
    __pyx_v_shift = (__pyx_v_shift + 7);

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":469 */
    __pyx_v_offset = (__pyx_v_offset + 1);
  }

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":470 */
  __pyx_4 = ((__pyx_v_c_bytes[__pyx_v_offset]) & 0x80);
  if (__pyx_4) {
    __pyx_2 = PyTuple_New(1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 471; goto __pyx_L1;}
    Py_INCREF(__pyx_k25p);
    PyTuple_SET_ITEM(__pyx_2, 0, __pyx_k25p);
    __pyx_3 = PyObject_CallObject(PyExc_ValueError, __pyx_2); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 471; goto __pyx_L1;}
    Py_DECREF(__pyx_2); __pyx_2 = 0;
    __Pyx_Raise(__pyx_3, 0, 0);
    Py_DECREF(__pyx_3); __pyx_3 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 471; goto __pyx_L1;}
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":473 */
  __pyx_v_val = (__pyx_v_val | ((__pyx_v_c_bytes[__pyx_v_offset]) << __pyx_v_shift));

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":474 */
  __pyx_v_offset = (__pyx_v_offset + 1);

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":475 */
  __pyx_1 = (__pyx_v_val < 0);
  if (__pyx_1) {

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":476 */
    __pyx_v_uval = __pyx_v_val;

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":477 */
    __pyx_2 = PyLong_FromUnsignedLong(__pyx_v_uval); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 477; goto __pyx_L1;}
    __pyx_3 = PyInt_FromLong(__pyx_v_offset); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 477; goto __pyx_L1;}
    __pyx_5 = PyTuple_New(2); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 477; goto __pyx_L1;}
    PyTuple_SET_ITEM(__pyx_5, 0, __pyx_2);
    PyTuple_SET_ITEM(__pyx_5, 1, __pyx_3);
    __pyx_2 = 0;
    __pyx_3 = 0;
    __pyx_r = __pyx_5;
    __pyx_5 = 0;
    goto __pyx_L0;
    goto __pyx_L6;
  }
  __pyx_L6:;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":478 */
  __pyx_2 = PyInt_FromLong(__pyx_v_val); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 478; goto __pyx_L1;}
  __pyx_3 = PyInt_FromLong(__pyx_v_offset); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 478; goto __pyx_L1;}
  __pyx_5 = PyTuple_New(2); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 478; goto __pyx_L1;}
  PyTuple_SET_ITEM(__pyx_5, 0, __pyx_2);
  PyTuple_SET_ITEM(__pyx_5, 1, __pyx_3);
  __pyx_2 = 0;
  __pyx_3 = 0;
  __pyx_r = __pyx_5;
  __pyx_5 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; Py_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_2);
  Py_XDECREF(__pyx_3);
  Py_XDECREF(__pyx_5);
  __Pyx_AddTraceback("bzrlib._groupcompress_pyx.decode_base128_int");
  __pyx_r = 0;
  __pyx_L0:;
  Py_DECREF(__pyx_v_bytes);
  return __pyx_r;
}
static struct __pyx_vtabstruct_6bzrlib_18_groupcompress_pyx_DeltaIndex __pyx_vtable_6bzrlib_18_groupcompress_pyx_DeltaIndex;

static PyObject *__pyx_tp_new_6bzrlib_18_groupcompress_pyx_DeltaIndex(PyTypeObject *t, PyObject *a, PyObject *k) {
  struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *p;
  PyObject *o = (*t->tp_alloc)(t, 0);
  if (!o) return 0;
  p = ((struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *)o);
  *(struct __pyx_vtabstruct_6bzrlib_18_groupcompress_pyx_DeltaIndex **)&p->__pyx_vtab = __pyx_vtabptr_6bzrlib_18_groupcompress_pyx_DeltaIndex;
  p->_sources = Py_None; Py_INCREF(Py_None);
  return o;
}

static void __pyx_tp_dealloc_6bzrlib_18_groupcompress_pyx_DeltaIndex(PyObject *o) {
  struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *p = (struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *)o;
  {
    PyObject *etype, *eval, *etb;
    PyErr_Fetch(&etype, &eval, &etb);
    ++o->ob_refcnt;
    __pyx_f_6bzrlib_18_groupcompress_pyx_10DeltaIndex___dealloc__(o);
    if (PyErr_Occurred()) PyErr_WriteUnraisable(o);
    --o->ob_refcnt;
    PyErr_Restore(etype, eval, etb);
  }
  Py_XDECREF(p->_sources);
  (*o->ob_type->tp_free)(o);
}

static int __pyx_tp_traverse_6bzrlib_18_groupcompress_pyx_DeltaIndex(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *p = (struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *)o;
  if (p->_sources) {
    e = (*v)(p->_sources, a); if (e) return e;
  }
  return 0;
}

static int __pyx_tp_clear_6bzrlib_18_groupcompress_pyx_DeltaIndex(PyObject *o) {
  struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *p = (struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *)o;
  PyObject *t;
  t = p->_sources; 
  p->_sources = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(t);
  return 0;
}

static struct PyMethodDef __pyx_methods_6bzrlib_18_groupcompress_pyx_DeltaIndex[] = {
  {"_has_index", (PyCFunction)__pyx_f_6bzrlib_18_groupcompress_pyx_10DeltaIndex__has_index, METH_VARARGS|METH_KEYWORDS, 0},
  {"add_delta_source", (PyCFunction)__pyx_f_6bzrlib_18_groupcompress_pyx_10DeltaIndex_add_delta_source, METH_VARARGS|METH_KEYWORDS, __pyx_doc_6bzrlib_18_groupcompress_pyx_10DeltaIndex_add_delta_source},
  {"add_source", (PyCFunction)__pyx_f_6bzrlib_18_groupcompress_pyx_10DeltaIndex_add_source, METH_VARARGS|METH_KEYWORDS, __pyx_doc_6bzrlib_18_groupcompress_pyx_10DeltaIndex_add_source},
  {"make_delta", (PyCFunction)__pyx_f_6bzrlib_18_groupcompress_pyx_10DeltaIndex_make_delta, METH_VARARGS|METH_KEYWORDS, __pyx_doc_6bzrlib_18_groupcompress_pyx_10DeltaIndex_make_delta},
  {0, 0, 0, 0}
};

static struct PyMemberDef __pyx_members_6bzrlib_18_groupcompress_pyx_DeltaIndex[] = {
  {"_sources", T_OBJECT, offsetof(struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex, _sources), READONLY, 0},
  {"_max_num_sources", T_UINT, offsetof(struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex, _max_num_sources), READONLY, 0},
  {"_source_offset", T_ULONG, offsetof(struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex, _source_offset), 0, 0},
  {0, 0, 0, 0, 0}
};

static PyNumberMethods __pyx_tp_as_number_DeltaIndex = {
  0, /*nb_add*/
  0, /*nb_subtract*/
  0, /*nb_multiply*/
  0, /*nb_divide*/
  0, /*nb_remainder*/
  0, /*nb_divmod*/
  0, /*nb_power*/
  0, /*nb_negative*/
  0, /*nb_positive*/
  0, /*nb_absolute*/
  0, /*nb_nonzero*/
  0, /*nb_invert*/
  0, /*nb_lshift*/
  0, /*nb_rshift*/
  0, /*nb_and*/
  0, /*nb_xor*/
  0, /*nb_or*/
  0, /*nb_coerce*/
  0, /*nb_int*/
  0, /*nb_long*/
  0, /*nb_float*/
  0, /*nb_oct*/
  0, /*nb_hex*/
  0, /*nb_inplace_add*/
  0, /*nb_inplace_subtract*/
  0, /*nb_inplace_multiply*/
  0, /*nb_inplace_divide*/
  0, /*nb_inplace_remainder*/
  0, /*nb_inplace_power*/
  0, /*nb_inplace_lshift*/
  0, /*nb_inplace_rshift*/
  0, /*nb_inplace_and*/
  0, /*nb_inplace_xor*/
  0, /*nb_inplace_or*/
  0, /*nb_floor_divide*/
  0, /*nb_true_divide*/
  0, /*nb_inplace_floor_divide*/
  0, /*nb_inplace_true_divide*/
  #if Py_TPFLAGS_DEFAULT & Py_TPFLAGS_HAVE_INDEX
  0, /*nb_index*/
  #endif
};

static PySequenceMethods __pyx_tp_as_sequence_DeltaIndex = {
  0, /*sq_length*/
  0, /*sq_concat*/
  0, /*sq_repeat*/
  0, /*sq_item*/
  0, /*sq_slice*/
  0, /*sq_ass_item*/
  0, /*sq_ass_slice*/
  0, /*sq_contains*/
  0, /*sq_inplace_concat*/
  0, /*sq_inplace_repeat*/
};

static PyMappingMethods __pyx_tp_as_mapping_DeltaIndex = {
  0, /*mp_length*/
  0, /*mp_subscript*/
  0, /*mp_ass_subscript*/
};

static PyBufferProcs __pyx_tp_as_buffer_DeltaIndex = {
  0, /*bf_getreadbuffer*/
  0, /*bf_getwritebuffer*/
  0, /*bf_getsegcount*/
  0, /*bf_getcharbuffer*/
};

PyTypeObject __pyx_type_6bzrlib_18_groupcompress_pyx_DeltaIndex = {
  PyObject_HEAD_INIT(0)
  0, /*ob_size*/
  "bzrlib._groupcompress_pyx.DeltaIndex", /*tp_name*/
  sizeof(struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_6bzrlib_18_groupcompress_pyx_DeltaIndex, /*tp_dealloc*/
  0, /*tp_print*/
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  0, /*tp_compare*/
  __pyx_f_6bzrlib_18_groupcompress_pyx_10DeltaIndex___repr__, /*tp_repr*/
  &__pyx_tp_as_number_DeltaIndex, /*tp_as_number*/
  &__pyx_tp_as_sequence_DeltaIndex, /*tp_as_sequence*/
  &__pyx_tp_as_mapping_DeltaIndex, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  &__pyx_tp_as_buffer_DeltaIndex, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  0, /*tp_doc*/
  __pyx_tp_traverse_6bzrlib_18_groupcompress_pyx_DeltaIndex, /*tp_traverse*/
  __pyx_tp_clear_6bzrlib_18_groupcompress_pyx_DeltaIndex, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  __pyx_methods_6bzrlib_18_groupcompress_pyx_DeltaIndex, /*tp_methods*/
  __pyx_members_6bzrlib_18_groupcompress_pyx_DeltaIndex, /*tp_members*/
  0, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  0, /*tp_dictoffset*/
  __pyx_f_6bzrlib_18_groupcompress_pyx_10DeltaIndex___init__, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_6bzrlib_18_groupcompress_pyx_DeltaIndex, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
};

static struct PyMethodDef __pyx_methods[] = {
  {"make_delta_index", (PyCFunction)__pyx_f_6bzrlib_18_groupcompress_pyx_make_delta_index, METH_VARARGS|METH_KEYWORDS, 0},
  {"make_delta", (PyCFunction)__pyx_f_6bzrlib_18_groupcompress_pyx_make_delta, METH_VARARGS|METH_KEYWORDS, __pyx_doc_6bzrlib_18_groupcompress_pyx_make_delta},
  {"apply_delta", (PyCFunction)__pyx_f_6bzrlib_18_groupcompress_pyx_apply_delta, METH_VARARGS|METH_KEYWORDS, __pyx_doc_6bzrlib_18_groupcompress_pyx_apply_delta},
  {"apply_delta_to_source", (PyCFunction)__pyx_f_6bzrlib_18_groupcompress_pyx_apply_delta_to_source, METH_VARARGS|METH_KEYWORDS, __pyx_doc_6bzrlib_18_groupcompress_pyx_apply_delta_to_source},
  {"encode_base128_int", (PyCFunction)__pyx_f_6bzrlib_18_groupcompress_pyx_encode_base128_int, METH_VARARGS|METH_KEYWORDS, __pyx_doc_6bzrlib_18_groupcompress_pyx_encode_base128_int},
  {"decode_base128_int", (PyCFunction)__pyx_f_6bzrlib_18_groupcompress_pyx_decode_base128_int, METH_VARARGS|METH_KEYWORDS, __pyx_doc_6bzrlib_18_groupcompress_pyx_decode_base128_int},
  {0, 0, 0, 0}
};

static void __pyx_init_filenames(void); /*proto*/

PyMODINIT_FUNC init_groupcompress_pyx(void); /*proto*/
PyMODINIT_FUNC init_groupcompress_pyx(void) {
  PyObject *__pyx_1 = 0;
  __pyx_init_filenames();
  __pyx_m = Py_InitModule4("_groupcompress_pyx", __pyx_methods, __pyx_mdoc, 0, PYTHON_API_VERSION);
  if (!__pyx_m) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 17; goto __pyx_L1;};
  Py_INCREF(__pyx_m);
  __pyx_b = PyImport_AddModule("__builtin__");
  if (!__pyx_b) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 17; goto __pyx_L1;};
  if (PyObject_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 17; goto __pyx_L1;};
  if (__Pyx_InitStrings(__pyx_string_tab) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 17; goto __pyx_L1;};
  __pyx_vtabptr_6bzrlib_18_groupcompress_pyx_DeltaIndex = &__pyx_vtable_6bzrlib_18_groupcompress_pyx_DeltaIndex;
  *(void(**)(void))&__pyx_vtable_6bzrlib_18_groupcompress_pyx_DeltaIndex._populate_first_index = (void(*)(void))__pyx_f_6bzrlib_18_groupcompress_pyx_10DeltaIndex__populate_first_index;
  *(void(**)(void))&__pyx_vtable_6bzrlib_18_groupcompress_pyx_DeltaIndex._expand_sources = (void(*)(void))__pyx_f_6bzrlib_18_groupcompress_pyx_10DeltaIndex__expand_sources;
  __pyx_type_6bzrlib_18_groupcompress_pyx_DeltaIndex.tp_free = _PyObject_GC_Del;
  if (PyType_Ready(&__pyx_type_6bzrlib_18_groupcompress_pyx_DeltaIndex) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 86; goto __pyx_L1;}
  if (__Pyx_SetVtable(__pyx_type_6bzrlib_18_groupcompress_pyx_DeltaIndex.tp_dict, __pyx_vtabptr_6bzrlib_18_groupcompress_pyx_DeltaIndex) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 86; goto __pyx_L1;}
  if (PyObject_SetAttrString(__pyx_m, "DeltaIndex", (PyObject *)&__pyx_type_6bzrlib_18_groupcompress_pyx_DeltaIndex) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 86; goto __pyx_L1;}
  __pyx_ptype_6bzrlib_18_groupcompress_pyx_DeltaIndex = &__pyx_type_6bzrlib_18_groupcompress_pyx_DeltaIndex;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":97 */
  Py_INCREF(Py_None);
  __pyx_d1 = Py_None;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":215 */
  __pyx_1 = PyInt_FromLong(0); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 215; goto __pyx_L1;}
  __pyx_d2 = __pyx_1;
  __pyx_1 = 0;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_groupcompress_pyx.pyx":449 */
  return;
  __pyx_L1:;
  Py_XDECREF(__pyx_1);
  __Pyx_AddTraceback("bzrlib._groupcompress_pyx");
}

static char *__pyx_filenames[] = {
  "_groupcompress_pyx.pyx",
};

/* Runtime support code */

static void __pyx_init_filenames(void) {
  __pyx_f = __pyx_filenames;
}

static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb) {
    Py_XINCREF(type);
    Py_XINCREF(value);
    Py_XINCREF(tb);
    /* First, check the traceback argument, replacing None with NULL. */
    if (tb == Py_None) {
        Py_DECREF(tb);
        tb = 0;
    }
    else if (tb != NULL && !PyTraceBack_Check(tb)) {
        PyErr_SetString(PyExc_TypeError,
            "raise: arg 3 must be a traceback or None");
        goto raise_error;
    }
    /* Next, replace a missing value with None */
    if (value == NULL) {
        value = Py_None;
        Py_INCREF(value);
    }
    #if PY_VERSION_HEX < 0x02050000
    if (!PyClass_Check(type))
    #else
    if (!PyType_Check(type))
    #endif
    {
        /* Raising an instance.  The value should be a dummy. */
        if (value != Py_None) {
            PyErr_SetString(PyExc_TypeError,
                "instance exception may not have a separate value");
            goto raise_error;
        }
        /* Normalize to raise <class>, <instance> */
        Py_DECREF(value);
        value = type;
        #if PY_VERSION_HEX < 0x02050000
            if (PyInstance_Check(type)) {
                type = (PyObject*) ((PyInstanceObject*)type)->in_class;
                Py_INCREF(type);
            }
            else {
                PyErr_SetString(PyExc_TypeError,
                    "raise: exception must be an old-style class or instance");
                goto raise_error;
            }
        #else
            type = (PyObject*) type->ob_type;
            Py_INCREF(type);
            if (!PyType_IsSubtype((PyTypeObject *)type, (PyTypeObject *)PyExc_BaseException)) {
                PyErr_SetString(PyExc_TypeError,
                    "raise: exception class must be a subclass of BaseException");
                goto raise_error;
            }
        #endif
    }
    PyErr_Restore(type, value, tb);
    return;
raise_error:
    Py_XDECREF(value);
    Py_XDECREF(type);
    Py_XDECREF(tb);
    return;
}

static int __Pyx_InitStrings(__Pyx_StringTabEntry *t) {
    while (t->p) {
        *t->p = PyString_FromStringAndSize(t->s, t->n - 1);
        if (!*t->p)
            return -1;
        if (t->i)
            PyString_InternInPlace(t->p);
        ++t;
    }
    return 0;
}

static int __Pyx_SetVtable(PyObject *dict, void *vtable) {
    PyObject *pycobj = 0;
    int result;
    
    pycobj = PyCObject_FromVoidPtr(vtable, 0);
    if (!pycobj)
        goto bad;
    if (PyDict_SetItemString(dict, "__pyx_vtable__", pycobj) < 0)
        goto bad;
    result = 0;
    goto done;

bad:
    result = -1;
done:
    Py_XDECREF(pycobj);
    return result;
}

#include "compile.h"
#include "frameobject.h"
#include "traceback.h"

static void __Pyx_AddTraceback(char *funcname) {
    PyObject *py_srcfile = 0;
    PyObject *py_funcname = 0;
    PyObject *py_globals = 0;
    PyObject *empty_tuple = 0;
    PyObject *empty_string = 0;
    PyCodeObject *py_code = 0;
    PyFrameObject *py_frame = 0;
    
    py_srcfile = PyString_FromString(__pyx_filename);
    if (!py_srcfile) goto bad;
    py_funcname = PyString_FromString(funcname);
    if (!py_funcname) goto bad;
    py_globals = PyModule_GetDict(__pyx_m);
    if (!py_globals) goto bad;
    empty_tuple = PyTuple_New(0);
    if (!empty_tuple) goto bad;
    empty_string = PyString_FromString("");
    if (!empty_string) goto bad;
    py_code = PyCode_New(
        0,            /*int argcount,*/
        0,            /*int nlocals,*/
        0,            /*int stacksize,*/
        0,            /*int flags,*/
        empty_string, /*PyObject *code,*/
        empty_tuple,  /*PyObject *consts,*/
        empty_tuple,  /*PyObject *names,*/
        empty_tuple,  /*PyObject *varnames,*/
        empty_tuple,  /*PyObject *freevars,*/
        empty_tuple,  /*PyObject *cellvars,*/
        py_srcfile,   /*PyObject *filename,*/
        py_funcname,  /*PyObject *name,*/
        __pyx_lineno,   /*int firstlineno,*/
        empty_string  /*PyObject *lnotab*/
    );
    if (!py_code) goto bad;
    py_frame = PyFrame_New(
        PyThreadState_Get(), /*PyThreadState *tstate,*/
        py_code,             /*PyCodeObject *code,*/
        py_globals,          /*PyObject *globals,*/
        0                    /*PyObject *locals*/
    );
    if (!py_frame) goto bad;
    py_frame->f_lineno = __pyx_lineno;
    PyTraceBack_Here(py_frame);
bad:
    Py_XDECREF(py_srcfile);
    Py_XDECREF(py_funcname);
    Py_XDECREF(empty_tuple);
    Py_XDECREF(empty_string);
    Py_XDECREF(py_code);
    Py_XDECREF(py_frame);
}
