/* Generated by Cython 0.14.1 on Mon Jan 16 15:59:27 2012 */

#define PY_SSIZE_T_CLEAN
#include "Python.h"
#ifndef Py_PYTHON_H
    #error Python headers needed to compile C extensions, please install development version of Python.
#else

#include <stddef.h> /* For offsetof */
#ifndef offsetof
#define offsetof(type, member) ( (size_t) & ((type*)0) -> member )
#endif

#if !defined(WIN32) && !defined(MS_WINDOWS)
  #ifndef __stdcall
    #define __stdcall
  #endif
  #ifndef __cdecl
    #define __cdecl
  #endif
  #ifndef __fastcall
    #define __fastcall
  #endif
#endif

#ifndef DL_IMPORT
  #define DL_IMPORT(t) t
#endif
#ifndef DL_EXPORT
  #define DL_EXPORT(t) t
#endif

#ifndef PY_LONG_LONG
  #define PY_LONG_LONG LONG_LONG
#endif

#if PY_VERSION_HEX < 0x02040000
  #define METH_COEXIST 0
  #define PyDict_CheckExact(op) (Py_TYPE(op) == &PyDict_Type)
  #define PyDict_Contains(d,o)   PySequence_Contains(d,o)
#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 PY_FORMAT_SIZE_T ""
  #define PyInt_FromSsize_t(z) PyInt_FromLong(z)
  #define PyInt_AsSsize_t(o)   PyInt_AsLong(o)
  #define PyNumber_Index(o)    PyNumber_Int(o)
  #define PyIndex_Check(o)     PyNumber_Check(o)
  #define PyErr_WarnEx(category, message, stacklevel) PyErr_Warn(category, message)
#endif

#if PY_VERSION_HEX < 0x02060000
  #define Py_REFCNT(ob) (((PyObject*)(ob))->ob_refcnt)
  #define Py_TYPE(ob)   (((PyObject*)(ob))->ob_type)
  #define Py_SIZE(ob)   (((PyVarObject*)(ob))->ob_size)
  #define PyVarObject_HEAD_INIT(type, size) \
          PyObject_HEAD_INIT(type) size,
  #define PyType_Modified(t)

  typedef struct {
     void *buf;
     PyObject *obj;
     Py_ssize_t len;
     Py_ssize_t itemsize;
     int readonly;
     int ndim;
     char *format;
     Py_ssize_t *shape;
     Py_ssize_t *strides;
     Py_ssize_t *suboffsets;
     void *internal;
  } Py_buffer;

  #define PyBUF_SIMPLE 0
  #define PyBUF_WRITABLE 0x0001
  #define PyBUF_FORMAT 0x0004
  #define PyBUF_ND 0x0008
  #define PyBUF_STRIDES (0x0010 | PyBUF_ND)
  #define PyBUF_C_CONTIGUOUS (0x0020 | PyBUF_STRIDES)
  #define PyBUF_F_CONTIGUOUS (0x0040 | PyBUF_STRIDES)
  #define PyBUF_ANY_CONTIGUOUS (0x0080 | PyBUF_STRIDES)
  #define PyBUF_INDIRECT (0x0100 | PyBUF_STRIDES)

#endif

#if PY_MAJOR_VERSION < 3
  #define __Pyx_BUILTIN_MODULE_NAME "__builtin__"
#else
  #define __Pyx_BUILTIN_MODULE_NAME "builtins"
#endif

#if PY_MAJOR_VERSION >= 3
  #define Py_TPFLAGS_CHECKTYPES 0
  #define Py_TPFLAGS_HAVE_INDEX 0
#endif

#if (PY_VERSION_HEX < 0x02060000) || (PY_MAJOR_VERSION >= 3)
  #define Py_TPFLAGS_HAVE_NEWBUFFER 0
#endif

#if PY_MAJOR_VERSION >= 3
  #define PyBaseString_Type            PyUnicode_Type
  #define PyStringObject               PyUnicodeObject
  #define PyString_Type                PyUnicode_Type
  #define PyString_Check               PyUnicode_Check
  #define PyString_CheckExact          PyUnicode_CheckExact
#endif

#if PY_VERSION_HEX < 0x02060000
  #define PyBytesObject                PyStringObject
  #define PyBytes_Type                 PyString_Type
  #define PyBytes_Check                PyString_Check
  #define PyBytes_CheckExact           PyString_CheckExact
  #define PyBytes_FromString           PyString_FromString
  #define PyBytes_FromStringAndSize    PyString_FromStringAndSize
  #define PyBytes_FromFormat           PyString_FromFormat
  #define PyBytes_DecodeEscape         PyString_DecodeEscape
  #define PyBytes_AsString             PyString_AsString
  #define PyBytes_AsStringAndSize      PyString_AsStringAndSize
  #define PyBytes_Size                 PyString_Size
  #define PyBytes_AS_STRING            PyString_AS_STRING
  #define PyBytes_GET_SIZE             PyString_GET_SIZE
  #define PyBytes_Repr                 PyString_Repr
  #define PyBytes_Concat               PyString_Concat
  #define PyBytes_ConcatAndDel         PyString_ConcatAndDel
#endif

#if PY_VERSION_HEX < 0x02060000
  #define PySet_Check(obj)             PyObject_TypeCheck(obj, &PySet_Type)
  #define PyFrozenSet_Check(obj)       PyObject_TypeCheck(obj, &PyFrozenSet_Type)
#endif
#ifndef PySet_CheckExact
  #define PySet_CheckExact(obj)        (Py_TYPE(obj) == &PySet_Type)
#endif

#define __Pyx_TypeCheck(obj, type) PyObject_TypeCheck(obj, (PyTypeObject *)type)

#if PY_MAJOR_VERSION >= 3
  #define PyIntObject                  PyLongObject
  #define PyInt_Type                   PyLong_Type
  #define PyInt_Check(op)              PyLong_Check(op)
  #define PyInt_CheckExact(op)         PyLong_CheckExact(op)
  #define PyInt_FromString             PyLong_FromString
  #define PyInt_FromUnicode            PyLong_FromUnicode
  #define PyInt_FromLong               PyLong_FromLong
  #define PyInt_FromSize_t             PyLong_FromSize_t
  #define PyInt_FromSsize_t            PyLong_FromSsize_t
  #define PyInt_AsLong                 PyLong_AsLong
  #define PyInt_AS_LONG                PyLong_AS_LONG
  #define PyInt_AsSsize_t              PyLong_AsSsize_t
  #define PyInt_AsUnsignedLongMask     PyLong_AsUnsignedLongMask
  #define PyInt_AsUnsignedLongLongMask PyLong_AsUnsignedLongLongMask
#endif

#if PY_MAJOR_VERSION >= 3
  #define PyBoolObject                 PyLongObject
#endif


#if PY_MAJOR_VERSION >= 3
  #define __Pyx_PyNumber_Divide(x,y)         PyNumber_TrueDivide(x,y)
  #define __Pyx_PyNumber_InPlaceDivide(x,y)  PyNumber_InPlaceTrueDivide(x,y)
#else
  #define __Pyx_PyNumber_Divide(x,y)         PyNumber_Divide(x,y)
  #define __Pyx_PyNumber_InPlaceDivide(x,y)  PyNumber_InPlaceDivide(x,y)
#endif

#if (PY_MAJOR_VERSION < 3) || (PY_VERSION_HEX >= 0x03010300)
  #define __Pyx_PySequence_GetSlice(obj, a, b) PySequence_GetSlice(obj, a, b)
  #define __Pyx_PySequence_SetSlice(obj, a, b, value) PySequence_SetSlice(obj, a, b, value)
  #define __Pyx_PySequence_DelSlice(obj, a, b) PySequence_DelSlice(obj, a, b)
#else
  #define __Pyx_PySequence_GetSlice(obj, a, b) (unlikely(!(obj)) ? \
        (PyErr_SetString(PyExc_SystemError, "null argument to internal routine"), (PyObject*)0) : \
        (likely((obj)->ob_type->tp_as_mapping) ? (PySequence_GetSlice(obj, a, b)) : \
            (PyErr_Format(PyExc_TypeError, "'%.200s' object is unsliceable", (obj)->ob_type->tp_name), (PyObject*)0)))
  #define __Pyx_PySequence_SetSlice(obj, a, b, value) (unlikely(!(obj)) ? \
        (PyErr_SetString(PyExc_SystemError, "null argument to internal routine"), -1) : \
        (likely((obj)->ob_type->tp_as_mapping) ? (PySequence_SetSlice(obj, a, b, value)) : \
            (PyErr_Format(PyExc_TypeError, "'%.200s' object doesn't support slice assignment", (obj)->ob_type->tp_name), -1)))
  #define __Pyx_PySequence_DelSlice(obj, a, b) (unlikely(!(obj)) ? \
        (PyErr_SetString(PyExc_SystemError, "null argument to internal routine"), -1) : \
        (likely((obj)->ob_type->tp_as_mapping) ? (PySequence_DelSlice(obj, a, b)) : \
            (PyErr_Format(PyExc_TypeError, "'%.200s' object doesn't support slice deletion", (obj)->ob_type->tp_name), -1)))
#endif

#if PY_MAJOR_VERSION >= 3
  #define PyMethod_New(func, self, klass) ((self) ? PyMethod_New(func, self) : PyInstanceMethod_New(func))
#endif

#if PY_VERSION_HEX < 0x02050000
  #define __Pyx_GetAttrString(o,n)   PyObject_GetAttrString((o),((char *)(n)))
  #define __Pyx_SetAttrString(o,n,a) PyObject_SetAttrString((o),((char *)(n)),(a))
  #define __Pyx_DelAttrString(o,n)   PyObject_DelAttrString((o),((char *)(n)))
#else
  #define __Pyx_GetAttrString(o,n)   PyObject_GetAttrString((o),(n))
  #define __Pyx_SetAttrString(o,n,a) PyObject_SetAttrString((o),(n),(a))
  #define __Pyx_DelAttrString(o,n)   PyObject_DelAttrString((o),(n))
#endif

#if PY_VERSION_HEX < 0x02050000
  #define __Pyx_NAMESTR(n) ((char *)(n))
  #define __Pyx_DOCSTR(n)  ((char *)(n))
#else
  #define __Pyx_NAMESTR(n) (n)
  #define __Pyx_DOCSTR(n)  (n)
#endif

#ifdef __cplusplus
#define __PYX_EXTERN_C extern "C"
#else
#define __PYX_EXTERN_C extern
#endif

#if defined(WIN32) || defined(MS_WINDOWS)
#define _USE_MATH_DEFINES
#endif
#include <math.h>
#define __PYX_HAVE_API__bzrlib___known_graph_pyx
#include "python-compat.h"

#ifdef PYREX_WITHOUT_ASSERTIONS
#define CYTHON_WITHOUT_ASSERTIONS
#endif


/* inline attribute */
#ifndef CYTHON_INLINE
  #if defined(__GNUC__)
    #define CYTHON_INLINE __inline__
  #elif defined(_MSC_VER)
    #define CYTHON_INLINE __inline
  #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
    #define CYTHON_INLINE inline
  #else
    #define CYTHON_INLINE
  #endif
#endif

/* unused attribute */
#ifndef CYTHON_UNUSED
# if defined(__GNUC__)
#   if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4))
#     define CYTHON_UNUSED __attribute__ ((__unused__))
#   else
#     define CYTHON_UNUSED
#   endif
# elif defined(__ICC) || defined(__INTEL_COMPILER)
#   define CYTHON_UNUSED __attribute__ ((__unused__))
# else
#   define CYTHON_UNUSED
# endif
#endif

typedef struct {PyObject **p; char *s; const long n; const char* encoding; const char is_unicode; const char is_str; const char intern; } __Pyx_StringTabEntry; /*proto*/


/* Type Conversion Predeclarations */

#define __Pyx_PyBytes_FromUString(s) PyBytes_FromString((char*)s)
#define __Pyx_PyBytes_AsUString(s)   ((unsigned char*) PyBytes_AsString(s))

#define __Pyx_PyBool_FromLong(b) ((b) ? (Py_INCREF(Py_True), Py_True) : (Py_INCREF(Py_False), Py_False))
static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject*);
static CYTHON_INLINE PyObject* __Pyx_PyNumber_Int(PyObject* x);

static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject*);
static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t);
static CYTHON_INLINE size_t __Pyx_PyInt_AsSize_t(PyObject*);

#define __pyx_PyFloat_AsDouble(x) (PyFloat_CheckExact(x) ? PyFloat_AS_DOUBLE(x) : PyFloat_AsDouble(x))


#ifdef __GNUC__
/* Test for GCC > 2.95 */
#if __GNUC__ > 2 || (__GNUC__ == 2 && (__GNUC_MINOR__ > 95))
#define likely(x)   __builtin_expect(!!(x), 1)
#define unlikely(x) __builtin_expect(!!(x), 0)
#else /* __GNUC__ > 2 ... */
#define likely(x)   (x)
#define unlikely(x) (x)
#endif /* __GNUC__ > 2 ... */
#else /* __GNUC__ */
#define likely(x)   (x)
#define unlikely(x) (x)
#endif /* __GNUC__ */
    
static PyObject *__pyx_m;
static PyObject *__pyx_b;
static PyObject *__pyx_empty_tuple;
static PyObject *__pyx_empty_bytes;
static int __pyx_lineno;
static int __pyx_clineno = 0;
static const char * __pyx_cfilenm= __FILE__;
static const char *__pyx_filename;


static const char *__pyx_f[] = {
  "_known_graph_pyx.pyx",
};

/* Type declarations */

/* "bzrlib/_known_graph_pyx.pyx":666
 * 
 * 
 * cdef class _MergeSortNode:             # <<<<<<<<<<<<<<
 *     """Tracks information about a node during the merge_sort operation."""
 * 
 */

struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode {
  PyObject_HEAD
  struct __pyx_vtabstruct_6bzrlib_16_known_graph_pyx__MergeSortNode *__pyx_vtab;
  PyObject *key;
  long merge_depth;
  PyObject *end_of_merge;
  struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *left_parent;
  struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *left_pending_parent;
  PyObject *pending_parents;
  long _revno_first;
  long _revno_second;
  long _revno_last;
  int is_first_child;
  int seen_by_child;
  int completed;
};

/* "bzrlib/_known_graph_pyx.pyx":192
 * cdef class _MergeSorter
 * 
 * cdef class KnownGraph:             # <<<<<<<<<<<<<<
 *     """This is a class which assumes we already know the full graph."""
 * 
 */

struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph {
  PyObject_HEAD
  struct __pyx_vtabstruct_6bzrlib_16_known_graph_pyx_KnownGraph *__pyx_vtab;
  PyObject *_nodes;
  PyObject *_known_heads;
  int do_cache;
};

/* "bzrlib/_known_graph_pyx.pyx":63
 * 
 * 
 * cdef class _KnownGraphNode:             # <<<<<<<<<<<<<<
 *     """Represents a single object in the known graph."""
 * 
 */

struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode {
  PyObject_HEAD
  struct __pyx_vtabstruct_6bzrlib_16_known_graph_pyx__KnownGraphNode *__pyx_vtab;
  PyObject *key;
  PyObject *parents;
  PyObject *children;
  long gdfo;
  int seen;
  PyObject *extra;
};

/* "bzrlib/_known_graph_pyx.pyx":190
 * 
 * 
 * cdef class _MergeSorter             # <<<<<<<<<<<<<<
 * 
 * cdef class KnownGraph:
 */

struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSorter {
  PyObject_HEAD
  struct __pyx_vtabstruct_6bzrlib_16_known_graph_pyx__MergeSorter *__pyx_vtab;
  struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *graph;
  PyObject *_depth_first_stack;
  Py_ssize_t _last_stack_item;
  PyObject *_revno_to_branch_count;
  PyObject *_scheduled_nodes;
};


/* "bzrlib/_known_graph_pyx.pyx":724
 * 
 * 
 * cdef class _MergeSorter:             # <<<<<<<<<<<<<<
 *     """This class does the work of computing the merge_sort ordering.
 * 
 */

struct __pyx_vtabstruct_6bzrlib_16_known_graph_pyx__MergeSorter {
  struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *(*_get_ms_node)(struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSorter *, struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *);
  PyObject *(*_push_node)(struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSorter *, struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *, long);
  PyObject *(*_pop_node)(struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSorter *);
  PyObject *(*_schedule_stack)(struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSorter *);
  PyObject *(*topo_order)(struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSorter *);
};
static struct __pyx_vtabstruct_6bzrlib_16_known_graph_pyx__MergeSorter *__pyx_vtabptr_6bzrlib_16_known_graph_pyx__MergeSorter;


/* "bzrlib/_known_graph_pyx.pyx":63
 * 
 * 
 * cdef class _KnownGraphNode:             # <<<<<<<<<<<<<<
 *     """Represents a single object in the known graph."""
 * 
 */

struct __pyx_vtabstruct_6bzrlib_16_known_graph_pyx__KnownGraphNode {
  PyObject *(*clear_references)(struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *);
};
static struct __pyx_vtabstruct_6bzrlib_16_known_graph_pyx__KnownGraphNode *__pyx_vtabptr_6bzrlib_16_known_graph_pyx__KnownGraphNode;


/* "bzrlib/_known_graph_pyx.pyx":666
 * 
 * 
 * cdef class _MergeSortNode:             # <<<<<<<<<<<<<<
 *     """Tracks information about a node during the merge_sort operation."""
 * 
 */

struct __pyx_vtabstruct_6bzrlib_16_known_graph_pyx__MergeSortNode {
  int (*has_pending_parents)(struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *);
  PyObject *(*_revno)(struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *);
};
static struct __pyx_vtabstruct_6bzrlib_16_known_graph_pyx__MergeSortNode *__pyx_vtabptr_6bzrlib_16_known_graph_pyx__MergeSortNode;


/* "bzrlib/_known_graph_pyx.pyx":192
 * cdef class _MergeSorter
 * 
 * cdef class KnownGraph:             # <<<<<<<<<<<<<<
 *     """This is a class which assumes we already know the full graph."""
 * 
 */

struct __pyx_vtabstruct_6bzrlib_16_known_graph_pyx_KnownGraph {
  struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *(*_get_or_create_node)(struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *, PyObject *);
  PyObject *(*_populate_parents)(struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *, struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *, PyObject *);
};
static struct __pyx_vtabstruct_6bzrlib_16_known_graph_pyx_KnownGraph *__pyx_vtabptr_6bzrlib_16_known_graph_pyx_KnownGraph;

#ifndef CYTHON_REFNANNY
  #define CYTHON_REFNANNY 0
#endif

#if CYTHON_REFNANNY
  typedef struct {
    void (*INCREF)(void*, PyObject*, int);
    void (*DECREF)(void*, PyObject*, int);
    void (*GOTREF)(void*, PyObject*, int);
    void (*GIVEREF)(void*, PyObject*, int);
    void* (*SetupContext)(const char*, int, const char*);
    void (*FinishContext)(void**);
  } __Pyx_RefNannyAPIStruct;
  static __Pyx_RefNannyAPIStruct *__Pyx_RefNanny = NULL;
  static __Pyx_RefNannyAPIStruct * __Pyx_RefNannyImportAPI(const char *modname) {
    PyObject *m = NULL, *p = NULL;
    void *r = NULL;
    m = PyImport_ImportModule((char *)modname);
    if (!m) goto end;
    p = PyObject_GetAttrString(m, (char *)"RefNannyAPI");
    if (!p) goto end;
    r = PyLong_AsVoidPtr(p);
  end:
    Py_XDECREF(p);
    Py_XDECREF(m);
    return (__Pyx_RefNannyAPIStruct *)r;
  }
  #define __Pyx_RefNannySetupContext(name)           void *__pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__)
  #define __Pyx_RefNannyFinishContext()           __Pyx_RefNanny->FinishContext(&__pyx_refnanny)
  #define __Pyx_INCREF(r) __Pyx_RefNanny->INCREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
  #define __Pyx_DECREF(r) __Pyx_RefNanny->DECREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
  #define __Pyx_GOTREF(r) __Pyx_RefNanny->GOTREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
  #define __Pyx_GIVEREF(r) __Pyx_RefNanny->GIVEREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
  #define __Pyx_XDECREF(r) do { if((r) != NULL) {__Pyx_DECREF(r);} } while(0)
#else
  #define __Pyx_RefNannySetupContext(name)
  #define __Pyx_RefNannyFinishContext()
  #define __Pyx_INCREF(r) Py_INCREF(r)
  #define __Pyx_DECREF(r) Py_DECREF(r)
  #define __Pyx_GOTREF(r)
  #define __Pyx_GIVEREF(r)
  #define __Pyx_XDECREF(r) Py_XDECREF(r)
#endif /* CYTHON_REFNANNY */
#define __Pyx_XGIVEREF(r) do { if((r) != NULL) {__Pyx_GIVEREF(r);} } while(0)
#define __Pyx_XGOTREF(r) do { if((r) != NULL) {__Pyx_GOTREF(r);} } while(0)

static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name); /*proto*/

static void __Pyx_RaiseDoubleKeywordsError(
    const char* func_name, PyObject* kw_name); /*proto*/

static int __Pyx_ParseOptionalKeywords(PyObject *kwds, PyObject **argnames[],     PyObject *kwds2, PyObject *values[], Py_ssize_t num_pos_args,     const char* function_name); /*proto*/

static void __Pyx_RaiseArgtupleInvalid(const char* func_name, int exact,
    Py_ssize_t num_min, Py_ssize_t num_max, Py_ssize_t num_found); /*proto*/

static CYTHON_INLINE int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type); /*proto*/

static CYTHON_INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *value, PyObject *tb); /*proto*/
static CYTHON_INLINE void __Pyx_ErrFetch(PyObject **type, PyObject **value, PyObject **tb); /*proto*/

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


static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j) {
    PyObject *r;
    if (!j) return NULL;
    r = PyObject_GetItem(o, j);
    Py_DECREF(j);
    return r;
}


#define __Pyx_GetItemInt_List(o, i, size, to_py_func) (((size) <= sizeof(Py_ssize_t)) ? \
                                                    __Pyx_GetItemInt_List_Fast(o, i) : \
                                                    __Pyx_GetItemInt_Generic(o, to_py_func(i)))

static CYTHON_INLINE PyObject *__Pyx_GetItemInt_List_Fast(PyObject *o, Py_ssize_t i) {
    if (likely(o != Py_None)) {
        if (likely((0 <= i) & (i < PyList_GET_SIZE(o)))) {
            PyObject *r = PyList_GET_ITEM(o, i);
            Py_INCREF(r);
            return r;
        }
        else if ((-PyList_GET_SIZE(o) <= i) & (i < 0)) {
            PyObject *r = PyList_GET_ITEM(o, PyList_GET_SIZE(o) + i);
            Py_INCREF(r);
            return r;
        }
    }
    return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i));
}

#define __Pyx_GetItemInt_Tuple(o, i, size, to_py_func) (((size) <= sizeof(Py_ssize_t)) ? \
                                                    __Pyx_GetItemInt_Tuple_Fast(o, i) : \
                                                    __Pyx_GetItemInt_Generic(o, to_py_func(i)))

static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Tuple_Fast(PyObject *o, Py_ssize_t i) {
    if (likely(o != Py_None)) {
        if (likely((0 <= i) & (i < PyTuple_GET_SIZE(o)))) {
            PyObject *r = PyTuple_GET_ITEM(o, i);
            Py_INCREF(r);
            return r;
        }
        else if ((-PyTuple_GET_SIZE(o) <= i) & (i < 0)) {
            PyObject *r = PyTuple_GET_ITEM(o, PyTuple_GET_SIZE(o) + i);
            Py_INCREF(r);
            return r;
        }
    }
    return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i));
}


#define __Pyx_GetItemInt(o, i, size, to_py_func) (((size) <= sizeof(Py_ssize_t)) ? \
                                                    __Pyx_GetItemInt_Fast(o, i) : \
                                                    __Pyx_GetItemInt_Generic(o, to_py_func(i)))

static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i) {
    PyObject *r;
    if (PyList_CheckExact(o) && ((0 <= i) & (i < PyList_GET_SIZE(o)))) {
        r = PyList_GET_ITEM(o, i);
        Py_INCREF(r);
    }
    else if (PyTuple_CheckExact(o) && ((0 <= i) & (i < PyTuple_GET_SIZE(o)))) {
        r = PyTuple_GET_ITEM(o, i);
        Py_INCREF(r);
    }
    else if (Py_TYPE(o)->tp_as_sequence && Py_TYPE(o)->tp_as_sequence->sq_item && (likely(i >= 0))) {
        r = PySequence_GetItem(o, i);
    }
    else {
        r = __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i));
    }
    return r;
}

static CYTHON_INLINE long __Pyx_NegateNonNeg(long b) { return unlikely(b < 0) ? b : !b; }
static CYTHON_INLINE PyObject* __Pyx_PyBoolOrNull_FromLong(long b) {
    return unlikely(b < 0) ? NULL : __Pyx_PyBool_FromLong(b);
}

static CYTHON_INLINE PyObject* __Pyx_PyObject_Pop(PyObject* L) {
    PyObject *r, *m;
#if PY_VERSION_HEX >= 0x02040000
    if (likely(PyList_CheckExact(L))
            /* Check that both the size is positive and no reallocation shrinking needs to be done. */
            && likely(PyList_GET_SIZE(L) > (((PyListObject*)L)->allocated >> 1))) {
        Py_SIZE(L) -= 1;
        return PyList_GET_ITEM(L, PyList_GET_SIZE(L));
    }
#endif
    m = __Pyx_GetAttrString(L, "pop");
    if (!m) return NULL;
    r = PyObject_CallObject(m, NULL);
    Py_DECREF(m);
    return r;
}

static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list); /*proto*/

#if PY_VERSION_HEX < 0x02050000
#ifndef PyAnySet_CheckExact

#define PyAnySet_CheckExact(ob) \
    ((ob)->ob_type == &PySet_Type || \
     (ob)->ob_type == &PyFrozenSet_Type)

#define PySet_New(iterable) \
    PyObject_CallFunctionObjArgs((PyObject *)&PySet_Type, (iterable), NULL)

#define Pyx_PyFrozenSet_New(iterable) \
    PyObject_CallFunctionObjArgs((PyObject *)&PyFrozenSet_Type, (iterable), NULL)

#define PySet_Size(anyset) \
    PyObject_Size((anyset))

#define PySet_Contains(anyset, key) \
    PySequence_Contains((anyset), (key))

#define PySet_Pop(set) \
    PyObject_CallMethod(set, (char *)"pop", NULL)

static CYTHON_INLINE int PySet_Clear(PyObject *set) {
    PyObject *ret = PyObject_CallMethod(set, (char *)"clear", NULL);
    if (!ret) return -1;
    Py_DECREF(ret); return 0;
}

static CYTHON_INLINE int PySet_Discard(PyObject *set, PyObject *key) {
    PyObject *ret = PyObject_CallMethod(set, (char *)"discard", (char *)"O", key);
    if (!ret) return -1;
    Py_DECREF(ret); return 0;
}

static CYTHON_INLINE int PySet_Add(PyObject *set, PyObject *key) {
    PyObject *ret = PyObject_CallMethod(set, (char *)"add", (char *)"O", key);
    if (!ret) return -1;
    Py_DECREF(ret); return 0;
}

#endif /* PyAnySet_CheckExact (<= Py2.4) */

#if PY_VERSION_HEX < 0x02040000
#ifndef Py_SETOBJECT_H
#define Py_SETOBJECT_H

static PyTypeObject *__Pyx_PySet_Type = NULL;
static PyTypeObject *__Pyx_PyFrozenSet_Type = NULL;

#define PySet_Type (*__Pyx_PySet_Type)
#define PyFrozenSet_Type (*__Pyx_PyFrozenSet_Type)

#define PyAnySet_Check(ob) \
    (PyAnySet_CheckExact(ob) || \
     PyType_IsSubtype((ob)->ob_type, &PySet_Type) || \
     PyType_IsSubtype((ob)->ob_type, &PyFrozenSet_Type))

#define PyFrozenSet_CheckExact(ob) ((ob)->ob_type == &PyFrozenSet_Type)

static int __Pyx_Py23SetsImport(void) {
    PyObject *sets=0, *Set=0, *ImmutableSet=0;

    sets = PyImport_ImportModule((char *)"sets");
    if (!sets) goto bad;
    Set = PyObject_GetAttrString(sets, (char *)"Set");
    if (!Set) goto bad;
    ImmutableSet = PyObject_GetAttrString(sets, (char *)"ImmutableSet");
    if (!ImmutableSet) goto bad;
    Py_DECREF(sets);

    __Pyx_PySet_Type       = (PyTypeObject*) Set;
    __Pyx_PyFrozenSet_Type = (PyTypeObject*) ImmutableSet;

    return 0;

 bad:
    Py_XDECREF(sets);
    Py_XDECREF(Set);
    Py_XDECREF(ImmutableSet);
    return -1;
}

#else
static int __Pyx_Py23SetsImport(void) { return 0; }
#endif /* !Py_SETOBJECT_H */
#endif /* < Py2.4  */
#endif /* < Py2.5  */

static CYTHON_INLINE unsigned char __Pyx_PyInt_AsUnsignedChar(PyObject *);

static CYTHON_INLINE unsigned short __Pyx_PyInt_AsUnsignedShort(PyObject *);

static CYTHON_INLINE unsigned int __Pyx_PyInt_AsUnsignedInt(PyObject *);

static CYTHON_INLINE char __Pyx_PyInt_AsChar(PyObject *);

static CYTHON_INLINE short __Pyx_PyInt_AsShort(PyObject *);

static CYTHON_INLINE int __Pyx_PyInt_AsInt(PyObject *);

static CYTHON_INLINE signed char __Pyx_PyInt_AsSignedChar(PyObject *);

static CYTHON_INLINE signed short __Pyx_PyInt_AsSignedShort(PyObject *);

static CYTHON_INLINE signed int __Pyx_PyInt_AsSignedInt(PyObject *);

static CYTHON_INLINE int __Pyx_PyInt_AsLongDouble(PyObject *);

static CYTHON_INLINE unsigned long __Pyx_PyInt_AsUnsignedLong(PyObject *);

static CYTHON_INLINE unsigned PY_LONG_LONG __Pyx_PyInt_AsUnsignedLongLong(PyObject *);

static CYTHON_INLINE long __Pyx_PyInt_AsLong(PyObject *);

static CYTHON_INLINE PY_LONG_LONG __Pyx_PyInt_AsLongLong(PyObject *);

static CYTHON_INLINE signed long __Pyx_PyInt_AsSignedLong(PyObject *);

static CYTHON_INLINE signed PY_LONG_LONG __Pyx_PyInt_AsSignedLongLong(PyObject *);

static void __Pyx_WriteUnraisable(const char *name); /*proto*/

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

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

static int __Pyx_InitStrings(__Pyx_StringTabEntry *t); /*proto*/
/* Module declarations from bzrlib._known_graph_pyx */

static PyTypeObject *__pyx_ptype_6bzrlib_16_known_graph_pyx__KnownGraphNode = 0;
static PyTypeObject *__pyx_ptype_6bzrlib_16_known_graph_pyx__MergeSorter = 0;
static PyTypeObject *__pyx_ptype_6bzrlib_16_known_graph_pyx_KnownGraph = 0;
static PyTypeObject *__pyx_ptype_6bzrlib_16_known_graph_pyx__MergeSortNode = 0;
static PyObject *__pyx_v_6bzrlib_16_known_graph_pyx_NULL_REVISION = 0;
static struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *__pyx_f_6bzrlib_16_known_graph_pyx__get_list_node(PyObject *, Py_ssize_t); /*proto*/
static struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *__pyx_f_6bzrlib_16_known_graph_pyx__get_tuple_node(PyObject *, Py_ssize_t); /*proto*/
static PyObject *__pyx_f_6bzrlib_16_known_graph_pyx__sort_list_nodes(PyObject *, int); /*proto*/
#define __Pyx_MODULE_NAME "bzrlib._known_graph_pyx"
static int __pyx_module_is_main_bzrlib___known_graph_pyx = 0;

/* Implementation of bzrlib._known_graph_pyx */
static PyObject *__pyx_builtin_TypeError;
static PyObject *__pyx_builtin_ValueError;
static PyObject *__pyx_builtin_KeyError;
static PyObject *__pyx_builtin_sorted;
static PyObject *__pyx_builtin_RuntimeError;
static char __pyx_k_1[] = "%s(%s  gdfo:%s par:%s child:%s)";
static char __pyx_k_2[] = "lst_or_tpl must be a list or tuple.";
static char __pyx_k_5[] = "parent_map should be a dict of {key:parent_keys}";
static char __pyx_k_7[] = "Parent key mismatch, existing node %s has parents of %s not %s";
static char __pyx_k_8[] = "key %s not in nodes";
static char __pyx_k_9[] = "";
static char __pyx_k_10[] = "%s(%s depth:%s rev:%s,%s,%s first:%s seen:%s)";
static char __pyx_k_11[] = "Something wrong with: %s";
static char __pyx_k_12[] = "_revno_to_branch_count";
static char __pyx_k_13[] = "ghost nodes should not be pushed onto the stack: %s";
static char __pyx_k_14[] = "Implementation of Graph algorithms when we have already loaded everything.\n";
static char __pyx_k_15[] = "bzrlib._known_graph_pyx";
static char __pyx_k__gc[] = "gc";
static char __pyx_k__key[] = "key";
static char __pyx_k__pop[] = "pop";
static char __pyx_k__gdfo[] = "gdfo";
static char __pyx_k__seen[] = "seen";
static char __pyx_k__sort[] = "sort";
static char __pyx_k__clear[] = "clear";
static char __pyx_k__deque[] = "deque";
static char __pyx_k__extra[] = "extra";
static char __pyx_k__graph[] = "graph";
static char __pyx_k___nodes[] = "_nodes";
static char __pyx_k___revno[] = "_revno";
static char __pyx_k__append[] = "append";
static char __pyx_k__bzrlib[] = "bzrlib";
static char __pyx_k__errors[] = "errors";
static char __pyx_k__extend[] = "extend";
static char __pyx_k__sorted[] = "sorted";
static char __pyx_k__get_key[] = "get_key";
static char __pyx_k__parents[] = "parents";
static char __pyx_k__popleft[] = "popleft";
static char __pyx_k__reverse[] = "reverse";
static char __pyx_k__tip_key[] = "tip_key";
static char __pyx_k__KeyError[] = "KeyError";
static char __pyx_k____main__[] = "__main__";
static char __pyx_k____name__[] = "__name__";
static char __pyx_k____test__[] = "__test__";
static char __pyx_k__children[] = "children";
static char __pyx_k__do_cache[] = "do_cache";
static char __pyx_k__revision[] = "revision";
static char __pyx_k__TypeError[] = "TypeError";
static char __pyx_k____class__[] = "__class__";
static char __pyx_k___pop_node[] = "_pop_node";
static char __pyx_k__completed[] = "completed";
static char __pyx_k__ValueError[] = "ValueError";
static char __pyx_k___find_gdfo[] = "_find_gdfo";
static char __pyx_k___find_tips[] = "_find_tips";
static char __pyx_k___push_node[] = "_push_node";
static char __pyx_k__child_keys[] = "child_keys";
static char __pyx_k__parent_map[] = "parent_map";
static char __pyx_k__topo_order[] = "topo_order";
static char __pyx_k___find_tails[] = "_find_tails";
static char __pyx_k___revno_last[] = "_revno_last";
static char __pyx_k__collections[] = "collections";
static char __pyx_k__known_graph[] = "known_graph";
static char __pyx_k__left_parent[] = "left_parent";
static char __pyx_k__merge_depth[] = "merge_depth";
static char __pyx_k__parent_keys[] = "parent_keys";
static char __pyx_k__RuntimeError[] = "RuntimeError";
static char __pyx_k___get_ms_node[] = "_get_ms_node";
static char __pyx_k___known_heads[] = "_known_heads";
static char __pyx_k___revno_first[] = "_revno_first";
static char __pyx_k__end_of_merge[] = "end_of_merge";
static char __pyx_k__NULL_REVISION[] = "NULL_REVISION";
static char __pyx_k___revno_second[] = "_revno_second";
static char __pyx_k__seen_by_child[] = "seen_by_child";
static char __pyx_k__is_first_child[] = "is_first_child";
static char __pyx_k__GraphCycleError[] = "GraphCycleError";
static char __pyx_k___schedule_stack[] = "_schedule_stack";
static char __pyx_k__pending_parents[] = "pending_parents";
static char __pyx_k___last_stack_item[] = "_last_stack_item";
static char __pyx_k___scheduled_nodes[] = "_scheduled_nodes";
static char __pyx_k__clear_references[] = "clear_references";
static char __pyx_k___initialize_nodes[] = "_initialize_nodes";
static char __pyx_k___populate_parents[] = "_populate_parents";
static char __pyx_k___depth_first_stack[] = "_depth_first_stack";
static char __pyx_k___get_or_create_node[] = "_get_or_create_node";
static char __pyx_k__has_pending_parents[] = "has_pending_parents";
static char __pyx_k__left_pending_parent[] = "left_pending_parent";
static PyObject *__pyx_kp_s_1;
static PyObject *__pyx_kp_s_10;
static PyObject *__pyx_kp_s_11;
static PyObject *__pyx_n_s_12;
static PyObject *__pyx_kp_s_13;
static PyObject *__pyx_n_s_15;
static PyObject *__pyx_kp_s_2;
static PyObject *__pyx_kp_s_5;
static PyObject *__pyx_kp_s_7;
static PyObject *__pyx_kp_s_8;
static PyObject *__pyx_kp_s_9;
static PyObject *__pyx_n_s__GraphCycleError;
static PyObject *__pyx_n_s__KeyError;
static PyObject *__pyx_n_s__NULL_REVISION;
static PyObject *__pyx_n_s__RuntimeError;
static PyObject *__pyx_n_s__TypeError;
static PyObject *__pyx_n_s__ValueError;
static PyObject *__pyx_n_s____class__;
static PyObject *__pyx_n_s____main__;
static PyObject *__pyx_n_s____name__;
static PyObject *__pyx_n_s____test__;
static PyObject *__pyx_n_s___depth_first_stack;
static PyObject *__pyx_n_s___find_gdfo;
static PyObject *__pyx_n_s___find_tails;
static PyObject *__pyx_n_s___find_tips;
static PyObject *__pyx_n_s___get_ms_node;
static PyObject *__pyx_n_s___get_or_create_node;
static PyObject *__pyx_n_s___initialize_nodes;
static PyObject *__pyx_n_s___known_heads;
static PyObject *__pyx_n_s___last_stack_item;
static PyObject *__pyx_n_s___nodes;
static PyObject *__pyx_n_s___pop_node;
static PyObject *__pyx_n_s___populate_parents;
static PyObject *__pyx_n_s___push_node;
static PyObject *__pyx_n_s___revno;
static PyObject *__pyx_n_s___revno_first;
static PyObject *__pyx_n_s___revno_last;
static PyObject *__pyx_n_s___revno_second;
static PyObject *__pyx_n_s___schedule_stack;
static PyObject *__pyx_n_s___scheduled_nodes;
static PyObject *__pyx_n_s__append;
static PyObject *__pyx_n_s__bzrlib;
static PyObject *__pyx_n_s__child_keys;
static PyObject *__pyx_n_s__children;
static PyObject *__pyx_n_s__clear;
static PyObject *__pyx_n_s__clear_references;
static PyObject *__pyx_n_s__collections;
static PyObject *__pyx_n_s__completed;
static PyObject *__pyx_n_s__deque;
static PyObject *__pyx_n_s__do_cache;
static PyObject *__pyx_n_s__end_of_merge;
static PyObject *__pyx_n_s__errors;
static PyObject *__pyx_n_s__extend;
static PyObject *__pyx_n_s__extra;
static PyObject *__pyx_n_s__gc;
static PyObject *__pyx_n_s__gdfo;
static PyObject *__pyx_n_s__get_key;
static PyObject *__pyx_n_s__graph;
static PyObject *__pyx_n_s__has_pending_parents;
static PyObject *__pyx_n_s__is_first_child;
static PyObject *__pyx_n_s__key;
static PyObject *__pyx_n_s__known_graph;
static PyObject *__pyx_n_s__left_parent;
static PyObject *__pyx_n_s__left_pending_parent;
static PyObject *__pyx_n_s__merge_depth;
static PyObject *__pyx_n_s__parent_keys;
static PyObject *__pyx_n_s__parent_map;
static PyObject *__pyx_n_s__parents;
static PyObject *__pyx_n_s__pending_parents;
static PyObject *__pyx_n_s__pop;
static PyObject *__pyx_n_s__popleft;
static PyObject *__pyx_n_s__reverse;
static PyObject *__pyx_n_s__revision;
static PyObject *__pyx_n_s__seen;
static PyObject *__pyx_n_s__seen_by_child;
static PyObject *__pyx_n_s__sort;
static PyObject *__pyx_n_s__sorted;
static PyObject *__pyx_n_s__tip_key;
static PyObject *__pyx_n_s__topo_order;
static PyObject *__pyx_int_0;
static PyObject *__pyx_int_1;
static PyObject *__pyx_k_4;
static PyObject *__pyx_k_tuple_3;
static PyObject *__pyx_k_tuple_6;

/* "bzrlib/_known_graph_pyx.pyx":73
 *     cdef object extra
 * 
 *     def __init__(self, key):             # <<<<<<<<<<<<<<
 *         self.key = key
 *         self.parents = None
 */

static int __pyx_pf_6bzrlib_16_known_graph_pyx_15_KnownGraphNode___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_pf_6bzrlib_16_known_graph_pyx_15_KnownGraphNode___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_key = 0;
  int __pyx_r;
  PyObject *__pyx_t_1 = NULL;
  static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__key,0};
  __Pyx_RefNannySetupContext("__init__");
  if (unlikely(__pyx_kwds)) {
    Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
    PyObject* values[1] = {0};
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      case  0: break;
      default: goto __pyx_L5_argtuple_error;
    }
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  0:
      values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__key);
      if (likely(values[0])) kw_args--;
      else goto __pyx_L5_argtuple_error;
    }
    if (unlikely(kw_args > 0)) {
      if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "__init__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 73; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    }
    __pyx_v_key = values[0];
  } else if (PyTuple_GET_SIZE(__pyx_args) != 1) {
    goto __pyx_L5_argtuple_error;
  } else {
    __pyx_v_key = PyTuple_GET_ITEM(__pyx_args, 0);
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("__init__", 1, 1, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 73; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("bzrlib._known_graph_pyx._KnownGraphNode.__init__");
  __Pyx_RefNannyFinishContext();
  return -1;
  __pyx_L4_argument_unpacking_done:;

  /* "bzrlib/_known_graph_pyx.pyx":74
 * 
 *     def __init__(self, key):
 *         self.key = key             # <<<<<<<<<<<<<<
 *         self.parents = None
 * 
 */
  __Pyx_INCREF(__pyx_v_key);
  __Pyx_GIVEREF(__pyx_v_key);
  __Pyx_GOTREF(((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_v_self)->key);
  __Pyx_DECREF(((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_v_self)->key);
  ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_v_self)->key = __pyx_v_key;

  /* "bzrlib/_known_graph_pyx.pyx":75
 *     def __init__(self, key):
 *         self.key = key
 *         self.parents = None             # <<<<<<<<<<<<<<
 * 
 *         self.children = []
 */
  __Pyx_INCREF(Py_None);
  __Pyx_GIVEREF(Py_None);
  __Pyx_GOTREF(((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_v_self)->parents);
  __Pyx_DECREF(((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_v_self)->parents);
  ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_v_self)->parents = Py_None;

  /* "bzrlib/_known_graph_pyx.pyx":77
 *         self.parents = None
 * 
 *         self.children = []             # <<<<<<<<<<<<<<
 *         # Greatest distance from origin
 *         self.gdfo = -1
 */
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_1));
  __Pyx_GIVEREF(((PyObject *)__pyx_t_1));
  __Pyx_GOTREF(((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_v_self)->children);
  __Pyx_DECREF(((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_v_self)->children);
  ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_v_self)->children = ((PyObject *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "bzrlib/_known_graph_pyx.pyx":79
 *         self.children = []
 *         # Greatest distance from origin
 *         self.gdfo = -1             # <<<<<<<<<<<<<<
 *         self.seen = 0
 *         self.extra = None
 */
  ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_v_self)->gdfo = -1;

  /* "bzrlib/_known_graph_pyx.pyx":80
 *         # Greatest distance from origin
 *         self.gdfo = -1
 *         self.seen = 0             # <<<<<<<<<<<<<<
 *         self.extra = None
 * 
 */
  ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_v_self)->seen = 0;

  /* "bzrlib/_known_graph_pyx.pyx":81
 *         self.gdfo = -1
 *         self.seen = 0
 *         self.extra = None             # <<<<<<<<<<<<<<
 * 
 *     property child_keys:
 */
  __Pyx_INCREF(Py_None);
  __Pyx_GIVEREF(Py_None);
  __Pyx_GOTREF(((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_v_self)->extra);
  __Pyx_DECREF(((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_v_self)->extra);
  ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_v_self)->extra = Py_None;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("bzrlib._known_graph_pyx._KnownGraphNode.__init__");
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "bzrlib/_known_graph_pyx.pyx":84
 * 
 *     property child_keys:
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             cdef _KnownGraphNode child
 * 
 */

static PyObject *__pyx_pf_6bzrlib_16_known_graph_pyx_15_KnownGraphNode_10child_keys___get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pf_6bzrlib_16_known_graph_pyx_15_KnownGraphNode_10child_keys___get__(PyObject *__pyx_v_self) {
  struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *__pyx_v_child;
  PyObject *__pyx_v_keys;
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  Py_ssize_t __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_t_4;
  __Pyx_RefNannySetupContext("__get__");
  __pyx_v_child = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)Py_None); __Pyx_INCREF(Py_None);
  __pyx_v_keys = ((PyObject*)Py_None); __Pyx_INCREF(Py_None);

  /* "bzrlib/_known_graph_pyx.pyx":87
 *             cdef _KnownGraphNode child
 * 
 *             keys = []             # <<<<<<<<<<<<<<
 *             for child in self.children:
 *                 PyList_Append(keys, child.key)
 */
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 87; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_1));
  __Pyx_DECREF(((PyObject *)__pyx_v_keys));
  __pyx_v_keys = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "bzrlib/_known_graph_pyx.pyx":88
 * 
 *             keys = []
 *             for child in self.children:             # <<<<<<<<<<<<<<
 *                 PyList_Append(keys, child.key)
 *             return keys
 */
  if (PyList_CheckExact(((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_v_self)->children) || PyTuple_CheckExact(((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_v_self)->children)) {
    __pyx_t_2 = 0; __pyx_t_1 = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_v_self)->children; __Pyx_INCREF(__pyx_t_1);
  } else {
    __pyx_t_2 = -1; __pyx_t_1 = PyObject_GetIter(((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_v_self)->children); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
  }
  for (;;) {
    if (likely(PyList_CheckExact(__pyx_t_1))) {
      if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_1)) break;
      __pyx_t_3 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_3); __pyx_t_2++;
    } else if (likely(PyTuple_CheckExact(__pyx_t_1))) {
      if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
      __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_3); __pyx_t_2++;
    } else {
      __pyx_t_3 = PyIter_Next(__pyx_t_1);
      if (!__pyx_t_3) {
        if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        break;
      }
      __Pyx_GOTREF(__pyx_t_3);
    }
    if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_6bzrlib_16_known_graph_pyx__KnownGraphNode))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(((PyObject *)__pyx_v_child));
    __pyx_v_child = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_t_3);
    __pyx_t_3 = 0;

    /* "bzrlib/_known_graph_pyx.pyx":89
 *             keys = []
 *             for child in self.children:
 *                 PyList_Append(keys, child.key)             # <<<<<<<<<<<<<<
 *             return keys
 * 
 */
    __pyx_t_3 = __pyx_v_child->key;
    __Pyx_INCREF(__pyx_t_3);
    __pyx_t_4 = PyList_Append(((PyObject *)__pyx_v_keys), __pyx_t_3); if (unlikely(__pyx_t_4 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 89; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "bzrlib/_known_graph_pyx.pyx":90
 *             for child in self.children:
 *                 PyList_Append(keys, child.key)
 *             return keys             # <<<<<<<<<<<<<<
 * 
 *     property parent_keys:
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(((PyObject *)__pyx_v_keys));
  __pyx_r = ((PyObject *)__pyx_v_keys);
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("bzrlib._known_graph_pyx._KnownGraphNode.child_keys.__get__");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_DECREF((PyObject *)__pyx_v_child);
  __Pyx_DECREF(__pyx_v_keys);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "bzrlib/_known_graph_pyx.pyx":93
 * 
 *     property parent_keys:
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             if self.parents is None:
 *                 return None
 */

static PyObject *__pyx_pf_6bzrlib_16_known_graph_pyx_15_KnownGraphNode_11parent_keys___get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pf_6bzrlib_16_known_graph_pyx_15_KnownGraphNode_11parent_keys___get__(PyObject *__pyx_v_self) {
  struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *__pyx_v_parent;
  PyObject *__pyx_v_keys;
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  Py_ssize_t __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_t_5;
  __Pyx_RefNannySetupContext("__get__");
  __pyx_v_parent = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)Py_None); __Pyx_INCREF(Py_None);
  __pyx_v_keys = ((PyObject*)Py_None); __Pyx_INCREF(Py_None);

  /* "bzrlib/_known_graph_pyx.pyx":94
 *     property parent_keys:
 *         def __get__(self):
 *             if self.parents is None:             # <<<<<<<<<<<<<<
 *                 return None
 * 
 */
  __pyx_t_1 = (((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_v_self)->parents == Py_None);
  if (__pyx_t_1) {

    /* "bzrlib/_known_graph_pyx.pyx":95
 *         def __get__(self):
 *             if self.parents is None:
 *                 return None             # <<<<<<<<<<<<<<
 * 
 *             cdef _KnownGraphNode parent
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(Py_None);
    __pyx_r = Py_None;
    goto __pyx_L0;
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "bzrlib/_known_graph_pyx.pyx":99
 *             cdef _KnownGraphNode parent
 * 
 *             keys = []             # <<<<<<<<<<<<<<
 *             for parent in self.parents:
 *                 PyList_Append(keys, parent.key)
 */
  __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 99; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_2));
  __Pyx_DECREF(((PyObject *)__pyx_v_keys));
  __pyx_v_keys = __pyx_t_2;
  __pyx_t_2 = 0;

  /* "bzrlib/_known_graph_pyx.pyx":100
 * 
 *             keys = []
 *             for parent in self.parents:             # <<<<<<<<<<<<<<
 *                 PyList_Append(keys, parent.key)
 *             return keys
 */
  if (PyList_CheckExact(((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_v_self)->parents) || PyTuple_CheckExact(((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_v_self)->parents)) {
    __pyx_t_3 = 0; __pyx_t_2 = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_v_self)->parents; __Pyx_INCREF(__pyx_t_2);
  } else {
    __pyx_t_3 = -1; __pyx_t_2 = PyObject_GetIter(((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_v_self)->parents); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
  }
  for (;;) {
    if (likely(PyList_CheckExact(__pyx_t_2))) {
      if (__pyx_t_3 >= PyList_GET_SIZE(__pyx_t_2)) break;
      __pyx_t_4 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_3); __Pyx_INCREF(__pyx_t_4); __pyx_t_3++;
    } else if (likely(PyTuple_CheckExact(__pyx_t_2))) {
      if (__pyx_t_3 >= PyTuple_GET_SIZE(__pyx_t_2)) break;
      __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_3); __Pyx_INCREF(__pyx_t_4); __pyx_t_3++;
    } else {
      __pyx_t_4 = PyIter_Next(__pyx_t_2);
      if (!__pyx_t_4) {
        if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        break;
      }
      __Pyx_GOTREF(__pyx_t_4);
    }
    if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_ptype_6bzrlib_16_known_graph_pyx__KnownGraphNode))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(((PyObject *)__pyx_v_parent));
    __pyx_v_parent = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_t_4);
    __pyx_t_4 = 0;

    /* "bzrlib/_known_graph_pyx.pyx":101
 *             keys = []
 *             for parent in self.parents:
 *                 PyList_Append(keys, parent.key)             # <<<<<<<<<<<<<<
 *             return keys
 * 
 */
    __pyx_t_4 = __pyx_v_parent->key;
    __Pyx_INCREF(__pyx_t_4);
    __pyx_t_5 = PyList_Append(((PyObject *)__pyx_v_keys), __pyx_t_4); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 101; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "bzrlib/_known_graph_pyx.pyx":102
 *             for parent in self.parents:
 *                 PyList_Append(keys, parent.key)
 *             return keys             # <<<<<<<<<<<<<<
 * 
 *     cdef clear_references(self):
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(((PyObject *)__pyx_v_keys));
  __pyx_r = ((PyObject *)__pyx_v_keys);
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("bzrlib._known_graph_pyx._KnownGraphNode.parent_keys.__get__");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_DECREF((PyObject *)__pyx_v_parent);
  __Pyx_DECREF(__pyx_v_keys);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "bzrlib/_known_graph_pyx.pyx":104
 *             return keys
 * 
 *     cdef clear_references(self):             # <<<<<<<<<<<<<<
 *         self.parents = None
 *         self.children = None
 */

static  PyObject *__pyx_f_6bzrlib_16_known_graph_pyx_15_KnownGraphNode_clear_references(struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannySetupContext("clear_references");

  /* "bzrlib/_known_graph_pyx.pyx":105
 * 
 *     cdef clear_references(self):
 *         self.parents = None             # <<<<<<<<<<<<<<
 *         self.children = None
 * 
 */
  __Pyx_INCREF(Py_None);
  __Pyx_GIVEREF(Py_None);
  __Pyx_GOTREF(__pyx_v_self->parents);
  __Pyx_DECREF(__pyx_v_self->parents);
  __pyx_v_self->parents = Py_None;

  /* "bzrlib/_known_graph_pyx.pyx":106
 *     cdef clear_references(self):
 *         self.parents = None
 *         self.children = None             # <<<<<<<<<<<<<<
 * 
 *     def __repr__(self):
 */
  __Pyx_INCREF(Py_None);
  __Pyx_GIVEREF(Py_None);
  __Pyx_GOTREF(__pyx_v_self->children);
  __Pyx_DECREF(__pyx_v_self->children);
  __pyx_v_self->children = Py_None;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "bzrlib/_known_graph_pyx.pyx":108
 *         self.children = None
 * 
 *     def __repr__(self):             # <<<<<<<<<<<<<<
 *         cdef _KnownGraphNode node
 * 
 */

static PyObject *__pyx_pf_6bzrlib_16_known_graph_pyx_15_KnownGraphNode_1__repr__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pf_6bzrlib_16_known_graph_pyx_15_KnownGraphNode_1__repr__(PyObject *__pyx_v_self) {
  struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *__pyx_v_node;
  PyObject *__pyx_v_parent_keys;
  PyObject *__pyx_v_child_keys;
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  Py_ssize_t __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_t_5;
  PyObject *__pyx_t_6 = NULL;
  __Pyx_RefNannySetupContext("__repr__");
  __pyx_v_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)Py_None); __Pyx_INCREF(Py_None);
  __pyx_v_parent_keys = ((PyObject*)Py_None); __Pyx_INCREF(Py_None);
  __pyx_v_child_keys = ((PyObject*)Py_None); __Pyx_INCREF(Py_None);

  /* "bzrlib/_known_graph_pyx.pyx":111
 *         cdef _KnownGraphNode node
 * 
 *         parent_keys = []             # <<<<<<<<<<<<<<
 *         if self.parents is not None:
 *             for node in self.parents:
 */
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 111; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_1));
  __Pyx_DECREF(((PyObject *)__pyx_v_parent_keys));
  __pyx_v_parent_keys = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "bzrlib/_known_graph_pyx.pyx":112
 * 
 *         parent_keys = []
 *         if self.parents is not None:             # <<<<<<<<<<<<<<
 *             for node in self.parents:
 *                 parent_keys.append(node.key)
 */
  __pyx_t_2 = (((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_v_self)->parents != Py_None);
  if (__pyx_t_2) {

    /* "bzrlib/_known_graph_pyx.pyx":113
 *         parent_keys = []
 *         if self.parents is not None:
 *             for node in self.parents:             # <<<<<<<<<<<<<<
 *                 parent_keys.append(node.key)
 *         child_keys = []
 */
    if (PyList_CheckExact(((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_v_self)->parents) || PyTuple_CheckExact(((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_v_self)->parents)) {
      __pyx_t_3 = 0; __pyx_t_1 = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_v_self)->parents; __Pyx_INCREF(__pyx_t_1);
    } else {
      __pyx_t_3 = -1; __pyx_t_1 = PyObject_GetIter(((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_v_self)->parents); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 113; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
    }
    for (;;) {
      if (likely(PyList_CheckExact(__pyx_t_1))) {
        if (__pyx_t_3 >= PyList_GET_SIZE(__pyx_t_1)) break;
        __pyx_t_4 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_3); __Pyx_INCREF(__pyx_t_4); __pyx_t_3++;
      } else if (likely(PyTuple_CheckExact(__pyx_t_1))) {
        if (__pyx_t_3 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
        __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_3); __Pyx_INCREF(__pyx_t_4); __pyx_t_3++;
      } else {
        __pyx_t_4 = PyIter_Next(__pyx_t_1);
        if (!__pyx_t_4) {
          if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 113; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          break;
        }
        __Pyx_GOTREF(__pyx_t_4);
      }
      if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_ptype_6bzrlib_16_known_graph_pyx__KnownGraphNode))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 113; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(((PyObject *)__pyx_v_node));
      __pyx_v_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_t_4);
      __pyx_t_4 = 0;

      /* "bzrlib/_known_graph_pyx.pyx":114
 *         if self.parents is not None:
 *             for node in self.parents:
 *                 parent_keys.append(node.key)             # <<<<<<<<<<<<<<
 *         child_keys = []
 *         if self.children is not None:
 */
      if (unlikely(__pyx_v_parent_keys == Py_None)) {
        PyErr_SetString(PyExc_AttributeError, "'NoneType' object has no attribute 'append'"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 114; __pyx_clineno = __LINE__; goto __pyx_L1_error;} 
      }
      __pyx_t_4 = __pyx_v_node->key;
      __Pyx_INCREF(__pyx_t_4);
      __pyx_t_5 = PyList_Append(__pyx_v_parent_keys, __pyx_t_4); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 114; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "bzrlib/_known_graph_pyx.pyx":115
 *             for node in self.parents:
 *                 parent_keys.append(node.key)
 *         child_keys = []             # <<<<<<<<<<<<<<
 *         if self.children is not None:
 *             for node in self.children:
 */
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 115; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_1));
  __Pyx_DECREF(((PyObject *)__pyx_v_child_keys));
  __pyx_v_child_keys = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "bzrlib/_known_graph_pyx.pyx":116
 *                 parent_keys.append(node.key)
 *         child_keys = []
 *         if self.children is not None:             # <<<<<<<<<<<<<<
 *             for node in self.children:
 *                 child_keys.append(node.key)
 */
  __pyx_t_2 = (((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_v_self)->children != Py_None);
  if (__pyx_t_2) {

    /* "bzrlib/_known_graph_pyx.pyx":117
 *         child_keys = []
 *         if self.children is not None:
 *             for node in self.children:             # <<<<<<<<<<<<<<
 *                 child_keys.append(node.key)
 *         return '%s(%s  gdfo:%s par:%s child:%s)' % (
 */
    if (PyList_CheckExact(((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_v_self)->children) || PyTuple_CheckExact(((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_v_self)->children)) {
      __pyx_t_3 = 0; __pyx_t_1 = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_v_self)->children; __Pyx_INCREF(__pyx_t_1);
    } else {
      __pyx_t_3 = -1; __pyx_t_1 = PyObject_GetIter(((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_v_self)->children); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 117; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
    }
    for (;;) {
      if (likely(PyList_CheckExact(__pyx_t_1))) {
        if (__pyx_t_3 >= PyList_GET_SIZE(__pyx_t_1)) break;
        __pyx_t_4 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_3); __Pyx_INCREF(__pyx_t_4); __pyx_t_3++;
      } else if (likely(PyTuple_CheckExact(__pyx_t_1))) {
        if (__pyx_t_3 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
        __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_3); __Pyx_INCREF(__pyx_t_4); __pyx_t_3++;
      } else {
        __pyx_t_4 = PyIter_Next(__pyx_t_1);
        if (!__pyx_t_4) {
          if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 117; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          break;
        }
        __Pyx_GOTREF(__pyx_t_4);
      }
      if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_ptype_6bzrlib_16_known_graph_pyx__KnownGraphNode))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 117; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(((PyObject *)__pyx_v_node));
      __pyx_v_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_t_4);
      __pyx_t_4 = 0;

      /* "bzrlib/_known_graph_pyx.pyx":118
 *         if self.children is not None:
 *             for node in self.children:
 *                 child_keys.append(node.key)             # <<<<<<<<<<<<<<
 *         return '%s(%s  gdfo:%s par:%s child:%s)' % (
 *             self.__class__.__name__, self.key, self.gdfo,
 */
      if (unlikely(__pyx_v_child_keys == Py_None)) {
        PyErr_SetString(PyExc_AttributeError, "'NoneType' object has no attribute 'append'"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 118; __pyx_clineno = __LINE__; goto __pyx_L1_error;} 
      }
      __pyx_t_4 = __pyx_v_node->key;
      __Pyx_INCREF(__pyx_t_4);
      __pyx_t_5 = PyList_Append(__pyx_v_child_keys, __pyx_t_4); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 118; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    goto __pyx_L8;
  }
  __pyx_L8:;

  /* "bzrlib/_known_graph_pyx.pyx":119
 *             for node in self.children:
 *                 child_keys.append(node.key)
 *         return '%s(%s  gdfo:%s par:%s child:%s)' % (             # <<<<<<<<<<<<<<
 *             self.__class__.__name__, self.key, self.gdfo,
 *             parent_keys, child_keys)
 */
  __Pyx_XDECREF(__pyx_r);

  /* "bzrlib/_known_graph_pyx.pyx":120
 *                 child_keys.append(node.key)
 *         return '%s(%s  gdfo:%s par:%s child:%s)' % (
 *             self.__class__.__name__, self.key, self.gdfo,             # <<<<<<<<<<<<<<
 *             parent_keys, child_keys)
 * 
 */
  __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s____class__); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 120; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_4 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s____name__); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 120; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyInt_FromLong(((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_v_self)->gdfo); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 120; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);

  /* "bzrlib/_known_graph_pyx.pyx":121
 *         return '%s(%s  gdfo:%s par:%s child:%s)' % (
 *             self.__class__.__name__, self.key, self.gdfo,
 *             parent_keys, child_keys)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_6 = PyTuple_New(5); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 120; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_6));
  PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_4);
  __Pyx_INCREF(((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_v_self)->key);
  PyTuple_SET_ITEM(__pyx_t_6, 1, ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_v_self)->key);
  __Pyx_GIVEREF(((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_v_self)->key);
  PyTuple_SET_ITEM(__pyx_t_6, 2, __pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_1);
  __Pyx_INCREF(((PyObject *)__pyx_v_parent_keys));
  PyTuple_SET_ITEM(__pyx_t_6, 3, ((PyObject *)__pyx_v_parent_keys));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_parent_keys));
  __Pyx_INCREF(((PyObject *)__pyx_v_child_keys));
  PyTuple_SET_ITEM(__pyx_t_6, 4, ((PyObject *)__pyx_v_child_keys));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_child_keys));
  __pyx_t_4 = 0;
  __pyx_t_1 = 0;
  __pyx_t_1 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_1), ((PyObject *)__pyx_t_6)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 119; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_1));
  __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0;
  __pyx_r = ((PyObject *)__pyx_t_1);
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_AddTraceback("bzrlib._known_graph_pyx._KnownGraphNode.__repr__");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_DECREF((PyObject *)__pyx_v_node);
  __Pyx_DECREF(__pyx_v_parent_keys);
  __Pyx_DECREF(__pyx_v_child_keys);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "bzrlib/_known_graph_pyx.pyx":69
 *     cdef object parents
 *     cdef object children
 *     cdef public long gdfo             # <<<<<<<<<<<<<<
 *     cdef int seen
 *     cdef object extra
 */

static PyObject *__pyx_pf_6bzrlib_16_known_graph_pyx_15_KnownGraphNode_4gdfo___get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pf_6bzrlib_16_known_graph_pyx_15_KnownGraphNode_4gdfo___get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  __Pyx_RefNannySetupContext("__get__");
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyInt_FromLong(((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_v_self)->gdfo); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("bzrlib._known_graph_pyx._KnownGraphNode.gdfo.__get__");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_6bzrlib_16_known_graph_pyx_15_KnownGraphNode_4gdfo_1__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/
static int __pyx_pf_6bzrlib_16_known_graph_pyx_15_KnownGraphNode_4gdfo_1__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) {
  int __pyx_r;
  long __pyx_t_1;
  __Pyx_RefNannySetupContext("__set__");
  __pyx_t_1 = __Pyx_PyInt_AsLong(__pyx_v_value); if (unlikely((__pyx_t_1 == (long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_v_self)->gdfo = __pyx_t_1;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("bzrlib._known_graph_pyx._KnownGraphNode.gdfo.__set__");
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "bzrlib/_known_graph_pyx.pyx":124
 * 
 * 
 * cdef _KnownGraphNode _get_list_node(lst, Py_ssize_t pos):             # <<<<<<<<<<<<<<
 *     cdef PyObject *temp_node
 * 
 */

static  struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *__pyx_f_6bzrlib_16_known_graph_pyx__get_list_node(PyObject *__pyx_v_lst, Py_ssize_t __pyx_v_pos) {
  PyObject *__pyx_v_temp_node;
  struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *__pyx_r = NULL;
  __Pyx_RefNannySetupContext("_get_list_node");

  /* "bzrlib/_known_graph_pyx.pyx":127
 *     cdef PyObject *temp_node
 * 
 *     temp_node = PyList_GET_ITEM(lst, pos)             # <<<<<<<<<<<<<<
 *     return <_KnownGraphNode>temp_node
 * 
 */
  __pyx_v_temp_node = PyList_GET_ITEM(__pyx_v_lst, __pyx_v_pos);

  /* "bzrlib/_known_graph_pyx.pyx":128
 * 
 *     temp_node = PyList_GET_ITEM(lst, pos)
 *     return <_KnownGraphNode>temp_node             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(((PyObject *)__pyx_r));
  __Pyx_INCREF(((PyObject *)((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_v_temp_node)));
  __pyx_r = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_v_temp_node);
  goto __pyx_L0;

  __pyx_r = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)Py_None); __Pyx_INCREF(Py_None);
  __pyx_L0:;
  __Pyx_XGIVEREF((PyObject *)__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "bzrlib/_known_graph_pyx.pyx":131
 * 
 * 
 * cdef _KnownGraphNode _get_tuple_node(tpl, Py_ssize_t pos):             # <<<<<<<<<<<<<<
 *     cdef PyObject *temp_node
 * 
 */

static  struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *__pyx_f_6bzrlib_16_known_graph_pyx__get_tuple_node(PyObject *__pyx_v_tpl, Py_ssize_t __pyx_v_pos) {
  PyObject *__pyx_v_temp_node;
  struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *__pyx_r = NULL;
  __Pyx_RefNannySetupContext("_get_tuple_node");

  /* "bzrlib/_known_graph_pyx.pyx":134
 *     cdef PyObject *temp_node
 * 
 *     temp_node = PyTuple_GET_ITEM(tpl, pos)             # <<<<<<<<<<<<<<
 *     return <_KnownGraphNode>temp_node
 * 
 */
  __pyx_v_temp_node = PyTuple_GET_ITEM(__pyx_v_tpl, __pyx_v_pos);

  /* "bzrlib/_known_graph_pyx.pyx":135
 * 
 *     temp_node = PyTuple_GET_ITEM(tpl, pos)
 *     return <_KnownGraphNode>temp_node             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(((PyObject *)__pyx_r));
  __Pyx_INCREF(((PyObject *)((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_v_temp_node)));
  __pyx_r = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_v_temp_node);
  goto __pyx_L0;

  __pyx_r = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)Py_None); __Pyx_INCREF(Py_None);
  __pyx_L0:;
  __Pyx_XGIVEREF((PyObject *)__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "bzrlib/_known_graph_pyx.pyx":138
 * 
 * 
 * def get_key(node):             # <<<<<<<<<<<<<<
 *     cdef _KnownGraphNode real_node
 *     real_node = node
 */

static PyObject *__pyx_pf_6bzrlib_16_known_graph_pyx_get_key(PyObject *__pyx_self, PyObject *__pyx_v_node); /*proto*/
static PyMethodDef __pyx_mdef_6bzrlib_16_known_graph_pyx_get_key = {__Pyx_NAMESTR("get_key"), (PyCFunction)__pyx_pf_6bzrlib_16_known_graph_pyx_get_key, METH_O, __Pyx_DOCSTR(0)};
static PyObject *__pyx_pf_6bzrlib_16_known_graph_pyx_get_key(PyObject *__pyx_self, PyObject *__pyx_v_node) {
  struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *__pyx_v_real_node;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannySetupContext("get_key");
  __pyx_self = __pyx_self;
  __pyx_v_real_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)Py_None); __Pyx_INCREF(Py_None);

  /* "bzrlib/_known_graph_pyx.pyx":140
 * def get_key(node):
 *     cdef _KnownGraphNode real_node
 *     real_node = node             # <<<<<<<<<<<<<<
 *     return real_node.key
 * 
 */
  if (!(likely(((__pyx_v_node) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_node, __pyx_ptype_6bzrlib_16_known_graph_pyx__KnownGraphNode))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 140; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_INCREF(__pyx_v_node);
  __Pyx_DECREF(((PyObject *)__pyx_v_real_node));
  __pyx_v_real_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_v_node);

  /* "bzrlib/_known_graph_pyx.pyx":141
 *     cdef _KnownGraphNode real_node
 *     real_node = node
 *     return real_node.key             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_real_node->key);
  __pyx_r = __pyx_v_real_node->key;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("bzrlib._known_graph_pyx.get_key");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_DECREF((PyObject *)__pyx_v_real_node);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "bzrlib/_known_graph_pyx.pyx":144
 * 
 * 
 * cdef object _sort_list_nodes(object lst_or_tpl, int reverse):             # <<<<<<<<<<<<<<
 *     """Sort a list of _KnownGraphNode objects.
 * 
 */

static  PyObject *__pyx_f_6bzrlib_16_known_graph_pyx__sort_list_nodes(PyObject *__pyx_v_lst_or_tpl, int __pyx_v_reverse) {
  struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *__pyx_v_node1;
  struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *__pyx_v_node2;
  int __pyx_v_do_swap;
  int __pyx_v_is_tuple;
  Py_ssize_t __pyx_v_length;
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  int __pyx_t_2;
  int __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  Py_ssize_t __pyx_t_5;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  __Pyx_RefNannySetupContext("_sort_list_nodes");
  __Pyx_INCREF(__pyx_v_lst_or_tpl);
  __pyx_v_node1 = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)Py_None); __Pyx_INCREF(Py_None);
  __pyx_v_node2 = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)Py_None); __Pyx_INCREF(Py_None);

  /* "bzrlib/_known_graph_pyx.pyx":154
 *     cdef Py_ssize_t length
 * 
 *     is_tuple = PyTuple_CheckExact(lst_or_tpl)             # <<<<<<<<<<<<<<
 *     if not (is_tuple or PyList_CheckExact(lst_or_tpl)):
 *         raise TypeError('lst_or_tpl must be a list or tuple.')
 */
  __pyx_v_is_tuple = PyTuple_CheckExact(__pyx_v_lst_or_tpl);

  /* "bzrlib/_known_graph_pyx.pyx":155
 * 
 *     is_tuple = PyTuple_CheckExact(lst_or_tpl)
 *     if not (is_tuple or PyList_CheckExact(lst_or_tpl)):             # <<<<<<<<<<<<<<
 *         raise TypeError('lst_or_tpl must be a list or tuple.')
 *     length = len(lst_or_tpl)
 */
  if (!__pyx_v_is_tuple) {
    __pyx_t_1 = PyList_CheckExact(__pyx_v_lst_or_tpl);
    __pyx_t_2 = __pyx_t_1;
  } else {
    __pyx_t_2 = __pyx_v_is_tuple;
  }
  __pyx_t_3 = (!__pyx_t_2);
  if (__pyx_t_3) {

    /* "bzrlib/_known_graph_pyx.pyx":156
 *     is_tuple = PyTuple_CheckExact(lst_or_tpl)
 *     if not (is_tuple or PyList_CheckExact(lst_or_tpl)):
 *         raise TypeError('lst_or_tpl must be a list or tuple.')             # <<<<<<<<<<<<<<
 *     length = len(lst_or_tpl)
 *     if length == 0 or length == 1:
 */
    __pyx_t_4 = PyObject_Call(__pyx_builtin_TypeError, ((PyObject *)__pyx_k_tuple_3), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 156; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_Raise(__pyx_t_4, 0, 0);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 156; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "bzrlib/_known_graph_pyx.pyx":157
 *     if not (is_tuple or PyList_CheckExact(lst_or_tpl)):
 *         raise TypeError('lst_or_tpl must be a list or tuple.')
 *     length = len(lst_or_tpl)             # <<<<<<<<<<<<<<
 *     if length == 0 or length == 1:
 *         return lst_or_tpl
 */
  __pyx_t_5 = PyObject_Length(__pyx_v_lst_or_tpl); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 157; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_length = __pyx_t_5;

  /* "bzrlib/_known_graph_pyx.pyx":158
 *         raise TypeError('lst_or_tpl must be a list or tuple.')
 *     length = len(lst_or_tpl)
 *     if length == 0 or length == 1:             # <<<<<<<<<<<<<<
 *         return lst_or_tpl
 *     if length == 2:
 */
  switch (__pyx_v_length) {
    case 0:
    case 1:

    /* "bzrlib/_known_graph_pyx.pyx":159
 *     length = len(lst_or_tpl)
 *     if length == 0 or length == 1:
 *         return lst_or_tpl             # <<<<<<<<<<<<<<
 *     if length == 2:
 *         if is_tuple:
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(__pyx_v_lst_or_tpl);
    __pyx_r = __pyx_v_lst_or_tpl;
    goto __pyx_L0;
    break;
  }

  /* "bzrlib/_known_graph_pyx.pyx":160
 *     if length == 0 or length == 1:
 *         return lst_or_tpl
 *     if length == 2:             # <<<<<<<<<<<<<<
 *         if is_tuple:
 *             node1 = _get_tuple_node(lst_or_tpl, 0)
 */
  __pyx_t_3 = (__pyx_v_length == 2);
  if (__pyx_t_3) {

    /* "bzrlib/_known_graph_pyx.pyx":161
 *         return lst_or_tpl
 *     if length == 2:
 *         if is_tuple:             # <<<<<<<<<<<<<<
 *             node1 = _get_tuple_node(lst_or_tpl, 0)
 *             node2 = _get_tuple_node(lst_or_tpl, 1)
 */
    if (__pyx_v_is_tuple) {

      /* "bzrlib/_known_graph_pyx.pyx":162
 *     if length == 2:
 *         if is_tuple:
 *             node1 = _get_tuple_node(lst_or_tpl, 0)             # <<<<<<<<<<<<<<
 *             node2 = _get_tuple_node(lst_or_tpl, 1)
 *         else:
 */
      __pyx_t_4 = ((PyObject *)__pyx_f_6bzrlib_16_known_graph_pyx__get_tuple_node(__pyx_v_lst_or_tpl, 0)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 162; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(((PyObject *)__pyx_v_node1));
      __pyx_v_node1 = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_t_4);
      __pyx_t_4 = 0;

      /* "bzrlib/_known_graph_pyx.pyx":163
 *         if is_tuple:
 *             node1 = _get_tuple_node(lst_or_tpl, 0)
 *             node2 = _get_tuple_node(lst_or_tpl, 1)             # <<<<<<<<<<<<<<
 *         else:
 *             node1 = _get_list_node(lst_or_tpl, 0)
 */
      __pyx_t_4 = ((PyObject *)__pyx_f_6bzrlib_16_known_graph_pyx__get_tuple_node(__pyx_v_lst_or_tpl, 1)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 163; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(((PyObject *)__pyx_v_node2));
      __pyx_v_node2 = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_t_4);
      __pyx_t_4 = 0;
      goto __pyx_L5;
    }
    /*else*/ {

      /* "bzrlib/_known_graph_pyx.pyx":165
 *             node2 = _get_tuple_node(lst_or_tpl, 1)
 *         else:
 *             node1 = _get_list_node(lst_or_tpl, 0)             # <<<<<<<<<<<<<<
 *             node2 = _get_list_node(lst_or_tpl, 1)
 *         if reverse:
 */
      __pyx_t_4 = ((PyObject *)__pyx_f_6bzrlib_16_known_graph_pyx__get_list_node(__pyx_v_lst_or_tpl, 0)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 165; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(((PyObject *)__pyx_v_node1));
      __pyx_v_node1 = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_t_4);
      __pyx_t_4 = 0;

      /* "bzrlib/_known_graph_pyx.pyx":166
 *         else:
 *             node1 = _get_list_node(lst_or_tpl, 0)
 *             node2 = _get_list_node(lst_or_tpl, 1)             # <<<<<<<<<<<<<<
 *         if reverse:
 *             do_swap = PyObject_RichCompareBool(node1.key, node2.key, Py_LT)
 */
      __pyx_t_4 = ((PyObject *)__pyx_f_6bzrlib_16_known_graph_pyx__get_list_node(__pyx_v_lst_or_tpl, 1)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 166; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(((PyObject *)__pyx_v_node2));
      __pyx_v_node2 = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_t_4);
      __pyx_t_4 = 0;
    }
    __pyx_L5:;

    /* "bzrlib/_known_graph_pyx.pyx":167
 *             node1 = _get_list_node(lst_or_tpl, 0)
 *             node2 = _get_list_node(lst_or_tpl, 1)
 *         if reverse:             # <<<<<<<<<<<<<<
 *             do_swap = PyObject_RichCompareBool(node1.key, node2.key, Py_LT)
 *         else:
 */
    if (__pyx_v_reverse) {

      /* "bzrlib/_known_graph_pyx.pyx":168
 *             node2 = _get_list_node(lst_or_tpl, 1)
 *         if reverse:
 *             do_swap = PyObject_RichCompareBool(node1.key, node2.key, Py_LT)             # <<<<<<<<<<<<<<
 *         else:
 *             do_swap = PyObject_RichCompareBool(node2.key, node1.key, Py_LT)
 */
      __pyx_t_4 = __pyx_v_node1->key;
      __Pyx_INCREF(__pyx_t_4);
      __pyx_t_6 = __pyx_v_node2->key;
      __Pyx_INCREF(__pyx_t_6);
      __pyx_v_do_swap = PyObject_RichCompareBool(__pyx_t_4, __pyx_t_6, Py_LT);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      goto __pyx_L6;
    }
    /*else*/ {

      /* "bzrlib/_known_graph_pyx.pyx":170
 *             do_swap = PyObject_RichCompareBool(node1.key, node2.key, Py_LT)
 *         else:
 *             do_swap = PyObject_RichCompareBool(node2.key, node1.key, Py_LT)             # <<<<<<<<<<<<<<
 *         if not do_swap:
 *             return lst_or_tpl
 */
      __pyx_t_6 = __pyx_v_node2->key;
      __Pyx_INCREF(__pyx_t_6);
      __pyx_t_4 = __pyx_v_node1->key;
      __Pyx_INCREF(__pyx_t_4);
      __pyx_v_do_swap = PyObject_RichCompareBool(__pyx_t_6, __pyx_t_4, Py_LT);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    }
    __pyx_L6:;

    /* "bzrlib/_known_graph_pyx.pyx":171
 *         else:
 *             do_swap = PyObject_RichCompareBool(node2.key, node1.key, Py_LT)
 *         if not do_swap:             # <<<<<<<<<<<<<<
 *             return lst_or_tpl
 *         if is_tuple:
 */
    __pyx_t_3 = (!__pyx_v_do_swap);
    if (__pyx_t_3) {

      /* "bzrlib/_known_graph_pyx.pyx":172
 *             do_swap = PyObject_RichCompareBool(node2.key, node1.key, Py_LT)
 *         if not do_swap:
 *             return lst_or_tpl             # <<<<<<<<<<<<<<
 *         if is_tuple:
 *             return (node2, node1)
 */
      __Pyx_XDECREF(__pyx_r);
      __Pyx_INCREF(__pyx_v_lst_or_tpl);
      __pyx_r = __pyx_v_lst_or_tpl;
      goto __pyx_L0;
      goto __pyx_L7;
    }
    __pyx_L7:;

    /* "bzrlib/_known_graph_pyx.pyx":173
 *         if not do_swap:
 *             return lst_or_tpl
 *         if is_tuple:             # <<<<<<<<<<<<<<
 *             return (node2, node1)
 *         else:
 */
    if (__pyx_v_is_tuple) {

      /* "bzrlib/_known_graph_pyx.pyx":174
 *             return lst_or_tpl
 *         if is_tuple:
 *             return (node2, node1)             # <<<<<<<<<<<<<<
 *         else:
 *             # Swap 'in-place', since lists are mutable
 */
      __Pyx_XDECREF(__pyx_r);
      __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 174; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(((PyObject *)__pyx_t_4));
      __Pyx_INCREF(((PyObject *)__pyx_v_node2));
      PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_v_node2));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_node2));
      __Pyx_INCREF(((PyObject *)__pyx_v_node1));
      PyTuple_SET_ITEM(__pyx_t_4, 1, ((PyObject *)__pyx_v_node1));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_node1));
      __pyx_r = ((PyObject *)__pyx_t_4);
      __pyx_t_4 = 0;
      goto __pyx_L0;
      goto __pyx_L8;
    }
    /*else*/ {

      /* "bzrlib/_known_graph_pyx.pyx":177
 *         else:
 *             # Swap 'in-place', since lists are mutable
 *             Py_INCREF(node1)             # <<<<<<<<<<<<<<
 *             PyList_SetItem(lst_or_tpl, 1, node1)
 *             Py_INCREF(node2)
 */
      Py_INCREF(((PyObject *)__pyx_v_node1));

      /* "bzrlib/_known_graph_pyx.pyx":178
 *             # Swap 'in-place', since lists are mutable
 *             Py_INCREF(node1)
 *             PyList_SetItem(lst_or_tpl, 1, node1)             # <<<<<<<<<<<<<<
 *             Py_INCREF(node2)
 *             PyList_SetItem(lst_or_tpl, 0, node2)
 */
      __pyx_t_1 = PyList_SetItem(__pyx_v_lst_or_tpl, 1, ((PyObject *)__pyx_v_node1)); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 178; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

      /* "bzrlib/_known_graph_pyx.pyx":179
 *             Py_INCREF(node1)
 *             PyList_SetItem(lst_or_tpl, 1, node1)
 *             Py_INCREF(node2)             # <<<<<<<<<<<<<<
 *             PyList_SetItem(lst_or_tpl, 0, node2)
 *             return lst_or_tpl
 */
      Py_INCREF(((PyObject *)__pyx_v_node2));

      /* "bzrlib/_known_graph_pyx.pyx":180
 *             PyList_SetItem(lst_or_tpl, 1, node1)
 *             Py_INCREF(node2)
 *             PyList_SetItem(lst_or_tpl, 0, node2)             # <<<<<<<<<<<<<<
 *             return lst_or_tpl
 *     # For all other sizes, we just use 'sorted()'
 */
      __pyx_t_1 = PyList_SetItem(__pyx_v_lst_or_tpl, 0, ((PyObject *)__pyx_v_node2)); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 180; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

      /* "bzrlib/_known_graph_pyx.pyx":181
 *             Py_INCREF(node2)
 *             PyList_SetItem(lst_or_tpl, 0, node2)
 *             return lst_or_tpl             # <<<<<<<<<<<<<<
 *     # For all other sizes, we just use 'sorted()'
 *     if is_tuple:
 */
      __Pyx_XDECREF(__pyx_r);
      __Pyx_INCREF(__pyx_v_lst_or_tpl);
      __pyx_r = __pyx_v_lst_or_tpl;
      goto __pyx_L0;
    }
    __pyx_L8:;
    goto __pyx_L4;
  }
  __pyx_L4:;

  /* "bzrlib/_known_graph_pyx.pyx":183
 *             return lst_or_tpl
 *     # For all other sizes, we just use 'sorted()'
 *     if is_tuple:             # <<<<<<<<<<<<<<
 *         # Note that sorted() is just list(iterable).sort()
 *         lst_or_tpl = list(lst_or_tpl)
 */
  if (__pyx_v_is_tuple) {

    /* "bzrlib/_known_graph_pyx.pyx":185
 *     if is_tuple:
 *         # Note that sorted() is just list(iterable).sort()
 *         lst_or_tpl = list(lst_or_tpl)             # <<<<<<<<<<<<<<
 *     lst_or_tpl.sort(key=get_key, reverse=reverse)
 *     return lst_or_tpl
 */
    __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 185; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_4));
    __Pyx_INCREF(__pyx_v_lst_or_tpl);
    PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_lst_or_tpl);
    __Pyx_GIVEREF(__pyx_v_lst_or_tpl);
    __pyx_t_6 = PyObject_Call(((PyObject *)((PyObject*)(&PyList_Type))), ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 185; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_v_lst_or_tpl);
    __pyx_v_lst_or_tpl = __pyx_t_6;
    __pyx_t_6 = 0;
    goto __pyx_L9;
  }
  __pyx_L9:;

  /* "bzrlib/_known_graph_pyx.pyx":186
 *         # Note that sorted() is just list(iterable).sort()
 *         lst_or_tpl = list(lst_or_tpl)
 *     lst_or_tpl.sort(key=get_key, reverse=reverse)             # <<<<<<<<<<<<<<
 *     return lst_or_tpl
 * 
 */
  __pyx_t_6 = PyObject_GetAttr(__pyx_v_lst_or_tpl, __pyx_n_s__sort); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 186; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_4 = PyDict_New(); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 186; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_4));
  __pyx_t_7 = __Pyx_GetName(__pyx_m, __pyx_n_s__get_key); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 186; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_7);
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__key), __pyx_t_7) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 186; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = PyInt_FromLong(__pyx_v_reverse); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 186; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_7);
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__reverse), __pyx_t_7) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 186; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = PyEval_CallObjectWithKeywords(__pyx_t_6, ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_4)); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 186; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

  /* "bzrlib/_known_graph_pyx.pyx":187
 *         lst_or_tpl = list(lst_or_tpl)
 *     lst_or_tpl.sort(key=get_key, reverse=reverse)
 *     return lst_or_tpl             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_lst_or_tpl);
  __pyx_r = __pyx_v_lst_or_tpl;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_AddTraceback("bzrlib._known_graph_pyx._sort_list_nodes");
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_DECREF((PyObject *)__pyx_v_node1);
  __Pyx_DECREF((PyObject *)__pyx_v_node2);
  __Pyx_DECREF(__pyx_v_lst_or_tpl);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "bzrlib/_known_graph_pyx.pyx":199
 *     cdef public int do_cache
 * 
 *     def __init__(self, parent_map, do_cache=True):             # <<<<<<<<<<<<<<
 *         """Create a new KnownGraph instance.
 * 
 */

static int __pyx_pf_6bzrlib_16_known_graph_pyx_10KnownGraph___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_6bzrlib_16_known_graph_pyx_10KnownGraph___init__[] = "Create a new KnownGraph instance.\n\n        :param parent_map: A dictionary mapping key => parent_keys\n        ";
struct wrapperbase __pyx_wrapperbase_6bzrlib_16_known_graph_pyx_10KnownGraph___init__;
static int __pyx_pf_6bzrlib_16_known_graph_pyx_10KnownGraph___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_parent_map = 0;
  PyObject *__pyx_v_do_cache = 0;
  int __pyx_r;
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__parent_map,&__pyx_n_s__do_cache,0};
  __Pyx_RefNannySetupContext("__init__");
  if (unlikely(__pyx_kwds)) {
    Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
    PyObject* values[2] = {0,0};
    values[1] = __pyx_k_4;
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      case  0: break;
      default: goto __pyx_L5_argtuple_error;
    }
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  0:
      values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__parent_map);
      if (likely(values[0])) kw_args--;
      else goto __pyx_L5_argtuple_error;
      case  1:
      if (kw_args > 0) {
        PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__do_cache);
        if (value) { values[1] = value; kw_args--; }
      }
    }
    if (unlikely(kw_args > 0)) {
      if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "__init__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 199; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    }
    __pyx_v_parent_map = values[0];
    __pyx_v_do_cache = values[1];
  } else {
    __pyx_v_do_cache = __pyx_k_4;
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  2: __pyx_v_do_cache = PyTuple_GET_ITEM(__pyx_args, 1);
      case  1: __pyx_v_parent_map = PyTuple_GET_ITEM(__pyx_args, 0);
      break;
      default: goto __pyx_L5_argtuple_error;
    }
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("__init__", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 199; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("bzrlib._known_graph_pyx.KnownGraph.__init__");
  __Pyx_RefNannyFinishContext();
  return -1;
  __pyx_L4_argument_unpacking_done:;

  /* "bzrlib/_known_graph_pyx.pyx":205
 *         """
 *         # tests at pre-allocating the node dict actually slowed things down
 *         self._nodes = {}             # <<<<<<<<<<<<<<
 *         # Maps {sorted(revision_id, revision_id): heads}
 *         self._known_heads = {}
 */
  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 205; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_1));
  __Pyx_GIVEREF(((PyObject *)__pyx_t_1));
  __Pyx_GOTREF(((struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *)__pyx_v_self)->_nodes);
  __Pyx_DECREF(((struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *)__pyx_v_self)->_nodes);
  ((struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *)__pyx_v_self)->_nodes = ((PyObject *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "bzrlib/_known_graph_pyx.pyx":207
 *         self._nodes = {}
 *         # Maps {sorted(revision_id, revision_id): heads}
 *         self._known_heads = {}             # <<<<<<<<<<<<<<
 *         self.do_cache = int(do_cache)
 *         # TODO: consider disabling gc since we are allocating a lot of nodes
 */
  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 207; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_1));
  __Pyx_GIVEREF(((PyObject *)__pyx_t_1));
  __Pyx_GOTREF(((struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *)__pyx_v_self)->_known_heads);
  __Pyx_DECREF(((struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *)__pyx_v_self)->_known_heads);
  ((struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *)__pyx_v_self)->_known_heads = ((PyObject *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "bzrlib/_known_graph_pyx.pyx":208
 *         # Maps {sorted(revision_id, revision_id): heads}
 *         self._known_heads = {}
 *         self.do_cache = int(do_cache)             # <<<<<<<<<<<<<<
 *         # TODO: consider disabling gc since we are allocating a lot of nodes
 *         #       that won't be collectable anyway. real world testing has not
 */
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 208; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_1));
  __Pyx_INCREF(__pyx_v_do_cache);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_do_cache);
  __Pyx_GIVEREF(__pyx_v_do_cache);
  __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject*)(&PyInt_Type))), ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 208; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __pyx_t_3 = __Pyx_PyInt_AsInt(__pyx_t_2); if (unlikely((__pyx_t_3 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 208; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  ((struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *)__pyx_v_self)->do_cache = __pyx_t_3;

  /* "bzrlib/_known_graph_pyx.pyx":212
 *         #       that won't be collectable anyway. real world testing has not
 *         #       shown a specific impact, yet.
 *         self._initialize_nodes(parent_map)             # <<<<<<<<<<<<<<
 *         self._find_gdfo()
 * 
 */
  __pyx_t_2 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s___initialize_nodes); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 212; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 212; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_1));
  __Pyx_INCREF(__pyx_v_parent_map);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_parent_map);
  __Pyx_GIVEREF(__pyx_v_parent_map);
  __pyx_t_4 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 212; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "bzrlib/_known_graph_pyx.pyx":213
 *         #       shown a specific impact, yet.
 *         self._initialize_nodes(parent_map)
 *         self._find_gdfo()             # <<<<<<<<<<<<<<
 * 
 *     def __dealloc__(self):
 */
  __pyx_t_4 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s___find_gdfo); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 213; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_1 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 213; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("bzrlib._known_graph_pyx.KnownGraph.__init__");
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "bzrlib/_known_graph_pyx.pyx":215
 *         self._find_gdfo()
 * 
 *     def __dealloc__(self):             # <<<<<<<<<<<<<<
 *         cdef _KnownGraphNode child
 *         cdef Py_ssize_t pos
 */

static void __pyx_pf_6bzrlib_16_known_graph_pyx_10KnownGraph_1__dealloc__(PyObject *__pyx_v_self); /*proto*/
static void __pyx_pf_6bzrlib_16_known_graph_pyx_10KnownGraph_1__dealloc__(PyObject *__pyx_v_self) {
  struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *__pyx_v_child;
  Py_ssize_t __pyx_v_pos;
  PyObject *__pyx_v_temp_node;
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  __Pyx_RefNannySetupContext("__dealloc__");
  __pyx_v_child = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)Py_None); __Pyx_INCREF(Py_None);

  /* "bzrlib/_known_graph_pyx.pyx":220
 *         cdef PyObject *temp_node
 * 
 *         while PyDict_Next(self._nodes, &pos, NULL, &temp_node):             # <<<<<<<<<<<<<<
 *             child = <_KnownGraphNode>temp_node
 *             child.clear_references()
 */
  while (1) {
    __pyx_t_1 = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *)__pyx_v_self)->_nodes;
    __Pyx_INCREF(__pyx_t_1);
    __pyx_t_2 = PyDict_Next(__pyx_t_1, (&__pyx_v_pos), NULL, (&__pyx_v_temp_node));
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (!__pyx_t_2) break;

    /* "bzrlib/_known_graph_pyx.pyx":221
 * 
 *         while PyDict_Next(self._nodes, &pos, NULL, &temp_node):
 *             child = <_KnownGraphNode>temp_node             # <<<<<<<<<<<<<<
 *             child.clear_references()
 * 
 */
    __Pyx_INCREF(((PyObject *)((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_v_temp_node)));
    __Pyx_DECREF(((PyObject *)__pyx_v_child));
    __pyx_v_child = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_v_temp_node);

    /* "bzrlib/_known_graph_pyx.pyx":222
 *         while PyDict_Next(self._nodes, &pos, NULL, &temp_node):
 *             child = <_KnownGraphNode>temp_node
 *             child.clear_references()             # <<<<<<<<<<<<<<
 * 
 *     cdef _KnownGraphNode _get_or_create_node(self, key):
 */
    __pyx_t_1 = ((struct __pyx_vtabstruct_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_v_child->__pyx_vtab)->clear_references(__pyx_v_child); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 222; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  }

  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("bzrlib._known_graph_pyx.KnownGraph.__dealloc__");
  __pyx_L0:;
  __Pyx_DECREF((PyObject *)__pyx_v_child);
  __Pyx_RefNannyFinishContext();
}

/* "bzrlib/_known_graph_pyx.pyx":224
 *             child.clear_references()
 * 
 *     cdef _KnownGraphNode _get_or_create_node(self, key):             # <<<<<<<<<<<<<<
 *         cdef PyObject *temp_node
 *         cdef _KnownGraphNode node
 */

static  struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *__pyx_f_6bzrlib_16_known_graph_pyx_10KnownGraph__get_or_create_node(struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *__pyx_v_self, PyObject *__pyx_v_key) {
  PyObject *__pyx_v_temp_node;
  struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *__pyx_v_node;
  struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_t_4;
  __Pyx_RefNannySetupContext("_get_or_create_node");
  __pyx_v_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)Py_None); __Pyx_INCREF(Py_None);

  /* "bzrlib/_known_graph_pyx.pyx":228
 *         cdef _KnownGraphNode node
 * 
 *         temp_node = PyDict_GetItem(self._nodes, key)             # <<<<<<<<<<<<<<
 *         if temp_node == NULL:
 *             node = _KnownGraphNode(key)
 */
  __pyx_t_1 = __pyx_v_self->_nodes;
  __Pyx_INCREF(__pyx_t_1);
  __pyx_v_temp_node = PyDict_GetItem(__pyx_t_1, __pyx_v_key);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "bzrlib/_known_graph_pyx.pyx":229
 * 
 *         temp_node = PyDict_GetItem(self._nodes, key)
 *         if temp_node == NULL:             # <<<<<<<<<<<<<<
 *             node = _KnownGraphNode(key)
 *             PyDict_SetItem(self._nodes, key, node)
 */
  __pyx_t_2 = (__pyx_v_temp_node == NULL);
  if (__pyx_t_2) {

    /* "bzrlib/_known_graph_pyx.pyx":230
 *         temp_node = PyDict_GetItem(self._nodes, key)
 *         if temp_node == NULL:
 *             node = _KnownGraphNode(key)             # <<<<<<<<<<<<<<
 *             PyDict_SetItem(self._nodes, key, node)
 *         else:
 */
    __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 230; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_1));
    __Pyx_INCREF(__pyx_v_key);
    PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_key);
    __Pyx_GIVEREF(__pyx_v_key);
    __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_6bzrlib_16_known_graph_pyx__KnownGraphNode)), ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 230; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_v_node));
    __pyx_v_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_t_3);
    __pyx_t_3 = 0;

    /* "bzrlib/_known_graph_pyx.pyx":231
 *         if temp_node == NULL:
 *             node = _KnownGraphNode(key)
 *             PyDict_SetItem(self._nodes, key, node)             # <<<<<<<<<<<<<<
 *         else:
 *             node = <_KnownGraphNode>temp_node
 */
    __pyx_t_3 = __pyx_v_self->_nodes;
    __Pyx_INCREF(__pyx_t_3);
    __pyx_t_4 = PyDict_SetItem(__pyx_t_3, __pyx_v_key, ((PyObject *)__pyx_v_node)); if (unlikely(__pyx_t_4 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 231; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    goto __pyx_L3;
  }
  /*else*/ {

    /* "bzrlib/_known_graph_pyx.pyx":233
 *             PyDict_SetItem(self._nodes, key, node)
 *         else:
 *             node = <_KnownGraphNode>temp_node             # <<<<<<<<<<<<<<
 *         return node
 * 
 */
    __Pyx_INCREF(((PyObject *)((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_v_temp_node)));
    __Pyx_DECREF(((PyObject *)__pyx_v_node));
    __pyx_v_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_v_temp_node);
  }
  __pyx_L3:;

  /* "bzrlib/_known_graph_pyx.pyx":234
 *         else:
 *             node = <_KnownGraphNode>temp_node
 *         return node             # <<<<<<<<<<<<<<
 * 
 *     cdef _populate_parents(self, _KnownGraphNode node, parent_keys):
 */
  __Pyx_XDECREF(((PyObject *)__pyx_r));
  __Pyx_INCREF(((PyObject *)__pyx_v_node));
  __pyx_r = __pyx_v_node;
  goto __pyx_L0;

  __pyx_r = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)Py_None); __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("bzrlib._known_graph_pyx.KnownGraph._get_or_create_node");
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_DECREF((PyObject *)__pyx_v_node);
  __Pyx_XGIVEREF((PyObject *)__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "bzrlib/_known_graph_pyx.pyx":236
 *         return node
 * 
 *     cdef _populate_parents(self, _KnownGraphNode node, parent_keys):             # <<<<<<<<<<<<<<
 *         cdef Py_ssize_t num_parent_keys, pos
 *         cdef _KnownGraphNode parent_node
 */

static  PyObject *__pyx_f_6bzrlib_16_known_graph_pyx_10KnownGraph__populate_parents(struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *__pyx_v_self, struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *__pyx_v_node, PyObject *__pyx_v_parent_keys) {
  Py_ssize_t __pyx_v_num_parent_keys;
  Py_ssize_t __pyx_v_pos;
  struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *__pyx_v_parent_node;
  PyObject *__pyx_v_parent_nodes;
  PyObject *__pyx_r = NULL;
  Py_ssize_t __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_t_4;
  __Pyx_RefNannySetupContext("_populate_parents");
  __pyx_v_parent_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)Py_None); __Pyx_INCREF(Py_None);
  __pyx_v_parent_nodes = Py_None; __Pyx_INCREF(Py_None);

  /* "bzrlib/_known_graph_pyx.pyx":240
 *         cdef _KnownGraphNode parent_node
 * 
 *         num_parent_keys = len(parent_keys)             # <<<<<<<<<<<<<<
 *         # We know how many parents, so we pre allocate the tuple
 *         parent_nodes = PyTuple_New(num_parent_keys)
 */
  __pyx_t_1 = PyObject_Length(__pyx_v_parent_keys); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 240; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_num_parent_keys = __pyx_t_1;

  /* "bzrlib/_known_graph_pyx.pyx":242
 *         num_parent_keys = len(parent_keys)
 *         # We know how many parents, so we pre allocate the tuple
 *         parent_nodes = PyTuple_New(num_parent_keys)             # <<<<<<<<<<<<<<
 *         for pos from 0 <= pos < num_parent_keys:
 *             # Note: it costs us 10ms out of 40ms to lookup all of these
 */
  __pyx_t_2 = PyTuple_New(__pyx_v_num_parent_keys); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 242; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_v_parent_nodes);
  __pyx_v_parent_nodes = __pyx_t_2;
  __pyx_t_2 = 0;

  /* "bzrlib/_known_graph_pyx.pyx":243
 *         # We know how many parents, so we pre allocate the tuple
 *         parent_nodes = PyTuple_New(num_parent_keys)
 *         for pos from 0 <= pos < num_parent_keys:             # <<<<<<<<<<<<<<
 *             # Note: it costs us 10ms out of 40ms to lookup all of these
 *             #       parents, it doesn't seem to be an allocation overhead,
 */
  __pyx_t_1 = __pyx_v_num_parent_keys;
  for (__pyx_v_pos = 0; __pyx_v_pos < __pyx_t_1; __pyx_v_pos++) {

    /* "bzrlib/_known_graph_pyx.pyx":251
 *             #       node.
 *             # We use [] because parent_keys may be a tuple or list
 *             parent_node = self._get_or_create_node(parent_keys[pos])             # <<<<<<<<<<<<<<
 *             # PyTuple_SET_ITEM will steal a reference, so INCREF first
 *             Py_INCREF(parent_node)
 */
    __pyx_t_2 = __Pyx_GetItemInt(__pyx_v_parent_keys, __pyx_v_pos, sizeof(Py_ssize_t), PyInt_FromSsize_t); if (!__pyx_t_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 251; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_3 = ((PyObject *)((struct __pyx_vtabstruct_6bzrlib_16_known_graph_pyx_KnownGraph *)__pyx_v_self->__pyx_vtab)->_get_or_create_node(__pyx_v_self, __pyx_t_2)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 251; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_v_parent_node));
    __pyx_v_parent_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_t_3);
    __pyx_t_3 = 0;

    /* "bzrlib/_known_graph_pyx.pyx":253
 *             parent_node = self._get_or_create_node(parent_keys[pos])
 *             # PyTuple_SET_ITEM will steal a reference, so INCREF first
 *             Py_INCREF(parent_node)             # <<<<<<<<<<<<<<
 *             PyTuple_SET_ITEM(parent_nodes, pos, parent_node)
 *             PyList_Append(parent_node.children, node)
 */
    Py_INCREF(((PyObject *)__pyx_v_parent_node));

    /* "bzrlib/_known_graph_pyx.pyx":254
 *             # PyTuple_SET_ITEM will steal a reference, so INCREF first
 *             Py_INCREF(parent_node)
 *             PyTuple_SET_ITEM(parent_nodes, pos, parent_node)             # <<<<<<<<<<<<<<
 *             PyList_Append(parent_node.children, node)
 *         node.parents = parent_nodes
 */
    PyTuple_SET_ITEM(__pyx_v_parent_nodes, __pyx_v_pos, ((PyObject *)__pyx_v_parent_node));

    /* "bzrlib/_known_graph_pyx.pyx":255
 *             Py_INCREF(parent_node)
 *             PyTuple_SET_ITEM(parent_nodes, pos, parent_node)
 *             PyList_Append(parent_node.children, node)             # <<<<<<<<<<<<<<
 *         node.parents = parent_nodes
 * 
 */
    __pyx_t_3 = __pyx_v_parent_node->children;
    __Pyx_INCREF(__pyx_t_3);
    __pyx_t_4 = PyList_Append(__pyx_t_3, ((PyObject *)__pyx_v_node)); if (unlikely(__pyx_t_4 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 255; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  }

  /* "bzrlib/_known_graph_pyx.pyx":256
 *             PyTuple_SET_ITEM(parent_nodes, pos, parent_node)
 *             PyList_Append(parent_node.children, node)
 *         node.parents = parent_nodes             # <<<<<<<<<<<<<<
 * 
 *     def _initialize_nodes(self, parent_map):
 */
  __Pyx_INCREF(__pyx_v_parent_nodes);
  __Pyx_GIVEREF(__pyx_v_parent_nodes);
  __Pyx_GOTREF(__pyx_v_node->parents);
  __Pyx_DECREF(__pyx_v_node->parents);
  __pyx_v_node->parents = __pyx_v_parent_nodes;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("bzrlib._known_graph_pyx.KnownGraph._populate_parents");
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_DECREF((PyObject *)__pyx_v_parent_node);
  __Pyx_DECREF(__pyx_v_parent_nodes);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "bzrlib/_known_graph_pyx.pyx":258
 *         node.parents = parent_nodes
 * 
 *     def _initialize_nodes(self, parent_map):             # <<<<<<<<<<<<<<
 *         """Populate self._nodes.
 * 
 */

static PyObject *__pyx_pf_6bzrlib_16_known_graph_pyx_10KnownGraph_2_initialize_nodes(PyObject *__pyx_v_self, PyObject *__pyx_v_parent_map); /*proto*/
static char __pyx_doc_6bzrlib_16_known_graph_pyx_10KnownGraph_2_initialize_nodes[] = "Populate self._nodes.\n\n        After this has finished:\n        - self._nodes will have an entry for every entry in parent_map.\n        - ghosts will have a parent_keys = None,\n        - all nodes found will also have child_keys populated with all known\n          child keys,\n        ";
static PyObject *__pyx_pf_6bzrlib_16_known_graph_pyx_10KnownGraph_2_initialize_nodes(PyObject *__pyx_v_self, PyObject *__pyx_v_parent_map) {
  PyObject *__pyx_v_temp_key;
  PyObject *__pyx_v_temp_parent_keys;
  Py_ssize_t __pyx_v_pos;
  struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *__pyx_v_node;
  PyObject *__pyx_v_key;
  PyObject *__pyx_v_parent_keys;
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  __Pyx_RefNannySetupContext("_initialize_nodes");
  __pyx_v_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)Py_None); __Pyx_INCREF(Py_None);
  __pyx_v_key = Py_None; __Pyx_INCREF(Py_None);
  __pyx_v_parent_keys = Py_None; __Pyx_INCREF(Py_None);

  /* "bzrlib/_known_graph_pyx.pyx":272
 *         cdef _KnownGraphNode parent_node
 * 
 *         if not PyDict_CheckExact(parent_map):             # <<<<<<<<<<<<<<
 *             raise TypeError('parent_map should be a dict of {key:parent_keys}')
 *         # for key, parent_keys in parent_map.iteritems():
 */
  __pyx_t_1 = (!PyDict_CheckExact(__pyx_v_parent_map));
  if (__pyx_t_1) {

    /* "bzrlib/_known_graph_pyx.pyx":273
 * 
 *         if not PyDict_CheckExact(parent_map):
 *             raise TypeError('parent_map should be a dict of {key:parent_keys}')             # <<<<<<<<<<<<<<
 *         # for key, parent_keys in parent_map.iteritems():
 *         pos = 0
 */
    __pyx_t_2 = PyObject_Call(__pyx_builtin_TypeError, ((PyObject *)__pyx_k_tuple_6), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 273; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_Raise(__pyx_t_2, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 273; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "bzrlib/_known_graph_pyx.pyx":275
 *             raise TypeError('parent_map should be a dict of {key:parent_keys}')
 *         # for key, parent_keys in parent_map.iteritems():
 *         pos = 0             # <<<<<<<<<<<<<<
 *         while PyDict_Next(parent_map, &pos, &temp_key, &temp_parent_keys):
 *             key = <object>temp_key
 */
  __pyx_v_pos = 0;

  /* "bzrlib/_known_graph_pyx.pyx":276
 *         # for key, parent_keys in parent_map.iteritems():
 *         pos = 0
 *         while PyDict_Next(parent_map, &pos, &temp_key, &temp_parent_keys):             # <<<<<<<<<<<<<<
 *             key = <object>temp_key
 *             parent_keys = <object>temp_parent_keys
 */
  while (1) {
    __pyx_t_3 = PyDict_Next(__pyx_v_parent_map, (&__pyx_v_pos), (&__pyx_v_temp_key), (&__pyx_v_temp_parent_keys));
    if (!__pyx_t_3) break;

    /* "bzrlib/_known_graph_pyx.pyx":277
 *         pos = 0
 *         while PyDict_Next(parent_map, &pos, &temp_key, &temp_parent_keys):
 *             key = <object>temp_key             # <<<<<<<<<<<<<<
 *             parent_keys = <object>temp_parent_keys
 *             node = self._get_or_create_node(key)
 */
    __Pyx_INCREF(((PyObject *)__pyx_v_temp_key));
    __Pyx_DECREF(__pyx_v_key);
    __pyx_v_key = ((PyObject *)__pyx_v_temp_key);

    /* "bzrlib/_known_graph_pyx.pyx":278
 *         while PyDict_Next(parent_map, &pos, &temp_key, &temp_parent_keys):
 *             key = <object>temp_key
 *             parent_keys = <object>temp_parent_keys             # <<<<<<<<<<<<<<
 *             node = self._get_or_create_node(key)
 *             self._populate_parents(node, parent_keys)
 */
    __Pyx_INCREF(((PyObject *)__pyx_v_temp_parent_keys));
    __Pyx_DECREF(__pyx_v_parent_keys);
    __pyx_v_parent_keys = ((PyObject *)__pyx_v_temp_parent_keys);

    /* "bzrlib/_known_graph_pyx.pyx":279
 *             key = <object>temp_key
 *             parent_keys = <object>temp_parent_keys
 *             node = self._get_or_create_node(key)             # <<<<<<<<<<<<<<
 *             self._populate_parents(node, parent_keys)
 * 
 */
    __pyx_t_2 = ((PyObject *)((struct __pyx_vtabstruct_6bzrlib_16_known_graph_pyx_KnownGraph *)((struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *)__pyx_v_self)->__pyx_vtab)->_get_or_create_node(((struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *)__pyx_v_self), __pyx_v_key)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 279; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(((PyObject *)__pyx_v_node));
    __pyx_v_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_t_2);
    __pyx_t_2 = 0;

    /* "bzrlib/_known_graph_pyx.pyx":280
 *             parent_keys = <object>temp_parent_keys
 *             node = self._get_or_create_node(key)
 *             self._populate_parents(node, parent_keys)             # <<<<<<<<<<<<<<
 * 
 *     def _find_tails(self):
 */
    __pyx_t_2 = ((struct __pyx_vtabstruct_6bzrlib_16_known_graph_pyx_KnownGraph *)((struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *)__pyx_v_self)->__pyx_vtab)->_populate_parents(((struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *)__pyx_v_self), __pyx_v_node, __pyx_v_parent_keys); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 280; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  }

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("bzrlib._known_graph_pyx.KnownGraph._initialize_nodes");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_DECREF((PyObject *)__pyx_v_node);
  __Pyx_DECREF(__pyx_v_key);
  __Pyx_DECREF(__pyx_v_parent_keys);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "bzrlib/_known_graph_pyx.pyx":282
 *             self._populate_parents(node, parent_keys)
 * 
 *     def _find_tails(self):             # <<<<<<<<<<<<<<
 *         cdef PyObject *temp_node
 *         cdef _KnownGraphNode node
 */

static PyObject *__pyx_pf_6bzrlib_16_known_graph_pyx_10KnownGraph_3_find_tails(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static PyObject *__pyx_pf_6bzrlib_16_known_graph_pyx_10KnownGraph_3_find_tails(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_v_temp_node;
  struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *__pyx_v_node;
  Py_ssize_t __pyx_v_pos;
  PyObject *__pyx_v_tails;
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  int __pyx_t_3;
  int __pyx_t_4;
  int __pyx_t_5;
  __Pyx_RefNannySetupContext("_find_tails");
  __pyx_v_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)Py_None); __Pyx_INCREF(Py_None);
  __pyx_v_tails = ((PyObject*)Py_None); __Pyx_INCREF(Py_None);

  /* "bzrlib/_known_graph_pyx.pyx":287
 *         cdef Py_ssize_t pos
 * 
 *         tails = []             # <<<<<<<<<<<<<<
 *         pos = 0
 *         while PyDict_Next(self._nodes, &pos, NULL, &temp_node):
 */
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 287; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_1));
  __Pyx_DECREF(((PyObject *)__pyx_v_tails));
  __pyx_v_tails = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "bzrlib/_known_graph_pyx.pyx":288
 * 
 *         tails = []
 *         pos = 0             # <<<<<<<<<<<<<<
 *         while PyDict_Next(self._nodes, &pos, NULL, &temp_node):
 *             node = <_KnownGraphNode>temp_node
 */
  __pyx_v_pos = 0;

  /* "bzrlib/_known_graph_pyx.pyx":289
 *         tails = []
 *         pos = 0
 *         while PyDict_Next(self._nodes, &pos, NULL, &temp_node):             # <<<<<<<<<<<<<<
 *             node = <_KnownGraphNode>temp_node
 *             if node.parents is None or PyTuple_GET_SIZE(node.parents) == 0:
 */
  while (1) {
    __pyx_t_1 = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *)__pyx_v_self)->_nodes;
    __Pyx_INCREF(__pyx_t_1);
    __pyx_t_2 = PyDict_Next(__pyx_t_1, (&__pyx_v_pos), NULL, (&__pyx_v_temp_node));
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (!__pyx_t_2) break;

    /* "bzrlib/_known_graph_pyx.pyx":290
 *         pos = 0
 *         while PyDict_Next(self._nodes, &pos, NULL, &temp_node):
 *             node = <_KnownGraphNode>temp_node             # <<<<<<<<<<<<<<
 *             if node.parents is None or PyTuple_GET_SIZE(node.parents) == 0:
 *                 node.gdfo = 1
 */
    __Pyx_INCREF(((PyObject *)((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_v_temp_node)));
    __Pyx_DECREF(((PyObject *)__pyx_v_node));
    __pyx_v_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_v_temp_node);

    /* "bzrlib/_known_graph_pyx.pyx":291
 *         while PyDict_Next(self._nodes, &pos, NULL, &temp_node):
 *             node = <_KnownGraphNode>temp_node
 *             if node.parents is None or PyTuple_GET_SIZE(node.parents) == 0:             # <<<<<<<<<<<<<<
 *                 node.gdfo = 1
 *                 PyList_Append(tails, node)
 */
    __pyx_t_3 = (__pyx_v_node->parents == Py_None);
    if (!__pyx_t_3) {
      __pyx_t_1 = __pyx_v_node->parents;
      __Pyx_INCREF(__pyx_t_1);
      __pyx_t_4 = (PyTuple_GET_SIZE(__pyx_t_1) == 0);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_5 = __pyx_t_4;
    } else {
      __pyx_t_5 = __pyx_t_3;
    }
    if (__pyx_t_5) {

      /* "bzrlib/_known_graph_pyx.pyx":292
 *             node = <_KnownGraphNode>temp_node
 *             if node.parents is None or PyTuple_GET_SIZE(node.parents) == 0:
 *                 node.gdfo = 1             # <<<<<<<<<<<<<<
 *                 PyList_Append(tails, node)
 *         return tails
 */
      __pyx_v_node->gdfo = 1;

      /* "bzrlib/_known_graph_pyx.pyx":293
 *             if node.parents is None or PyTuple_GET_SIZE(node.parents) == 0:
 *                 node.gdfo = 1
 *                 PyList_Append(tails, node)             # <<<<<<<<<<<<<<
 *         return tails
 * 
 */
      __pyx_t_2 = PyList_Append(((PyObject *)__pyx_v_tails), ((PyObject *)__pyx_v_node)); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 293; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      goto __pyx_L7;
    }
    __pyx_L7:;
  }

  /* "bzrlib/_known_graph_pyx.pyx":294
 *                 node.gdfo = 1
 *                 PyList_Append(tails, node)
 *         return tails             # <<<<<<<<<<<<<<
 * 
 *     def _find_tips(self):
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(((PyObject *)__pyx_v_tails));
  __pyx_r = ((PyObject *)__pyx_v_tails);
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("bzrlib._known_graph_pyx.KnownGraph._find_tails");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_DECREF((PyObject *)__pyx_v_node);
  __Pyx_DECREF(__pyx_v_tails);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "bzrlib/_known_graph_pyx.pyx":296
 *         return tails
 * 
 *     def _find_tips(self):             # <<<<<<<<<<<<<<
 *         cdef PyObject *temp_node
 *         cdef _KnownGraphNode node
 */

static PyObject *__pyx_pf_6bzrlib_16_known_graph_pyx_10KnownGraph_4_find_tips(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static PyObject *__pyx_pf_6bzrlib_16_known_graph_pyx_10KnownGraph_4_find_tips(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_v_temp_node;
  struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *__pyx_v_node;
  Py_ssize_t __pyx_v_pos;
  PyObject *__pyx_v_tips;
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  int __pyx_t_3;
  __Pyx_RefNannySetupContext("_find_tips");
  __pyx_v_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)Py_None); __Pyx_INCREF(Py_None);
  __pyx_v_tips = ((PyObject*)Py_None); __Pyx_INCREF(Py_None);

  /* "bzrlib/_known_graph_pyx.pyx":301
 *         cdef Py_ssize_t pos
 * 
 *         tips = []             # <<<<<<<<<<<<<<
 *         pos = 0
 *         while PyDict_Next(self._nodes, &pos, NULL, &temp_node):
 */
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 301; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_1));
  __Pyx_DECREF(((PyObject *)__pyx_v_tips));
  __pyx_v_tips = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "bzrlib/_known_graph_pyx.pyx":302
 * 
 *         tips = []
 *         pos = 0             # <<<<<<<<<<<<<<
 *         while PyDict_Next(self._nodes, &pos, NULL, &temp_node):
 *             node = <_KnownGraphNode>temp_node
 */
  __pyx_v_pos = 0;

  /* "bzrlib/_known_graph_pyx.pyx":303
 *         tips = []
 *         pos = 0
 *         while PyDict_Next(self._nodes, &pos, NULL, &temp_node):             # <<<<<<<<<<<<<<
 *             node = <_KnownGraphNode>temp_node
 *             if PyList_GET_SIZE(node.children) == 0:
 */
  while (1) {
    __pyx_t_1 = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *)__pyx_v_self)->_nodes;
    __Pyx_INCREF(__pyx_t_1);
    __pyx_t_2 = PyDict_Next(__pyx_t_1, (&__pyx_v_pos), NULL, (&__pyx_v_temp_node));
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (!__pyx_t_2) break;

    /* "bzrlib/_known_graph_pyx.pyx":304
 *         pos = 0
 *         while PyDict_Next(self._nodes, &pos, NULL, &temp_node):
 *             node = <_KnownGraphNode>temp_node             # <<<<<<<<<<<<<<
 *             if PyList_GET_SIZE(node.children) == 0:
 *                 PyList_Append(tips, node)
 */
    __Pyx_INCREF(((PyObject *)((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_v_temp_node)));
    __Pyx_DECREF(((PyObject *)__pyx_v_node));
    __pyx_v_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_v_temp_node);

    /* "bzrlib/_known_graph_pyx.pyx":305
 *         while PyDict_Next(self._nodes, &pos, NULL, &temp_node):
 *             node = <_KnownGraphNode>temp_node
 *             if PyList_GET_SIZE(node.children) == 0:             # <<<<<<<<<<<<<<
 *                 PyList_Append(tips, node)
 *         return tips
 */
    __pyx_t_1 = __pyx_v_node->children;
    __Pyx_INCREF(__pyx_t_1);
    __pyx_t_3 = (PyList_GET_SIZE(__pyx_t_1) == 0);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (__pyx_t_3) {

      /* "bzrlib/_known_graph_pyx.pyx":306
 *             node = <_KnownGraphNode>temp_node
 *             if PyList_GET_SIZE(node.children) == 0:
 *                 PyList_Append(tips, node)             # <<<<<<<<<<<<<<
 *         return tips
 * 
 */
      __pyx_t_2 = PyList_Append(((PyObject *)__pyx_v_tips), ((PyObject *)__pyx_v_node)); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 306; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      goto __pyx_L7;
    }
    __pyx_L7:;
  }

  /* "bzrlib/_known_graph_pyx.pyx":307
 *             if PyList_GET_SIZE(node.children) == 0:
 *                 PyList_Append(tips, node)
 *         return tips             # <<<<<<<<<<<<<<
 * 
 *     def _find_gdfo(self):
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(((PyObject *)__pyx_v_tips));
  __pyx_r = ((PyObject *)__pyx_v_tips);
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("bzrlib._known_graph_pyx.KnownGraph._find_tips");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_DECREF((PyObject *)__pyx_v_node);
  __Pyx_DECREF(__pyx_v_tips);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "bzrlib/_known_graph_pyx.pyx":309
 *         return tips
 * 
 *     def _find_gdfo(self):             # <<<<<<<<<<<<<<
 *         cdef _KnownGraphNode node
 *         cdef _KnownGraphNode child
 */

static PyObject *__pyx_pf_6bzrlib_16_known_graph_pyx_10KnownGraph_5_find_gdfo(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static PyObject *__pyx_pf_6bzrlib_16_known_graph_pyx_10KnownGraph_5_find_gdfo(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *__pyx_v_node;
  struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *__pyx_v_child;
  Py_ssize_t __pyx_v_pos;
  Py_ssize_t __pyx_v_last_item;
  long __pyx_v_next_gdfo;
  PyObject *__pyx_v_pending;
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  Py_ssize_t __pyx_t_4;
  int __pyx_t_5;
  __Pyx_RefNannySetupContext("_find_gdfo");
  __pyx_v_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)Py_None); __Pyx_INCREF(Py_None);
  __pyx_v_child = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)Py_None); __Pyx_INCREF(Py_None);
  __pyx_v_pending = Py_None; __Pyx_INCREF(Py_None);

  /* "bzrlib/_known_graph_pyx.pyx":318
 *         cdef long next_gdfo
 * 
 *         pending = self._find_tails()             # <<<<<<<<<<<<<<
 * 
 *         last_item = PyList_GET_SIZE(pending) - 1
 */
  __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s___find_tails); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 318; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 318; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_v_pending);
  __pyx_v_pending = __pyx_t_2;
  __pyx_t_2 = 0;

  /* "bzrlib/_known_graph_pyx.pyx":320
 *         pending = self._find_tails()
 * 
 *         last_item = PyList_GET_SIZE(pending) - 1             # <<<<<<<<<<<<<<
 *         while last_item >= 0:
 *             # Avoid pop followed by push, instead, peek, and replace
 */
  __pyx_v_last_item = (PyList_GET_SIZE(__pyx_v_pending) - 1);

  /* "bzrlib/_known_graph_pyx.pyx":321
 * 
 *         last_item = PyList_GET_SIZE(pending) - 1
 *         while last_item >= 0:             # <<<<<<<<<<<<<<
 *             # Avoid pop followed by push, instead, peek, and replace
 *             # timing shows this is 930ms => 770ms for OOo
 */
  while (1) {
    __pyx_t_3 = (__pyx_v_last_item >= 0);
    if (!__pyx_t_3) break;

    /* "bzrlib/_known_graph_pyx.pyx":324
 *             # Avoid pop followed by push, instead, peek, and replace
 *             # timing shows this is 930ms => 770ms for OOo
 *             node = _get_list_node(pending, last_item)             # <<<<<<<<<<<<<<
 *             last_item = last_item - 1
 *             next_gdfo = node.gdfo + 1
 */
    __pyx_t_2 = ((PyObject *)__pyx_f_6bzrlib_16_known_graph_pyx__get_list_node(__pyx_v_pending, __pyx_v_last_item)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 324; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(((PyObject *)__pyx_v_node));
    __pyx_v_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_t_2);
    __pyx_t_2 = 0;

    /* "bzrlib/_known_graph_pyx.pyx":325
 *             # timing shows this is 930ms => 770ms for OOo
 *             node = _get_list_node(pending, last_item)
 *             last_item = last_item - 1             # <<<<<<<<<<<<<<
 *             next_gdfo = node.gdfo + 1
 *             for pos from 0 <= pos < PyList_GET_SIZE(node.children):
 */
    __pyx_v_last_item = (__pyx_v_last_item - 1);

    /* "bzrlib/_known_graph_pyx.pyx":326
 *             node = _get_list_node(pending, last_item)
 *             last_item = last_item - 1
 *             next_gdfo = node.gdfo + 1             # <<<<<<<<<<<<<<
 *             for pos from 0 <= pos < PyList_GET_SIZE(node.children):
 *                 child = _get_list_node(node.children, pos)
 */
    __pyx_v_next_gdfo = (__pyx_v_node->gdfo + 1);

    /* "bzrlib/_known_graph_pyx.pyx":327
 *             last_item = last_item - 1
 *             next_gdfo = node.gdfo + 1
 *             for pos from 0 <= pos < PyList_GET_SIZE(node.children):             # <<<<<<<<<<<<<<
 *                 child = _get_list_node(node.children, pos)
 *                 if next_gdfo > child.gdfo:
 */
    __pyx_t_2 = __pyx_v_node->children;
    __Pyx_INCREF(__pyx_t_2);
    __pyx_t_4 = PyList_GET_SIZE(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    for (__pyx_v_pos = 0; __pyx_v_pos < __pyx_t_4; __pyx_v_pos++) {

      /* "bzrlib/_known_graph_pyx.pyx":328
 *             next_gdfo = node.gdfo + 1
 *             for pos from 0 <= pos < PyList_GET_SIZE(node.children):
 *                 child = _get_list_node(node.children, pos)             # <<<<<<<<<<<<<<
 *                 if next_gdfo > child.gdfo:
 *                     child.gdfo = next_gdfo
 */
      __pyx_t_2 = __pyx_v_node->children;
      __Pyx_INCREF(__pyx_t_2);
      __pyx_t_1 = ((PyObject *)__pyx_f_6bzrlib_16_known_graph_pyx__get_list_node(__pyx_t_2, __pyx_v_pos)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 328; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_DECREF(((PyObject *)__pyx_v_child));
      __pyx_v_child = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_t_1);
      __pyx_t_1 = 0;

      /* "bzrlib/_known_graph_pyx.pyx":329
 *             for pos from 0 <= pos < PyList_GET_SIZE(node.children):
 *                 child = _get_list_node(node.children, pos)
 *                 if next_gdfo > child.gdfo:             # <<<<<<<<<<<<<<
 *                     child.gdfo = next_gdfo
 *                 child.seen = child.seen + 1
 */
      __pyx_t_3 = (__pyx_v_next_gdfo > __pyx_v_child->gdfo);
      if (__pyx_t_3) {

        /* "bzrlib/_known_graph_pyx.pyx":330
 *                 child = _get_list_node(node.children, pos)
 *                 if next_gdfo > child.gdfo:
 *                     child.gdfo = next_gdfo             # <<<<<<<<<<<<<<
 *                 child.seen = child.seen + 1
 *                 if child.seen == PyTuple_GET_SIZE(child.parents):
 */
        __pyx_v_child->gdfo = __pyx_v_next_gdfo;
        goto __pyx_L9;
      }
      __pyx_L9:;

      /* "bzrlib/_known_graph_pyx.pyx":331
 *                 if next_gdfo > child.gdfo:
 *                     child.gdfo = next_gdfo
 *                 child.seen = child.seen + 1             # <<<<<<<<<<<<<<
 *                 if child.seen == PyTuple_GET_SIZE(child.parents):
 *                     # This child is populated, queue it to be walked
 */
      __pyx_v_child->seen = (__pyx_v_child->seen + 1);

      /* "bzrlib/_known_graph_pyx.pyx":332
 *                     child.gdfo = next_gdfo
 *                 child.seen = child.seen + 1
 *                 if child.seen == PyTuple_GET_SIZE(child.parents):             # <<<<<<<<<<<<<<
 *                     # This child is populated, queue it to be walked
 *                     last_item = last_item + 1
 */
      __pyx_t_1 = __pyx_v_child->parents;
      __Pyx_INCREF(__pyx_t_1);
      __pyx_t_3 = (__pyx_v_child->seen == PyTuple_GET_SIZE(__pyx_t_1));
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      if (__pyx_t_3) {

        /* "bzrlib/_known_graph_pyx.pyx":334
 *                 if child.seen == PyTuple_GET_SIZE(child.parents):
 *                     # This child is populated, queue it to be walked
 *                     last_item = last_item + 1             # <<<<<<<<<<<<<<
 *                     if last_item < PyList_GET_SIZE(pending):
 *                         Py_INCREF(child) # SetItem steals a ref
 */
        __pyx_v_last_item = (__pyx_v_last_item + 1);

        /* "bzrlib/_known_graph_pyx.pyx":335
 *                     # This child is populated, queue it to be walked
 *                     last_item = last_item + 1
 *                     if last_item < PyList_GET_SIZE(pending):             # <<<<<<<<<<<<<<
 *                         Py_INCREF(child) # SetItem steals a ref
 *                         PyList_SetItem(pending, last_item, child)
 */
        __pyx_t_3 = (__pyx_v_last_item < PyList_GET_SIZE(__pyx_v_pending));
        if (__pyx_t_3) {

          /* "bzrlib/_known_graph_pyx.pyx":336
 *                     last_item = last_item + 1
 *                     if last_item < PyList_GET_SIZE(pending):
 *                         Py_INCREF(child) # SetItem steals a ref             # <<<<<<<<<<<<<<
 *                         PyList_SetItem(pending, last_item, child)
 *                     else:
 */
          Py_INCREF(((PyObject *)__pyx_v_child));

          /* "bzrlib/_known_graph_pyx.pyx":337
 *                     if last_item < PyList_GET_SIZE(pending):
 *                         Py_INCREF(child) # SetItem steals a ref
 *                         PyList_SetItem(pending, last_item, child)             # <<<<<<<<<<<<<<
 *                     else:
 *                         PyList_Append(pending, child)
 */
          __pyx_t_5 = PyList_SetItem(__pyx_v_pending, __pyx_v_last_item, ((PyObject *)__pyx_v_child)); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 337; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          goto __pyx_L11;
        }
        /*else*/ {

          /* "bzrlib/_known_graph_pyx.pyx":339
 *                         PyList_SetItem(pending, last_item, child)
 *                     else:
 *                         PyList_Append(pending, child)             # <<<<<<<<<<<<<<
 *                     # We have queued this node, we don't need to track it
 *                     # anymore
 */
          __pyx_t_5 = PyList_Append(__pyx_v_pending, ((PyObject *)__pyx_v_child)); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 339; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        __pyx_L11:;

        /* "bzrlib/_known_graph_pyx.pyx":342
 *                     # We have queued this node, we don't need to track it
 *                     # anymore
 *                     child.seen = 0             # <<<<<<<<<<<<<<
 * 
 *     def add_node(self, key, parent_keys):
 */
        __pyx_v_child->seen = 0;
        goto __pyx_L10;
      }
      __pyx_L10:;
    }
  }

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("bzrlib._known_graph_pyx.KnownGraph._find_gdfo");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_DECREF((PyObject *)__pyx_v_node);
  __Pyx_DECREF((PyObject *)__pyx_v_child);
  __Pyx_DECREF(__pyx_v_pending);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "bzrlib/_known_graph_pyx.pyx":344
 *                     child.seen = 0
 * 
 *     def add_node(self, key, parent_keys):             # <<<<<<<<<<<<<<
 *         """Add a new node to the graph.
 * 
 */

static PyObject *__pyx_pf_6bzrlib_16_known_graph_pyx_10KnownGraph_6add_node(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_6bzrlib_16_known_graph_pyx_10KnownGraph_6add_node[] = "Add a new node to the graph.\n\n        If this fills in a ghost, then the gdfos of all children will be\n        updated accordingly.\n        \n        :param key: The node being added. If this is a duplicate, this is a\n            no-op.\n        :param parent_keys: The parents of the given node.\n        :return: None (should we return if this was a ghost, etc?)\n        ";
static PyObject *__pyx_pf_6bzrlib_16_known_graph_pyx_10KnownGraph_6add_node(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_key = 0;
  PyObject *__pyx_v_parent_keys = 0;
  PyObject *__pyx_v_maybe_node;
  struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *__pyx_v_node;
  struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *__pyx_v_parent_node;
  struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *__pyx_v_child_node;
  long __pyx_v_parent_gdfo;
  long __pyx_v_next_gdfo;
  PyObject *__pyx_v_existing_parent_keys;
  PyObject *__pyx_v_pending;
  PyObject *__pyx_v_pending_popleft;
  PyObject *__pyx_v_pending_append;
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  Py_ssize_t __pyx_t_4;
  int __pyx_t_5;
  PyObject *__pyx_t_6 = NULL;
  static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__key,&__pyx_n_s__parent_keys,0};
  __Pyx_RefNannySetupContext("add_node");
  if (unlikely(__pyx_kwds)) {
    Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
    PyObject* values[2] = {0,0};
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      case  0: break;
      default: goto __pyx_L5_argtuple_error;
    }
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  0:
      values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__key);
      if (likely(values[0])) kw_args--;
      else goto __pyx_L5_argtuple_error;
      case  1:
      values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__parent_keys);
      if (likely(values[1])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("add_node", 1, 2, 2, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 344; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    }
    if (unlikely(kw_args > 0)) {
      if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "add_node") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 344; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    }
    __pyx_v_key = values[0];
    __pyx_v_parent_keys = values[1];
  } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
    goto __pyx_L5_argtuple_error;
  } else {
    __pyx_v_key = PyTuple_GET_ITEM(__pyx_args, 0);
    __pyx_v_parent_keys = PyTuple_GET_ITEM(__pyx_args, 1);
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("add_node", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 344; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("bzrlib._known_graph_pyx.KnownGraph.add_node");
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __Pyx_INCREF(__pyx_v_parent_keys);
  __pyx_v_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)Py_None); __Pyx_INCREF(Py_None);
  __pyx_v_parent_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)Py_None); __Pyx_INCREF(Py_None);
  __pyx_v_child_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)Py_None); __Pyx_INCREF(Py_None);
  __pyx_v_existing_parent_keys = ((PyObject*)Py_None); __Pyx_INCREF(Py_None);
  __pyx_v_pending = Py_None; __Pyx_INCREF(Py_None);
  __pyx_v_pending_popleft = Py_None; __Pyx_INCREF(Py_None);
  __pyx_v_pending_append = Py_None; __Pyx_INCREF(Py_None);

  /* "bzrlib/_known_graph_pyx.pyx":359
 *         cdef long parent_gdfo, next_gdfo
 * 
 *         maybe_node = PyDict_GetItem(self._nodes, key)             # <<<<<<<<<<<<<<
 *         if maybe_node != NULL:
 *             node = <_KnownGraphNode>maybe_node
 */
  __pyx_t_1 = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *)__pyx_v_self)->_nodes;
  __Pyx_INCREF(__pyx_t_1);
  __pyx_v_maybe_node = PyDict_GetItem(__pyx_t_1, __pyx_v_key);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "bzrlib/_known_graph_pyx.pyx":360
 * 
 *         maybe_node = PyDict_GetItem(self._nodes, key)
 *         if maybe_node != NULL:             # <<<<<<<<<<<<<<
 *             node = <_KnownGraphNode>maybe_node
 *             if node.parents is None:
 */
  __pyx_t_2 = (__pyx_v_maybe_node != NULL);
  if (__pyx_t_2) {

    /* "bzrlib/_known_graph_pyx.pyx":361
 *         maybe_node = PyDict_GetItem(self._nodes, key)
 *         if maybe_node != NULL:
 *             node = <_KnownGraphNode>maybe_node             # <<<<<<<<<<<<<<
 *             if node.parents is None:
 *                 # We are filling in a ghost
 */
    __Pyx_INCREF(((PyObject *)((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_v_maybe_node)));
    __Pyx_DECREF(((PyObject *)__pyx_v_node));
    __pyx_v_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_v_maybe_node);

    /* "bzrlib/_known_graph_pyx.pyx":362
 *         if maybe_node != NULL:
 *             node = <_KnownGraphNode>maybe_node
 *             if node.parents is None:             # <<<<<<<<<<<<<<
 *                 # We are filling in a ghost
 *                 self._populate_parents(node, parent_keys)
 */
    __pyx_t_2 = (__pyx_v_node->parents == Py_None);
    if (__pyx_t_2) {

      /* "bzrlib/_known_graph_pyx.pyx":364
 *             if node.parents is None:
 *                 # We are filling in a ghost
 *                 self._populate_parents(node, parent_keys)             # <<<<<<<<<<<<<<
 *                 # We can't trust cached heads anymore
 *                 self._known_heads.clear()
 */
      __pyx_t_1 = ((struct __pyx_vtabstruct_6bzrlib_16_known_graph_pyx_KnownGraph *)((struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *)__pyx_v_self)->__pyx_vtab)->_populate_parents(((struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *)__pyx_v_self), __pyx_v_node, __pyx_v_parent_keys); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 364; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

      /* "bzrlib/_known_graph_pyx.pyx":366
 *                 self._populate_parents(node, parent_keys)
 *                 # We can't trust cached heads anymore
 *                 self._known_heads.clear()             # <<<<<<<<<<<<<<
 *             else: # Ensure that the parent_key list matches
 *                 existing_parent_keys = []
 */
      __pyx_t_1 = PyObject_GetAttr(((struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *)__pyx_v_self)->_known_heads, __pyx_n_s__clear); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 366; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 366; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      goto __pyx_L7;
    }
    /*else*/ {

      /* "bzrlib/_known_graph_pyx.pyx":368
 *                 self._known_heads.clear()
 *             else: # Ensure that the parent_key list matches
 *                 existing_parent_keys = []             # <<<<<<<<<<<<<<
 *                 for parent_node in node.parents:
 *                     existing_parent_keys.append(parent_node.key)
 */
      __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 368; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(((PyObject *)__pyx_t_3));
      __Pyx_DECREF(((PyObject *)__pyx_v_existing_parent_keys));
      __pyx_v_existing_parent_keys = __pyx_t_3;
      __pyx_t_3 = 0;

      /* "bzrlib/_known_graph_pyx.pyx":369
 *             else: # Ensure that the parent_key list matches
 *                 existing_parent_keys = []
 *                 for parent_node in node.parents:             # <<<<<<<<<<<<<<
 *                     existing_parent_keys.append(parent_node.key)
 *                 # Make sure we use a list for the comparison, in case it was a
 */
      if (PyList_CheckExact(__pyx_v_node->parents) || PyTuple_CheckExact(__pyx_v_node->parents)) {
        __pyx_t_4 = 0; __pyx_t_3 = __pyx_v_node->parents; __Pyx_INCREF(__pyx_t_3);
      } else {
        __pyx_t_4 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_v_node->parents); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 369; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_3);
      }
      for (;;) {
        if (likely(PyList_CheckExact(__pyx_t_3))) {
          if (__pyx_t_4 >= PyList_GET_SIZE(__pyx_t_3)) break;
          __pyx_t_1 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_4); __Pyx_INCREF(__pyx_t_1); __pyx_t_4++;
        } else if (likely(PyTuple_CheckExact(__pyx_t_3))) {
          if (__pyx_t_4 >= PyTuple_GET_SIZE(__pyx_t_3)) break;
          __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_4); __Pyx_INCREF(__pyx_t_1); __pyx_t_4++;
        } else {
          __pyx_t_1 = PyIter_Next(__pyx_t_3);
          if (!__pyx_t_1) {
            if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 369; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
            break;
          }
          __Pyx_GOTREF(__pyx_t_1);
        }
        if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_6bzrlib_16_known_graph_pyx__KnownGraphNode))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 369; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(((PyObject *)__pyx_v_parent_node));
        __pyx_v_parent_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_t_1);
        __pyx_t_1 = 0;

        /* "bzrlib/_known_graph_pyx.pyx":370
 *                 existing_parent_keys = []
 *                 for parent_node in node.parents:
 *                     existing_parent_keys.append(parent_node.key)             # <<<<<<<<<<<<<<
 *                 # Make sure we use a list for the comparison, in case it was a
 *                 # tuple, etc
 */
        if (unlikely(__pyx_v_existing_parent_keys == Py_None)) {
          PyErr_SetString(PyExc_AttributeError, "'NoneType' object has no attribute 'append'"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 370; __pyx_clineno = __LINE__; goto __pyx_L1_error;} 
        }
        __pyx_t_1 = __pyx_v_parent_node->key;
        __Pyx_INCREF(__pyx_t_1);
        __pyx_t_5 = PyList_Append(__pyx_v_existing_parent_keys, __pyx_t_1); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 370; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      }
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

      /* "bzrlib/_known_graph_pyx.pyx":373
 *                 # Make sure we use a list for the comparison, in case it was a
 *                 # tuple, etc
 *                 parent_keys = list(parent_keys)             # <<<<<<<<<<<<<<
 *                 if existing_parent_keys == parent_keys:
 *                     # Exact match, nothing more to do
 */
      __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 373; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(((PyObject *)__pyx_t_3));
      __Pyx_INCREF(__pyx_v_parent_keys);
      PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_parent_keys);
      __Pyx_GIVEREF(__pyx_v_parent_keys);
      __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)(&PyList_Type))), ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 373; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
      __Pyx_DECREF(__pyx_v_parent_keys);
      __pyx_v_parent_keys = __pyx_t_1;
      __pyx_t_1 = 0;

      /* "bzrlib/_known_graph_pyx.pyx":374
 *                 # tuple, etc
 *                 parent_keys = list(parent_keys)
 *                 if existing_parent_keys == parent_keys:             # <<<<<<<<<<<<<<
 *                     # Exact match, nothing more to do
 *                     return
 */
      __pyx_t_1 = PyObject_RichCompare(((PyObject *)__pyx_v_existing_parent_keys), __pyx_v_parent_keys, Py_EQ); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 374; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 374; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      if (__pyx_t_2) {

        /* "bzrlib/_known_graph_pyx.pyx":376
 *                 if existing_parent_keys == parent_keys:
 *                     # Exact match, nothing more to do
 *                     return             # <<<<<<<<<<<<<<
 *                 else:
 *                     raise ValueError('Parent key mismatch, existing node %s'
 */
        __Pyx_XDECREF(__pyx_r);
        __pyx_r = Py_None; __Pyx_INCREF(Py_None);
        goto __pyx_L0;
        goto __pyx_L10;
      }
      /*else*/ {

        /* "bzrlib/_known_graph_pyx.pyx":380
 *                     raise ValueError('Parent key mismatch, existing node %s'
 *                         ' has parents of %s not %s'
 *                         % (key, existing_parent_keys, parent_keys))             # <<<<<<<<<<<<<<
 *         else:
 *             node = _KnownGraphNode(key)
 */
        __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 380; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(((PyObject *)__pyx_t_1));
        __Pyx_INCREF(__pyx_v_key);
        PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_key);
        __Pyx_GIVEREF(__pyx_v_key);
        __Pyx_INCREF(((PyObject *)__pyx_v_existing_parent_keys));
        PyTuple_SET_ITEM(__pyx_t_1, 1, ((PyObject *)__pyx_v_existing_parent_keys));
        __Pyx_GIVEREF(((PyObject *)__pyx_v_existing_parent_keys));
        __Pyx_INCREF(__pyx_v_parent_keys);
        PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_v_parent_keys);
        __Pyx_GIVEREF(__pyx_v_parent_keys);
        __pyx_t_3 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_7), ((PyObject *)__pyx_t_1)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 380; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(((PyObject *)__pyx_t_3));
        __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
        __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 378; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(((PyObject *)__pyx_t_1));
        PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_t_3));
        __Pyx_GIVEREF(((PyObject *)__pyx_t_3));
        __pyx_t_3 = 0;
        __pyx_t_3 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 378; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
        __Pyx_Raise(__pyx_t_3, 0, 0);
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 378; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      __pyx_L10:;
    }
    __pyx_L7:;
    goto __pyx_L6;
  }
  /*else*/ {

    /* "bzrlib/_known_graph_pyx.pyx":382
 *                         % (key, existing_parent_keys, parent_keys))
 *         else:
 *             node = _KnownGraphNode(key)             # <<<<<<<<<<<<<<
 *             PyDict_SetItem(self._nodes, key, node)
 *             self._populate_parents(node, parent_keys)
 */
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 382; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_3));
    __Pyx_INCREF(__pyx_v_key);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_key);
    __Pyx_GIVEREF(__pyx_v_key);
    __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_6bzrlib_16_known_graph_pyx__KnownGraphNode)), ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 382; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_v_node));
    __pyx_v_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_t_1);
    __pyx_t_1 = 0;

    /* "bzrlib/_known_graph_pyx.pyx":383
 *         else:
 *             node = _KnownGraphNode(key)
 *             PyDict_SetItem(self._nodes, key, node)             # <<<<<<<<<<<<<<
 *             self._populate_parents(node, parent_keys)
 *         parent_gdfo = 0
 */
    __pyx_t_1 = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *)__pyx_v_self)->_nodes;
    __Pyx_INCREF(__pyx_t_1);
    __pyx_t_5 = PyDict_SetItem(__pyx_t_1, __pyx_v_key, ((PyObject *)__pyx_v_node)); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 383; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "bzrlib/_known_graph_pyx.pyx":384
 *             node = _KnownGraphNode(key)
 *             PyDict_SetItem(self._nodes, key, node)
 *             self._populate_parents(node, parent_keys)             # <<<<<<<<<<<<<<
 *         parent_gdfo = 0
 *         for parent_node in node.parents:
 */
    __pyx_t_1 = ((struct __pyx_vtabstruct_6bzrlib_16_known_graph_pyx_KnownGraph *)((struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *)__pyx_v_self)->__pyx_vtab)->_populate_parents(((struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *)__pyx_v_self), __pyx_v_node, __pyx_v_parent_keys); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 384; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  }
  __pyx_L6:;

  /* "bzrlib/_known_graph_pyx.pyx":385
 *             PyDict_SetItem(self._nodes, key, node)
 *             self._populate_parents(node, parent_keys)
 *         parent_gdfo = 0             # <<<<<<<<<<<<<<
 *         for parent_node in node.parents:
 *             if parent_node.gdfo == -1:
 */
  __pyx_v_parent_gdfo = 0;

  /* "bzrlib/_known_graph_pyx.pyx":386
 *             self._populate_parents(node, parent_keys)
 *         parent_gdfo = 0
 *         for parent_node in node.parents:             # <<<<<<<<<<<<<<
 *             if parent_node.gdfo == -1:
 *                 # This is a newly introduced ghost, so it gets gdfo of 1
 */
  if (PyList_CheckExact(__pyx_v_node->parents) || PyTuple_CheckExact(__pyx_v_node->parents)) {
    __pyx_t_4 = 0; __pyx_t_1 = __pyx_v_node->parents; __Pyx_INCREF(__pyx_t_1);
  } else {
    __pyx_t_4 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_v_node->parents); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 386; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
  }
  for (;;) {
    if (likely(PyList_CheckExact(__pyx_t_1))) {
      if (__pyx_t_4 >= PyList_GET_SIZE(__pyx_t_1)) break;
      __pyx_t_3 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_4); __Pyx_INCREF(__pyx_t_3); __pyx_t_4++;
    } else if (likely(PyTuple_CheckExact(__pyx_t_1))) {
      if (__pyx_t_4 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
      __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_4); __Pyx_INCREF(__pyx_t_3); __pyx_t_4++;
    } else {
      __pyx_t_3 = PyIter_Next(__pyx_t_1);
      if (!__pyx_t_3) {
        if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 386; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        break;
      }
      __Pyx_GOTREF(__pyx_t_3);
    }
    if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_6bzrlib_16_known_graph_pyx__KnownGraphNode))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 386; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(((PyObject *)__pyx_v_parent_node));
    __pyx_v_parent_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_t_3);
    __pyx_t_3 = 0;

    /* "bzrlib/_known_graph_pyx.pyx":387
 *         parent_gdfo = 0
 *         for parent_node in node.parents:
 *             if parent_node.gdfo == -1:             # <<<<<<<<<<<<<<
 *                 # This is a newly introduced ghost, so it gets gdfo of 1
 *                 parent_node.gdfo = 1
 */
    __pyx_t_2 = (__pyx_v_parent_node->gdfo == -1);
    if (__pyx_t_2) {

      /* "bzrlib/_known_graph_pyx.pyx":389
 *             if parent_node.gdfo == -1:
 *                 # This is a newly introduced ghost, so it gets gdfo of 1
 *                 parent_node.gdfo = 1             # <<<<<<<<<<<<<<
 *             if parent_gdfo < parent_node.gdfo:
 *                 parent_gdfo = parent_node.gdfo
 */
      __pyx_v_parent_node->gdfo = 1;
      goto __pyx_L13;
    }
    __pyx_L13:;

    /* "bzrlib/_known_graph_pyx.pyx":390
 *                 # This is a newly introduced ghost, so it gets gdfo of 1
 *                 parent_node.gdfo = 1
 *             if parent_gdfo < parent_node.gdfo:             # <<<<<<<<<<<<<<
 *                 parent_gdfo = parent_node.gdfo
 *         node.gdfo = parent_gdfo + 1
 */
    __pyx_t_2 = (__pyx_v_parent_gdfo < __pyx_v_parent_node->gdfo);
    if (__pyx_t_2) {

      /* "bzrlib/_known_graph_pyx.pyx":391
 *                 parent_node.gdfo = 1
 *             if parent_gdfo < parent_node.gdfo:
 *                 parent_gdfo = parent_node.gdfo             # <<<<<<<<<<<<<<
 *         node.gdfo = parent_gdfo + 1
 *         # Now fill the gdfo to all children
 */
      __pyx_v_parent_gdfo = __pyx_v_parent_node->gdfo;
      goto __pyx_L14;
    }
    __pyx_L14:;
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "bzrlib/_known_graph_pyx.pyx":392
 *             if parent_gdfo < parent_node.gdfo:
 *                 parent_gdfo = parent_node.gdfo
 *         node.gdfo = parent_gdfo + 1             # <<<<<<<<<<<<<<
 *         # Now fill the gdfo to all children
 *         # Note that this loop is slightly inefficient, in that we may visit the
 */
  __pyx_v_node->gdfo = (__pyx_v_parent_gdfo + 1);

  /* "bzrlib/_known_graph_pyx.pyx":401
 *         # than DFD. So that if a longer path is possible, we walk it before we
 *         # get to the final child
 *         pending = deque([node])             # <<<<<<<<<<<<<<
 *         pending_popleft = pending.popleft
 *         pending_append = pending.append
 */
  __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__deque); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 401; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = PyList_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 401; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_3));
  __Pyx_INCREF(((PyObject *)__pyx_v_node));
  PyList_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_v_node));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_node));
  __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 401; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_6));
  PyTuple_SET_ITEM(__pyx_t_6, 0, ((PyObject *)__pyx_t_3));
  __Pyx_GIVEREF(((PyObject *)__pyx_t_3));
  __pyx_t_3 = 0;
  __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_6), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 401; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0;
  __Pyx_DECREF(__pyx_v_pending);
  __pyx_v_pending = __pyx_t_3;
  __pyx_t_3 = 0;

  /* "bzrlib/_known_graph_pyx.pyx":402
 *         # get to the final child
 *         pending = deque([node])
 *         pending_popleft = pending.popleft             # <<<<<<<<<<<<<<
 *         pending_append = pending.append
 *         while pending:
 */
  __pyx_t_3 = PyObject_GetAttr(__pyx_v_pending, __pyx_n_s__popleft); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 402; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_v_pending_popleft);
  __pyx_v_pending_popleft = __pyx_t_3;
  __pyx_t_3 = 0;

  /* "bzrlib/_known_graph_pyx.pyx":403
 *         pending = deque([node])
 *         pending_popleft = pending.popleft
 *         pending_append = pending.append             # <<<<<<<<<<<<<<
 *         while pending:
 *             node = pending_popleft()
 */
  __pyx_t_3 = PyObject_GetAttr(__pyx_v_pending, __pyx_n_s__append); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 403; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_v_pending_append);
  __pyx_v_pending_append = __pyx_t_3;
  __pyx_t_3 = 0;

  /* "bzrlib/_known_graph_pyx.pyx":404
 *         pending_popleft = pending.popleft
 *         pending_append = pending.append
 *         while pending:             # <<<<<<<<<<<<<<
 *             node = pending_popleft()
 *             next_gdfo = node.gdfo + 1
 */
  while (1) {
    __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_pending); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 404; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (!__pyx_t_2) break;

    /* "bzrlib/_known_graph_pyx.pyx":405
 *         pending_append = pending.append
 *         while pending:
 *             node = pending_popleft()             # <<<<<<<<<<<<<<
 *             next_gdfo = node.gdfo + 1
 *             for child_node in node.children:
 */
    __pyx_t_3 = PyObject_Call(__pyx_v_pending_popleft, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 405; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_6bzrlib_16_known_graph_pyx__KnownGraphNode))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 405; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(((PyObject *)__pyx_v_node));
    __pyx_v_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_t_3);
    __pyx_t_3 = 0;

    /* "bzrlib/_known_graph_pyx.pyx":406
 *         while pending:
 *             node = pending_popleft()
 *             next_gdfo = node.gdfo + 1             # <<<<<<<<<<<<<<
 *             for child_node in node.children:
 *                 if child_node.gdfo < next_gdfo:
 */
    __pyx_v_next_gdfo = (__pyx_v_node->gdfo + 1);

    /* "bzrlib/_known_graph_pyx.pyx":407
 *             node = pending_popleft()
 *             next_gdfo = node.gdfo + 1
 *             for child_node in node.children:             # <<<<<<<<<<<<<<
 *                 if child_node.gdfo < next_gdfo:
 *                     # This child is being updated, we need to check its
 */
    if (PyList_CheckExact(__pyx_v_node->children) || PyTuple_CheckExact(__pyx_v_node->children)) {
      __pyx_t_4 = 0; __pyx_t_3 = __pyx_v_node->children; __Pyx_INCREF(__pyx_t_3);
    } else {
      __pyx_t_4 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_v_node->children); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 407; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
    }
    for (;;) {
      if (likely(PyList_CheckExact(__pyx_t_3))) {
        if (__pyx_t_4 >= PyList_GET_SIZE(__pyx_t_3)) break;
        __pyx_t_6 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_4); __Pyx_INCREF(__pyx_t_6); __pyx_t_4++;
      } else if (likely(PyTuple_CheckExact(__pyx_t_3))) {
        if (__pyx_t_4 >= PyTuple_GET_SIZE(__pyx_t_3)) break;
        __pyx_t_6 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_4); __Pyx_INCREF(__pyx_t_6); __pyx_t_4++;
      } else {
        __pyx_t_6 = PyIter_Next(__pyx_t_3);
        if (!__pyx_t_6) {
          if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 407; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          break;
        }
        __Pyx_GOTREF(__pyx_t_6);
      }
      if (!(likely(((__pyx_t_6) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_6, __pyx_ptype_6bzrlib_16_known_graph_pyx__KnownGraphNode))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 407; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(((PyObject *)__pyx_v_child_node));
      __pyx_v_child_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_t_6);
      __pyx_t_6 = 0;

      /* "bzrlib/_known_graph_pyx.pyx":408
 *             next_gdfo = node.gdfo + 1
 *             for child_node in node.children:
 *                 if child_node.gdfo < next_gdfo:             # <<<<<<<<<<<<<<
 *                     # This child is being updated, we need to check its
 *                     # children
 */
      __pyx_t_2 = (__pyx_v_child_node->gdfo < __pyx_v_next_gdfo);
      if (__pyx_t_2) {

        /* "bzrlib/_known_graph_pyx.pyx":411
 *                     # This child is being updated, we need to check its
 *                     # children
 *                     child_node.gdfo = next_gdfo             # <<<<<<<<<<<<<<
 *                     pending_append(child_node)
 * 
 */
        __pyx_v_child_node->gdfo = __pyx_v_next_gdfo;

        /* "bzrlib/_known_graph_pyx.pyx":412
 *                     # children
 *                     child_node.gdfo = next_gdfo
 *                     pending_append(child_node)             # <<<<<<<<<<<<<<
 * 
 *     def heads(self, keys):
 */
        __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 412; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(((PyObject *)__pyx_t_6));
        __Pyx_INCREF(((PyObject *)__pyx_v_child_node));
        PyTuple_SET_ITEM(__pyx_t_6, 0, ((PyObject *)__pyx_v_child_node));
        __Pyx_GIVEREF(((PyObject *)__pyx_v_child_node));
        __pyx_t_1 = PyObject_Call(__pyx_v_pending_append, ((PyObject *)__pyx_t_6), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 412; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0;
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        goto __pyx_L19;
      }
      __pyx_L19:;
    }
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  }

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_AddTraceback("bzrlib._known_graph_pyx.KnownGraph.add_node");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_DECREF((PyObject *)__pyx_v_node);
  __Pyx_DECREF((PyObject *)__pyx_v_parent_node);
  __Pyx_DECREF((PyObject *)__pyx_v_child_node);
  __Pyx_DECREF(__pyx_v_existing_parent_keys);
  __Pyx_DECREF(__pyx_v_pending);
  __Pyx_DECREF(__pyx_v_pending_popleft);
  __Pyx_DECREF(__pyx_v_pending_append);
  __Pyx_DECREF(__pyx_v_parent_keys);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "bzrlib/_known_graph_pyx.pyx":414
 *                     pending_append(child_node)
 * 
 *     def heads(self, keys):             # <<<<<<<<<<<<<<
 *         """Return the heads from amongst keys.
 * 
 */

static PyObject *__pyx_pf_6bzrlib_16_known_graph_pyx_10KnownGraph_7heads(PyObject *__pyx_v_self, PyObject *__pyx_v_keys); /*proto*/
static char __pyx_doc_6bzrlib_16_known_graph_pyx_10KnownGraph_7heads[] = "Return the heads from amongst keys.\n\n        This is done by searching the ancestries of each key.  Any key that is\n        reachable from another key is not returned; all the others are.\n\n        This operation scales with the relative depth between any two keys. It\n        uses gdfo to avoid walking all ancestry.\n\n        :param keys: An iterable of keys.\n        :return: A set of the heads. Note that as a set there is no ordering\n            information. Callers will need to filter their input to create\n            order if they need it.\n        ";
static PyObject *__pyx_pf_6bzrlib_16_known_graph_pyx_10KnownGraph_7heads(PyObject *__pyx_v_self, PyObject *__pyx_v_keys) {
  PyObject *__pyx_v_maybe_node;
  PyObject *__pyx_v_maybe_heads;
  PyObject *__pyx_v_temp_node;
  struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *__pyx_v_node;
  Py_ssize_t __pyx_v_pos;
  Py_ssize_t __pyx_v_last_item;
  long __pyx_v_min_gdfo;
  PyObject *__pyx_v_heads_key;
  PyObject *__pyx_v_candidate_nodes;
  PyObject *__pyx_v_key;
  PyObject *__pyx_v_cleanup;
  PyObject *__pyx_v_pending;
  struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *__pyx_v_parent_node;
  PyObject *__pyx_v_heads;
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  Py_ssize_t __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  int __pyx_t_6;
  int __pyx_t_7;
  int __pyx_t_8;
  __Pyx_RefNannySetupContext("heads");
  __pyx_v_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)Py_None); __Pyx_INCREF(Py_None);
  __pyx_v_heads_key = ((PyObject*)Py_None); __Pyx_INCREF(Py_None);
  __pyx_v_candidate_nodes = ((PyObject*)Py_None); __Pyx_INCREF(Py_None);
  __pyx_v_key = Py_None; __Pyx_INCREF(Py_None);
  __pyx_v_cleanup = ((PyObject*)Py_None); __Pyx_INCREF(Py_None);
  __pyx_v_pending = ((PyObject*)Py_None); __Pyx_INCREF(Py_None);
  __pyx_v_parent_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)Py_None); __Pyx_INCREF(Py_None);
  __pyx_v_heads = Py_None; __Pyx_INCREF(Py_None);

  /* "bzrlib/_known_graph_pyx.pyx":435
 *         cdef long min_gdfo
 * 
 *         heads_key = frozenset(keys)             # <<<<<<<<<<<<<<
 *         maybe_heads = PyDict_GetItem(self._known_heads, heads_key)
 *         if maybe_heads != NULL:
 */
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 435; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_1));
  __Pyx_INCREF(__pyx_v_keys);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_keys);
  __Pyx_GIVEREF(__pyx_v_keys);
  __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject*)(&PyFrozenSet_Type))), ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 435; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_v_heads_key));
  __pyx_v_heads_key = ((PyObject*)__pyx_t_2);
  __pyx_t_2 = 0;

  /* "bzrlib/_known_graph_pyx.pyx":436
 * 
 *         heads_key = frozenset(keys)
 *         maybe_heads = PyDict_GetItem(self._known_heads, heads_key)             # <<<<<<<<<<<<<<
 *         if maybe_heads != NULL:
 *             return <object>maybe_heads
 */
  __pyx_t_2 = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *)__pyx_v_self)->_known_heads;
  __Pyx_INCREF(__pyx_t_2);
  __pyx_v_maybe_heads = PyDict_GetItem(__pyx_t_2, ((PyObject *)__pyx_v_heads_key));
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "bzrlib/_known_graph_pyx.pyx":437
 *         heads_key = frozenset(keys)
 *         maybe_heads = PyDict_GetItem(self._known_heads, heads_key)
 *         if maybe_heads != NULL:             # <<<<<<<<<<<<<<
 *             return <object>maybe_heads
 *         # Not cached, compute it ourselves
 */
  __pyx_t_3 = (__pyx_v_maybe_heads != NULL);
  if (__pyx_t_3) {

    /* "bzrlib/_known_graph_pyx.pyx":438
 *         maybe_heads = PyDict_GetItem(self._known_heads, heads_key)
 *         if maybe_heads != NULL:
 *             return <object>maybe_heads             # <<<<<<<<<<<<<<
 *         # Not cached, compute it ourselves
 *         candidate_nodes = {}
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(((PyObject *)__pyx_v_maybe_heads));
    __pyx_r = ((PyObject *)__pyx_v_maybe_heads);
    goto __pyx_L0;
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "bzrlib/_known_graph_pyx.pyx":440
 *             return <object>maybe_heads
 *         # Not cached, compute it ourselves
 *         candidate_nodes = {}             # <<<<<<<<<<<<<<
 *         for key in keys:
 *             maybe_node = PyDict_GetItem(self._nodes, key)
 */
  __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 440; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_2));
  __Pyx_DECREF(((PyObject *)__pyx_v_candidate_nodes));
  __pyx_v_candidate_nodes = __pyx_t_2;
  __pyx_t_2 = 0;

  /* "bzrlib/_known_graph_pyx.pyx":441
 *         # Not cached, compute it ourselves
 *         candidate_nodes = {}
 *         for key in keys:             # <<<<<<<<<<<<<<
 *             maybe_node = PyDict_GetItem(self._nodes, key)
 *             if maybe_node == NULL:
 */
  if (PyList_CheckExact(__pyx_v_keys) || PyTuple_CheckExact(__pyx_v_keys)) {
    __pyx_t_4 = 0; __pyx_t_2 = __pyx_v_keys; __Pyx_INCREF(__pyx_t_2);
  } else {
    __pyx_t_4 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_v_keys); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 441; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
  }
  for (;;) {
    if (likely(PyList_CheckExact(__pyx_t_2))) {
      if (__pyx_t_4 >= PyList_GET_SIZE(__pyx_t_2)) break;
      __pyx_t_1 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_4); __Pyx_INCREF(__pyx_t_1); __pyx_t_4++;
    } else if (likely(PyTuple_CheckExact(__pyx_t_2))) {
      if (__pyx_t_4 >= PyTuple_GET_SIZE(__pyx_t_2)) break;
      __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_4); __Pyx_INCREF(__pyx_t_1); __pyx_t_4++;
    } else {
      __pyx_t_1 = PyIter_Next(__pyx_t_2);
      if (!__pyx_t_1) {
        if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 441; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        break;
      }
      __Pyx_GOTREF(__pyx_t_1);
    }
    __Pyx_DECREF(__pyx_v_key);
    __pyx_v_key = __pyx_t_1;
    __pyx_t_1 = 0;

    /* "bzrlib/_known_graph_pyx.pyx":442
 *         candidate_nodes = {}
 *         for key in keys:
 *             maybe_node = PyDict_GetItem(self._nodes, key)             # <<<<<<<<<<<<<<
 *             if maybe_node == NULL:
 *                 raise KeyError('key %s not in nodes' % (key,))
 */
    __pyx_t_1 = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *)__pyx_v_self)->_nodes;
    __Pyx_INCREF(__pyx_t_1);
    __pyx_v_maybe_node = PyDict_GetItem(__pyx_t_1, __pyx_v_key);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "bzrlib/_known_graph_pyx.pyx":443
 *         for key in keys:
 *             maybe_node = PyDict_GetItem(self._nodes, key)
 *             if maybe_node == NULL:             # <<<<<<<<<<<<<<
 *                 raise KeyError('key %s not in nodes' % (key,))
 *             PyDict_SetItem(candidate_nodes, key, <object>maybe_node)
 */
    __pyx_t_3 = (__pyx_v_maybe_node == NULL);
    if (__pyx_t_3) {

      /* "bzrlib/_known_graph_pyx.pyx":444
 *             maybe_node = PyDict_GetItem(self._nodes, key)
 *             if maybe_node == NULL:
 *                 raise KeyError('key %s not in nodes' % (key,))             # <<<<<<<<<<<<<<
 *             PyDict_SetItem(candidate_nodes, key, <object>maybe_node)
 *         maybe_node = PyDict_GetItem(candidate_nodes, NULL_REVISION)
 */
      __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 444; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(((PyObject *)__pyx_t_1));
      __Pyx_INCREF(__pyx_v_key);
      PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_key);
      __Pyx_GIVEREF(__pyx_v_key);
      __pyx_t_5 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_8), ((PyObject *)__pyx_t_1)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 444; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(((PyObject *)__pyx_t_5));
      __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
      __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 444; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(((PyObject *)__pyx_t_1));
      PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_t_5));
      __Pyx_GIVEREF(((PyObject *)__pyx_t_5));
      __pyx_t_5 = 0;
      __pyx_t_5 = PyObject_Call(__pyx_builtin_KeyError, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 444; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
      __Pyx_Raise(__pyx_t_5, 0, 0);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 444; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      goto __pyx_L8;
    }
    __pyx_L8:;

    /* "bzrlib/_known_graph_pyx.pyx":445
 *             if maybe_node == NULL:
 *                 raise KeyError('key %s not in nodes' % (key,))
 *             PyDict_SetItem(candidate_nodes, key, <object>maybe_node)             # <<<<<<<<<<<<<<
 *         maybe_node = PyDict_GetItem(candidate_nodes, NULL_REVISION)
 *         if maybe_node != NULL:
 */
    __pyx_t_6 = PyDict_SetItem(((PyObject *)__pyx_v_candidate_nodes), __pyx_v_key, ((PyObject *)__pyx_v_maybe_node)); if (unlikely(__pyx_t_6 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 445; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "bzrlib/_known_graph_pyx.pyx":446
 *                 raise KeyError('key %s not in nodes' % (key,))
 *             PyDict_SetItem(candidate_nodes, key, <object>maybe_node)
 *         maybe_node = PyDict_GetItem(candidate_nodes, NULL_REVISION)             # <<<<<<<<<<<<<<
 *         if maybe_node != NULL:
 *             # NULL_REVISION is only a head if it is the only entry
 */
  __pyx_v_maybe_node = PyDict_GetItem(((PyObject *)__pyx_v_candidate_nodes), __pyx_v_6bzrlib_16_known_graph_pyx_NULL_REVISION);

  /* "bzrlib/_known_graph_pyx.pyx":447
 *             PyDict_SetItem(candidate_nodes, key, <object>maybe_node)
 *         maybe_node = PyDict_GetItem(candidate_nodes, NULL_REVISION)
 *         if maybe_node != NULL:             # <<<<<<<<<<<<<<
 *             # NULL_REVISION is only a head if it is the only entry
 *             candidate_nodes.pop(NULL_REVISION)
 */
  __pyx_t_3 = (__pyx_v_maybe_node != NULL);
  if (__pyx_t_3) {

    /* "bzrlib/_known_graph_pyx.pyx":449
 *         if maybe_node != NULL:
 *             # NULL_REVISION is only a head if it is the only entry
 *             candidate_nodes.pop(NULL_REVISION)             # <<<<<<<<<<<<<<
 *             if not candidate_nodes:
 *                 return frozenset([NULL_REVISION])
 */
    __pyx_t_2 = PyObject_GetAttr(((PyObject *)__pyx_v_candidate_nodes), __pyx_n_s__pop); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 449; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 449; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_5));
    __Pyx_INCREF(__pyx_v_6bzrlib_16_known_graph_pyx_NULL_REVISION);
    PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_v_6bzrlib_16_known_graph_pyx_NULL_REVISION);
    __Pyx_GIVEREF(__pyx_v_6bzrlib_16_known_graph_pyx_NULL_REVISION);
    __pyx_t_1 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 449; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "bzrlib/_known_graph_pyx.pyx":450
 *             # NULL_REVISION is only a head if it is the only entry
 *             candidate_nodes.pop(NULL_REVISION)
 *             if not candidate_nodes:             # <<<<<<<<<<<<<<
 *                 return frozenset([NULL_REVISION])
 *             # The keys changed, so recalculate heads_key
 */
    __pyx_t_3 = __Pyx_PyObject_IsTrue(((PyObject *)__pyx_v_candidate_nodes)); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 450; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_7 = (!__pyx_t_3);
    if (__pyx_t_7) {

      /* "bzrlib/_known_graph_pyx.pyx":451
 *             candidate_nodes.pop(NULL_REVISION)
 *             if not candidate_nodes:
 *                 return frozenset([NULL_REVISION])             # <<<<<<<<<<<<<<
 *             # The keys changed, so recalculate heads_key
 *             heads_key = frozenset(candidate_nodes)
 */
      __Pyx_XDECREF(__pyx_r);
      __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 451; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(((PyObject *)__pyx_t_1));
      __Pyx_INCREF(__pyx_v_6bzrlib_16_known_graph_pyx_NULL_REVISION);
      PyList_SET_ITEM(__pyx_t_1, 0, __pyx_v_6bzrlib_16_known_graph_pyx_NULL_REVISION);
      __Pyx_GIVEREF(__pyx_v_6bzrlib_16_known_graph_pyx_NULL_REVISION);
      __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 451; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(((PyObject *)__pyx_t_5));
      PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_t_1));
      __Pyx_GIVEREF(((PyObject *)__pyx_t_1));
      __pyx_t_1 = 0;
      __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)(&PyFrozenSet_Type))), ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 451; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
      __pyx_r = __pyx_t_1;
      __pyx_t_1 = 0;
      goto __pyx_L0;
      goto __pyx_L10;
    }
    __pyx_L10:;

    /* "bzrlib/_known_graph_pyx.pyx":453
 *                 return frozenset([NULL_REVISION])
 *             # The keys changed, so recalculate heads_key
 *             heads_key = frozenset(candidate_nodes)             # <<<<<<<<<<<<<<
 *         if PyDict_Size(candidate_nodes) < 2:
 *             return heads_key
 */
    __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 453; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_1));
    __Pyx_INCREF(((PyObject *)__pyx_v_candidate_nodes));
    PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_v_candidate_nodes));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_candidate_nodes));
    __pyx_t_5 = PyObject_Call(((PyObject *)((PyObject*)(&PyFrozenSet_Type))), ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 453; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_v_heads_key));
    __pyx_v_heads_key = ((PyObject*)__pyx_t_5);
    __pyx_t_5 = 0;
    goto __pyx_L9;
  }
  __pyx_L9:;

  /* "bzrlib/_known_graph_pyx.pyx":454
 *             # The keys changed, so recalculate heads_key
 *             heads_key = frozenset(candidate_nodes)
 *         if PyDict_Size(candidate_nodes) < 2:             # <<<<<<<<<<<<<<
 *             return heads_key
 * 
 */
  __pyx_t_4 = PyDict_Size(((PyObject *)__pyx_v_candidate_nodes)); if (unlikely(__pyx_t_4 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 454; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_7 = (__pyx_t_4 < 2);
  if (__pyx_t_7) {

    /* "bzrlib/_known_graph_pyx.pyx":455
 *             heads_key = frozenset(candidate_nodes)
 *         if PyDict_Size(candidate_nodes) < 2:
 *             return heads_key             # <<<<<<<<<<<<<<
 * 
 *         cleanup = []
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(((PyObject *)__pyx_v_heads_key));
    __pyx_r = ((PyObject *)__pyx_v_heads_key);
    goto __pyx_L0;
    goto __pyx_L11;
  }
  __pyx_L11:;

  /* "bzrlib/_known_graph_pyx.pyx":457
 *             return heads_key
 * 
 *         cleanup = []             # <<<<<<<<<<<<<<
 *         pending = []
 *         # we know a gdfo cannot be longer than a linear chain of all nodes
 */
  __pyx_t_5 = PyList_New(0); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 457; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_5));
  __Pyx_DECREF(((PyObject *)__pyx_v_cleanup));
  __pyx_v_cleanup = __pyx_t_5;
  __pyx_t_5 = 0;

  /* "bzrlib/_known_graph_pyx.pyx":458
 * 
 *         cleanup = []
 *         pending = []             # <<<<<<<<<<<<<<
 *         # we know a gdfo cannot be longer than a linear chain of all nodes
 *         min_gdfo = PyDict_Size(self._nodes) + 1
 */
  __pyx_t_5 = PyList_New(0); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 458; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_5));
  __Pyx_DECREF(((PyObject *)__pyx_v_pending));
  __pyx_v_pending = __pyx_t_5;
  __pyx_t_5 = 0;

  /* "bzrlib/_known_graph_pyx.pyx":460
 *         pending = []
 *         # we know a gdfo cannot be longer than a linear chain of all nodes
 *         min_gdfo = PyDict_Size(self._nodes) + 1             # <<<<<<<<<<<<<<
 *         # Build up nodes that need to be walked, note that starting nodes are
 *         # not added to seen()
 */
  __pyx_t_5 = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *)__pyx_v_self)->_nodes;
  __Pyx_INCREF(__pyx_t_5);
  __pyx_t_4 = PyDict_Size(__pyx_t_5); if (unlikely(__pyx_t_4 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 460; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_v_min_gdfo = (__pyx_t_4 + 1);

  /* "bzrlib/_known_graph_pyx.pyx":463
 *         # Build up nodes that need to be walked, note that starting nodes are
 *         # not added to seen()
 *         pos = 0             # <<<<<<<<<<<<<<
 *         while PyDict_Next(candidate_nodes, &pos, NULL, &temp_node):
 *             node = <_KnownGraphNode>temp_node
 */
  __pyx_v_pos = 0;

  /* "bzrlib/_known_graph_pyx.pyx":464
 *         # not added to seen()
 *         pos = 0
 *         while PyDict_Next(candidate_nodes, &pos, NULL, &temp_node):             # <<<<<<<<<<<<<<
 *             node = <_KnownGraphNode>temp_node
 *             if node.parents is not None:
 */
  while (1) {
    __pyx_t_6 = PyDict_Next(((PyObject *)__pyx_v_candidate_nodes), (&__pyx_v_pos), NULL, (&__pyx_v_temp_node));
    if (!__pyx_t_6) break;

    /* "bzrlib/_known_graph_pyx.pyx":465
 *         pos = 0
 *         while PyDict_Next(candidate_nodes, &pos, NULL, &temp_node):
 *             node = <_KnownGraphNode>temp_node             # <<<<<<<<<<<<<<
 *             if node.parents is not None:
 *                 pending.extend(node.parents)
 */
    __Pyx_INCREF(((PyObject *)((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_v_temp_node)));
    __Pyx_DECREF(((PyObject *)__pyx_v_node));
    __pyx_v_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_v_temp_node);

    /* "bzrlib/_known_graph_pyx.pyx":466
 *         while PyDict_Next(candidate_nodes, &pos, NULL, &temp_node):
 *             node = <_KnownGraphNode>temp_node
 *             if node.parents is not None:             # <<<<<<<<<<<<<<
 *                 pending.extend(node.parents)
 *             if node.gdfo < min_gdfo:
 */
    __pyx_t_7 = (__pyx_v_node->parents != Py_None);
    if (__pyx_t_7) {

      /* "bzrlib/_known_graph_pyx.pyx":467
 *             node = <_KnownGraphNode>temp_node
 *             if node.parents is not None:
 *                 pending.extend(node.parents)             # <<<<<<<<<<<<<<
 *             if node.gdfo < min_gdfo:
 *                 min_gdfo = node.gdfo
 */
      __pyx_t_5 = PyObject_GetAttr(((PyObject *)__pyx_v_pending), __pyx_n_s__extend); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 467; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 467; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(((PyObject *)__pyx_t_1));
      __Pyx_INCREF(__pyx_v_node->parents);
      PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_node->parents);
      __Pyx_GIVEREF(__pyx_v_node->parents);
      __pyx_t_2 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 467; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      goto __pyx_L14;
    }
    __pyx_L14:;

    /* "bzrlib/_known_graph_pyx.pyx":468
 *             if node.parents is not None:
 *                 pending.extend(node.parents)
 *             if node.gdfo < min_gdfo:             # <<<<<<<<<<<<<<
 *                 min_gdfo = node.gdfo
 * 
 */
    __pyx_t_7 = (__pyx_v_node->gdfo < __pyx_v_min_gdfo);
    if (__pyx_t_7) {

      /* "bzrlib/_known_graph_pyx.pyx":469
 *                 pending.extend(node.parents)
 *             if node.gdfo < min_gdfo:
 *                 min_gdfo = node.gdfo             # <<<<<<<<<<<<<<
 * 
 *         # Now do all the real work
 */
      __pyx_v_min_gdfo = __pyx_v_node->gdfo;
      goto __pyx_L15;
    }
    __pyx_L15:;
  }

  /* "bzrlib/_known_graph_pyx.pyx":472
 * 
 *         # Now do all the real work
 *         last_item = PyList_GET_SIZE(pending) - 1             # <<<<<<<<<<<<<<
 *         while last_item >= 0:
 *             node = _get_list_node(pending, last_item)
 */
  __pyx_v_last_item = (PyList_GET_SIZE(((PyObject *)__pyx_v_pending)) - 1);

  /* "bzrlib/_known_graph_pyx.pyx":473
 *         # Now do all the real work
 *         last_item = PyList_GET_SIZE(pending) - 1
 *         while last_item >= 0:             # <<<<<<<<<<<<<<
 *             node = _get_list_node(pending, last_item)
 *             last_item = last_item - 1
 */
  while (1) {
    __pyx_t_7 = (__pyx_v_last_item >= 0);
    if (!__pyx_t_7) break;

    /* "bzrlib/_known_graph_pyx.pyx":474
 *         last_item = PyList_GET_SIZE(pending) - 1
 *         while last_item >= 0:
 *             node = _get_list_node(pending, last_item)             # <<<<<<<<<<<<<<
 *             last_item = last_item - 1
 *             if node.seen:
 */
    __pyx_t_2 = ((PyObject *)__pyx_f_6bzrlib_16_known_graph_pyx__get_list_node(((PyObject *)__pyx_v_pending), __pyx_v_last_item)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 474; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(((PyObject *)__pyx_v_node));
    __pyx_v_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_t_2);
    __pyx_t_2 = 0;

    /* "bzrlib/_known_graph_pyx.pyx":475
 *         while last_item >= 0:
 *             node = _get_list_node(pending, last_item)
 *             last_item = last_item - 1             # <<<<<<<<<<<<<<
 *             if node.seen:
 *                 # node already appears in some ancestry
 */
    __pyx_v_last_item = (__pyx_v_last_item - 1);

    /* "bzrlib/_known_graph_pyx.pyx":476
 *             node = _get_list_node(pending, last_item)
 *             last_item = last_item - 1
 *             if node.seen:             # <<<<<<<<<<<<<<
 *                 # node already appears in some ancestry
 *                 continue
 */
    if (__pyx_v_node->seen) {

      /* "bzrlib/_known_graph_pyx.pyx":478
 *             if node.seen:
 *                 # node already appears in some ancestry
 *                 continue             # <<<<<<<<<<<<<<
 *             PyList_Append(cleanup, node)
 *             node.seen = 1
 */
      goto __pyx_L16_continue;
      goto __pyx_L18;
    }
    __pyx_L18:;

    /* "bzrlib/_known_graph_pyx.pyx":479
 *                 # node already appears in some ancestry
 *                 continue
 *             PyList_Append(cleanup, node)             # <<<<<<<<<<<<<<
 *             node.seen = 1
 *             if node.gdfo <= min_gdfo:
 */
    __pyx_t_6 = PyList_Append(((PyObject *)__pyx_v_cleanup), ((PyObject *)__pyx_v_node)); if (unlikely(__pyx_t_6 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 479; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

    /* "bzrlib/_known_graph_pyx.pyx":480
 *                 continue
 *             PyList_Append(cleanup, node)
 *             node.seen = 1             # <<<<<<<<<<<<<<
 *             if node.gdfo <= min_gdfo:
 *                 continue
 */
    __pyx_v_node->seen = 1;

    /* "bzrlib/_known_graph_pyx.pyx":481
 *             PyList_Append(cleanup, node)
 *             node.seen = 1
 *             if node.gdfo <= min_gdfo:             # <<<<<<<<<<<<<<
 *                 continue
 *             if node.parents is not None and PyTuple_GET_SIZE(node.parents) > 0:
 */
    __pyx_t_7 = (__pyx_v_node->gdfo <= __pyx_v_min_gdfo);
    if (__pyx_t_7) {

      /* "bzrlib/_known_graph_pyx.pyx":482
 *             node.seen = 1
 *             if node.gdfo <= min_gdfo:
 *                 continue             # <<<<<<<<<<<<<<
 *             if node.parents is not None and PyTuple_GET_SIZE(node.parents) > 0:
 *                 for pos from 0 <= pos < PyTuple_GET_SIZE(node.parents):
 */
      goto __pyx_L16_continue;
      goto __pyx_L19;
    }
    __pyx_L19:;

    /* "bzrlib/_known_graph_pyx.pyx":483
 *             if node.gdfo <= min_gdfo:
 *                 continue
 *             if node.parents is not None and PyTuple_GET_SIZE(node.parents) > 0:             # <<<<<<<<<<<<<<
 *                 for pos from 0 <= pos < PyTuple_GET_SIZE(node.parents):
 *                     parent_node = _get_tuple_node(node.parents, pos)
 */
    __pyx_t_7 = (__pyx_v_node->parents != Py_None);
    if (__pyx_t_7) {
      __pyx_t_2 = __pyx_v_node->parents;
      __Pyx_INCREF(__pyx_t_2);
      __pyx_t_3 = (PyTuple_GET_SIZE(__pyx_t_2) > 0);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_8 = __pyx_t_3;
    } else {
      __pyx_t_8 = __pyx_t_7;
    }
    if (__pyx_t_8) {

      /* "bzrlib/_known_graph_pyx.pyx":484
 *                 continue
 *             if node.parents is not None and PyTuple_GET_SIZE(node.parents) > 0:
 *                 for pos from 0 <= pos < PyTuple_GET_SIZE(node.parents):             # <<<<<<<<<<<<<<
 *                     parent_node = _get_tuple_node(node.parents, pos)
 *                     last_item = last_item + 1
 */
      __pyx_t_2 = __pyx_v_node->parents;
      __Pyx_INCREF(__pyx_t_2);
      __pyx_t_4 = PyTuple_GET_SIZE(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      for (__pyx_v_pos = 0; __pyx_v_pos < __pyx_t_4; __pyx_v_pos++) {

        /* "bzrlib/_known_graph_pyx.pyx":485
 *             if node.parents is not None and PyTuple_GET_SIZE(node.parents) > 0:
 *                 for pos from 0 <= pos < PyTuple_GET_SIZE(node.parents):
 *                     parent_node = _get_tuple_node(node.parents, pos)             # <<<<<<<<<<<<<<
 *                     last_item = last_item + 1
 *                     if last_item < PyList_GET_SIZE(pending):
 */
        __pyx_t_2 = __pyx_v_node->parents;
        __Pyx_INCREF(__pyx_t_2);
        __pyx_t_1 = ((PyObject *)__pyx_f_6bzrlib_16_known_graph_pyx__get_tuple_node(__pyx_t_2, __pyx_v_pos)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 485; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __Pyx_DECREF(((PyObject *)__pyx_v_parent_node));
        __pyx_v_parent_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_t_1);
        __pyx_t_1 = 0;

        /* "bzrlib/_known_graph_pyx.pyx":486
 *                 for pos from 0 <= pos < PyTuple_GET_SIZE(node.parents):
 *                     parent_node = _get_tuple_node(node.parents, pos)
 *                     last_item = last_item + 1             # <<<<<<<<<<<<<<
 *                     if last_item < PyList_GET_SIZE(pending):
 *                         Py_INCREF(parent_node) # SetItem steals a ref
 */
        __pyx_v_last_item = (__pyx_v_last_item + 1);

        /* "bzrlib/_known_graph_pyx.pyx":487
 *                     parent_node = _get_tuple_node(node.parents, pos)
 *                     last_item = last_item + 1
 *                     if last_item < PyList_GET_SIZE(pending):             # <<<<<<<<<<<<<<
 *                         Py_INCREF(parent_node) # SetItem steals a ref
 *                         PyList_SetItem(pending, last_item, parent_node)
 */
        __pyx_t_8 = (__pyx_v_last_item < PyList_GET_SIZE(((PyObject *)__pyx_v_pending)));
        if (__pyx_t_8) {

          /* "bzrlib/_known_graph_pyx.pyx":488
 *                     last_item = last_item + 1
 *                     if last_item < PyList_GET_SIZE(pending):
 *                         Py_INCREF(parent_node) # SetItem steals a ref             # <<<<<<<<<<<<<<
 *                         PyList_SetItem(pending, last_item, parent_node)
 *                     else:
 */
          Py_INCREF(((PyObject *)__pyx_v_parent_node));

          /* "bzrlib/_known_graph_pyx.pyx":489
 *                     if last_item < PyList_GET_SIZE(pending):
 *                         Py_INCREF(parent_node) # SetItem steals a ref
 *                         PyList_SetItem(pending, last_item, parent_node)             # <<<<<<<<<<<<<<
 *                     else:
 *                         PyList_Append(pending, parent_node)
 */
          __pyx_t_6 = PyList_SetItem(((PyObject *)__pyx_v_pending), __pyx_v_last_item, ((PyObject *)__pyx_v_parent_node)); if (unlikely(__pyx_t_6 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 489; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          goto __pyx_L23;
        }
        /*else*/ {

          /* "bzrlib/_known_graph_pyx.pyx":491
 *                         PyList_SetItem(pending, last_item, parent_node)
 *                     else:
 *                         PyList_Append(pending, parent_node)             # <<<<<<<<<<<<<<
 *         heads = []
 *         pos = 0
 */
          __pyx_t_6 = PyList_Append(((PyObject *)__pyx_v_pending), ((PyObject *)__pyx_v_parent_node)); if (unlikely(__pyx_t_6 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 491; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        __pyx_L23:;
      }
      goto __pyx_L20;
    }
    __pyx_L20:;
    __pyx_L16_continue:;
  }

  /* "bzrlib/_known_graph_pyx.pyx":492
 *                     else:
 *                         PyList_Append(pending, parent_node)
 *         heads = []             # <<<<<<<<<<<<<<
 *         pos = 0
 *         while PyDict_Next(candidate_nodes, &pos, NULL, &temp_node):
 */
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 492; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_1));
  __Pyx_DECREF(__pyx_v_heads);
  __pyx_v_heads = ((PyObject *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "bzrlib/_known_graph_pyx.pyx":493
 *                         PyList_Append(pending, parent_node)
 *         heads = []
 *         pos = 0             # <<<<<<<<<<<<<<
 *         while PyDict_Next(candidate_nodes, &pos, NULL, &temp_node):
 *             node = <_KnownGraphNode>temp_node
 */
  __pyx_v_pos = 0;

  /* "bzrlib/_known_graph_pyx.pyx":494
 *         heads = []
 *         pos = 0
 *         while PyDict_Next(candidate_nodes, &pos, NULL, &temp_node):             # <<<<<<<<<<<<<<
 *             node = <_KnownGraphNode>temp_node
 *             if not node.seen:
 */
  while (1) {
    __pyx_t_6 = PyDict_Next(((PyObject *)__pyx_v_candidate_nodes), (&__pyx_v_pos), NULL, (&__pyx_v_temp_node));
    if (!__pyx_t_6) break;

    /* "bzrlib/_known_graph_pyx.pyx":495
 *         pos = 0
 *         while PyDict_Next(candidate_nodes, &pos, NULL, &temp_node):
 *             node = <_KnownGraphNode>temp_node             # <<<<<<<<<<<<<<
 *             if not node.seen:
 *                 PyList_Append(heads, node.key)
 */
    __Pyx_INCREF(((PyObject *)((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_v_temp_node)));
    __Pyx_DECREF(((PyObject *)__pyx_v_node));
    __pyx_v_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_v_temp_node);

    /* "bzrlib/_known_graph_pyx.pyx":496
 *         while PyDict_Next(candidate_nodes, &pos, NULL, &temp_node):
 *             node = <_KnownGraphNode>temp_node
 *             if not node.seen:             # <<<<<<<<<<<<<<
 *                 PyList_Append(heads, node.key)
 *         heads = frozenset(heads)
 */
    __pyx_t_8 = (!__pyx_v_node->seen);
    if (__pyx_t_8) {

      /* "bzrlib/_known_graph_pyx.pyx":497
 *             node = <_KnownGraphNode>temp_node
 *             if not node.seen:
 *                 PyList_Append(heads, node.key)             # <<<<<<<<<<<<<<
 *         heads = frozenset(heads)
 *         for pos from 0 <= pos < PyList_GET_SIZE(cleanup):
 */
      __pyx_t_1 = __pyx_v_node->key;
      __Pyx_INCREF(__pyx_t_1);
      __pyx_t_6 = PyList_Append(__pyx_v_heads, __pyx_t_1); if (unlikely(__pyx_t_6 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 497; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      goto __pyx_L26;
    }
    __pyx_L26:;
  }

  /* "bzrlib/_known_graph_pyx.pyx":498
 *             if not node.seen:
 *                 PyList_Append(heads, node.key)
 *         heads = frozenset(heads)             # <<<<<<<<<<<<<<
 *         for pos from 0 <= pos < PyList_GET_SIZE(cleanup):
 *             node = _get_list_node(cleanup, pos)
 */
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 498; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_1));
  __Pyx_INCREF(__pyx_v_heads);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_heads);
  __Pyx_GIVEREF(__pyx_v_heads);
  __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject*)(&PyFrozenSet_Type))), ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 498; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_v_heads);
  __pyx_v_heads = __pyx_t_2;
  __pyx_t_2 = 0;

  /* "bzrlib/_known_graph_pyx.pyx":499
 *                 PyList_Append(heads, node.key)
 *         heads = frozenset(heads)
 *         for pos from 0 <= pos < PyList_GET_SIZE(cleanup):             # <<<<<<<<<<<<<<
 *             node = _get_list_node(cleanup, pos)
 *             node.seen = 0
 */
  __pyx_t_4 = PyList_GET_SIZE(((PyObject *)__pyx_v_cleanup));
  for (__pyx_v_pos = 0; __pyx_v_pos < __pyx_t_4; __pyx_v_pos++) {

    /* "bzrlib/_known_graph_pyx.pyx":500
 *         heads = frozenset(heads)
 *         for pos from 0 <= pos < PyList_GET_SIZE(cleanup):
 *             node = _get_list_node(cleanup, pos)             # <<<<<<<<<<<<<<
 *             node.seen = 0
 *         if self.do_cache:
 */
    __pyx_t_2 = ((PyObject *)__pyx_f_6bzrlib_16_known_graph_pyx__get_list_node(((PyObject *)__pyx_v_cleanup), __pyx_v_pos)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 500; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(((PyObject *)__pyx_v_node));
    __pyx_v_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_t_2);
    __pyx_t_2 = 0;

    /* "bzrlib/_known_graph_pyx.pyx":501
 *         for pos from 0 <= pos < PyList_GET_SIZE(cleanup):
 *             node = _get_list_node(cleanup, pos)
 *             node.seen = 0             # <<<<<<<<<<<<<<
 *         if self.do_cache:
 *             PyDict_SetItem(self._known_heads, heads_key, heads)
 */
    __pyx_v_node->seen = 0;
  }

  /* "bzrlib/_known_graph_pyx.pyx":502
 *             node = _get_list_node(cleanup, pos)
 *             node.seen = 0
 *         if self.do_cache:             # <<<<<<<<<<<<<<
 *             PyDict_SetItem(self._known_heads, heads_key, heads)
 *         return heads
 */
  if (((struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *)__pyx_v_self)->do_cache) {

    /* "bzrlib/_known_graph_pyx.pyx":503
 *             node.seen = 0
 *         if self.do_cache:
 *             PyDict_SetItem(self._known_heads, heads_key, heads)             # <<<<<<<<<<<<<<
 *         return heads
 * 
 */
    __pyx_t_2 = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *)__pyx_v_self)->_known_heads;
    __Pyx_INCREF(__pyx_t_2);
    __pyx_t_6 = PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_v_heads_key), __pyx_v_heads); if (unlikely(__pyx_t_6 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 503; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    goto __pyx_L29;
  }
  __pyx_L29:;

  /* "bzrlib/_known_graph_pyx.pyx":504
 *         if self.do_cache:
 *             PyDict_SetItem(self._known_heads, heads_key, heads)
 *         return heads             # <<<<<<<<<<<<<<
 * 
 *     def topo_sort(self):
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_heads);
  __pyx_r = __pyx_v_heads;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("bzrlib._known_graph_pyx.KnownGraph.heads");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_DECREF((PyObject *)__pyx_v_node);
  __Pyx_DECREF(__pyx_v_heads_key);
  __Pyx_DECREF(__pyx_v_candidate_nodes);
  __Pyx_DECREF(__pyx_v_key);
  __Pyx_DECREF(__pyx_v_cleanup);
  __Pyx_DECREF(__pyx_v_pending);
  __Pyx_DECREF((PyObject *)__pyx_v_parent_node);
  __Pyx_DECREF(__pyx_v_heads);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "bzrlib/_known_graph_pyx.pyx":506
 *         return heads
 * 
 *     def topo_sort(self):             # <<<<<<<<<<<<<<
 *         """Return the nodes in topological order.
 * 
 */

static PyObject *__pyx_pf_6bzrlib_16_known_graph_pyx_10KnownGraph_8topo_sort(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_6bzrlib_16_known_graph_pyx_10KnownGraph_8topo_sort[] = "Return the nodes in topological order.\n\n        All parents must occur before all children.\n        ";
static PyObject *__pyx_pf_6bzrlib_16_known_graph_pyx_10KnownGraph_8topo_sort(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *__pyx_v_node;
  struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *__pyx_v_child;
  Py_ssize_t __pyx_v_pos;
  Py_ssize_t __pyx_v_last_item;
  PyObject *__pyx_v_pending;
  PyObject *__pyx_v_topo_order;
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  Py_ssize_t __pyx_t_4;
  int __pyx_t_5;
  int __pyx_t_6;
  PyObject *__pyx_t_7 = NULL;
  int __pyx_t_8;
  __Pyx_RefNannySetupContext("topo_sort");
  __pyx_v_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)Py_None); __Pyx_INCREF(Py_None);
  __pyx_v_child = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)Py_None); __Pyx_INCREF(Py_None);
  __pyx_v_pending = Py_None; __Pyx_INCREF(Py_None);
  __pyx_v_topo_order = ((PyObject*)Py_None); __Pyx_INCREF(Py_None);

  /* "bzrlib/_known_graph_pyx.pyx":523
 *         cdef Py_ssize_t last_item
 * 
 *         pending = self._find_tails()             # <<<<<<<<<<<<<<
 *         if PyList_GET_SIZE(pending) == 0 and len(self._nodes) > 0:
 *             raise errors.GraphCycleError(self._nodes)
 */
  __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s___find_tails); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 523; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 523; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_v_pending);
  __pyx_v_pending = __pyx_t_2;
  __pyx_t_2 = 0;

  /* "bzrlib/_known_graph_pyx.pyx":524
 * 
 *         pending = self._find_tails()
 *         if PyList_GET_SIZE(pending) == 0 and len(self._nodes) > 0:             # <<<<<<<<<<<<<<
 *             raise errors.GraphCycleError(self._nodes)
 * 
 */
  __pyx_t_3 = (PyList_GET_SIZE(__pyx_v_pending) == 0);
  if (__pyx_t_3) {
    __pyx_t_2 = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *)__pyx_v_self)->_nodes;
    __Pyx_INCREF(__pyx_t_2);
    __pyx_t_4 = PyObject_Length(__pyx_t_2); if (unlikely(__pyx_t_4 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 524; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_5 = (__pyx_t_4 > 0);
    __pyx_t_6 = __pyx_t_5;
  } else {
    __pyx_t_6 = __pyx_t_3;
  }
  if (__pyx_t_6) {

    /* "bzrlib/_known_graph_pyx.pyx":525
 *         pending = self._find_tails()
 *         if PyList_GET_SIZE(pending) == 0 and len(self._nodes) > 0:
 *             raise errors.GraphCycleError(self._nodes)             # <<<<<<<<<<<<<<
 * 
 *         topo_order = []
 */
    __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__errors); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 525; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_1 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__GraphCycleError); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 525; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 525; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_2));
    __Pyx_INCREF(((struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *)__pyx_v_self)->_nodes);
    PyTuple_SET_ITEM(__pyx_t_2, 0, ((struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *)__pyx_v_self)->_nodes);
    __Pyx_GIVEREF(((struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *)__pyx_v_self)->_nodes);
    __pyx_t_7 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 525; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
    __Pyx_Raise(__pyx_t_7, 0, 0);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 525; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "bzrlib/_known_graph_pyx.pyx":527
 *             raise errors.GraphCycleError(self._nodes)
 * 
 *         topo_order = []             # <<<<<<<<<<<<<<
 * 
 *         last_item = PyList_GET_SIZE(pending) - 1
 */
  __pyx_t_7 = PyList_New(0); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 527; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_7));
  __Pyx_DECREF(((PyObject *)__pyx_v_topo_order));
  __pyx_v_topo_order = __pyx_t_7;
  __pyx_t_7 = 0;

  /* "bzrlib/_known_graph_pyx.pyx":529
 *         topo_order = []
 * 
 *         last_item = PyList_GET_SIZE(pending) - 1             # <<<<<<<<<<<<<<
 *         while last_item >= 0:
 *             # Avoid pop followed by push, instead, peek, and replace
 */
  __pyx_v_last_item = (PyList_GET_SIZE(__pyx_v_pending) - 1);

  /* "bzrlib/_known_graph_pyx.pyx":530
 * 
 *         last_item = PyList_GET_SIZE(pending) - 1
 *         while last_item >= 0:             # <<<<<<<<<<<<<<
 *             # Avoid pop followed by push, instead, peek, and replace
 *             # timing shows this is 930ms => 770ms for OOo
 */
  while (1) {
    __pyx_t_6 = (__pyx_v_last_item >= 0);
    if (!__pyx_t_6) break;

    /* "bzrlib/_known_graph_pyx.pyx":533
 *             # Avoid pop followed by push, instead, peek, and replace
 *             # timing shows this is 930ms => 770ms for OOo
 *             node = _get_list_node(pending, last_item)             # <<<<<<<<<<<<<<
 *             last_item = last_item - 1
 *             if node.parents is not None:
 */
    __pyx_t_7 = ((PyObject *)__pyx_f_6bzrlib_16_known_graph_pyx__get_list_node(__pyx_v_pending, __pyx_v_last_item)); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 533; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(((PyObject *)__pyx_v_node));
    __pyx_v_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_t_7);
    __pyx_t_7 = 0;

    /* "bzrlib/_known_graph_pyx.pyx":534
 *             # timing shows this is 930ms => 770ms for OOo
 *             node = _get_list_node(pending, last_item)
 *             last_item = last_item - 1             # <<<<<<<<<<<<<<
 *             if node.parents is not None:
 *                 # We don't include ghost parents
 */
    __pyx_v_last_item = (__pyx_v_last_item - 1);

    /* "bzrlib/_known_graph_pyx.pyx":535
 *             node = _get_list_node(pending, last_item)
 *             last_item = last_item - 1
 *             if node.parents is not None:             # <<<<<<<<<<<<<<
 *                 # We don't include ghost parents
 *                 PyList_Append(topo_order, node.key)
 */
    __pyx_t_6 = (__pyx_v_node->parents != Py_None);
    if (__pyx_t_6) {

      /* "bzrlib/_known_graph_pyx.pyx":537
 *             if node.parents is not None:
 *                 # We don't include ghost parents
 *                 PyList_Append(topo_order, node.key)             # <<<<<<<<<<<<<<
 *             for pos from 0 <= pos < PyList_GET_SIZE(node.children):
 *                 child = _get_list_node(node.children, pos)
 */
      __pyx_t_7 = __pyx_v_node->key;
      __Pyx_INCREF(__pyx_t_7);
      __pyx_t_8 = PyList_Append(((PyObject *)__pyx_v_topo_order), __pyx_t_7); if (unlikely(__pyx_t_8 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 537; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      goto __pyx_L8;
    }
    __pyx_L8:;

    /* "bzrlib/_known_graph_pyx.pyx":538
 *                 # We don't include ghost parents
 *                 PyList_Append(topo_order, node.key)
 *             for pos from 0 <= pos < PyList_GET_SIZE(node.children):             # <<<<<<<<<<<<<<
 *                 child = _get_list_node(node.children, pos)
 *                 if child.gdfo == -1:
 */
    __pyx_t_7 = __pyx_v_node->children;
    __Pyx_INCREF(__pyx_t_7);
    __pyx_t_4 = PyList_GET_SIZE(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    for (__pyx_v_pos = 0; __pyx_v_pos < __pyx_t_4; __pyx_v_pos++) {

      /* "bzrlib/_known_graph_pyx.pyx":539
 *                 PyList_Append(topo_order, node.key)
 *             for pos from 0 <= pos < PyList_GET_SIZE(node.children):
 *                 child = _get_list_node(node.children, pos)             # <<<<<<<<<<<<<<
 *                 if child.gdfo == -1:
 *                     # We know we have a graph cycle because a node has a parent
 */
      __pyx_t_7 = __pyx_v_node->children;
      __Pyx_INCREF(__pyx_t_7);
      __pyx_t_2 = ((PyObject *)__pyx_f_6bzrlib_16_known_graph_pyx__get_list_node(__pyx_t_7, __pyx_v_pos)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 539; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __Pyx_DECREF(((PyObject *)__pyx_v_child));
      __pyx_v_child = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_t_2);
      __pyx_t_2 = 0;

      /* "bzrlib/_known_graph_pyx.pyx":540
 *             for pos from 0 <= pos < PyList_GET_SIZE(node.children):
 *                 child = _get_list_node(node.children, pos)
 *                 if child.gdfo == -1:             # <<<<<<<<<<<<<<
 *                     # We know we have a graph cycle because a node has a parent
 *                     # which we couldn't find
 */
      __pyx_t_6 = (__pyx_v_child->gdfo == -1);
      if (__pyx_t_6) {

        /* "bzrlib/_known_graph_pyx.pyx":543
 *                     # We know we have a graph cycle because a node has a parent
 *                     # which we couldn't find
 *                     raise errors.GraphCycleError(self._nodes)             # <<<<<<<<<<<<<<
 *                 child.seen = child.seen + 1
 *                 if child.seen == PyTuple_GET_SIZE(child.parents):
 */
        __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__errors); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 543; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_2);
        __pyx_t_7 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__GraphCycleError); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 543; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_7);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 543; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(((PyObject *)__pyx_t_2));
        __Pyx_INCREF(((struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *)__pyx_v_self)->_nodes);
        PyTuple_SET_ITEM(__pyx_t_2, 0, ((struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *)__pyx_v_self)->_nodes);
        __Pyx_GIVEREF(((struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *)__pyx_v_self)->_nodes);
        __pyx_t_1 = PyObject_Call(__pyx_t_7, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 543; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
        __Pyx_Raise(__pyx_t_1, 0, 0);
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 543; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        goto __pyx_L11;
      }
      __pyx_L11:;

      /* "bzrlib/_known_graph_pyx.pyx":544
 *                     # which we couldn't find
 *                     raise errors.GraphCycleError(self._nodes)
 *                 child.seen = child.seen + 1             # <<<<<<<<<<<<<<
 *                 if child.seen == PyTuple_GET_SIZE(child.parents):
 *                     # All parents of this child have been yielded, queue this
 */
      __pyx_v_child->seen = (__pyx_v_child->seen + 1);

      /* "bzrlib/_known_graph_pyx.pyx":545
 *                     raise errors.GraphCycleError(self._nodes)
 *                 child.seen = child.seen + 1
 *                 if child.seen == PyTuple_GET_SIZE(child.parents):             # <<<<<<<<<<<<<<
 *                     # All parents of this child have been yielded, queue this
 *                     # one to be yielded as well
 */
      __pyx_t_1 = __pyx_v_child->parents;
      __Pyx_INCREF(__pyx_t_1);
      __pyx_t_6 = (__pyx_v_child->seen == PyTuple_GET_SIZE(__pyx_t_1));
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      if (__pyx_t_6) {

        /* "bzrlib/_known_graph_pyx.pyx":548
 *                     # All parents of this child have been yielded, queue this
 *                     # one to be yielded as well
 *                     last_item = last_item + 1             # <<<<<<<<<<<<<<
 *                     if last_item < PyList_GET_SIZE(pending):
 *                         Py_INCREF(child) # SetItem steals a ref
 */
        __pyx_v_last_item = (__pyx_v_last_item + 1);

        /* "bzrlib/_known_graph_pyx.pyx":549
 *                     # one to be yielded as well
 *                     last_item = last_item + 1
 *                     if last_item < PyList_GET_SIZE(pending):             # <<<<<<<<<<<<<<
 *                         Py_INCREF(child) # SetItem steals a ref
 *                         PyList_SetItem(pending, last_item, child)
 */
        __pyx_t_6 = (__pyx_v_last_item < PyList_GET_SIZE(__pyx_v_pending));
        if (__pyx_t_6) {

          /* "bzrlib/_known_graph_pyx.pyx":550
 *                     last_item = last_item + 1
 *                     if last_item < PyList_GET_SIZE(pending):
 *                         Py_INCREF(child) # SetItem steals a ref             # <<<<<<<<<<<<<<
 *                         PyList_SetItem(pending, last_item, child)
 *                     else:
 */
          Py_INCREF(((PyObject *)__pyx_v_child));

          /* "bzrlib/_known_graph_pyx.pyx":551
 *                     if last_item < PyList_GET_SIZE(pending):
 *                         Py_INCREF(child) # SetItem steals a ref
 *                         PyList_SetItem(pending, last_item, child)             # <<<<<<<<<<<<<<
 *                     else:
 *                         PyList_Append(pending, child)
 */
          __pyx_t_8 = PyList_SetItem(__pyx_v_pending, __pyx_v_last_item, ((PyObject *)__pyx_v_child)); if (unlikely(__pyx_t_8 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 551; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          goto __pyx_L13;
        }
        /*else*/ {

          /* "bzrlib/_known_graph_pyx.pyx":553
 *                         PyList_SetItem(pending, last_item, child)
 *                     else:
 *                         PyList_Append(pending, child)             # <<<<<<<<<<<<<<
 *                     # We have queued this node, we don't need to track it
 *                     # anymore
 */
          __pyx_t_8 = PyList_Append(__pyx_v_pending, ((PyObject *)__pyx_v_child)); if (unlikely(__pyx_t_8 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 553; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        __pyx_L13:;

        /* "bzrlib/_known_graph_pyx.pyx":556
 *                     # We have queued this node, we don't need to track it
 *                     # anymore
 *                     child.seen = 0             # <<<<<<<<<<<<<<
 *         # We started from the parents, so we don't need to do anymore work
 *         return topo_order
 */
        __pyx_v_child->seen = 0;
        goto __pyx_L12;
      }
      __pyx_L12:;
    }
  }

  /* "bzrlib/_known_graph_pyx.pyx":558
 *                     child.seen = 0
 *         # We started from the parents, so we don't need to do anymore work
 *         return topo_order             # <<<<<<<<<<<<<<
 * 
 *     def gc_sort(self):
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(((PyObject *)__pyx_v_topo_order));
  __pyx_r = ((PyObject *)__pyx_v_topo_order);
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_AddTraceback("bzrlib._known_graph_pyx.KnownGraph.topo_sort");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_DECREF((PyObject *)__pyx_v_node);
  __Pyx_DECREF((PyObject *)__pyx_v_child);
  __Pyx_DECREF(__pyx_v_pending);
  __Pyx_DECREF(__pyx_v_topo_order);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "bzrlib/_known_graph_pyx.pyx":560
 *         return topo_order
 * 
 *     def gc_sort(self):             # <<<<<<<<<<<<<<
 *         """Return a reverse topological ordering which is 'stable'.
 * 
 */

static PyObject *__pyx_pf_6bzrlib_16_known_graph_pyx_10KnownGraph_9gc_sort(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_6bzrlib_16_known_graph_pyx_10KnownGraph_9gc_sort[] = "Return a reverse topological ordering which is 'stable'.\n\n        There are a few constraints:\n          1) Reverse topological (all children before all parents)\n          2) Grouped by prefix\n          3) 'stable' sorting, so that we get the same result, independent of\n             machine, or extra data.\n        To do this, we use the same basic algorithm as topo_sort, but when we\n        aren't sure what node to access next, we sort them lexicographically.\n        ";
static PyObject *__pyx_pf_6bzrlib_16_known_graph_pyx_10KnownGraph_9gc_sort(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_v_temp;
  Py_ssize_t __pyx_v_pos;
  Py_ssize_t __pyx_v_last_item;
  struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *__pyx_v_node;
  struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *__pyx_v_parent_node;
  PyObject *__pyx_v_tips;
  PyObject *__pyx_v_prefix_tips;
  PyObject *__pyx_v_prefix;
  PyObject *__pyx_v_tip_nodes;
  PyObject *__pyx_v_result;
  PyObject *__pyx_v_pending;
  PyObject *__pyx_v_parents;
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  Py_ssize_t __pyx_t_3;
  Py_ssize_t __pyx_t_4;
  int __pyx_t_5;
  int __pyx_t_6;
  int __pyx_t_7;
  PyObject *__pyx_t_8 = NULL;
  __Pyx_RefNannySetupContext("gc_sort");
  __pyx_v_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)Py_None); __Pyx_INCREF(Py_None);
  __pyx_v_parent_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)Py_None); __Pyx_INCREF(Py_None);
  __pyx_v_tips = Py_None; __Pyx_INCREF(Py_None);
  __pyx_v_prefix_tips = ((PyObject*)Py_None); __Pyx_INCREF(Py_None);
  __pyx_v_prefix = Py_None; __Pyx_INCREF(Py_None);
  __pyx_v_tip_nodes = Py_None; __Pyx_INCREF(Py_None);
  __pyx_v_result = ((PyObject*)Py_None); __Pyx_INCREF(Py_None);
  __pyx_v_pending = Py_None; __Pyx_INCREF(Py_None);
  __pyx_v_parents = Py_None; __Pyx_INCREF(Py_None);

  /* "bzrlib/_known_graph_pyx.pyx":575
 *         cdef _KnownGraphNode node, node2, parent_node
 * 
 *         tips = self._find_tips()             # <<<<<<<<<<<<<<
 *         # Split the tips based on prefix
 *         prefix_tips = {}
 */
  __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s___find_tips); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 575; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 575; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_v_tips);
  __pyx_v_tips = __pyx_t_2;
  __pyx_t_2 = 0;

  /* "bzrlib/_known_graph_pyx.pyx":577
 *         tips = self._find_tips()
 *         # Split the tips based on prefix
 *         prefix_tips = {}             # <<<<<<<<<<<<<<
 *         for pos from 0 <= pos < PyList_GET_SIZE(tips):
 *             node = _get_list_node(tips, pos)
 */
  __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 577; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_2));
  __Pyx_DECREF(((PyObject *)__pyx_v_prefix_tips));
  __pyx_v_prefix_tips = __pyx_t_2;
  __pyx_t_2 = 0;

  /* "bzrlib/_known_graph_pyx.pyx":578
 *         # Split the tips based on prefix
 *         prefix_tips = {}
 *         for pos from 0 <= pos < PyList_GET_SIZE(tips):             # <<<<<<<<<<<<<<
 *             node = _get_list_node(tips, pos)
 *             if PyString_CheckExact(node.key) or len(node.key) == 1:
 */
  __pyx_t_3 = PyList_GET_SIZE(__pyx_v_tips);
  for (__pyx_v_pos = 0; __pyx_v_pos < __pyx_t_3; __pyx_v_pos++) {

    /* "bzrlib/_known_graph_pyx.pyx":579
 *         prefix_tips = {}
 *         for pos from 0 <= pos < PyList_GET_SIZE(tips):
 *             node = _get_list_node(tips, pos)             # <<<<<<<<<<<<<<
 *             if PyString_CheckExact(node.key) or len(node.key) == 1:
 *                 prefix = ''
 */
    __pyx_t_2 = ((PyObject *)__pyx_f_6bzrlib_16_known_graph_pyx__get_list_node(__pyx_v_tips, __pyx_v_pos)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 579; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(((PyObject *)__pyx_v_node));
    __pyx_v_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_t_2);
    __pyx_t_2 = 0;

    /* "bzrlib/_known_graph_pyx.pyx":580
 *         for pos from 0 <= pos < PyList_GET_SIZE(tips):
 *             node = _get_list_node(tips, pos)
 *             if PyString_CheckExact(node.key) or len(node.key) == 1:             # <<<<<<<<<<<<<<
 *                 prefix = ''
 *             else:
 */
    __pyx_t_2 = __pyx_v_node->key;
    __Pyx_INCREF(__pyx_t_2);
    if (!PyString_CheckExact(__pyx_t_2)) {
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_1 = __pyx_v_node->key;
      __Pyx_INCREF(__pyx_t_1);
      __pyx_t_4 = PyObject_Length(__pyx_t_1); if (unlikely(__pyx_t_4 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 580; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_5 = (__pyx_t_4 == 1);
      __pyx_t_6 = __pyx_t_5;
    } else {
      __pyx_t_6 = PyString_CheckExact(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    }
    if (__pyx_t_6) {

      /* "bzrlib/_known_graph_pyx.pyx":581
 *             node = _get_list_node(tips, pos)
 *             if PyString_CheckExact(node.key) or len(node.key) == 1:
 *                 prefix = ''             # <<<<<<<<<<<<<<
 *             else:
 *                 prefix = node.key[0]
 */
      __Pyx_INCREF(((PyObject *)__pyx_kp_s_9));
      __Pyx_DECREF(__pyx_v_prefix);
      __pyx_v_prefix = ((PyObject *)__pyx_kp_s_9);
      goto __pyx_L7;
    }
    /*else*/ {

      /* "bzrlib/_known_graph_pyx.pyx":583
 *                 prefix = ''
 *             else:
 *                 prefix = node.key[0]             # <<<<<<<<<<<<<<
 *             temp = PyDict_GetItem(prefix_tips, prefix)
 *             if temp == NULL:
 */
      __pyx_t_2 = __Pyx_GetItemInt(__pyx_v_node->key, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 583; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_v_prefix);
      __pyx_v_prefix = __pyx_t_2;
      __pyx_t_2 = 0;
    }
    __pyx_L7:;

    /* "bzrlib/_known_graph_pyx.pyx":584
 *             else:
 *                 prefix = node.key[0]
 *             temp = PyDict_GetItem(prefix_tips, prefix)             # <<<<<<<<<<<<<<
 *             if temp == NULL:
 *                 prefix_tips[prefix] = [node]
 */
    __pyx_v_temp = PyDict_GetItem(((PyObject *)__pyx_v_prefix_tips), __pyx_v_prefix);

    /* "bzrlib/_known_graph_pyx.pyx":585
 *                 prefix = node.key[0]
 *             temp = PyDict_GetItem(prefix_tips, prefix)
 *             if temp == NULL:             # <<<<<<<<<<<<<<
 *                 prefix_tips[prefix] = [node]
 *             else:
 */
    __pyx_t_6 = (__pyx_v_temp == NULL);
    if (__pyx_t_6) {

      /* "bzrlib/_known_graph_pyx.pyx":586
 *             temp = PyDict_GetItem(prefix_tips, prefix)
 *             if temp == NULL:
 *                 prefix_tips[prefix] = [node]             # <<<<<<<<<<<<<<
 *             else:
 *                 tip_nodes = <object>temp
 */
      __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 586; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(((PyObject *)__pyx_t_2));
      __Pyx_INCREF(((PyObject *)__pyx_v_node));
      PyList_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_node));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_node));
      if (PyDict_SetItem(((PyObject *)__pyx_v_prefix_tips), __pyx_v_prefix, ((PyObject *)__pyx_t_2)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 586; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
      goto __pyx_L8;
    }
    /*else*/ {

      /* "bzrlib/_known_graph_pyx.pyx":588
 *                 prefix_tips[prefix] = [node]
 *             else:
 *                 tip_nodes = <object>temp             # <<<<<<<<<<<<<<
 *                 PyList_Append(tip_nodes, node)
 * 
 */
      __Pyx_INCREF(((PyObject *)__pyx_v_temp));
      __Pyx_DECREF(__pyx_v_tip_nodes);
      __pyx_v_tip_nodes = ((PyObject *)__pyx_v_temp);

      /* "bzrlib/_known_graph_pyx.pyx":589
 *             else:
 *                 tip_nodes = <object>temp
 *                 PyList_Append(tip_nodes, node)             # <<<<<<<<<<<<<<
 * 
 *         result = []
 */
      __pyx_t_7 = PyList_Append(__pyx_v_tip_nodes, ((PyObject *)__pyx_v_node)); if (unlikely(__pyx_t_7 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 589; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __pyx_L8:;
  }

  /* "bzrlib/_known_graph_pyx.pyx":591
 *                 PyList_Append(tip_nodes, node)
 * 
 *         result = []             # <<<<<<<<<<<<<<
 *         for prefix in sorted(prefix_tips):
 *             temp = PyDict_GetItem(prefix_tips, prefix)
 */
  __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 591; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_2));
  __Pyx_DECREF(((PyObject *)__pyx_v_result));
  __pyx_v_result = __pyx_t_2;
  __pyx_t_2 = 0;

  /* "bzrlib/_known_graph_pyx.pyx":592
 * 
 *         result = []
 *         for prefix in sorted(prefix_tips):             # <<<<<<<<<<<<<<
 *             temp = PyDict_GetItem(prefix_tips, prefix)
 *             assert temp != NULL
 */
  __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 592; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_2));
  __Pyx_INCREF(((PyObject *)__pyx_v_prefix_tips));
  PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_prefix_tips));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_prefix_tips));
  __pyx_t_1 = PyObject_Call(__pyx_builtin_sorted, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 592; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  if (PyList_CheckExact(__pyx_t_1) || PyTuple_CheckExact(__pyx_t_1)) {
    __pyx_t_3 = 0; __pyx_t_2 = __pyx_t_1; __Pyx_INCREF(__pyx_t_2);
  } else {
    __pyx_t_3 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 592; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  for (;;) {
    if (likely(PyList_CheckExact(__pyx_t_2))) {
      if (__pyx_t_3 >= PyList_GET_SIZE(__pyx_t_2)) break;
      __pyx_t_1 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_3); __Pyx_INCREF(__pyx_t_1); __pyx_t_3++;
    } else if (likely(PyTuple_CheckExact(__pyx_t_2))) {
      if (__pyx_t_3 >= PyTuple_GET_SIZE(__pyx_t_2)) break;
      __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_3); __Pyx_INCREF(__pyx_t_1); __pyx_t_3++;
    } else {
      __pyx_t_1 = PyIter_Next(__pyx_t_2);
      if (!__pyx_t_1) {
        if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 592; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        break;
      }
      __Pyx_GOTREF(__pyx_t_1);
    }
    __Pyx_DECREF(__pyx_v_prefix);
    __pyx_v_prefix = __pyx_t_1;
    __pyx_t_1 = 0;

    /* "bzrlib/_known_graph_pyx.pyx":593
 *         result = []
 *         for prefix in sorted(prefix_tips):
 *             temp = PyDict_GetItem(prefix_tips, prefix)             # <<<<<<<<<<<<<<
 *             assert temp != NULL
 *             tip_nodes = <object>temp
 */
    __pyx_v_temp = PyDict_GetItem(((PyObject *)__pyx_v_prefix_tips), __pyx_v_prefix);

    /* "bzrlib/_known_graph_pyx.pyx":594
 *         for prefix in sorted(prefix_tips):
 *             temp = PyDict_GetItem(prefix_tips, prefix)
 *             assert temp != NULL             # <<<<<<<<<<<<<<
 *             tip_nodes = <object>temp
 *             pending = _sort_list_nodes(tip_nodes, 1)
 */
    #ifndef CYTHON_WITHOUT_ASSERTIONS
    if (unlikely(!(__pyx_v_temp != NULL))) {
      PyErr_SetNone(PyExc_AssertionError);
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 594; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    #endif

    /* "bzrlib/_known_graph_pyx.pyx":595
 *             temp = PyDict_GetItem(prefix_tips, prefix)
 *             assert temp != NULL
 *             tip_nodes = <object>temp             # <<<<<<<<<<<<<<
 *             pending = _sort_list_nodes(tip_nodes, 1)
 *             last_item = PyList_GET_SIZE(pending) - 1
 */
    __Pyx_INCREF(((PyObject *)__pyx_v_temp));
    __Pyx_DECREF(__pyx_v_tip_nodes);
    __pyx_v_tip_nodes = ((PyObject *)__pyx_v_temp);

    /* "bzrlib/_known_graph_pyx.pyx":596
 *             assert temp != NULL
 *             tip_nodes = <object>temp
 *             pending = _sort_list_nodes(tip_nodes, 1)             # <<<<<<<<<<<<<<
 *             last_item = PyList_GET_SIZE(pending) - 1
 *             while last_item >= 0:
 */
    __pyx_t_1 = __pyx_f_6bzrlib_16_known_graph_pyx__sort_list_nodes(__pyx_v_tip_nodes, 1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 596; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_v_pending);
    __pyx_v_pending = __pyx_t_1;
    __pyx_t_1 = 0;

    /* "bzrlib/_known_graph_pyx.pyx":597
 *             tip_nodes = <object>temp
 *             pending = _sort_list_nodes(tip_nodes, 1)
 *             last_item = PyList_GET_SIZE(pending) - 1             # <<<<<<<<<<<<<<
 *             while last_item >= 0:
 *                 node = _get_list_node(pending, last_item)
 */
    __pyx_v_last_item = (PyList_GET_SIZE(__pyx_v_pending) - 1);

    /* "bzrlib/_known_graph_pyx.pyx":598
 *             pending = _sort_list_nodes(tip_nodes, 1)
 *             last_item = PyList_GET_SIZE(pending) - 1
 *             while last_item >= 0:             # <<<<<<<<<<<<<<
 *                 node = _get_list_node(pending, last_item)
 *                 last_item = last_item - 1
 */
    while (1) {
      __pyx_t_6 = (__pyx_v_last_item >= 0);
      if (!__pyx_t_6) break;

      /* "bzrlib/_known_graph_pyx.pyx":599
 *             last_item = PyList_GET_SIZE(pending) - 1
 *             while last_item >= 0:
 *                 node = _get_list_node(pending, last_item)             # <<<<<<<<<<<<<<
 *                 last_item = last_item - 1
 *                 if node.parents is None:
 */
      __pyx_t_1 = ((PyObject *)__pyx_f_6bzrlib_16_known_graph_pyx__get_list_node(__pyx_v_pending, __pyx_v_last_item)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 599; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(((PyObject *)__pyx_v_node));
      __pyx_v_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_t_1);
      __pyx_t_1 = 0;

      /* "bzrlib/_known_graph_pyx.pyx":600
 *             while last_item >= 0:
 *                 node = _get_list_node(pending, last_item)
 *                 last_item = last_item - 1             # <<<<<<<<<<<<<<
 *                 if node.parents is None:
 *                     # Ghost
 */
      __pyx_v_last_item = (__pyx_v_last_item - 1);

      /* "bzrlib/_known_graph_pyx.pyx":601
 *                 node = _get_list_node(pending, last_item)
 *                 last_item = last_item - 1
 *                 if node.parents is None:             # <<<<<<<<<<<<<<
 *                     # Ghost
 *                     continue
 */
      __pyx_t_6 = (__pyx_v_node->parents == Py_None);
      if (__pyx_t_6) {

        /* "bzrlib/_known_graph_pyx.pyx":603
 *                 if node.parents is None:
 *                     # Ghost
 *                     continue             # <<<<<<<<<<<<<<
 *                 PyList_Append(result, node.key)
 *                 # Sorting the parent keys isn't strictly necessary for stable
 */
        goto __pyx_L11_continue;
        goto __pyx_L13;
      }
      __pyx_L13:;

      /* "bzrlib/_known_graph_pyx.pyx":604
 *                     # Ghost
 *                     continue
 *                 PyList_Append(result, node.key)             # <<<<<<<<<<<<<<
 *                 # Sorting the parent keys isn't strictly necessary for stable
 *                 # sorting of a given graph. But it does help minimize the
 */
      __pyx_t_1 = __pyx_v_node->key;
      __Pyx_INCREF(__pyx_t_1);
      __pyx_t_7 = PyList_Append(((PyObject *)__pyx_v_result), __pyx_t_1); if (unlikely(__pyx_t_7 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 604; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

      /* "bzrlib/_known_graph_pyx.pyx":611
 *                 #   4.73ms  no sort
 *                 #   7.73ms  RichCompareBool sort
 *                 parents = _sort_list_nodes(node.parents, 1)             # <<<<<<<<<<<<<<
 *                 for pos from 0 <= pos < len(parents):
 *                     if PyTuple_CheckExact(parents):
 */
      __pyx_t_1 = __pyx_v_node->parents;
      __Pyx_INCREF(__pyx_t_1);
      __pyx_t_8 = __pyx_f_6bzrlib_16_known_graph_pyx__sort_list_nodes(__pyx_t_1, 1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 611; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_DECREF(__pyx_v_parents);
      __pyx_v_parents = __pyx_t_8;
      __pyx_t_8 = 0;

      /* "bzrlib/_known_graph_pyx.pyx":612
 *                 #   7.73ms  RichCompareBool sort
 *                 parents = _sort_list_nodes(node.parents, 1)
 *                 for pos from 0 <= pos < len(parents):             # <<<<<<<<<<<<<<
 *                     if PyTuple_CheckExact(parents):
 *                         parent_node = _get_tuple_node(parents, pos)
 */
      __pyx_t_4 = PyObject_Length(__pyx_v_parents); if (unlikely(__pyx_t_4 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 612; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      for (__pyx_v_pos = 0; __pyx_v_pos < __pyx_t_4; __pyx_v_pos++) {

        /* "bzrlib/_known_graph_pyx.pyx":613
 *                 parents = _sort_list_nodes(node.parents, 1)
 *                 for pos from 0 <= pos < len(parents):
 *                     if PyTuple_CheckExact(parents):             # <<<<<<<<<<<<<<
 *                         parent_node = _get_tuple_node(parents, pos)
 *                     else:
 */
        __pyx_t_7 = PyTuple_CheckExact(__pyx_v_parents);
        if (__pyx_t_7) {

          /* "bzrlib/_known_graph_pyx.pyx":614
 *                 for pos from 0 <= pos < len(parents):
 *                     if PyTuple_CheckExact(parents):
 *                         parent_node = _get_tuple_node(parents, pos)             # <<<<<<<<<<<<<<
 *                     else:
 *                         parent_node = _get_list_node(parents, pos)
 */
          __pyx_t_8 = ((PyObject *)__pyx_f_6bzrlib_16_known_graph_pyx__get_tuple_node(__pyx_v_parents, __pyx_v_pos)); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 614; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_8);
          __Pyx_DECREF(((PyObject *)__pyx_v_parent_node));
          __pyx_v_parent_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_t_8);
          __pyx_t_8 = 0;
          goto __pyx_L16;
        }
        /*else*/ {

          /* "bzrlib/_known_graph_pyx.pyx":616
 *                         parent_node = _get_tuple_node(parents, pos)
 *                     else:
 *                         parent_node = _get_list_node(parents, pos)             # <<<<<<<<<<<<<<
 *                     # TODO: GraphCycle detection
 *                     parent_node.seen = parent_node.seen + 1
 */
          __pyx_t_8 = ((PyObject *)__pyx_f_6bzrlib_16_known_graph_pyx__get_list_node(__pyx_v_parents, __pyx_v_pos)); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 616; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_8);
          __Pyx_DECREF(((PyObject *)__pyx_v_parent_node));
          __pyx_v_parent_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_t_8);
          __pyx_t_8 = 0;
        }
        __pyx_L16:;

        /* "bzrlib/_known_graph_pyx.pyx":618
 *                         parent_node = _get_list_node(parents, pos)
 *                     # TODO: GraphCycle detection
 *                     parent_node.seen = parent_node.seen + 1             # <<<<<<<<<<<<<<
 *                     if (parent_node.seen
 *                         == PyList_GET_SIZE(parent_node.children)):
 */
        __pyx_v_parent_node->seen = (__pyx_v_parent_node->seen + 1);

        /* "bzrlib/_known_graph_pyx.pyx":620
 *                     parent_node.seen = parent_node.seen + 1
 *                     if (parent_node.seen
 *                         == PyList_GET_SIZE(parent_node.children)):             # <<<<<<<<<<<<<<
 *                         # All children have been processed, queue up this
 *                         # parent
 */
        __pyx_t_8 = __pyx_v_parent_node->children;
        __Pyx_INCREF(__pyx_t_8);
        __pyx_t_6 = (__pyx_v_parent_node->seen == PyList_GET_SIZE(__pyx_t_8));
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        if (__pyx_t_6) {

          /* "bzrlib/_known_graph_pyx.pyx":623
 *                         # All children have been processed, queue up this
 *                         # parent
 *                         last_item = last_item + 1             # <<<<<<<<<<<<<<
 *                         if last_item < PyList_GET_SIZE(pending):
 *                             Py_INCREF(parent_node) # SetItem steals a ref
 */
          __pyx_v_last_item = (__pyx_v_last_item + 1);

          /* "bzrlib/_known_graph_pyx.pyx":624
 *                         # parent
 *                         last_item = last_item + 1
 *                         if last_item < PyList_GET_SIZE(pending):             # <<<<<<<<<<<<<<
 *                             Py_INCREF(parent_node) # SetItem steals a ref
 *                             PyList_SetItem(pending, last_item, parent_node)
 */
          __pyx_t_6 = (__pyx_v_last_item < PyList_GET_SIZE(__pyx_v_pending));
          if (__pyx_t_6) {

            /* "bzrlib/_known_graph_pyx.pyx":625
 *                         last_item = last_item + 1
 *                         if last_item < PyList_GET_SIZE(pending):
 *                             Py_INCREF(parent_node) # SetItem steals a ref             # <<<<<<<<<<<<<<
 *                             PyList_SetItem(pending, last_item, parent_node)
 *                         else:
 */
            Py_INCREF(((PyObject *)__pyx_v_parent_node));

            /* "bzrlib/_known_graph_pyx.pyx":626
 *                         if last_item < PyList_GET_SIZE(pending):
 *                             Py_INCREF(parent_node) # SetItem steals a ref
 *                             PyList_SetItem(pending, last_item, parent_node)             # <<<<<<<<<<<<<<
 *                         else:
 *                             PyList_Append(pending, parent_node)
 */
            __pyx_t_7 = PyList_SetItem(__pyx_v_pending, __pyx_v_last_item, ((PyObject *)__pyx_v_parent_node)); if (unlikely(__pyx_t_7 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 626; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
            goto __pyx_L18;
          }
          /*else*/ {

            /* "bzrlib/_known_graph_pyx.pyx":628
 *                             PyList_SetItem(pending, last_item, parent_node)
 *                         else:
 *                             PyList_Append(pending, parent_node)             # <<<<<<<<<<<<<<
 *                         parent_node.seen = 0
 *         return result
 */
            __pyx_t_7 = PyList_Append(__pyx_v_pending, ((PyObject *)__pyx_v_parent_node)); if (unlikely(__pyx_t_7 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 628; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          }
          __pyx_L18:;

          /* "bzrlib/_known_graph_pyx.pyx":629
 *                         else:
 *                             PyList_Append(pending, parent_node)
 *                         parent_node.seen = 0             # <<<<<<<<<<<<<<
 *         return result
 * 
 */
          __pyx_v_parent_node->seen = 0;
          goto __pyx_L17;
        }
        __pyx_L17:;
      }
      __pyx_L11_continue:;
    }
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "bzrlib/_known_graph_pyx.pyx":630
 *                             PyList_Append(pending, parent_node)
 *                         parent_node.seen = 0
 *         return result             # <<<<<<<<<<<<<<
 * 
 *     def merge_sort(self, tip_key):
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(((PyObject *)__pyx_v_result));
  __pyx_r = ((PyObject *)__pyx_v_result);
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_AddTraceback("bzrlib._known_graph_pyx.KnownGraph.gc_sort");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_DECREF((PyObject *)__pyx_v_node);
  __Pyx_DECREF((PyObject *)__pyx_v_parent_node);
  __Pyx_DECREF(__pyx_v_tips);
  __Pyx_DECREF(__pyx_v_prefix_tips);
  __Pyx_DECREF(__pyx_v_prefix);
  __Pyx_DECREF(__pyx_v_tip_nodes);
  __Pyx_DECREF(__pyx_v_result);
  __Pyx_DECREF(__pyx_v_pending);
  __Pyx_DECREF(__pyx_v_parents);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "bzrlib/_known_graph_pyx.pyx":632
 *         return result
 * 
 *     def merge_sort(self, tip_key):             # <<<<<<<<<<<<<<
 *         """Compute the merge sorted graph output."""
 *         cdef _MergeSorter sorter
 */

static PyObject *__pyx_pf_6bzrlib_16_known_graph_pyx_10KnownGraph_10merge_sort(PyObject *__pyx_v_self, PyObject *__pyx_v_tip_key); /*proto*/
static char __pyx_doc_6bzrlib_16_known_graph_pyx_10KnownGraph_10merge_sort[] = "Compute the merge sorted graph output.";
static PyObject *__pyx_pf_6bzrlib_16_known_graph_pyx_10KnownGraph_10merge_sort(PyObject *__pyx_v_self, PyObject *__pyx_v_tip_key) {
  struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSorter *__pyx_v_sorter;
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  __Pyx_RefNannySetupContext("merge_sort");
  __pyx_v_sorter = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSorter *)Py_None); __Pyx_INCREF(Py_None);

  /* "bzrlib/_known_graph_pyx.pyx":639
 *         #       that won't be collectable anyway. real world testing has not
 *         #       shown a specific impact, yet.
 *         sorter = _MergeSorter(self, tip_key)             # <<<<<<<<<<<<<<
 *         return sorter.topo_order()
 * 
 */
  __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 639; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_1));
  __Pyx_INCREF(__pyx_v_self);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_self);
  __Pyx_GIVEREF(__pyx_v_self);
  __Pyx_INCREF(__pyx_v_tip_key);
  PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_tip_key);
  __Pyx_GIVEREF(__pyx_v_tip_key);
  __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_6bzrlib_16_known_graph_pyx__MergeSorter)), ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 639; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_v_sorter));
  __pyx_v_sorter = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSorter *)__pyx_t_2);
  __pyx_t_2 = 0;

  /* "bzrlib/_known_graph_pyx.pyx":640
 *         #       shown a specific impact, yet.
 *         sorter = _MergeSorter(self, tip_key)
 *         return sorter.topo_order()             # <<<<<<<<<<<<<<
 * 
 *     def get_parent_keys(self, key):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = ((struct __pyx_vtabstruct_6bzrlib_16_known_graph_pyx__MergeSorter *)__pyx_v_sorter->__pyx_vtab)->topo_order(__pyx_v_sorter); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 640; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("bzrlib._known_graph_pyx.KnownGraph.merge_sort");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_DECREF((PyObject *)__pyx_v_sorter);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "bzrlib/_known_graph_pyx.pyx":642
 *         return sorter.topo_order()
 * 
 *     def get_parent_keys(self, key):             # <<<<<<<<<<<<<<
 *         """Get the parents for a key
 * 
 */

static PyObject *__pyx_pf_6bzrlib_16_known_graph_pyx_10KnownGraph_11get_parent_keys(PyObject *__pyx_v_self, PyObject *__pyx_v_key); /*proto*/
static char __pyx_doc_6bzrlib_16_known_graph_pyx_10KnownGraph_11get_parent_keys[] = "Get the parents for a key\n        \n        Returns a list containg the parents keys. If the key is a ghost,\n        None is returned. A KeyError will be raised if the key is not in\n        the graph.\n        \n        :param keys: Key to check (eg revision_id)\n        :return: A list of parents\n        ";
static PyObject *__pyx_pf_6bzrlib_16_known_graph_pyx_10KnownGraph_11get_parent_keys(PyObject *__pyx_v_self, PyObject *__pyx_v_key) {
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  __Pyx_RefNannySetupContext("get_parent_keys");

  /* "bzrlib/_known_graph_pyx.pyx":652
 *         :return: A list of parents
 *         """
 *         return self._nodes[key].parent_keys             # <<<<<<<<<<<<<<
 * 
 *     def get_child_keys(self, key):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyObject_GetItem(((struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *)__pyx_v_self)->_nodes, __pyx_v_key); if (!__pyx_t_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 652; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__parent_keys); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 652; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("bzrlib._known_graph_pyx.KnownGraph.get_parent_keys");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "bzrlib/_known_graph_pyx.pyx":654
 *         return self._nodes[key].parent_keys
 * 
 *     def get_child_keys(self, key):             # <<<<<<<<<<<<<<
 *         """Get the children for a key
 * 
 */

static PyObject *__pyx_pf_6bzrlib_16_known_graph_pyx_10KnownGraph_12get_child_keys(PyObject *__pyx_v_self, PyObject *__pyx_v_key); /*proto*/
static char __pyx_doc_6bzrlib_16_known_graph_pyx_10KnownGraph_12get_child_keys[] = "Get the children for a key\n        \n        Returns a list containg the children keys. A KeyError will be raised\n        if the key is not in the graph.\n        \n        :param keys: Key to check (eg revision_id)\n        :return: A list of children\n        ";
static PyObject *__pyx_pf_6bzrlib_16_known_graph_pyx_10KnownGraph_12get_child_keys(PyObject *__pyx_v_self, PyObject *__pyx_v_key) {
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  __Pyx_RefNannySetupContext("get_child_keys");

  /* "bzrlib/_known_graph_pyx.pyx":663
 *         :return: A list of children
 *         """
 *         return self._nodes[key].child_keys             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyObject_GetItem(((struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *)__pyx_v_self)->_nodes, __pyx_v_key); if (!__pyx_t_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 663; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__child_keys); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 663; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("bzrlib._known_graph_pyx.KnownGraph.get_child_keys");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "bzrlib/_known_graph_pyx.pyx":195
 *     """This is a class which assumes we already know the full graph."""
 * 
 *     cdef public object _nodes             # <<<<<<<<<<<<<<
 *     cdef public object _known_heads
 *     cdef public int do_cache
 */

static PyObject *__pyx_pf_6bzrlib_16_known_graph_pyx_10KnownGraph_6_nodes___get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pf_6bzrlib_16_known_graph_pyx_10KnownGraph_6_nodes___get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannySetupContext("__get__");
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(((struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *)__pyx_v_self)->_nodes);
  __pyx_r = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *)__pyx_v_self)->_nodes;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_6bzrlib_16_known_graph_pyx_10KnownGraph_6_nodes_1__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/
static int __pyx_pf_6bzrlib_16_known_graph_pyx_10KnownGraph_6_nodes_1__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) {
  int __pyx_r;
  __Pyx_RefNannySetupContext("__set__");
  __Pyx_INCREF(__pyx_v_value);
  __Pyx_GIVEREF(__pyx_v_value);
  __Pyx_GOTREF(((struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *)__pyx_v_self)->_nodes);
  __Pyx_DECREF(((struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *)__pyx_v_self)->_nodes);
  ((struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *)__pyx_v_self)->_nodes = __pyx_v_value;

  __pyx_r = 0;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_6bzrlib_16_known_graph_pyx_10KnownGraph_6_nodes_2__del__(PyObject *__pyx_v_self); /*proto*/
static int __pyx_pf_6bzrlib_16_known_graph_pyx_10KnownGraph_6_nodes_2__del__(PyObject *__pyx_v_self) {
  int __pyx_r;
  __Pyx_RefNannySetupContext("__del__");
  __Pyx_INCREF(Py_None);
  __Pyx_GIVEREF(Py_None);
  __Pyx_GOTREF(((struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *)__pyx_v_self)->_nodes);
  __Pyx_DECREF(((struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *)__pyx_v_self)->_nodes);
  ((struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *)__pyx_v_self)->_nodes = Py_None;

  __pyx_r = 0;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "bzrlib/_known_graph_pyx.pyx":196
 * 
 *     cdef public object _nodes
 *     cdef public object _known_heads             # <<<<<<<<<<<<<<
 *     cdef public int do_cache
 * 
 */

static PyObject *__pyx_pf_6bzrlib_16_known_graph_pyx_10KnownGraph_12_known_heads___get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pf_6bzrlib_16_known_graph_pyx_10KnownGraph_12_known_heads___get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannySetupContext("__get__");
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(((struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *)__pyx_v_self)->_known_heads);
  __pyx_r = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *)__pyx_v_self)->_known_heads;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_6bzrlib_16_known_graph_pyx_10KnownGraph_12_known_heads_1__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/
static int __pyx_pf_6bzrlib_16_known_graph_pyx_10KnownGraph_12_known_heads_1__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) {
  int __pyx_r;
  __Pyx_RefNannySetupContext("__set__");
  __Pyx_INCREF(__pyx_v_value);
  __Pyx_GIVEREF(__pyx_v_value);
  __Pyx_GOTREF(((struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *)__pyx_v_self)->_known_heads);
  __Pyx_DECREF(((struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *)__pyx_v_self)->_known_heads);
  ((struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *)__pyx_v_self)->_known_heads = __pyx_v_value;

  __pyx_r = 0;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_6bzrlib_16_known_graph_pyx_10KnownGraph_12_known_heads_2__del__(PyObject *__pyx_v_self); /*proto*/
static int __pyx_pf_6bzrlib_16_known_graph_pyx_10KnownGraph_12_known_heads_2__del__(PyObject *__pyx_v_self) {
  int __pyx_r;
  __Pyx_RefNannySetupContext("__del__");
  __Pyx_INCREF(Py_None);
  __Pyx_GIVEREF(Py_None);
  __Pyx_GOTREF(((struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *)__pyx_v_self)->_known_heads);
  __Pyx_DECREF(((struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *)__pyx_v_self)->_known_heads);
  ((struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *)__pyx_v_self)->_known_heads = Py_None;

  __pyx_r = 0;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "bzrlib/_known_graph_pyx.pyx":197
 *     cdef public object _nodes
 *     cdef public object _known_heads
 *     cdef public int do_cache             # <<<<<<<<<<<<<<
 * 
 *     def __init__(self, parent_map, do_cache=True):
 */

static PyObject *__pyx_pf_6bzrlib_16_known_graph_pyx_10KnownGraph_8do_cache___get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pf_6bzrlib_16_known_graph_pyx_10KnownGraph_8do_cache___get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  __Pyx_RefNannySetupContext("__get__");
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyInt_FromLong(((struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *)__pyx_v_self)->do_cache); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 197; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("bzrlib._known_graph_pyx.KnownGraph.do_cache.__get__");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_6bzrlib_16_known_graph_pyx_10KnownGraph_8do_cache_1__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/
static int __pyx_pf_6bzrlib_16_known_graph_pyx_10KnownGraph_8do_cache_1__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) {
  int __pyx_r;
  int __pyx_t_1;
  __Pyx_RefNannySetupContext("__set__");
  __pyx_t_1 = __Pyx_PyInt_AsInt(__pyx_v_value); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 197; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  ((struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *)__pyx_v_self)->do_cache = __pyx_t_1;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("bzrlib._known_graph_pyx.KnownGraph.do_cache.__set__");
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "bzrlib/_known_graph_pyx.pyx":686
 *     cdef int completed # Fully Processed
 * 
 *     def __init__(self, key):             # <<<<<<<<<<<<<<
 *         self.key = key
 *         self.merge_depth = -1
 */

static int __pyx_pf_6bzrlib_16_known_graph_pyx_14_MergeSortNode___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_pf_6bzrlib_16_known_graph_pyx_14_MergeSortNode___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_key = 0;
  int __pyx_r;
  static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__key,0};
  __Pyx_RefNannySetupContext("__init__");
  if (unlikely(__pyx_kwds)) {
    Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
    PyObject* values[1] = {0};
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      case  0: break;
      default: goto __pyx_L5_argtuple_error;
    }
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  0:
      values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__key);
      if (likely(values[0])) kw_args--;
      else goto __pyx_L5_argtuple_error;
    }
    if (unlikely(kw_args > 0)) {
      if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "__init__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 686; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    }
    __pyx_v_key = values[0];
  } else if (PyTuple_GET_SIZE(__pyx_args) != 1) {
    goto __pyx_L5_argtuple_error;
  } else {
    __pyx_v_key = PyTuple_GET_ITEM(__pyx_args, 0);
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("__init__", 1, 1, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 686; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("bzrlib._known_graph_pyx._MergeSortNode.__init__");
  __Pyx_RefNannyFinishContext();
  return -1;
  __pyx_L4_argument_unpacking_done:;

  /* "bzrlib/_known_graph_pyx.pyx":687
 * 
 *     def __init__(self, key):
 *         self.key = key             # <<<<<<<<<<<<<<
 *         self.merge_depth = -1
 *         self.left_parent = None
 */
  __Pyx_INCREF(__pyx_v_key);
  __Pyx_GIVEREF(__pyx_v_key);
  __Pyx_GOTREF(((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)__pyx_v_self)->key);
  __Pyx_DECREF(((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)__pyx_v_self)->key);
  ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)__pyx_v_self)->key = __pyx_v_key;

  /* "bzrlib/_known_graph_pyx.pyx":688
 *     def __init__(self, key):
 *         self.key = key
 *         self.merge_depth = -1             # <<<<<<<<<<<<<<
 *         self.left_parent = None
 *         self.left_pending_parent = None
 */
  ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)__pyx_v_self)->merge_depth = -1;

  /* "bzrlib/_known_graph_pyx.pyx":689
 *         self.key = key
 *         self.merge_depth = -1
 *         self.left_parent = None             # <<<<<<<<<<<<<<
 *         self.left_pending_parent = None
 *         self.pending_parents = None
 */
  __Pyx_INCREF(Py_None);
  __Pyx_GIVEREF(Py_None);
  __Pyx_GOTREF(((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)__pyx_v_self)->left_parent);
  __Pyx_DECREF(((PyObject *)((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)__pyx_v_self)->left_parent));
  ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)__pyx_v_self)->left_parent = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)Py_None);

  /* "bzrlib/_known_graph_pyx.pyx":690
 *         self.merge_depth = -1
 *         self.left_parent = None
 *         self.left_pending_parent = None             # <<<<<<<<<<<<<<
 *         self.pending_parents = None
 *         self._revno_first = -1
 */
  __Pyx_INCREF(Py_None);
  __Pyx_GIVEREF(Py_None);
  __Pyx_GOTREF(((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)__pyx_v_self)->left_pending_parent);
  __Pyx_DECREF(((PyObject *)((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)__pyx_v_self)->left_pending_parent));
  ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)__pyx_v_self)->left_pending_parent = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)Py_None);

  /* "bzrlib/_known_graph_pyx.pyx":691
 *         self.left_parent = None
 *         self.left_pending_parent = None
 *         self.pending_parents = None             # <<<<<<<<<<<<<<
 *         self._revno_first = -1
 *         self._revno_second = -1
 */
  __Pyx_INCREF(Py_None);
  __Pyx_GIVEREF(Py_None);
  __Pyx_GOTREF(((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)__pyx_v_self)->pending_parents);
  __Pyx_DECREF(((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)__pyx_v_self)->pending_parents);
  ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)__pyx_v_self)->pending_parents = Py_None;

  /* "bzrlib/_known_graph_pyx.pyx":692
 *         self.left_pending_parent = None
 *         self.pending_parents = None
 *         self._revno_first = -1             # <<<<<<<<<<<<<<
 *         self._revno_second = -1
 *         self._revno_last = -1
 */
  ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)__pyx_v_self)->_revno_first = -1;

  /* "bzrlib/_known_graph_pyx.pyx":693
 *         self.pending_parents = None
 *         self._revno_first = -1
 *         self._revno_second = -1             # <<<<<<<<<<<<<<
 *         self._revno_last = -1
 *         self.is_first_child = 0
 */
  ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)__pyx_v_self)->_revno_second = -1;

  /* "bzrlib/_known_graph_pyx.pyx":694
 *         self._revno_first = -1
 *         self._revno_second = -1
 *         self._revno_last = -1             # <<<<<<<<<<<<<<
 *         self.is_first_child = 0
 *         self.seen_by_child = 0
 */
  ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)__pyx_v_self)->_revno_last = -1;

  /* "bzrlib/_known_graph_pyx.pyx":695
 *         self._revno_second = -1
 *         self._revno_last = -1
 *         self.is_first_child = 0             # <<<<<<<<<<<<<<
 *         self.seen_by_child = 0
 *         self.completed = 0
 */
  ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)__pyx_v_self)->is_first_child = 0;

  /* "bzrlib/_known_graph_pyx.pyx":696
 *         self._revno_last = -1
 *         self.is_first_child = 0
 *         self.seen_by_child = 0             # <<<<<<<<<<<<<<
 *         self.completed = 0
 * 
 */
  ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)__pyx_v_self)->seen_by_child = 0;

  /* "bzrlib/_known_graph_pyx.pyx":697
 *         self.is_first_child = 0
 *         self.seen_by_child = 0
 *         self.completed = 0             # <<<<<<<<<<<<<<
 * 
 *     def __repr__(self):
 */
  ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)__pyx_v_self)->completed = 0;

  __pyx_r = 0;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "bzrlib/_known_graph_pyx.pyx":699
 *         self.completed = 0
 * 
 *     def __repr__(self):             # <<<<<<<<<<<<<<
 *         return '%s(%s depth:%s rev:%s,%s,%s first:%s seen:%s)' % (
 *             self.__class__.__name__, self.key,
 */

static PyObject *__pyx_pf_6bzrlib_16_known_graph_pyx_14_MergeSortNode_1__repr__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pf_6bzrlib_16_known_graph_pyx_14_MergeSortNode_1__repr__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  __Pyx_RefNannySetupContext("__repr__");

  /* "bzrlib/_known_graph_pyx.pyx":700
 * 
 *     def __repr__(self):
 *         return '%s(%s depth:%s rev:%s,%s,%s first:%s seen:%s)' % (             # <<<<<<<<<<<<<<
 *             self.__class__.__name__, self.key,
 *             self.merge_depth,
 */
  __Pyx_XDECREF(__pyx_r);

  /* "bzrlib/_known_graph_pyx.pyx":701
 *     def __repr__(self):
 *         return '%s(%s depth:%s rev:%s,%s,%s first:%s seen:%s)' % (
 *             self.__class__.__name__, self.key,             # <<<<<<<<<<<<<<
 *             self.merge_depth,
 *             self._revno_first, self._revno_second, self._revno_last,
 */
  __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s____class__); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 701; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s____name__); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 701; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "bzrlib/_known_graph_pyx.pyx":702
 *         return '%s(%s depth:%s rev:%s,%s,%s first:%s seen:%s)' % (
 *             self.__class__.__name__, self.key,
 *             self.merge_depth,             # <<<<<<<<<<<<<<
 *             self._revno_first, self._revno_second, self._revno_last,
 *             self.is_first_child, self.seen_by_child)
 */
  __pyx_t_1 = PyInt_FromLong(((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)__pyx_v_self)->merge_depth); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 702; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);

  /* "bzrlib/_known_graph_pyx.pyx":703
 *             self.__class__.__name__, self.key,
 *             self.merge_depth,
 *             self._revno_first, self._revno_second, self._revno_last,             # <<<<<<<<<<<<<<
 *             self.is_first_child, self.seen_by_child)
 * 
 */
  __pyx_t_3 = PyInt_FromLong(((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)__pyx_v_self)->_revno_first); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 703; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = PyInt_FromLong(((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)__pyx_v_self)->_revno_second); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 703; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = PyInt_FromLong(((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)__pyx_v_self)->_revno_last); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 703; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);

  /* "bzrlib/_known_graph_pyx.pyx":704
 *             self.merge_depth,
 *             self._revno_first, self._revno_second, self._revno_last,
 *             self.is_first_child, self.seen_by_child)             # <<<<<<<<<<<<<<
 * 
 *     cdef int has_pending_parents(self): # cannot_raise
 */
  __pyx_t_6 = PyInt_FromLong(((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)__pyx_v_self)->is_first_child); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 704; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_7 = PyInt_FromLong(((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)__pyx_v_self)->seen_by_child); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 704; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_8 = PyTuple_New(8); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 701; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_8));
  PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  __Pyx_INCREF(((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)__pyx_v_self)->key);
  PyTuple_SET_ITEM(__pyx_t_8, 1, ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)__pyx_v_self)->key);
  __Pyx_GIVEREF(((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)__pyx_v_self)->key);
  PyTuple_SET_ITEM(__pyx_t_8, 2, __pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_8, 3, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_8, 4, __pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_8, 5, __pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_8, 6, __pyx_t_6);
  __Pyx_GIVEREF(__pyx_t_6);
  PyTuple_SET_ITEM(__pyx_t_8, 7, __pyx_t_7);
  __Pyx_GIVEREF(__pyx_t_7);
  __pyx_t_2 = 0;
  __pyx_t_1 = 0;
  __pyx_t_3 = 0;
  __pyx_t_4 = 0;
  __pyx_t_5 = 0;
  __pyx_t_6 = 0;
  __pyx_t_7 = 0;
  __pyx_t_7 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_10), ((PyObject *)__pyx_t_8)); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 700; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_7));
  __Pyx_DECREF(((PyObject *)__pyx_t_8)); __pyx_t_8 = 0;
  __pyx_r = ((PyObject *)__pyx_t_7);
  __pyx_t_7 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_AddTraceback("bzrlib._known_graph_pyx._MergeSortNode.__repr__");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "bzrlib/_known_graph_pyx.pyx":706
 *             self.is_first_child, self.seen_by_child)
 * 
 *     cdef int has_pending_parents(self): # cannot_raise             # <<<<<<<<<<<<<<
 *         if self.left_pending_parent is not None or self.pending_parents:
 *             return 1
 */

static  int __pyx_f_6bzrlib_16_known_graph_pyx_14_MergeSortNode_has_pending_parents(struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *__pyx_v_self) {
  int __pyx_r;
  int __pyx_t_1;
  int __pyx_t_2;
  int __pyx_t_3;
  __Pyx_RefNannySetupContext("has_pending_parents");

  /* "bzrlib/_known_graph_pyx.pyx":707
 * 
 *     cdef int has_pending_parents(self): # cannot_raise
 *         if self.left_pending_parent is not None or self.pending_parents:             # <<<<<<<<<<<<<<
 *             return 1
 *         return 0
 */
  __pyx_t_1 = (((PyObject *)__pyx_v_self->left_pending_parent) != Py_None);
  if (!__pyx_t_1) {
    __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_self->pending_parents); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 707; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_3 = __pyx_t_2;
  } else {
    __pyx_t_3 = __pyx_t_1;
  }
  if (__pyx_t_3) {

    /* "bzrlib/_known_graph_pyx.pyx":708
 *     cdef int has_pending_parents(self): # cannot_raise
 *         if self.left_pending_parent is not None or self.pending_parents:
 *             return 1             # <<<<<<<<<<<<<<
 *         return 0
 * 
 */
    __pyx_r = 1;
    goto __pyx_L0;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "bzrlib/_known_graph_pyx.pyx":709
 *         if self.left_pending_parent is not None or self.pending_parents:
 *             return 1
 *         return 0             # <<<<<<<<<<<<<<
 * 
 *     cdef object _revno(self):
 */
  __pyx_r = 0;
  goto __pyx_L0;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_WriteUnraisable("bzrlib._known_graph_pyx._MergeSortNode.has_pending_parents");
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "bzrlib/_known_graph_pyx.pyx":711
 *         return 0
 * 
 *     cdef object _revno(self):             # <<<<<<<<<<<<<<
 *         if self._revno_first == -1:
 *             if self._revno_second != -1:
 */

static  PyObject *__pyx_f_6bzrlib_16_known_graph_pyx_14_MergeSortNode__revno(struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  __Pyx_RefNannySetupContext("_revno");

  /* "bzrlib/_known_graph_pyx.pyx":712
 * 
 *     cdef object _revno(self):
 *         if self._revno_first == -1:             # <<<<<<<<<<<<<<
 *             if self._revno_second != -1:
 *                 raise RuntimeError('Something wrong with: %s' % (self,))
 */
  __pyx_t_1 = (__pyx_v_self->_revno_first == -1);
  if (__pyx_t_1) {

    /* "bzrlib/_known_graph_pyx.pyx":713
 *     cdef object _revno(self):
 *         if self._revno_first == -1:
 *             if self._revno_second != -1:             # <<<<<<<<<<<<<<
 *                 raise RuntimeError('Something wrong with: %s' % (self,))
 *             return (self._revno_last,)
 */
    __pyx_t_1 = (__pyx_v_self->_revno_second != -1);
    if (__pyx_t_1) {

      /* "bzrlib/_known_graph_pyx.pyx":714
 *         if self._revno_first == -1:
 *             if self._revno_second != -1:
 *                 raise RuntimeError('Something wrong with: %s' % (self,))             # <<<<<<<<<<<<<<
 *             return (self._revno_last,)
 *         else:
 */
      __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 714; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(((PyObject *)__pyx_t_2));
      __Pyx_INCREF(((PyObject *)__pyx_v_self));
      PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_self));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_self));
      __pyx_t_3 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_11), ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 714; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(((PyObject *)__pyx_t_3));
      __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
      __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 714; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(((PyObject *)__pyx_t_2));
      PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_t_3));
      __Pyx_GIVEREF(((PyObject *)__pyx_t_3));
      __pyx_t_3 = 0;
      __pyx_t_3 = PyObject_Call(__pyx_builtin_RuntimeError, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 714; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
      __Pyx_Raise(__pyx_t_3, 0, 0);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 714; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      goto __pyx_L4;
    }
    __pyx_L4:;

    /* "bzrlib/_known_graph_pyx.pyx":715
 *             if self._revno_second != -1:
 *                 raise RuntimeError('Something wrong with: %s' % (self,))
 *             return (self._revno_last,)             # <<<<<<<<<<<<<<
 *         else:
 *             return (self._revno_first, self._revno_second, self._revno_last)
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_3 = PyInt_FromLong(__pyx_v_self->_revno_last); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 715; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 715; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_2));
    PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_3);
    __Pyx_GIVEREF(__pyx_t_3);
    __pyx_t_3 = 0;
    __pyx_r = ((PyObject *)__pyx_t_2);
    __pyx_t_2 = 0;
    goto __pyx_L0;
    goto __pyx_L3;
  }
  /*else*/ {

    /* "bzrlib/_known_graph_pyx.pyx":717
 *             return (self._revno_last,)
 *         else:
 *             return (self._revno_first, self._revno_second, self._revno_last)             # <<<<<<<<<<<<<<
 * 
 *     property revno:
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_2 = PyInt_FromLong(__pyx_v_self->_revno_first); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 717; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_3 = PyInt_FromLong(__pyx_v_self->_revno_second); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 717; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = PyInt_FromLong(__pyx_v_self->_revno_last); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 717; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = PyTuple_New(3); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 717; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_5));
    PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_2);
    __Pyx_GIVEREF(__pyx_t_2);
    PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_3);
    __Pyx_GIVEREF(__pyx_t_3);
    PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_t_4);
    __Pyx_GIVEREF(__pyx_t_4);
    __pyx_t_2 = 0;
    __pyx_t_3 = 0;
    __pyx_t_4 = 0;
    __pyx_r = ((PyObject *)__pyx_t_5);
    __pyx_t_5 = 0;
    goto __pyx_L0;
  }
  __pyx_L3:;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("bzrlib._known_graph_pyx._MergeSortNode._revno");
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "bzrlib/_known_graph_pyx.pyx":720
 * 
 *     property revno:
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self._revno()
 * 
 */

static PyObject *__pyx_pf_6bzrlib_16_known_graph_pyx_14_MergeSortNode_5revno___get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pf_6bzrlib_16_known_graph_pyx_14_MergeSortNode_5revno___get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  __Pyx_RefNannySetupContext("__get__");

  /* "bzrlib/_known_graph_pyx.pyx":721
 *     property revno:
 *         def __get__(self):
 *             return self._revno()             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = ((struct __pyx_vtabstruct_6bzrlib_16_known_graph_pyx__MergeSortNode *)((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)__pyx_v_self)->__pyx_vtab)->_revno(((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)__pyx_v_self)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 721; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("bzrlib._known_graph_pyx._MergeSortNode.revno.__get__");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "bzrlib/_known_graph_pyx.pyx":670
 * 
 *     # Public api
 *     cdef public object key             # <<<<<<<<<<<<<<
 *     cdef public long merge_depth
 *     cdef public object end_of_merge # True/False Is this the end of the current merge
 */

static PyObject *__pyx_pf_6bzrlib_16_known_graph_pyx_14_MergeSortNode_3key___get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pf_6bzrlib_16_known_graph_pyx_14_MergeSortNode_3key___get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannySetupContext("__get__");
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)__pyx_v_self)->key);
  __pyx_r = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)__pyx_v_self)->key;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_6bzrlib_16_known_graph_pyx_14_MergeSortNode_3key_1__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/
static int __pyx_pf_6bzrlib_16_known_graph_pyx_14_MergeSortNode_3key_1__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) {
  int __pyx_r;
  __Pyx_RefNannySetupContext("__set__");
  __Pyx_INCREF(__pyx_v_value);
  __Pyx_GIVEREF(__pyx_v_value);
  __Pyx_GOTREF(((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)__pyx_v_self)->key);
  __Pyx_DECREF(((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)__pyx_v_self)->key);
  ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)__pyx_v_self)->key = __pyx_v_value;

  __pyx_r = 0;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_6bzrlib_16_known_graph_pyx_14_MergeSortNode_3key_2__del__(PyObject *__pyx_v_self); /*proto*/
static int __pyx_pf_6bzrlib_16_known_graph_pyx_14_MergeSortNode_3key_2__del__(PyObject *__pyx_v_self) {
  int __pyx_r;
  __Pyx_RefNannySetupContext("__del__");
  __Pyx_INCREF(Py_None);
  __Pyx_GIVEREF(Py_None);
  __Pyx_GOTREF(((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)__pyx_v_self)->key);
  __Pyx_DECREF(((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)__pyx_v_self)->key);
  ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)__pyx_v_self)->key = Py_None;

  __pyx_r = 0;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "bzrlib/_known_graph_pyx.pyx":671
 *     # Public api
 *     cdef public object key
 *     cdef public long merge_depth             # <<<<<<<<<<<<<<
 *     cdef public object end_of_merge # True/False Is this the end of the current merge
 * 
 */

static PyObject *__pyx_pf_6bzrlib_16_known_graph_pyx_14_MergeSortNode_11merge_depth___get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pf_6bzrlib_16_known_graph_pyx_14_MergeSortNode_11merge_depth___get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  __Pyx_RefNannySetupContext("__get__");
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyInt_FromLong(((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)__pyx_v_self)->merge_depth); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 671; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("bzrlib._known_graph_pyx._MergeSortNode.merge_depth.__get__");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_6bzrlib_16_known_graph_pyx_14_MergeSortNode_11merge_depth_1__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/
static int __pyx_pf_6bzrlib_16_known_graph_pyx_14_MergeSortNode_11merge_depth_1__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) {
  int __pyx_r;
  long __pyx_t_1;
  __Pyx_RefNannySetupContext("__set__");
  __pyx_t_1 = __Pyx_PyInt_AsLong(__pyx_v_value); if (unlikely((__pyx_t_1 == (long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 671; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)__pyx_v_self)->merge_depth = __pyx_t_1;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("bzrlib._known_graph_pyx._MergeSortNode.merge_depth.__set__");
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "bzrlib/_known_graph_pyx.pyx":672
 *     cdef public object key
 *     cdef public long merge_depth
 *     cdef public object end_of_merge # True/False Is this the end of the current merge             # <<<<<<<<<<<<<<
 * 
 *     # Private api, used while computing the information
 */

static PyObject *__pyx_pf_6bzrlib_16_known_graph_pyx_14_MergeSortNode_12end_of_merge___get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pf_6bzrlib_16_known_graph_pyx_14_MergeSortNode_12end_of_merge___get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannySetupContext("__get__");
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)__pyx_v_self)->end_of_merge);
  __pyx_r = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)__pyx_v_self)->end_of_merge;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_6bzrlib_16_known_graph_pyx_14_MergeSortNode_12end_of_merge_1__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/
static int __pyx_pf_6bzrlib_16_known_graph_pyx_14_MergeSortNode_12end_of_merge_1__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) {
  int __pyx_r;
  __Pyx_RefNannySetupContext("__set__");
  __Pyx_INCREF(__pyx_v_value);
  __Pyx_GIVEREF(__pyx_v_value);
  __Pyx_GOTREF(((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)__pyx_v_self)->end_of_merge);
  __Pyx_DECREF(((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)__pyx_v_self)->end_of_merge);
  ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)__pyx_v_self)->end_of_merge = __pyx_v_value;

  __pyx_r = 0;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_6bzrlib_16_known_graph_pyx_14_MergeSortNode_12end_of_merge_2__del__(PyObject *__pyx_v_self); /*proto*/
static int __pyx_pf_6bzrlib_16_known_graph_pyx_14_MergeSortNode_12end_of_merge_2__del__(PyObject *__pyx_v_self) {
  int __pyx_r;
  __Pyx_RefNannySetupContext("__del__");
  __Pyx_INCREF(Py_None);
  __Pyx_GIVEREF(Py_None);
  __Pyx_GOTREF(((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)__pyx_v_self)->end_of_merge);
  __Pyx_DECREF(((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)__pyx_v_self)->end_of_merge);
  ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)__pyx_v_self)->end_of_merge = Py_None;

  __pyx_r = 0;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "bzrlib/_known_graph_pyx.pyx":743
 *     cdef object _scheduled_nodes # List of nodes ready to be yielded
 * 
 *     def __init__(self, known_graph, tip_key):             # <<<<<<<<<<<<<<
 *         cdef _KnownGraphNode node
 * 
 */

static int __pyx_pf_6bzrlib_16_known_graph_pyx_12_MergeSorter___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_pf_6bzrlib_16_known_graph_pyx_12_MergeSorter___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_known_graph = 0;
  PyObject *__pyx_v_tip_key = 0;
  struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *__pyx_v_node;
  int __pyx_r;
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  int __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_t_5;
  int __pyx_t_6;
  static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__known_graph,&__pyx_n_s__tip_key,0};
  __Pyx_RefNannySetupContext("__init__");
  if (unlikely(__pyx_kwds)) {
    Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
    PyObject* values[2] = {0,0};
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      case  0: break;
      default: goto __pyx_L5_argtuple_error;
    }
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  0:
      values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__known_graph);
      if (likely(values[0])) kw_args--;
      else goto __pyx_L5_argtuple_error;
      case  1:
      values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__tip_key);
      if (likely(values[1])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("__init__", 1, 2, 2, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 743; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    }
    if (unlikely(kw_args > 0)) {
      if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "__init__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 743; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    }
    __pyx_v_known_graph = values[0];
    __pyx_v_tip_key = values[1];
  } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
    goto __pyx_L5_argtuple_error;
  } else {
    __pyx_v_known_graph = PyTuple_GET_ITEM(__pyx_args, 0);
    __pyx_v_tip_key = PyTuple_GET_ITEM(__pyx_args, 1);
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("__init__", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 743; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("bzrlib._known_graph_pyx._MergeSorter.__init__");
  __Pyx_RefNannyFinishContext();
  return -1;
  __pyx_L4_argument_unpacking_done:;
  __pyx_v_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)Py_None); __Pyx_INCREF(Py_None);

  /* "bzrlib/_known_graph_pyx.pyx":746
 *         cdef _KnownGraphNode node
 * 
 *         self.graph = known_graph             # <<<<<<<<<<<<<<
 *         # self._ms_nodes = {}
 *         self._revno_to_branch_count = {}
 */
  if (!(likely(((__pyx_v_known_graph) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_known_graph, __pyx_ptype_6bzrlib_16_known_graph_pyx_KnownGraph))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 746; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_INCREF(__pyx_v_known_graph);
  __Pyx_GIVEREF(__pyx_v_known_graph);
  __Pyx_GOTREF(((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSorter *)__pyx_v_self)->graph);
  __Pyx_DECREF(((PyObject *)((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSorter *)__pyx_v_self)->graph));
  ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSorter *)__pyx_v_self)->graph = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *)__pyx_v_known_graph);

  /* "bzrlib/_known_graph_pyx.pyx":748
 *         self.graph = known_graph
 *         # self._ms_nodes = {}
 *         self._revno_to_branch_count = {}             # <<<<<<<<<<<<<<
 *         self._depth_first_stack = []
 *         self._last_stack_item = -1
 */
  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 748; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_1));
  __Pyx_GIVEREF(((PyObject *)__pyx_t_1));
  __Pyx_GOTREF(((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSorter *)__pyx_v_self)->_revno_to_branch_count);
  __Pyx_DECREF(((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSorter *)__pyx_v_self)->_revno_to_branch_count);
  ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSorter *)__pyx_v_self)->_revno_to_branch_count = ((PyObject *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "bzrlib/_known_graph_pyx.pyx":749
 *         # self._ms_nodes = {}
 *         self._revno_to_branch_count = {}
 *         self._depth_first_stack = []             # <<<<<<<<<<<<<<
 *         self._last_stack_item = -1
 *         self._scheduled_nodes = []
 */
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 749; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_1));
  __Pyx_GIVEREF(((PyObject *)__pyx_t_1));
  __Pyx_GOTREF(((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSorter *)__pyx_v_self)->_depth_first_stack);
  __Pyx_DECREF(((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSorter *)__pyx_v_self)->_depth_first_stack);
  ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSorter *)__pyx_v_self)->_depth_first_stack = ((PyObject *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "bzrlib/_known_graph_pyx.pyx":750
 *         self._revno_to_branch_count = {}
 *         self._depth_first_stack = []
 *         self._last_stack_item = -1             # <<<<<<<<<<<<<<
 *         self._scheduled_nodes = []
 *         if (tip_key is not None and tip_key != NULL_REVISION
 */
  ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSorter *)__pyx_v_self)->_last_stack_item = -1;

  /* "bzrlib/_known_graph_pyx.pyx":751
 *         self._depth_first_stack = []
 *         self._last_stack_item = -1
 *         self._scheduled_nodes = []             # <<<<<<<<<<<<<<
 *         if (tip_key is not None and tip_key != NULL_REVISION
 *             and tip_key != (NULL_REVISION,)):
 */
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 751; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_1));
  __Pyx_GIVEREF(((PyObject *)__pyx_t_1));
  __Pyx_GOTREF(((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSorter *)__pyx_v_self)->_scheduled_nodes);
  __Pyx_DECREF(((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSorter *)__pyx_v_self)->_scheduled_nodes);
  ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSorter *)__pyx_v_self)->_scheduled_nodes = ((PyObject *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "bzrlib/_known_graph_pyx.pyx":752
 *         self._last_stack_item = -1
 *         self._scheduled_nodes = []
 *         if (tip_key is not None and tip_key != NULL_REVISION             # <<<<<<<<<<<<<<
 *             and tip_key != (NULL_REVISION,)):
 *             node = self.graph._nodes[tip_key]
 */
  __pyx_t_2 = (__pyx_v_tip_key != Py_None);
  if (__pyx_t_2) {

    /* "bzrlib/_known_graph_pyx.pyx":753
 *         self._scheduled_nodes = []
 *         if (tip_key is not None and tip_key != NULL_REVISION
 *             and tip_key != (NULL_REVISION,)):             # <<<<<<<<<<<<<<
 *             node = self.graph._nodes[tip_key]
 *             self._push_node(node, 0)
 */
    __pyx_t_1 = PyObject_RichCompare(__pyx_v_tip_key, __pyx_v_6bzrlib_16_known_graph_pyx_NULL_REVISION, Py_NE); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 752; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 752; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (__pyx_t_3) {
      __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 753; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(((PyObject *)__pyx_t_1));
      __Pyx_INCREF(__pyx_v_6bzrlib_16_known_graph_pyx_NULL_REVISION);
      PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_6bzrlib_16_known_graph_pyx_NULL_REVISION);
      __Pyx_GIVEREF(__pyx_v_6bzrlib_16_known_graph_pyx_NULL_REVISION);
      __pyx_t_4 = PyObject_RichCompare(__pyx_v_tip_key, ((PyObject *)__pyx_t_1), Py_NE); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 753; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
      __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 753; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_6 = __pyx_t_5;
    } else {
      __pyx_t_6 = __pyx_t_3;
    }
    __pyx_t_3 = __pyx_t_6;
  } else {
    __pyx_t_3 = __pyx_t_2;
  }
  if (__pyx_t_3) {

    /* "bzrlib/_known_graph_pyx.pyx":754
 *         if (tip_key is not None and tip_key != NULL_REVISION
 *             and tip_key != (NULL_REVISION,)):
 *             node = self.graph._nodes[tip_key]             # <<<<<<<<<<<<<<
 *             self._push_node(node, 0)
 * 
 */
    __pyx_t_4 = PyObject_GetItem(((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSorter *)__pyx_v_self)->graph->_nodes, __pyx_v_tip_key); if (!__pyx_t_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 754; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_ptype_6bzrlib_16_known_graph_pyx__KnownGraphNode))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 754; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(((PyObject *)__pyx_v_node));
    __pyx_v_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_t_4);
    __pyx_t_4 = 0;

    /* "bzrlib/_known_graph_pyx.pyx":755
 *             and tip_key != (NULL_REVISION,)):
 *             node = self.graph._nodes[tip_key]
 *             self._push_node(node, 0)             # <<<<<<<<<<<<<<
 * 
 *     cdef _MergeSortNode _get_ms_node(self, _KnownGraphNode node):
 */
    __pyx_t_4 = ((struct __pyx_vtabstruct_6bzrlib_16_known_graph_pyx__MergeSorter *)((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSorter *)__pyx_v_self)->__pyx_vtab)->_push_node(((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSorter *)__pyx_v_self), __pyx_v_node, 0); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 755; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    goto __pyx_L6;
  }
  __pyx_L6:;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("bzrlib._known_graph_pyx._MergeSorter.__init__");
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_DECREF((PyObject *)__pyx_v_node);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "bzrlib/_known_graph_pyx.pyx":757
 *             self._push_node(node, 0)
 * 
 *     cdef _MergeSortNode _get_ms_node(self, _KnownGraphNode node):             # <<<<<<<<<<<<<<
 *         cdef PyObject *temp_node
 *         cdef _MergeSortNode ms_node
 */

static  struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *__pyx_f_6bzrlib_16_known_graph_pyx_12_MergeSorter__get_ms_node(struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSorter *__pyx_v_self, struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *__pyx_v_node) {
  struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *__pyx_v_ms_node;
  struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *__pyx_r = NULL;
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  __Pyx_RefNannySetupContext("_get_ms_node");
  __pyx_v_ms_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)Py_None); __Pyx_INCREF(Py_None);

  /* "bzrlib/_known_graph_pyx.pyx":761
 *         cdef _MergeSortNode ms_node
 * 
 *         if node.extra is None:             # <<<<<<<<<<<<<<
 *             ms_node = _MergeSortNode(node.key)
 *             node.extra = ms_node
 */
  __pyx_t_1 = (__pyx_v_node->extra == Py_None);
  if (__pyx_t_1) {

    /* "bzrlib/_known_graph_pyx.pyx":762
 * 
 *         if node.extra is None:
 *             ms_node = _MergeSortNode(node.key)             # <<<<<<<<<<<<<<
 *             node.extra = ms_node
 *         else:
 */
    __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 762; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_2));
    __Pyx_INCREF(__pyx_v_node->key);
    PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_node->key);
    __Pyx_GIVEREF(__pyx_v_node->key);
    __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_6bzrlib_16_known_graph_pyx__MergeSortNode)), ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 762; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_v_ms_node));
    __pyx_v_ms_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)__pyx_t_3);
    __pyx_t_3 = 0;

    /* "bzrlib/_known_graph_pyx.pyx":763
 *         if node.extra is None:
 *             ms_node = _MergeSortNode(node.key)
 *             node.extra = ms_node             # <<<<<<<<<<<<<<
 *         else:
 *             ms_node = <_MergeSortNode>node.extra
 */
    __Pyx_INCREF(((PyObject *)__pyx_v_ms_node));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_ms_node));
    __Pyx_GOTREF(__pyx_v_node->extra);
    __Pyx_DECREF(__pyx_v_node->extra);
    __pyx_v_node->extra = ((PyObject *)__pyx_v_ms_node);
    goto __pyx_L3;
  }
  /*else*/ {

    /* "bzrlib/_known_graph_pyx.pyx":765
 *             node.extra = ms_node
 *         else:
 *             ms_node = <_MergeSortNode>node.extra             # <<<<<<<<<<<<<<
 *         return ms_node
 * 
 */
    __Pyx_INCREF(((PyObject *)((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)__pyx_v_node->extra)));
    __Pyx_DECREF(((PyObject *)__pyx_v_ms_node));
    __pyx_v_ms_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)__pyx_v_node->extra);
  }
  __pyx_L3:;

  /* "bzrlib/_known_graph_pyx.pyx":766
 *         else:
 *             ms_node = <_MergeSortNode>node.extra
 *         return ms_node             # <<<<<<<<<<<<<<
 * 
 *     cdef _push_node(self, _KnownGraphNode node, long merge_depth):
 */
  __Pyx_XDECREF(((PyObject *)__pyx_r));
  __Pyx_INCREF(((PyObject *)__pyx_v_ms_node));
  __pyx_r = __pyx_v_ms_node;
  goto __pyx_L0;

  __pyx_r = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)Py_None); __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("bzrlib._known_graph_pyx._MergeSorter._get_ms_node");
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_DECREF((PyObject *)__pyx_v_ms_node);
  __Pyx_XGIVEREF((PyObject *)__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "bzrlib/_known_graph_pyx.pyx":768
 *         return ms_node
 * 
 *     cdef _push_node(self, _KnownGraphNode node, long merge_depth):             # <<<<<<<<<<<<<<
 *         cdef _KnownGraphNode parent_node
 *         cdef _MergeSortNode ms_node, ms_parent_node
 */

static  PyObject *__pyx_f_6bzrlib_16_known_graph_pyx_12_MergeSorter__push_node(struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSorter *__pyx_v_self, struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *__pyx_v_node, long __pyx_v_merge_depth) {
  struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *__pyx_v_parent_node;
  struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *__pyx_v_ms_node;
  struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *__pyx_v_ms_parent_node;
  Py_ssize_t __pyx_v_pos;
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  Py_ssize_t __pyx_t_4;
  int __pyx_t_5;
  __Pyx_RefNannySetupContext("_push_node");
  __pyx_v_parent_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)Py_None); __Pyx_INCREF(Py_None);
  __pyx_v_ms_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)Py_None); __Pyx_INCREF(Py_None);
  __pyx_v_ms_parent_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)Py_None); __Pyx_INCREF(Py_None);

  /* "bzrlib/_known_graph_pyx.pyx":773
 *         cdef Py_ssize_t pos
 * 
 *         ms_node = self._get_ms_node(node)             # <<<<<<<<<<<<<<
 *         ms_node.merge_depth = merge_depth
 *         if node.parents is None:
 */
  __pyx_t_1 = ((PyObject *)((struct __pyx_vtabstruct_6bzrlib_16_known_graph_pyx__MergeSorter *)__pyx_v_self->__pyx_vtab)->_get_ms_node(__pyx_v_self, __pyx_v_node)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 773; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(((PyObject *)__pyx_v_ms_node));
  __pyx_v_ms_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "bzrlib/_known_graph_pyx.pyx":774
 * 
 *         ms_node = self._get_ms_node(node)
 *         ms_node.merge_depth = merge_depth             # <<<<<<<<<<<<<<
 *         if node.parents is None:
 *             raise RuntimeError('ghost nodes should not be pushed'
 */
  __pyx_v_ms_node->merge_depth = __pyx_v_merge_depth;

  /* "bzrlib/_known_graph_pyx.pyx":775
 *         ms_node = self._get_ms_node(node)
 *         ms_node.merge_depth = merge_depth
 *         if node.parents is None:             # <<<<<<<<<<<<<<
 *             raise RuntimeError('ghost nodes should not be pushed'
 *                                ' onto the stack: %s' % (node,))
 */
  __pyx_t_2 = (__pyx_v_node->parents == Py_None);
  if (__pyx_t_2) {

    /* "bzrlib/_known_graph_pyx.pyx":777
 *         if node.parents is None:
 *             raise RuntimeError('ghost nodes should not be pushed'
 *                                ' onto the stack: %s' % (node,))             # <<<<<<<<<<<<<<
 *         if PyTuple_GET_SIZE(node.parents) > 0:
 *             parent_node = _get_tuple_node(node.parents, 0)
 */
    __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 777; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_1));
    __Pyx_INCREF(((PyObject *)__pyx_v_node));
    PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_v_node));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_node));
    __pyx_t_3 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_13), ((PyObject *)__pyx_t_1)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 777; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_3));
    __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
    __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 776; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_1));
    PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_t_3));
    __Pyx_GIVEREF(((PyObject *)__pyx_t_3));
    __pyx_t_3 = 0;
    __pyx_t_3 = PyObject_Call(__pyx_builtin_RuntimeError, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 776; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
    __Pyx_Raise(__pyx_t_3, 0, 0);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 776; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "bzrlib/_known_graph_pyx.pyx":778
 *             raise RuntimeError('ghost nodes should not be pushed'
 *                                ' onto the stack: %s' % (node,))
 *         if PyTuple_GET_SIZE(node.parents) > 0:             # <<<<<<<<<<<<<<
 *             parent_node = _get_tuple_node(node.parents, 0)
 *             ms_node.left_parent = parent_node
 */
  __pyx_t_3 = __pyx_v_node->parents;
  __Pyx_INCREF(__pyx_t_3);
  __pyx_t_2 = (PyTuple_GET_SIZE(__pyx_t_3) > 0);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (__pyx_t_2) {

    /* "bzrlib/_known_graph_pyx.pyx":779
 *                                ' onto the stack: %s' % (node,))
 *         if PyTuple_GET_SIZE(node.parents) > 0:
 *             parent_node = _get_tuple_node(node.parents, 0)             # <<<<<<<<<<<<<<
 *             ms_node.left_parent = parent_node
 *             if parent_node.parents is None: # left-hand ghost
 */
    __pyx_t_3 = __pyx_v_node->parents;
    __Pyx_INCREF(__pyx_t_3);
    __pyx_t_1 = ((PyObject *)__pyx_f_6bzrlib_16_known_graph_pyx__get_tuple_node(__pyx_t_3, 0)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 779; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_v_parent_node));
    __pyx_v_parent_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_t_1);
    __pyx_t_1 = 0;

    /* "bzrlib/_known_graph_pyx.pyx":780
 *         if PyTuple_GET_SIZE(node.parents) > 0:
 *             parent_node = _get_tuple_node(node.parents, 0)
 *             ms_node.left_parent = parent_node             # <<<<<<<<<<<<<<
 *             if parent_node.parents is None: # left-hand ghost
 *                 ms_node.left_pending_parent = None
 */
    __Pyx_INCREF(((PyObject *)__pyx_v_parent_node));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_parent_node));
    __Pyx_GOTREF(__pyx_v_ms_node->left_parent);
    __Pyx_DECREF(((PyObject *)__pyx_v_ms_node->left_parent));
    __pyx_v_ms_node->left_parent = __pyx_v_parent_node;

    /* "bzrlib/_known_graph_pyx.pyx":781
 *             parent_node = _get_tuple_node(node.parents, 0)
 *             ms_node.left_parent = parent_node
 *             if parent_node.parents is None: # left-hand ghost             # <<<<<<<<<<<<<<
 *                 ms_node.left_pending_parent = None
 *                 ms_node.left_parent = None
 */
    __pyx_t_2 = (__pyx_v_parent_node->parents == Py_None);
    if (__pyx_t_2) {

      /* "bzrlib/_known_graph_pyx.pyx":782
 *             ms_node.left_parent = parent_node
 *             if parent_node.parents is None: # left-hand ghost
 *                 ms_node.left_pending_parent = None             # <<<<<<<<<<<<<<
 *                 ms_node.left_parent = None
 *             else:
 */
      __Pyx_INCREF(Py_None);
      __Pyx_GIVEREF(Py_None);
      __Pyx_GOTREF(__pyx_v_ms_node->left_pending_parent);
      __Pyx_DECREF(((PyObject *)__pyx_v_ms_node->left_pending_parent));
      __pyx_v_ms_node->left_pending_parent = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)Py_None);

      /* "bzrlib/_known_graph_pyx.pyx":783
 *             if parent_node.parents is None: # left-hand ghost
 *                 ms_node.left_pending_parent = None
 *                 ms_node.left_parent = None             # <<<<<<<<<<<<<<
 *             else:
 *                 ms_node.left_pending_parent = parent_node
 */
      __Pyx_INCREF(Py_None);
      __Pyx_GIVEREF(Py_None);
      __Pyx_GOTREF(__pyx_v_ms_node->left_parent);
      __Pyx_DECREF(((PyObject *)__pyx_v_ms_node->left_parent));
      __pyx_v_ms_node->left_parent = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)Py_None);
      goto __pyx_L5;
    }
    /*else*/ {

      /* "bzrlib/_known_graph_pyx.pyx":785
 *                 ms_node.left_parent = None
 *             else:
 *                 ms_node.left_pending_parent = parent_node             # <<<<<<<<<<<<<<
 *         if PyTuple_GET_SIZE(node.parents) > 1:
 *             ms_node.pending_parents = []
 */
      __Pyx_INCREF(((PyObject *)__pyx_v_parent_node));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_parent_node));
      __Pyx_GOTREF(__pyx_v_ms_node->left_pending_parent);
      __Pyx_DECREF(((PyObject *)__pyx_v_ms_node->left_pending_parent));
      __pyx_v_ms_node->left_pending_parent = __pyx_v_parent_node;
    }
    __pyx_L5:;
    goto __pyx_L4;
  }
  __pyx_L4:;

  /* "bzrlib/_known_graph_pyx.pyx":786
 *             else:
 *                 ms_node.left_pending_parent = parent_node
 *         if PyTuple_GET_SIZE(node.parents) > 1:             # <<<<<<<<<<<<<<
 *             ms_node.pending_parents = []
 *             for pos from 1 <= pos < PyTuple_GET_SIZE(node.parents):
 */
  __pyx_t_1 = __pyx_v_node->parents;
  __Pyx_INCREF(__pyx_t_1);
  __pyx_t_2 = (PyTuple_GET_SIZE(__pyx_t_1) > 1);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (__pyx_t_2) {

    /* "bzrlib/_known_graph_pyx.pyx":787
 *                 ms_node.left_pending_parent = parent_node
 *         if PyTuple_GET_SIZE(node.parents) > 1:
 *             ms_node.pending_parents = []             # <<<<<<<<<<<<<<
 *             for pos from 1 <= pos < PyTuple_GET_SIZE(node.parents):
 *                 parent_node = _get_tuple_node(node.parents, pos)
 */
    __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 787; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_1));
    __Pyx_GIVEREF(((PyObject *)__pyx_t_1));
    __Pyx_GOTREF(__pyx_v_ms_node->pending_parents);
    __Pyx_DECREF(__pyx_v_ms_node->pending_parents);
    __pyx_v_ms_node->pending_parents = ((PyObject *)__pyx_t_1);
    __pyx_t_1 = 0;

    /* "bzrlib/_known_graph_pyx.pyx":788
 *         if PyTuple_GET_SIZE(node.parents) > 1:
 *             ms_node.pending_parents = []
 *             for pos from 1 <= pos < PyTuple_GET_SIZE(node.parents):             # <<<<<<<<<<<<<<
 *                 parent_node = _get_tuple_node(node.parents, pos)
 *                 if parent_node.parents is None: # ghost
 */
    __pyx_t_1 = __pyx_v_node->parents;
    __Pyx_INCREF(__pyx_t_1);
    __pyx_t_4 = PyTuple_GET_SIZE(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    for (__pyx_v_pos = 1; __pyx_v_pos < __pyx_t_4; __pyx_v_pos++) {

      /* "bzrlib/_known_graph_pyx.pyx":789
 *             ms_node.pending_parents = []
 *             for pos from 1 <= pos < PyTuple_GET_SIZE(node.parents):
 *                 parent_node = _get_tuple_node(node.parents, pos)             # <<<<<<<<<<<<<<
 *                 if parent_node.parents is None: # ghost
 *                     continue
 */
      __pyx_t_1 = __pyx_v_node->parents;
      __Pyx_INCREF(__pyx_t_1);
      __pyx_t_3 = ((PyObject *)__pyx_f_6bzrlib_16_known_graph_pyx__get_tuple_node(__pyx_t_1, __pyx_v_pos)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 789; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_DECREF(((PyObject *)__pyx_v_parent_node));
      __pyx_v_parent_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_t_3);
      __pyx_t_3 = 0;

      /* "bzrlib/_known_graph_pyx.pyx":790
 *             for pos from 1 <= pos < PyTuple_GET_SIZE(node.parents):
 *                 parent_node = _get_tuple_node(node.parents, pos)
 *                 if parent_node.parents is None: # ghost             # <<<<<<<<<<<<<<
 *                     continue
 *                 PyList_Append(ms_node.pending_parents, parent_node)
 */
      __pyx_t_2 = (__pyx_v_parent_node->parents == Py_None);
      if (__pyx_t_2) {

        /* "bzrlib/_known_graph_pyx.pyx":791
 *                 parent_node = _get_tuple_node(node.parents, pos)
 *                 if parent_node.parents is None: # ghost
 *                     continue             # <<<<<<<<<<<<<<
 *                 PyList_Append(ms_node.pending_parents, parent_node)
 * 
 */
        goto __pyx_L7_continue;
        goto __pyx_L9;
      }
      __pyx_L9:;

      /* "bzrlib/_known_graph_pyx.pyx":792
 *                 if parent_node.parents is None: # ghost
 *                     continue
 *                 PyList_Append(ms_node.pending_parents, parent_node)             # <<<<<<<<<<<<<<
 * 
 *         ms_node.is_first_child = 1
 */
      __pyx_t_3 = __pyx_v_ms_node->pending_parents;
      __Pyx_INCREF(__pyx_t_3);
      __pyx_t_5 = PyList_Append(__pyx_t_3, ((PyObject *)__pyx_v_parent_node)); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 792; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_L7_continue:;
    }
    goto __pyx_L6;
  }
  __pyx_L6:;

  /* "bzrlib/_known_graph_pyx.pyx":794
 *                 PyList_Append(ms_node.pending_parents, parent_node)
 * 
 *         ms_node.is_first_child = 1             # <<<<<<<<<<<<<<
 *         if ms_node.left_parent is not None:
 *             ms_parent_node = self._get_ms_node(ms_node.left_parent)
 */
  __pyx_v_ms_node->is_first_child = 1;

  /* "bzrlib/_known_graph_pyx.pyx":795
 * 
 *         ms_node.is_first_child = 1
 *         if ms_node.left_parent is not None:             # <<<<<<<<<<<<<<
 *             ms_parent_node = self._get_ms_node(ms_node.left_parent)
 *             if ms_parent_node.seen_by_child:
 */
  __pyx_t_2 = (((PyObject *)__pyx_v_ms_node->left_parent) != Py_None);
  if (__pyx_t_2) {

    /* "bzrlib/_known_graph_pyx.pyx":796
 *         ms_node.is_first_child = 1
 *         if ms_node.left_parent is not None:
 *             ms_parent_node = self._get_ms_node(ms_node.left_parent)             # <<<<<<<<<<<<<<
 *             if ms_parent_node.seen_by_child:
 *                 ms_node.is_first_child = 0
 */
    __pyx_t_3 = ((PyObject *)__pyx_v_ms_node->left_parent);
    __Pyx_INCREF(__pyx_t_3);
    __pyx_t_1 = ((PyObject *)((struct __pyx_vtabstruct_6bzrlib_16_known_graph_pyx__MergeSorter *)__pyx_v_self->__pyx_vtab)->_get_ms_node(__pyx_v_self, ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_t_3))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 796; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_v_ms_parent_node));
    __pyx_v_ms_parent_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)__pyx_t_1);
    __pyx_t_1 = 0;

    /* "bzrlib/_known_graph_pyx.pyx":797
 *         if ms_node.left_parent is not None:
 *             ms_parent_node = self._get_ms_node(ms_node.left_parent)
 *             if ms_parent_node.seen_by_child:             # <<<<<<<<<<<<<<
 *                 ms_node.is_first_child = 0
 *             ms_parent_node.seen_by_child = 1
 */
    if (__pyx_v_ms_parent_node->seen_by_child) {

      /* "bzrlib/_known_graph_pyx.pyx":798
 *             ms_parent_node = self._get_ms_node(ms_node.left_parent)
 *             if ms_parent_node.seen_by_child:
 *                 ms_node.is_first_child = 0             # <<<<<<<<<<<<<<
 *             ms_parent_node.seen_by_child = 1
 *         self._last_stack_item = self._last_stack_item + 1
 */
      __pyx_v_ms_node->is_first_child = 0;
      goto __pyx_L11;
    }
    __pyx_L11:;

    /* "bzrlib/_known_graph_pyx.pyx":799
 *             if ms_parent_node.seen_by_child:
 *                 ms_node.is_first_child = 0
 *             ms_parent_node.seen_by_child = 1             # <<<<<<<<<<<<<<
 *         self._last_stack_item = self._last_stack_item + 1
 *         if self._last_stack_item < PyList_GET_SIZE(self._depth_first_stack):
 */
    __pyx_v_ms_parent_node->seen_by_child = 1;
    goto __pyx_L10;
  }
  __pyx_L10:;

  /* "bzrlib/_known_graph_pyx.pyx":800
 *                 ms_node.is_first_child = 0
 *             ms_parent_node.seen_by_child = 1
 *         self._last_stack_item = self._last_stack_item + 1             # <<<<<<<<<<<<<<
 *         if self._last_stack_item < PyList_GET_SIZE(self._depth_first_stack):
 *             Py_INCREF(node) # SetItem steals a ref
 */
  __pyx_v_self->_last_stack_item = (__pyx_v_self->_last_stack_item + 1);

  /* "bzrlib/_known_graph_pyx.pyx":801
 *             ms_parent_node.seen_by_child = 1
 *         self._last_stack_item = self._last_stack_item + 1
 *         if self._last_stack_item < PyList_GET_SIZE(self._depth_first_stack):             # <<<<<<<<<<<<<<
 *             Py_INCREF(node) # SetItem steals a ref
 *             PyList_SetItem(self._depth_first_stack, self._last_stack_item,
 */
  __pyx_t_1 = __pyx_v_self->_depth_first_stack;
  __Pyx_INCREF(__pyx_t_1);
  __pyx_t_2 = (__pyx_v_self->_last_stack_item < PyList_GET_SIZE(__pyx_t_1));
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (__pyx_t_2) {

    /* "bzrlib/_known_graph_pyx.pyx":802
 *         self._last_stack_item = self._last_stack_item + 1
 *         if self._last_stack_item < PyList_GET_SIZE(self._depth_first_stack):
 *             Py_INCREF(node) # SetItem steals a ref             # <<<<<<<<<<<<<<
 *             PyList_SetItem(self._depth_first_stack, self._last_stack_item,
 *                            node)
 */
    Py_INCREF(((PyObject *)__pyx_v_node));

    /* "bzrlib/_known_graph_pyx.pyx":803
 *         if self._last_stack_item < PyList_GET_SIZE(self._depth_first_stack):
 *             Py_INCREF(node) # SetItem steals a ref
 *             PyList_SetItem(self._depth_first_stack, self._last_stack_item,             # <<<<<<<<<<<<<<
 *                            node)
 *         else:
 */
    __pyx_t_1 = __pyx_v_self->_depth_first_stack;
    __Pyx_INCREF(__pyx_t_1);

    /* "bzrlib/_known_graph_pyx.pyx":804
 *             Py_INCREF(node) # SetItem steals a ref
 *             PyList_SetItem(self._depth_first_stack, self._last_stack_item,
 *                            node)             # <<<<<<<<<<<<<<
 *         else:
 *             PyList_Append(self._depth_first_stack, node)
 */
    __pyx_t_5 = PyList_SetItem(__pyx_t_1, __pyx_v_self->_last_stack_item, ((PyObject *)__pyx_v_node)); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 803; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    goto __pyx_L12;
  }
  /*else*/ {

    /* "bzrlib/_known_graph_pyx.pyx":806
 *                            node)
 *         else:
 *             PyList_Append(self._depth_first_stack, node)             # <<<<<<<<<<<<<<
 * 
 *     cdef _pop_node(self):
 */
    __pyx_t_1 = __pyx_v_self->_depth_first_stack;
    __Pyx_INCREF(__pyx_t_1);
    __pyx_t_5 = PyList_Append(__pyx_t_1, ((PyObject *)__pyx_v_node)); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 806; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  }
  __pyx_L12:;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("bzrlib._known_graph_pyx._MergeSorter._push_node");
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_DECREF((PyObject *)__pyx_v_parent_node);
  __Pyx_DECREF((PyObject *)__pyx_v_ms_node);
  __Pyx_DECREF((PyObject *)__pyx_v_ms_parent_node);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "bzrlib/_known_graph_pyx.pyx":808
 *             PyList_Append(self._depth_first_stack, node)
 * 
 *     cdef _pop_node(self):             # <<<<<<<<<<<<<<
 *         cdef PyObject *temp
 *         cdef _MergeSortNode ms_node, ms_parent_node, ms_prev_node
 */

static  PyObject *__pyx_f_6bzrlib_16_known_graph_pyx_12_MergeSorter__pop_node(struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSorter *__pyx_v_self) {
  PyObject *__pyx_v_temp;
  struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *__pyx_v_ms_node;
  struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *__pyx_v_ms_parent_node;
  struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *__pyx_v_ms_prev_node;
  struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *__pyx_v_node;
  struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *__pyx_v_prev_node;
  long __pyx_v_base_revno;
  PyObject *__pyx_v_branch_count;
  PyObject *__pyx_v_root_count;
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  int __pyx_t_4;
  long __pyx_t_5;
  PyObject *__pyx_t_6 = NULL;
  int __pyx_t_7;
  int __pyx_t_8;
  __Pyx_RefNannySetupContext("_pop_node");
  __pyx_v_ms_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)Py_None); __Pyx_INCREF(Py_None);
  __pyx_v_ms_parent_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)Py_None); __Pyx_INCREF(Py_None);
  __pyx_v_ms_prev_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)Py_None); __Pyx_INCREF(Py_None);
  __pyx_v_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)Py_None); __Pyx_INCREF(Py_None);
  __pyx_v_prev_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)Py_None); __Pyx_INCREF(Py_None);
  __pyx_v_branch_count = Py_None; __Pyx_INCREF(Py_None);
  __pyx_v_root_count = Py_None; __Pyx_INCREF(Py_None);

  /* "bzrlib/_known_graph_pyx.pyx":813
 *         cdef _KnownGraphNode node, parent_node, prev_node
 * 
 *         node = _get_list_node(self._depth_first_stack, self._last_stack_item)             # <<<<<<<<<<<<<<
 *         ms_node = <_MergeSortNode>node.extra
 *         self._last_stack_item = self._last_stack_item - 1
 */
  __pyx_t_1 = __pyx_v_self->_depth_first_stack;
  __Pyx_INCREF(__pyx_t_1);
  __pyx_t_2 = ((PyObject *)__pyx_f_6bzrlib_16_known_graph_pyx__get_list_node(__pyx_t_1, __pyx_v_self->_last_stack_item)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 813; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_v_node));
  __pyx_v_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_t_2);
  __pyx_t_2 = 0;

  /* "bzrlib/_known_graph_pyx.pyx":814
 * 
 *         node = _get_list_node(self._depth_first_stack, self._last_stack_item)
 *         ms_node = <_MergeSortNode>node.extra             # <<<<<<<<<<<<<<
 *         self._last_stack_item = self._last_stack_item - 1
 *         if ms_node.left_parent is not None:
 */
  __Pyx_INCREF(((PyObject *)((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)__pyx_v_node->extra)));
  __Pyx_DECREF(((PyObject *)__pyx_v_ms_node));
  __pyx_v_ms_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)__pyx_v_node->extra);

  /* "bzrlib/_known_graph_pyx.pyx":815
 *         node = _get_list_node(self._depth_first_stack, self._last_stack_item)
 *         ms_node = <_MergeSortNode>node.extra
 *         self._last_stack_item = self._last_stack_item - 1             # <<<<<<<<<<<<<<
 *         if ms_node.left_parent is not None:
 *             # Assign the revision number from the left-hand parent
 */
  __pyx_v_self->_last_stack_item = (__pyx_v_self->_last_stack_item - 1);

  /* "bzrlib/_known_graph_pyx.pyx":816
 *         ms_node = <_MergeSortNode>node.extra
 *         self._last_stack_item = self._last_stack_item - 1
 *         if ms_node.left_parent is not None:             # <<<<<<<<<<<<<<
 *             # Assign the revision number from the left-hand parent
 *             ms_parent_node = <_MergeSortNode>ms_node.left_parent.extra
 */
  __pyx_t_3 = (((PyObject *)__pyx_v_ms_node->left_parent) != Py_None);
  if (__pyx_t_3) {

    /* "bzrlib/_known_graph_pyx.pyx":818
 *         if ms_node.left_parent is not None:
 *             # Assign the revision number from the left-hand parent
 *             ms_parent_node = <_MergeSortNode>ms_node.left_parent.extra             # <<<<<<<<<<<<<<
 *             if ms_node.is_first_child:
 *                 # First child just increments the final digit
 */
    __Pyx_INCREF(((PyObject *)((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)__pyx_v_ms_node->left_parent->extra)));
    __Pyx_DECREF(((PyObject *)__pyx_v_ms_parent_node));
    __pyx_v_ms_parent_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)__pyx_v_ms_node->left_parent->extra);

    /* "bzrlib/_known_graph_pyx.pyx":819
 *             # Assign the revision number from the left-hand parent
 *             ms_parent_node = <_MergeSortNode>ms_node.left_parent.extra
 *             if ms_node.is_first_child:             # <<<<<<<<<<<<<<
 *                 # First child just increments the final digit
 *                 ms_node._revno_first = ms_parent_node._revno_first
 */
    if (__pyx_v_ms_node->is_first_child) {

      /* "bzrlib/_known_graph_pyx.pyx":821
 *             if ms_node.is_first_child:
 *                 # First child just increments the final digit
 *                 ms_node._revno_first = ms_parent_node._revno_first             # <<<<<<<<<<<<<<
 *                 ms_node._revno_second = ms_parent_node._revno_second
 *                 ms_node._revno_last = ms_parent_node._revno_last + 1
 */
      __pyx_v_ms_node->_revno_first = __pyx_v_ms_parent_node->_revno_first;

      /* "bzrlib/_known_graph_pyx.pyx":822
 *                 # First child just increments the final digit
 *                 ms_node._revno_first = ms_parent_node._revno_first
 *                 ms_node._revno_second = ms_parent_node._revno_second             # <<<<<<<<<<<<<<
 *                 ms_node._revno_last = ms_parent_node._revno_last + 1
 *             else:
 */
      __pyx_v_ms_node->_revno_second = __pyx_v_ms_parent_node->_revno_second;

      /* "bzrlib/_known_graph_pyx.pyx":823
 *                 ms_node._revno_first = ms_parent_node._revno_first
 *                 ms_node._revno_second = ms_parent_node._revno_second
 *                 ms_node._revno_last = ms_parent_node._revno_last + 1             # <<<<<<<<<<<<<<
 *             else:
 *                 # Not the first child, make a new branch
 */
      __pyx_v_ms_node->_revno_last = (__pyx_v_ms_parent_node->_revno_last + 1);
      goto __pyx_L4;
    }
    /*else*/ {

      /* "bzrlib/_known_graph_pyx.pyx":827
 *                 # Not the first child, make a new branch
 *                 #  (mainline_revno, branch_count, 1)
 *                 if ms_parent_node._revno_first == -1:             # <<<<<<<<<<<<<<
 *                     # Mainline ancestor, the increment is on the last digit
 *                     base_revno = ms_parent_node._revno_last
 */
      __pyx_t_3 = (__pyx_v_ms_parent_node->_revno_first == -1);
      if (__pyx_t_3) {

        /* "bzrlib/_known_graph_pyx.pyx":829
 *                 if ms_parent_node._revno_first == -1:
 *                     # Mainline ancestor, the increment is on the last digit
 *                     base_revno = ms_parent_node._revno_last             # <<<<<<<<<<<<<<
 *                 else:
 *                     base_revno = ms_parent_node._revno_first
 */
        __pyx_v_base_revno = __pyx_v_ms_parent_node->_revno_last;
        goto __pyx_L5;
      }
      /*else*/ {

        /* "bzrlib/_known_graph_pyx.pyx":831
 *                     base_revno = ms_parent_node._revno_last
 *                 else:
 *                     base_revno = ms_parent_node._revno_first             # <<<<<<<<<<<<<<
 *                 temp = PyDict_GetItem(self._revno_to_branch_count,
 *                                       base_revno)
 */
        __pyx_v_base_revno = __pyx_v_ms_parent_node->_revno_first;
      }
      __pyx_L5:;

      /* "bzrlib/_known_graph_pyx.pyx":832
 *                 else:
 *                     base_revno = ms_parent_node._revno_first
 *                 temp = PyDict_GetItem(self._revno_to_branch_count,             # <<<<<<<<<<<<<<
 *                                       base_revno)
 *                 if temp == NULL:
 */
      __pyx_t_2 = __pyx_v_self->_revno_to_branch_count;
      __Pyx_INCREF(__pyx_t_2);

      /* "bzrlib/_known_graph_pyx.pyx":833
 *                     base_revno = ms_parent_node._revno_first
 *                 temp = PyDict_GetItem(self._revno_to_branch_count,
 *                                       base_revno)             # <<<<<<<<<<<<<<
 *                 if temp == NULL:
 *                     branch_count = 1
 */
      __pyx_t_1 = PyInt_FromLong(__pyx_v_base_revno); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 833; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_v_temp = PyDict_GetItem(__pyx_t_2, __pyx_t_1);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

      /* "bzrlib/_known_graph_pyx.pyx":834
 *                 temp = PyDict_GetItem(self._revno_to_branch_count,
 *                                       base_revno)
 *                 if temp == NULL:             # <<<<<<<<<<<<<<
 *                     branch_count = 1
 *                 else:
 */
      __pyx_t_3 = (__pyx_v_temp == NULL);
      if (__pyx_t_3) {

        /* "bzrlib/_known_graph_pyx.pyx":835
 *                                       base_revno)
 *                 if temp == NULL:
 *                     branch_count = 1             # <<<<<<<<<<<<<<
 *                 else:
 *                     branch_count = (<object>temp) + 1
 */
        __Pyx_INCREF(__pyx_int_1);
        __Pyx_DECREF(__pyx_v_branch_count);
        __pyx_v_branch_count = __pyx_int_1;
        goto __pyx_L6;
      }
      /*else*/ {

        /* "bzrlib/_known_graph_pyx.pyx":837
 *                     branch_count = 1
 *                 else:
 *                     branch_count = (<object>temp) + 1             # <<<<<<<<<<<<<<
 *                 PyDict_SetItem(self._revno_to_branch_count, base_revno,
 *                                branch_count)
 */
        __pyx_t_1 = PyNumber_Add(((PyObject *)__pyx_v_temp), __pyx_int_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 837; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_v_branch_count);
        __pyx_v_branch_count = __pyx_t_1;
        __pyx_t_1 = 0;
      }
      __pyx_L6:;

      /* "bzrlib/_known_graph_pyx.pyx":838
 *                 else:
 *                     branch_count = (<object>temp) + 1
 *                 PyDict_SetItem(self._revno_to_branch_count, base_revno,             # <<<<<<<<<<<<<<
 *                                branch_count)
 *                 ms_node._revno_first = base_revno
 */
      __pyx_t_1 = __pyx_v_self->_revno_to_branch_count;
      __Pyx_INCREF(__pyx_t_1);
      __pyx_t_2 = PyInt_FromLong(__pyx_v_base_revno); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 838; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);

      /* "bzrlib/_known_graph_pyx.pyx":839
 *                     branch_count = (<object>temp) + 1
 *                 PyDict_SetItem(self._revno_to_branch_count, base_revno,
 *                                branch_count)             # <<<<<<<<<<<<<<
 *                 ms_node._revno_first = base_revno
 *                 ms_node._revno_second = branch_count
 */
      __pyx_t_4 = PyDict_SetItem(__pyx_t_1, __pyx_t_2, __pyx_v_branch_count); if (unlikely(__pyx_t_4 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 838; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

      /* "bzrlib/_known_graph_pyx.pyx":840
 *                 PyDict_SetItem(self._revno_to_branch_count, base_revno,
 *                                branch_count)
 *                 ms_node._revno_first = base_revno             # <<<<<<<<<<<<<<
 *                 ms_node._revno_second = branch_count
 *                 ms_node._revno_last = 1
 */
      __pyx_v_ms_node->_revno_first = __pyx_v_base_revno;

      /* "bzrlib/_known_graph_pyx.pyx":841
 *                                branch_count)
 *                 ms_node._revno_first = base_revno
 *                 ms_node._revno_second = branch_count             # <<<<<<<<<<<<<<
 *                 ms_node._revno_last = 1
 *         else:
 */
      __pyx_t_5 = __Pyx_PyInt_AsLong(__pyx_v_branch_count); if (unlikely((__pyx_t_5 == (long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 841; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_v_ms_node->_revno_second = __pyx_t_5;

      /* "bzrlib/_known_graph_pyx.pyx":842
 *                 ms_node._revno_first = base_revno
 *                 ms_node._revno_second = branch_count
 *                 ms_node._revno_last = 1             # <<<<<<<<<<<<<<
 *         else:
 *             temp = PyDict_GetItem(self._revno_to_branch_count, 0)
 */
      __pyx_v_ms_node->_revno_last = 1;
    }
    __pyx_L4:;
    goto __pyx_L3;
  }
  /*else*/ {

    /* "bzrlib/_known_graph_pyx.pyx":844
 *                 ms_node._revno_last = 1
 *         else:
 *             temp = PyDict_GetItem(self._revno_to_branch_count, 0)             # <<<<<<<<<<<<<<
 *             if temp == NULL:
 *                 # The first root node doesn't have a 3-digit revno
 */
    __pyx_t_2 = __pyx_v_self->_revno_to_branch_count;
    __Pyx_INCREF(__pyx_t_2);
    __pyx_v_temp = PyDict_GetItem(__pyx_t_2, __pyx_int_0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

    /* "bzrlib/_known_graph_pyx.pyx":845
 *         else:
 *             temp = PyDict_GetItem(self._revno_to_branch_count, 0)
 *             if temp == NULL:             # <<<<<<<<<<<<<<
 *                 # The first root node doesn't have a 3-digit revno
 *                 root_count = 0
 */
    __pyx_t_3 = (__pyx_v_temp == NULL);
    if (__pyx_t_3) {

      /* "bzrlib/_known_graph_pyx.pyx":847
 *             if temp == NULL:
 *                 # The first root node doesn't have a 3-digit revno
 *                 root_count = 0             # <<<<<<<<<<<<<<
 *                 ms_node._revno_first = -1
 *                 ms_node._revno_second = -1
 */
      __Pyx_INCREF(__pyx_int_0);
      __Pyx_DECREF(__pyx_v_root_count);
      __pyx_v_root_count = __pyx_int_0;

      /* "bzrlib/_known_graph_pyx.pyx":848
 *                 # The first root node doesn't have a 3-digit revno
 *                 root_count = 0
 *                 ms_node._revno_first = -1             # <<<<<<<<<<<<<<
 *                 ms_node._revno_second = -1
 *                 ms_node._revno_last = 1
 */
      __pyx_v_ms_node->_revno_first = -1;

      /* "bzrlib/_known_graph_pyx.pyx":849
 *                 root_count = 0
 *                 ms_node._revno_first = -1
 *                 ms_node._revno_second = -1             # <<<<<<<<<<<<<<
 *                 ms_node._revno_last = 1
 *             else:
 */
      __pyx_v_ms_node->_revno_second = -1;

      /* "bzrlib/_known_graph_pyx.pyx":850
 *                 ms_node._revno_first = -1
 *                 ms_node._revno_second = -1
 *                 ms_node._revno_last = 1             # <<<<<<<<<<<<<<
 *             else:
 *                 root_count = (<object>temp) + 1
 */
      __pyx_v_ms_node->_revno_last = 1;
      goto __pyx_L7;
    }
    /*else*/ {

      /* "bzrlib/_known_graph_pyx.pyx":852
 *                 ms_node._revno_last = 1
 *             else:
 *                 root_count = (<object>temp) + 1             # <<<<<<<<<<<<<<
 *                 ms_node._revno_first = 0
 *                 ms_node._revno_second = root_count
 */
      __pyx_t_2 = PyNumber_Add(((PyObject *)__pyx_v_temp), __pyx_int_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 852; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_v_root_count);
      __pyx_v_root_count = __pyx_t_2;
      __pyx_t_2 = 0;

      /* "bzrlib/_known_graph_pyx.pyx":853
 *             else:
 *                 root_count = (<object>temp) + 1
 *                 ms_node._revno_first = 0             # <<<<<<<<<<<<<<
 *                 ms_node._revno_second = root_count
 *                 ms_node._revno_last = 1
 */
      __pyx_v_ms_node->_revno_first = 0;

      /* "bzrlib/_known_graph_pyx.pyx":854
 *                 root_count = (<object>temp) + 1
 *                 ms_node._revno_first = 0
 *                 ms_node._revno_second = root_count             # <<<<<<<<<<<<<<
 *                 ms_node._revno_last = 1
 *             PyDict_SetItem(self._revno_to_branch_count, 0, root_count)
 */
      __pyx_t_5 = __Pyx_PyInt_AsLong(__pyx_v_root_count); if (unlikely((__pyx_t_5 == (long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 854; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_v_ms_node->_revno_second = __pyx_t_5;

      /* "bzrlib/_known_graph_pyx.pyx":855
 *                 ms_node._revno_first = 0
 *                 ms_node._revno_second = root_count
 *                 ms_node._revno_last = 1             # <<<<<<<<<<<<<<
 *             PyDict_SetItem(self._revno_to_branch_count, 0, root_count)
 *         ms_node.completed = 1
 */
      __pyx_v_ms_node->_revno_last = 1;
    }
    __pyx_L7:;

    /* "bzrlib/_known_graph_pyx.pyx":856
 *                 ms_node._revno_second = root_count
 *                 ms_node._revno_last = 1
 *             PyDict_SetItem(self._revno_to_branch_count, 0, root_count)             # <<<<<<<<<<<<<<
 *         ms_node.completed = 1
 *         if PyList_GET_SIZE(self._scheduled_nodes) == 0:
 */
    __pyx_t_2 = __pyx_v_self->_revno_to_branch_count;
    __Pyx_INCREF(__pyx_t_2);
    __pyx_t_4 = PyDict_SetItem(__pyx_t_2, __pyx_int_0, __pyx_v_root_count); if (unlikely(__pyx_t_4 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 856; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  }
  __pyx_L3:;

  /* "bzrlib/_known_graph_pyx.pyx":857
 *                 ms_node._revno_last = 1
 *             PyDict_SetItem(self._revno_to_branch_count, 0, root_count)
 *         ms_node.completed = 1             # <<<<<<<<<<<<<<
 *         if PyList_GET_SIZE(self._scheduled_nodes) == 0:
 *             # The first scheduled node is always the end of merge
 */
  __pyx_v_ms_node->completed = 1;

  /* "bzrlib/_known_graph_pyx.pyx":858
 *             PyDict_SetItem(self._revno_to_branch_count, 0, root_count)
 *         ms_node.completed = 1
 *         if PyList_GET_SIZE(self._scheduled_nodes) == 0:             # <<<<<<<<<<<<<<
 *             # The first scheduled node is always the end of merge
 *             ms_node.end_of_merge = True
 */
  __pyx_t_2 = __pyx_v_self->_scheduled_nodes;
  __Pyx_INCREF(__pyx_t_2);
  __pyx_t_3 = (PyList_GET_SIZE(__pyx_t_2) == 0);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (__pyx_t_3) {

    /* "bzrlib/_known_graph_pyx.pyx":860
 *         if PyList_GET_SIZE(self._scheduled_nodes) == 0:
 *             # The first scheduled node is always the end of merge
 *             ms_node.end_of_merge = True             # <<<<<<<<<<<<<<
 *         else:
 *             prev_node = _get_list_node(self._scheduled_nodes,
 */
    __pyx_t_2 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 860; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_GIVEREF(__pyx_t_2);
    __Pyx_GOTREF(__pyx_v_ms_node->end_of_merge);
    __Pyx_DECREF(__pyx_v_ms_node->end_of_merge);
    __pyx_v_ms_node->end_of_merge = __pyx_t_2;
    __pyx_t_2 = 0;
    goto __pyx_L8;
  }
  /*else*/ {

    /* "bzrlib/_known_graph_pyx.pyx":862
 *             ms_node.end_of_merge = True
 *         else:
 *             prev_node = _get_list_node(self._scheduled_nodes,             # <<<<<<<<<<<<<<
 *                                     PyList_GET_SIZE(self._scheduled_nodes) - 1)
 *             ms_prev_node = <_MergeSortNode>prev_node.extra
 */
    __pyx_t_2 = __pyx_v_self->_scheduled_nodes;
    __Pyx_INCREF(__pyx_t_2);

    /* "bzrlib/_known_graph_pyx.pyx":863
 *         else:
 *             prev_node = _get_list_node(self._scheduled_nodes,
 *                                     PyList_GET_SIZE(self._scheduled_nodes) - 1)             # <<<<<<<<<<<<<<
 *             ms_prev_node = <_MergeSortNode>prev_node.extra
 *             if ms_prev_node.merge_depth < ms_node.merge_depth:
 */
    __pyx_t_1 = __pyx_v_self->_scheduled_nodes;
    __Pyx_INCREF(__pyx_t_1);
    __pyx_t_6 = ((PyObject *)__pyx_f_6bzrlib_16_known_graph_pyx__get_list_node(__pyx_t_2, (PyList_GET_SIZE(__pyx_t_1) - 1))); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 862; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_v_prev_node));
    __pyx_v_prev_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_t_6);
    __pyx_t_6 = 0;

    /* "bzrlib/_known_graph_pyx.pyx":864
 *             prev_node = _get_list_node(self._scheduled_nodes,
 *                                     PyList_GET_SIZE(self._scheduled_nodes) - 1)
 *             ms_prev_node = <_MergeSortNode>prev_node.extra             # <<<<<<<<<<<<<<
 *             if ms_prev_node.merge_depth < ms_node.merge_depth:
 *                 # The previously pushed node is to our left, so this is the end
 */
    __Pyx_INCREF(((PyObject *)((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)__pyx_v_prev_node->extra)));
    __Pyx_DECREF(((PyObject *)__pyx_v_ms_prev_node));
    __pyx_v_ms_prev_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)__pyx_v_prev_node->extra);

    /* "bzrlib/_known_graph_pyx.pyx":865
 *                                     PyList_GET_SIZE(self._scheduled_nodes) - 1)
 *             ms_prev_node = <_MergeSortNode>prev_node.extra
 *             if ms_prev_node.merge_depth < ms_node.merge_depth:             # <<<<<<<<<<<<<<
 *                 # The previously pushed node is to our left, so this is the end
 *                 # of this right-hand chain
 */
    __pyx_t_3 = (__pyx_v_ms_prev_node->merge_depth < __pyx_v_ms_node->merge_depth);
    if (__pyx_t_3) {

      /* "bzrlib/_known_graph_pyx.pyx":868
 *                 # The previously pushed node is to our left, so this is the end
 *                 # of this right-hand chain
 *                 ms_node.end_of_merge = True             # <<<<<<<<<<<<<<
 *             elif (ms_prev_node.merge_depth == ms_node.merge_depth
 *                   and prev_node not in node.parents):
 */
      __pyx_t_6 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 868; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_GIVEREF(__pyx_t_6);
      __Pyx_GOTREF(__pyx_v_ms_node->end_of_merge);
      __Pyx_DECREF(__pyx_v_ms_node->end_of_merge);
      __pyx_v_ms_node->end_of_merge = __pyx_t_6;
      __pyx_t_6 = 0;
      goto __pyx_L9;
    }

    /* "bzrlib/_known_graph_pyx.pyx":869
 *                 # of this right-hand chain
 *                 ms_node.end_of_merge = True
 *             elif (ms_prev_node.merge_depth == ms_node.merge_depth             # <<<<<<<<<<<<<<
 *                   and prev_node not in node.parents):
 *                 # The next node is not a direct parent of this node
 */
    __pyx_t_3 = (__pyx_v_ms_prev_node->merge_depth == __pyx_v_ms_node->merge_depth);
    if (__pyx_t_3) {

      /* "bzrlib/_known_graph_pyx.pyx":870
 *                 ms_node.end_of_merge = True
 *             elif (ms_prev_node.merge_depth == ms_node.merge_depth
 *                   and prev_node not in node.parents):             # <<<<<<<<<<<<<<
 *                 # The next node is not a direct parent of this node
 *                 ms_node.end_of_merge = True
 */
      __pyx_t_7 = (__Pyx_NegateNonNeg(PySequence_Contains(__pyx_v_node->parents, ((PyObject *)__pyx_v_prev_node)))); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 870; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_8 = __pyx_t_7;
    } else {
      __pyx_t_8 = __pyx_t_3;
    }
    if (__pyx_t_8) {

      /* "bzrlib/_known_graph_pyx.pyx":872
 *                   and prev_node not in node.parents):
 *                 # The next node is not a direct parent of this node
 *                 ms_node.end_of_merge = True             # <<<<<<<<<<<<<<
 *             else:
 *                 ms_node.end_of_merge = False
 */
      __pyx_t_6 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 872; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_GIVEREF(__pyx_t_6);
      __Pyx_GOTREF(__pyx_v_ms_node->end_of_merge);
      __Pyx_DECREF(__pyx_v_ms_node->end_of_merge);
      __pyx_v_ms_node->end_of_merge = __pyx_t_6;
      __pyx_t_6 = 0;
      goto __pyx_L9;
    }
    /*else*/ {

      /* "bzrlib/_known_graph_pyx.pyx":874
 *                 ms_node.end_of_merge = True
 *             else:
 *                 ms_node.end_of_merge = False             # <<<<<<<<<<<<<<
 *         PyList_Append(self._scheduled_nodes, node)
 * 
 */
      __pyx_t_6 = __Pyx_PyBool_FromLong(0); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 874; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_GIVEREF(__pyx_t_6);
      __Pyx_GOTREF(__pyx_v_ms_node->end_of_merge);
      __Pyx_DECREF(__pyx_v_ms_node->end_of_merge);
      __pyx_v_ms_node->end_of_merge = __pyx_t_6;
      __pyx_t_6 = 0;
    }
    __pyx_L9:;
  }
  __pyx_L8:;

  /* "bzrlib/_known_graph_pyx.pyx":875
 *             else:
 *                 ms_node.end_of_merge = False
 *         PyList_Append(self._scheduled_nodes, node)             # <<<<<<<<<<<<<<
 * 
 *     cdef _schedule_stack(self):
 */
  __pyx_t_6 = __pyx_v_self->_scheduled_nodes;
  __Pyx_INCREF(__pyx_t_6);
  __pyx_t_4 = PyList_Append(__pyx_t_6, ((PyObject *)__pyx_v_node)); if (unlikely(__pyx_t_4 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 875; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_AddTraceback("bzrlib._known_graph_pyx._MergeSorter._pop_node");
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_DECREF((PyObject *)__pyx_v_ms_node);
  __Pyx_DECREF((PyObject *)__pyx_v_ms_parent_node);
  __Pyx_DECREF((PyObject *)__pyx_v_ms_prev_node);
  __Pyx_DECREF((PyObject *)__pyx_v_node);
  __Pyx_DECREF((PyObject *)__pyx_v_prev_node);
  __Pyx_DECREF(__pyx_v_branch_count);
  __Pyx_DECREF(__pyx_v_root_count);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "bzrlib/_known_graph_pyx.pyx":877
 *         PyList_Append(self._scheduled_nodes, node)
 * 
 *     cdef _schedule_stack(self):             # <<<<<<<<<<<<<<
 *         cdef _KnownGraphNode last_node, next_node
 *         cdef _MergeSortNode ms_node, ms_last_node, ms_next_node
 */

static  PyObject *__pyx_f_6bzrlib_16_known_graph_pyx_12_MergeSorter__schedule_stack(struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSorter *__pyx_v_self) {
  struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *__pyx_v_last_node;
  struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *__pyx_v_next_node;
  struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *__pyx_v_ms_last_node;
  struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *__pyx_v_ms_next_node;
  long __pyx_v_next_merge_depth;
  PyObject *__pyx_v_ordered;
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_t_5;
  __Pyx_RefNannySetupContext("_schedule_stack");
  __pyx_v_last_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)Py_None); __Pyx_INCREF(Py_None);
  __pyx_v_next_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)Py_None); __Pyx_INCREF(Py_None);
  __pyx_v_ms_last_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)Py_None); __Pyx_INCREF(Py_None);
  __pyx_v_ms_next_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)Py_None); __Pyx_INCREF(Py_None);
  __pyx_v_ordered = ((PyObject*)Py_None); __Pyx_INCREF(Py_None);

  /* "bzrlib/_known_graph_pyx.pyx":881
 *         cdef _MergeSortNode ms_node, ms_last_node, ms_next_node
 *         cdef long next_merge_depth
 *         ordered = []             # <<<<<<<<<<<<<<
 *         while self._last_stack_item >= 0:
 *             # Peek at the last item on the stack
 */
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 881; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_1));
  __Pyx_DECREF(((PyObject *)__pyx_v_ordered));
  __pyx_v_ordered = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "bzrlib/_known_graph_pyx.pyx":882
 *         cdef long next_merge_depth
 *         ordered = []
 *         while self._last_stack_item >= 0:             # <<<<<<<<<<<<<<
 *             # Peek at the last item on the stack
 *             last_node = _get_list_node(self._depth_first_stack,
 */
  while (1) {
    __pyx_t_2 = (__pyx_v_self->_last_stack_item >= 0);
    if (!__pyx_t_2) break;

    /* "bzrlib/_known_graph_pyx.pyx":884
 *         while self._last_stack_item >= 0:
 *             # Peek at the last item on the stack
 *             last_node = _get_list_node(self._depth_first_stack,             # <<<<<<<<<<<<<<
 *                                        self._last_stack_item)
 *             if last_node.gdfo == -1:
 */
    __pyx_t_1 = __pyx_v_self->_depth_first_stack;
    __Pyx_INCREF(__pyx_t_1);

    /* "bzrlib/_known_graph_pyx.pyx":885
 *             # Peek at the last item on the stack
 *             last_node = _get_list_node(self._depth_first_stack,
 *                                        self._last_stack_item)             # <<<<<<<<<<<<<<
 *             if last_node.gdfo == -1:
 *                 # if _find_gdfo skipped a node, that means there is a graph
 */
    __pyx_t_3 = ((PyObject *)__pyx_f_6bzrlib_16_known_graph_pyx__get_list_node(__pyx_t_1, __pyx_v_self->_last_stack_item)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 884; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_v_last_node));
    __pyx_v_last_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_t_3);
    __pyx_t_3 = 0;

    /* "bzrlib/_known_graph_pyx.pyx":886
 *             last_node = _get_list_node(self._depth_first_stack,
 *                                        self._last_stack_item)
 *             if last_node.gdfo == -1:             # <<<<<<<<<<<<<<
 *                 # if _find_gdfo skipped a node, that means there is a graph
 *                 # cycle, error out now
 */
    __pyx_t_2 = (__pyx_v_last_node->gdfo == -1);
    if (__pyx_t_2) {

      /* "bzrlib/_known_graph_pyx.pyx":889
 *                 # if _find_gdfo skipped a node, that means there is a graph
 *                 # cycle, error out now
 *                 raise errors.GraphCycleError(self.graph._nodes)             # <<<<<<<<<<<<<<
 *             ms_last_node = <_MergeSortNode>last_node.extra
 *             if not ms_last_node.has_pending_parents():
 */
      __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__errors); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 889; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_1 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__GraphCycleError); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 889; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 889; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(((PyObject *)__pyx_t_3));
      __Pyx_INCREF(__pyx_v_self->graph->_nodes);
      PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_self->graph->_nodes);
      __Pyx_GIVEREF(__pyx_v_self->graph->_nodes);
      __pyx_t_4 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 889; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
      __Pyx_Raise(__pyx_t_4, 0, 0);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 889; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      goto __pyx_L5;
    }
    __pyx_L5:;

    /* "bzrlib/_known_graph_pyx.pyx":890
 *                 # cycle, error out now
 *                 raise errors.GraphCycleError(self.graph._nodes)
 *             ms_last_node = <_MergeSortNode>last_node.extra             # <<<<<<<<<<<<<<
 *             if not ms_last_node.has_pending_parents():
 *                 # Processed all parents, pop this node
 */
    __Pyx_INCREF(((PyObject *)((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)__pyx_v_last_node->extra)));
    __Pyx_DECREF(((PyObject *)__pyx_v_ms_last_node));
    __pyx_v_ms_last_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)__pyx_v_last_node->extra);

    /* "bzrlib/_known_graph_pyx.pyx":891
 *                 raise errors.GraphCycleError(self.graph._nodes)
 *             ms_last_node = <_MergeSortNode>last_node.extra
 *             if not ms_last_node.has_pending_parents():             # <<<<<<<<<<<<<<
 *                 # Processed all parents, pop this node
 *                 self._pop_node()
 */
    __pyx_t_2 = (!((struct __pyx_vtabstruct_6bzrlib_16_known_graph_pyx__MergeSortNode *)__pyx_v_ms_last_node->__pyx_vtab)->has_pending_parents(__pyx_v_ms_last_node));
    if (__pyx_t_2) {

      /* "bzrlib/_known_graph_pyx.pyx":893
 *             if not ms_last_node.has_pending_parents():
 *                 # Processed all parents, pop this node
 *                 self._pop_node()             # <<<<<<<<<<<<<<
 *                 continue
 *             while ms_last_node.has_pending_parents():
 */
      __pyx_t_4 = ((struct __pyx_vtabstruct_6bzrlib_16_known_graph_pyx__MergeSorter *)__pyx_v_self->__pyx_vtab)->_pop_node(__pyx_v_self); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 893; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

      /* "bzrlib/_known_graph_pyx.pyx":894
 *                 # Processed all parents, pop this node
 *                 self._pop_node()
 *                 continue             # <<<<<<<<<<<<<<
 *             while ms_last_node.has_pending_parents():
 *                 if ms_last_node.left_pending_parent is not None:
 */
      goto __pyx_L3_continue;
      goto __pyx_L6;
    }
    __pyx_L6:;

    /* "bzrlib/_known_graph_pyx.pyx":895
 *                 self._pop_node()
 *                 continue
 *             while ms_last_node.has_pending_parents():             # <<<<<<<<<<<<<<
 *                 if ms_last_node.left_pending_parent is not None:
 *                     # recurse depth first into the primary parent
 */
    while (1) {
      __pyx_t_5 = ((struct __pyx_vtabstruct_6bzrlib_16_known_graph_pyx__MergeSortNode *)__pyx_v_ms_last_node->__pyx_vtab)->has_pending_parents(__pyx_v_ms_last_node);
      if (!__pyx_t_5) break;

      /* "bzrlib/_known_graph_pyx.pyx":896
 *                 continue
 *             while ms_last_node.has_pending_parents():
 *                 if ms_last_node.left_pending_parent is not None:             # <<<<<<<<<<<<<<
 *                     # recurse depth first into the primary parent
 *                     next_node = ms_last_node.left_pending_parent
 */
      __pyx_t_2 = (((PyObject *)__pyx_v_ms_last_node->left_pending_parent) != Py_None);
      if (__pyx_t_2) {

        /* "bzrlib/_known_graph_pyx.pyx":898
 *                 if ms_last_node.left_pending_parent is not None:
 *                     # recurse depth first into the primary parent
 *                     next_node = ms_last_node.left_pending_parent             # <<<<<<<<<<<<<<
 *                     ms_last_node.left_pending_parent = None
 *                 else:
 */
        __Pyx_INCREF(((PyObject *)__pyx_v_ms_last_node->left_pending_parent));
        __Pyx_DECREF(((PyObject *)__pyx_v_next_node));
        __pyx_v_next_node = __pyx_v_ms_last_node->left_pending_parent;

        /* "bzrlib/_known_graph_pyx.pyx":899
 *                     # recurse depth first into the primary parent
 *                     next_node = ms_last_node.left_pending_parent
 *                     ms_last_node.left_pending_parent = None             # <<<<<<<<<<<<<<
 *                 else:
 *                     # place any merges in right-to-left order for scheduling
 */
        __Pyx_INCREF(Py_None);
        __Pyx_GIVEREF(Py_None);
        __Pyx_GOTREF(__pyx_v_ms_last_node->left_pending_parent);
        __Pyx_DECREF(((PyObject *)__pyx_v_ms_last_node->left_pending_parent));
        __pyx_v_ms_last_node->left_pending_parent = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)Py_None);
        goto __pyx_L9;
      }
      /*else*/ {

        /* "bzrlib/_known_graph_pyx.pyx":908
 *                     #       left most, which will display nicely (you get
 *                     #       smaller trees at the top of the combined merge).
 *                     next_node = ms_last_node.pending_parents.pop()             # <<<<<<<<<<<<<<
 *                 ms_next_node = self._get_ms_node(next_node)
 *                 if ms_next_node.completed:
 */
        __pyx_t_4 = __Pyx_PyObject_Pop(__pyx_v_ms_last_node->pending_parents); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 908; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_4);
        if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_ptype_6bzrlib_16_known_graph_pyx__KnownGraphNode))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 908; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(((PyObject *)__pyx_v_next_node));
        __pyx_v_next_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_t_4);
        __pyx_t_4 = 0;
      }
      __pyx_L9:;

      /* "bzrlib/_known_graph_pyx.pyx":909
 *                     #       smaller trees at the top of the combined merge).
 *                     next_node = ms_last_node.pending_parents.pop()
 *                 ms_next_node = self._get_ms_node(next_node)             # <<<<<<<<<<<<<<
 *                 if ms_next_node.completed:
 *                     # this parent was completed by a child on the
 */
      __pyx_t_4 = ((PyObject *)((struct __pyx_vtabstruct_6bzrlib_16_known_graph_pyx__MergeSorter *)__pyx_v_self->__pyx_vtab)->_get_ms_node(__pyx_v_self, __pyx_v_next_node)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 909; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(((PyObject *)__pyx_v_ms_next_node));
      __pyx_v_ms_next_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)__pyx_t_4);
      __pyx_t_4 = 0;

      /* "bzrlib/_known_graph_pyx.pyx":910
 *                     next_node = ms_last_node.pending_parents.pop()
 *                 ms_next_node = self._get_ms_node(next_node)
 *                 if ms_next_node.completed:             # <<<<<<<<<<<<<<
 *                     # this parent was completed by a child on the
 *                     # call stack. skip it.
 */
      if (__pyx_v_ms_next_node->completed) {

        /* "bzrlib/_known_graph_pyx.pyx":913
 *                     # this parent was completed by a child on the
 *                     # call stack. skip it.
 *                     continue             # <<<<<<<<<<<<<<
 *                 # otherwise transfer it from the source graph into the
 *                 # top of the current depth first search stack.
 */
        goto __pyx_L7_continue;
        goto __pyx_L10;
      }
      __pyx_L10:;

      /* "bzrlib/_known_graph_pyx.pyx":917
 *                 # top of the current depth first search stack.
 * 
 *                 if next_node is ms_last_node.left_parent:             # <<<<<<<<<<<<<<
 *                     next_merge_depth = ms_last_node.merge_depth
 *                 else:
 */
      __pyx_t_2 = (__pyx_v_next_node == __pyx_v_ms_last_node->left_parent);
      if (__pyx_t_2) {

        /* "bzrlib/_known_graph_pyx.pyx":918
 * 
 *                 if next_node is ms_last_node.left_parent:
 *                     next_merge_depth = ms_last_node.merge_depth             # <<<<<<<<<<<<<<
 *                 else:
 *                     next_merge_depth = ms_last_node.merge_depth + 1
 */
        __pyx_v_next_merge_depth = __pyx_v_ms_last_node->merge_depth;
        goto __pyx_L11;
      }
      /*else*/ {

        /* "bzrlib/_known_graph_pyx.pyx":920
 *                     next_merge_depth = ms_last_node.merge_depth
 *                 else:
 *                     next_merge_depth = ms_last_node.merge_depth + 1             # <<<<<<<<<<<<<<
 *                 self._push_node(next_node, next_merge_depth)
 *                 # and do not continue processing parents until this 'call'
 */
        __pyx_v_next_merge_depth = (__pyx_v_ms_last_node->merge_depth + 1);
      }
      __pyx_L11:;

      /* "bzrlib/_known_graph_pyx.pyx":921
 *                 else:
 *                     next_merge_depth = ms_last_node.merge_depth + 1
 *                 self._push_node(next_node, next_merge_depth)             # <<<<<<<<<<<<<<
 *                 # and do not continue processing parents until this 'call'
 *                 # has recursed.
 */
      __pyx_t_4 = ((struct __pyx_vtabstruct_6bzrlib_16_known_graph_pyx__MergeSorter *)__pyx_v_self->__pyx_vtab)->_push_node(__pyx_v_self, __pyx_v_next_node, __pyx_v_next_merge_depth); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 921; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

      /* "bzrlib/_known_graph_pyx.pyx":924
 *                 # and do not continue processing parents until this 'call'
 *                 # has recursed.
 *                 break             # <<<<<<<<<<<<<<
 * 
 *     cdef topo_order(self):
 */
      goto __pyx_L8_break;
      __pyx_L7_continue:;
    }
    __pyx_L8_break:;
    __pyx_L3_continue:;
  }

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("bzrlib._known_graph_pyx._MergeSorter._schedule_stack");
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_DECREF((PyObject *)__pyx_v_last_node);
  __Pyx_DECREF((PyObject *)__pyx_v_next_node);
  __Pyx_DECREF((PyObject *)__pyx_v_ms_last_node);
  __Pyx_DECREF((PyObject *)__pyx_v_ms_next_node);
  __Pyx_DECREF(__pyx_v_ordered);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "bzrlib/_known_graph_pyx.pyx":926
 *                 break
 * 
 *     cdef topo_order(self):             # <<<<<<<<<<<<<<
 *         cdef _MergeSortNode ms_node
 *         cdef _KnownGraphNode node
 */

static  PyObject *__pyx_f_6bzrlib_16_known_graph_pyx_12_MergeSorter_topo_order(struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSorter *__pyx_v_self) {
  struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *__pyx_v_ms_node;
  struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *__pyx_v_node;
  Py_ssize_t __pyx_v_pos;
  PyObject *__pyx_v_ordered;
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_t_4;
  __Pyx_RefNannySetupContext("topo_order");
  __pyx_v_ms_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)Py_None); __Pyx_INCREF(Py_None);
  __pyx_v_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)Py_None); __Pyx_INCREF(Py_None);
  __pyx_v_ordered = ((PyObject*)Py_None); __Pyx_INCREF(Py_None);

  /* "bzrlib/_known_graph_pyx.pyx":936
 *         #       We might consider moving the attributes into the base
 *         #       KnownGraph object.
 *         self._schedule_stack()             # <<<<<<<<<<<<<<
 * 
 *         # We've set up the basic schedule, now we can continue processing the
 */
  __pyx_t_1 = ((struct __pyx_vtabstruct_6bzrlib_16_known_graph_pyx__MergeSorter *)__pyx_v_self->__pyx_vtab)->_schedule_stack(__pyx_v_self); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 936; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "bzrlib/_known_graph_pyx.pyx":946
 *         #       7ms is computing the return tuple
 *         #       4ms is PyList_Append()
 *         ordered = []             # <<<<<<<<<<<<<<
 *         # output the result in reverse order, and separate the generated info
 *         for pos from PyList_GET_SIZE(self._scheduled_nodes) > pos >= 0:
 */
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 946; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_1));
  __Pyx_DECREF(((PyObject *)__pyx_v_ordered));
  __pyx_v_ordered = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "bzrlib/_known_graph_pyx.pyx":948
 *         ordered = []
 *         # output the result in reverse order, and separate the generated info
 *         for pos from PyList_GET_SIZE(self._scheduled_nodes) > pos >= 0:             # <<<<<<<<<<<<<<
 *             node = _get_list_node(self._scheduled_nodes, pos)
 *             ms_node = <_MergeSortNode>node.extra
 */
  __pyx_t_1 = __pyx_v_self->_scheduled_nodes;
  __Pyx_INCREF(__pyx_t_1);
  for (__pyx_v_pos = PyList_GET_SIZE(__pyx_t_1)-1; __pyx_v_pos >= 0; __pyx_v_pos--) {

    /* "bzrlib/_known_graph_pyx.pyx":949
 *         # output the result in reverse order, and separate the generated info
 *         for pos from PyList_GET_SIZE(self._scheduled_nodes) > pos >= 0:
 *             node = _get_list_node(self._scheduled_nodes, pos)             # <<<<<<<<<<<<<<
 *             ms_node = <_MergeSortNode>node.extra
 *             PyList_Append(ordered, ms_node)
 */
    __pyx_t_2 = __pyx_v_self->_scheduled_nodes;
    __Pyx_INCREF(__pyx_t_2);
    __pyx_t_3 = ((PyObject *)__pyx_f_6bzrlib_16_known_graph_pyx__get_list_node(__pyx_t_2, __pyx_v_pos)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 949; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_v_node));
    __pyx_v_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_t_3);
    __pyx_t_3 = 0;

    /* "bzrlib/_known_graph_pyx.pyx":950
 *         for pos from PyList_GET_SIZE(self._scheduled_nodes) > pos >= 0:
 *             node = _get_list_node(self._scheduled_nodes, pos)
 *             ms_node = <_MergeSortNode>node.extra             # <<<<<<<<<<<<<<
 *             PyList_Append(ordered, ms_node)
 *             node.extra = None
 */
    __Pyx_INCREF(((PyObject *)((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)__pyx_v_node->extra)));
    __Pyx_DECREF(((PyObject *)__pyx_v_ms_node));
    __pyx_v_ms_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)__pyx_v_node->extra);

    /* "bzrlib/_known_graph_pyx.pyx":951
 *             node = _get_list_node(self._scheduled_nodes, pos)
 *             ms_node = <_MergeSortNode>node.extra
 *             PyList_Append(ordered, ms_node)             # <<<<<<<<<<<<<<
 *             node.extra = None
 *         # Clear out the scheduled nodes now that we're done
 */
    __pyx_t_4 = PyList_Append(((PyObject *)__pyx_v_ordered), ((PyObject *)__pyx_v_ms_node)); if (unlikely(__pyx_t_4 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 951; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

    /* "bzrlib/_known_graph_pyx.pyx":952
 *             ms_node = <_MergeSortNode>node.extra
 *             PyList_Append(ordered, ms_node)
 *             node.extra = None             # <<<<<<<<<<<<<<
 *         # Clear out the scheduled nodes now that we're done
 *         self._scheduled_nodes = []
 */
    __Pyx_INCREF(Py_None);
    __Pyx_GIVEREF(Py_None);
    __Pyx_GOTREF(__pyx_v_node->extra);
    __Pyx_DECREF(__pyx_v_node->extra);
    __pyx_v_node->extra = Py_None;
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "bzrlib/_known_graph_pyx.pyx":954
 *             node.extra = None
 *         # Clear out the scheduled nodes now that we're done
 *         self._scheduled_nodes = []             # <<<<<<<<<<<<<<
 *         return ordered
 */
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 954; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_1));
  __Pyx_GIVEREF(((PyObject *)__pyx_t_1));
  __Pyx_GOTREF(__pyx_v_self->_scheduled_nodes);
  __Pyx_DECREF(__pyx_v_self->_scheduled_nodes);
  __pyx_v_self->_scheduled_nodes = ((PyObject *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "bzrlib/_known_graph_pyx.pyx":955
 *         # Clear out the scheduled nodes now that we're done
 *         self._scheduled_nodes = []
 *         return ordered             # <<<<<<<<<<<<<<
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(((PyObject *)__pyx_v_ordered));
  __pyx_r = ((PyObject *)__pyx_v_ordered);
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("bzrlib._known_graph_pyx._MergeSorter.topo_order");
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_DECREF((PyObject *)__pyx_v_ms_node);
  __Pyx_DECREF((PyObject *)__pyx_v_node);
  __Pyx_DECREF(__pyx_v_ordered);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
static struct __pyx_vtabstruct_6bzrlib_16_known_graph_pyx__KnownGraphNode __pyx_vtable_6bzrlib_16_known_graph_pyx__KnownGraphNode;

static PyObject *__pyx_tp_new_6bzrlib_16_known_graph_pyx__KnownGraphNode(PyTypeObject *t, PyObject *a, PyObject *k) {
  struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *p;
  PyObject *o = (*t->tp_alloc)(t, 0);
  if (!o) return 0;
  p = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)o);
  p->__pyx_vtab = __pyx_vtabptr_6bzrlib_16_known_graph_pyx__KnownGraphNode;
  p->key = Py_None; Py_INCREF(Py_None);
  p->parents = Py_None; Py_INCREF(Py_None);
  p->children = Py_None; Py_INCREF(Py_None);
  p->extra = Py_None; Py_INCREF(Py_None);
  return o;
}

static void __pyx_tp_dealloc_6bzrlib_16_known_graph_pyx__KnownGraphNode(PyObject *o) {
  struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *p = (struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)o;
  Py_XDECREF(p->key);
  Py_XDECREF(p->parents);
  Py_XDECREF(p->children);
  Py_XDECREF(p->extra);
  (*Py_TYPE(o)->tp_free)(o);
}

static int __pyx_tp_traverse_6bzrlib_16_known_graph_pyx__KnownGraphNode(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *p = (struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)o;
  if (p->key) {
    e = (*v)(p->key, a); if (e) return e;
  }
  if (p->parents) {
    e = (*v)(p->parents, a); if (e) return e;
  }
  if (p->children) {
    e = (*v)(p->children, a); if (e) return e;
  }
  if (p->extra) {
    e = (*v)(p->extra, a); if (e) return e;
  }
  return 0;
}

static int __pyx_tp_clear_6bzrlib_16_known_graph_pyx__KnownGraphNode(PyObject *o) {
  struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *p = (struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)o;
  PyObject* tmp;
  tmp = ((PyObject*)p->key);
  p->key = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->parents);
  p->parents = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->children);
  p->children = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->extra);
  p->extra = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  return 0;
}

static PyObject *__pyx_getprop_6bzrlib_16_known_graph_pyx_15_KnownGraphNode_child_keys(PyObject *o, void *x) {
  return __pyx_pf_6bzrlib_16_known_graph_pyx_15_KnownGraphNode_10child_keys___get__(o);
}

static PyObject *__pyx_getprop_6bzrlib_16_known_graph_pyx_15_KnownGraphNode_parent_keys(PyObject *o, void *x) {
  return __pyx_pf_6bzrlib_16_known_graph_pyx_15_KnownGraphNode_11parent_keys___get__(o);
}

static PyObject *__pyx_getprop_6bzrlib_16_known_graph_pyx_15_KnownGraphNode_gdfo(PyObject *o, void *x) {
  return __pyx_pf_6bzrlib_16_known_graph_pyx_15_KnownGraphNode_4gdfo___get__(o);
}

static int __pyx_setprop_6bzrlib_16_known_graph_pyx_15_KnownGraphNode_gdfo(PyObject *o, PyObject *v, void *x) {
  if (v) {
    return __pyx_pf_6bzrlib_16_known_graph_pyx_15_KnownGraphNode_4gdfo_1__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyMethodDef __pyx_methods_6bzrlib_16_known_graph_pyx__KnownGraphNode[] = {
  {0, 0, 0, 0}
};

static struct PyGetSetDef __pyx_getsets_6bzrlib_16_known_graph_pyx__KnownGraphNode[] = {
  {(char *)"child_keys", __pyx_getprop_6bzrlib_16_known_graph_pyx_15_KnownGraphNode_child_keys, 0, 0, 0},
  {(char *)"parent_keys", __pyx_getprop_6bzrlib_16_known_graph_pyx_15_KnownGraphNode_parent_keys, 0, 0, 0},
  {(char *)"gdfo", __pyx_getprop_6bzrlib_16_known_graph_pyx_15_KnownGraphNode_gdfo, __pyx_setprop_6bzrlib_16_known_graph_pyx_15_KnownGraphNode_gdfo, 0, 0},
  {0, 0, 0, 0, 0}
};

static PyNumberMethods __pyx_tp_as_number__KnownGraphNode = {
  0, /*nb_add*/
  0, /*nb_subtract*/
  0, /*nb_multiply*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_divide*/
  #endif
  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*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_coerce*/
  #endif
  0, /*nb_int*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_long*/
  #else
  0, /*reserved*/
  #endif
  0, /*nb_float*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_oct*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*nb_hex*/
  #endif
  0, /*nb_inplace_add*/
  0, /*nb_inplace_subtract*/
  0, /*nb_inplace_multiply*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_inplace_divide*/
  #endif
  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_VERSION_HEX >= 0x02050000
  0, /*nb_index*/
  #endif
};

static PySequenceMethods __pyx_tp_as_sequence__KnownGraphNode = {
  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__KnownGraphNode = {
  0, /*mp_length*/
  0, /*mp_subscript*/
  0, /*mp_ass_subscript*/
};

static PyBufferProcs __pyx_tp_as_buffer__KnownGraphNode = {
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getreadbuffer*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getwritebuffer*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getsegcount*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getcharbuffer*/
  #endif
  #if PY_VERSION_HEX >= 0x02060000
  0, /*bf_getbuffer*/
  #endif
  #if PY_VERSION_HEX >= 0x02060000
  0, /*bf_releasebuffer*/
  #endif
};

static PyTypeObject __pyx_type_6bzrlib_16_known_graph_pyx__KnownGraphNode = {
  PyVarObject_HEAD_INIT(0, 0)
  __Pyx_NAMESTR("bzrlib._known_graph_pyx._KnownGraphNode"), /*tp_name*/
  sizeof(struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_6bzrlib_16_known_graph_pyx__KnownGraphNode, /*tp_dealloc*/
  0, /*tp_print*/
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #else
  0, /*reserved*/
  #endif
  __pyx_pf_6bzrlib_16_known_graph_pyx_15_KnownGraphNode_1__repr__, /*tp_repr*/
  &__pyx_tp_as_number__KnownGraphNode, /*tp_as_number*/
  &__pyx_tp_as_sequence__KnownGraphNode, /*tp_as_sequence*/
  &__pyx_tp_as_mapping__KnownGraphNode, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  &__pyx_tp_as_buffer__KnownGraphNode, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  __Pyx_DOCSTR("Represents a single object in the known graph."), /*tp_doc*/
  __pyx_tp_traverse_6bzrlib_16_known_graph_pyx__KnownGraphNode, /*tp_traverse*/
  __pyx_tp_clear_6bzrlib_16_known_graph_pyx__KnownGraphNode, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  __pyx_methods_6bzrlib_16_known_graph_pyx__KnownGraphNode, /*tp_methods*/
  0, /*tp_members*/
  __pyx_getsets_6bzrlib_16_known_graph_pyx__KnownGraphNode, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  0, /*tp_dictoffset*/
  __pyx_pf_6bzrlib_16_known_graph_pyx_15_KnownGraphNode___init__, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_6bzrlib_16_known_graph_pyx__KnownGraphNode, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  #if PY_VERSION_HEX >= 0x02060000
  0, /*tp_version_tag*/
  #endif
};
static struct __pyx_vtabstruct_6bzrlib_16_known_graph_pyx__MergeSorter __pyx_vtable_6bzrlib_16_known_graph_pyx__MergeSorter;

static PyObject *__pyx_tp_new_6bzrlib_16_known_graph_pyx__MergeSorter(PyTypeObject *t, PyObject *a, PyObject *k) {
  struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSorter *p;
  PyObject *o = (*t->tp_alloc)(t, 0);
  if (!o) return 0;
  p = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSorter *)o);
  p->__pyx_vtab = __pyx_vtabptr_6bzrlib_16_known_graph_pyx__MergeSorter;
  p->graph = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *)Py_None); Py_INCREF(Py_None);
  p->_depth_first_stack = Py_None; Py_INCREF(Py_None);
  p->_revno_to_branch_count = Py_None; Py_INCREF(Py_None);
  p->_scheduled_nodes = Py_None; Py_INCREF(Py_None);
  return o;
}

static void __pyx_tp_dealloc_6bzrlib_16_known_graph_pyx__MergeSorter(PyObject *o) {
  struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSorter *p = (struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSorter *)o;
  Py_XDECREF(((PyObject *)p->graph));
  Py_XDECREF(p->_depth_first_stack);
  Py_XDECREF(p->_revno_to_branch_count);
  Py_XDECREF(p->_scheduled_nodes);
  (*Py_TYPE(o)->tp_free)(o);
}

static int __pyx_tp_traverse_6bzrlib_16_known_graph_pyx__MergeSorter(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSorter *p = (struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSorter *)o;
  if (p->graph) {
    e = (*v)(((PyObject*)p->graph), a); if (e) return e;
  }
  if (p->_depth_first_stack) {
    e = (*v)(p->_depth_first_stack, a); if (e) return e;
  }
  if (p->_revno_to_branch_count) {
    e = (*v)(p->_revno_to_branch_count, a); if (e) return e;
  }
  if (p->_scheduled_nodes) {
    e = (*v)(p->_scheduled_nodes, a); if (e) return e;
  }
  return 0;
}

static int __pyx_tp_clear_6bzrlib_16_known_graph_pyx__MergeSorter(PyObject *o) {
  struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSorter *p = (struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSorter *)o;
  PyObject* tmp;
  tmp = ((PyObject*)p->graph);
  p->graph = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *)Py_None); Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->_depth_first_stack);
  p->_depth_first_stack = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->_revno_to_branch_count);
  p->_revno_to_branch_count = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->_scheduled_nodes);
  p->_scheduled_nodes = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  return 0;
}

static PyMethodDef __pyx_methods_6bzrlib_16_known_graph_pyx__MergeSorter[] = {
  {0, 0, 0, 0}
};

static PyNumberMethods __pyx_tp_as_number__MergeSorter = {
  0, /*nb_add*/
  0, /*nb_subtract*/
  0, /*nb_multiply*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_divide*/
  #endif
  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*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_coerce*/
  #endif
  0, /*nb_int*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_long*/
  #else
  0, /*reserved*/
  #endif
  0, /*nb_float*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_oct*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*nb_hex*/
  #endif
  0, /*nb_inplace_add*/
  0, /*nb_inplace_subtract*/
  0, /*nb_inplace_multiply*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_inplace_divide*/
  #endif
  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_VERSION_HEX >= 0x02050000
  0, /*nb_index*/
  #endif
};

static PySequenceMethods __pyx_tp_as_sequence__MergeSorter = {
  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__MergeSorter = {
  0, /*mp_length*/
  0, /*mp_subscript*/
  0, /*mp_ass_subscript*/
};

static PyBufferProcs __pyx_tp_as_buffer__MergeSorter = {
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getreadbuffer*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getwritebuffer*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getsegcount*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getcharbuffer*/
  #endif
  #if PY_VERSION_HEX >= 0x02060000
  0, /*bf_getbuffer*/
  #endif
  #if PY_VERSION_HEX >= 0x02060000
  0, /*bf_releasebuffer*/
  #endif
};

static PyTypeObject __pyx_type_6bzrlib_16_known_graph_pyx__MergeSorter = {
  PyVarObject_HEAD_INIT(0, 0)
  __Pyx_NAMESTR("bzrlib._known_graph_pyx._MergeSorter"), /*tp_name*/
  sizeof(struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSorter), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_6bzrlib_16_known_graph_pyx__MergeSorter, /*tp_dealloc*/
  0, /*tp_print*/
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #else
  0, /*reserved*/
  #endif
  0, /*tp_repr*/
  &__pyx_tp_as_number__MergeSorter, /*tp_as_number*/
  &__pyx_tp_as_sequence__MergeSorter, /*tp_as_sequence*/
  &__pyx_tp_as_mapping__MergeSorter, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  &__pyx_tp_as_buffer__MergeSorter, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  __Pyx_DOCSTR("This class does the work of computing the merge_sort ordering.\n\n    We have some small advantages, in that we get all the extra information\n    that KnownGraph knows, like knowing the child lists, etc.\n    "), /*tp_doc*/
  __pyx_tp_traverse_6bzrlib_16_known_graph_pyx__MergeSorter, /*tp_traverse*/
  __pyx_tp_clear_6bzrlib_16_known_graph_pyx__MergeSorter, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  __pyx_methods_6bzrlib_16_known_graph_pyx__MergeSorter, /*tp_methods*/
  0, /*tp_members*/
  0, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  0, /*tp_dictoffset*/
  __pyx_pf_6bzrlib_16_known_graph_pyx_12_MergeSorter___init__, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_6bzrlib_16_known_graph_pyx__MergeSorter, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  #if PY_VERSION_HEX >= 0x02060000
  0, /*tp_version_tag*/
  #endif
};
static struct __pyx_vtabstruct_6bzrlib_16_known_graph_pyx_KnownGraph __pyx_vtable_6bzrlib_16_known_graph_pyx_KnownGraph;

static PyObject *__pyx_tp_new_6bzrlib_16_known_graph_pyx_KnownGraph(PyTypeObject *t, PyObject *a, PyObject *k) {
  struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *p;
  PyObject *o = (*t->tp_alloc)(t, 0);
  if (!o) return 0;
  p = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *)o);
  p->__pyx_vtab = __pyx_vtabptr_6bzrlib_16_known_graph_pyx_KnownGraph;
  p->_nodes = Py_None; Py_INCREF(Py_None);
  p->_known_heads = Py_None; Py_INCREF(Py_None);
  return o;
}

static void __pyx_tp_dealloc_6bzrlib_16_known_graph_pyx_KnownGraph(PyObject *o) {
  struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *p = (struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *)o;
  {
    PyObject *etype, *eval, *etb;
    PyErr_Fetch(&etype, &eval, &etb);
    ++Py_REFCNT(o);
    __pyx_pf_6bzrlib_16_known_graph_pyx_10KnownGraph_1__dealloc__(o);
    if (PyErr_Occurred()) PyErr_WriteUnraisable(o);
    --Py_REFCNT(o);
    PyErr_Restore(etype, eval, etb);
  }
  Py_XDECREF(p->_nodes);
  Py_XDECREF(p->_known_heads);
  (*Py_TYPE(o)->tp_free)(o);
}

static int __pyx_tp_traverse_6bzrlib_16_known_graph_pyx_KnownGraph(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *p = (struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *)o;
  if (p->_nodes) {
    e = (*v)(p->_nodes, a); if (e) return e;
  }
  if (p->_known_heads) {
    e = (*v)(p->_known_heads, a); if (e) return e;
  }
  return 0;
}

static int __pyx_tp_clear_6bzrlib_16_known_graph_pyx_KnownGraph(PyObject *o) {
  struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *p = (struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *)o;
  PyObject* tmp;
  tmp = ((PyObject*)p->_nodes);
  p->_nodes = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->_known_heads);
  p->_known_heads = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  return 0;
}

static PyObject *__pyx_getprop_6bzrlib_16_known_graph_pyx_10KnownGraph__nodes(PyObject *o, void *x) {
  return __pyx_pf_6bzrlib_16_known_graph_pyx_10KnownGraph_6_nodes___get__(o);
}

static int __pyx_setprop_6bzrlib_16_known_graph_pyx_10KnownGraph__nodes(PyObject *o, PyObject *v, void *x) {
  if (v) {
    return __pyx_pf_6bzrlib_16_known_graph_pyx_10KnownGraph_6_nodes_1__set__(o, v);
  }
  else {
    return __pyx_pf_6bzrlib_16_known_graph_pyx_10KnownGraph_6_nodes_2__del__(o);
  }
}

static PyObject *__pyx_getprop_6bzrlib_16_known_graph_pyx_10KnownGraph__known_heads(PyObject *o, void *x) {
  return __pyx_pf_6bzrlib_16_known_graph_pyx_10KnownGraph_12_known_heads___get__(o);
}

static int __pyx_setprop_6bzrlib_16_known_graph_pyx_10KnownGraph__known_heads(PyObject *o, PyObject *v, void *x) {
  if (v) {
    return __pyx_pf_6bzrlib_16_known_graph_pyx_10KnownGraph_12_known_heads_1__set__(o, v);
  }
  else {
    return __pyx_pf_6bzrlib_16_known_graph_pyx_10KnownGraph_12_known_heads_2__del__(o);
  }
}

static PyObject *__pyx_getprop_6bzrlib_16_known_graph_pyx_10KnownGraph_do_cache(PyObject *o, void *x) {
  return __pyx_pf_6bzrlib_16_known_graph_pyx_10KnownGraph_8do_cache___get__(o);
}

static int __pyx_setprop_6bzrlib_16_known_graph_pyx_10KnownGraph_do_cache(PyObject *o, PyObject *v, void *x) {
  if (v) {
    return __pyx_pf_6bzrlib_16_known_graph_pyx_10KnownGraph_8do_cache_1__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyMethodDef __pyx_methods_6bzrlib_16_known_graph_pyx_KnownGraph[] = {
  {__Pyx_NAMESTR("_initialize_nodes"), (PyCFunction)__pyx_pf_6bzrlib_16_known_graph_pyx_10KnownGraph_2_initialize_nodes, METH_O, __Pyx_DOCSTR(__pyx_doc_6bzrlib_16_known_graph_pyx_10KnownGraph_2_initialize_nodes)},
  {__Pyx_NAMESTR("_find_tails"), (PyCFunction)__pyx_pf_6bzrlib_16_known_graph_pyx_10KnownGraph_3_find_tails, METH_NOARGS, __Pyx_DOCSTR(0)},
  {__Pyx_NAMESTR("_find_tips"), (PyCFunction)__pyx_pf_6bzrlib_16_known_graph_pyx_10KnownGraph_4_find_tips, METH_NOARGS, __Pyx_DOCSTR(0)},
  {__Pyx_NAMESTR("_find_gdfo"), (PyCFunction)__pyx_pf_6bzrlib_16_known_graph_pyx_10KnownGraph_5_find_gdfo, METH_NOARGS, __Pyx_DOCSTR(0)},
  {__Pyx_NAMESTR("add_node"), (PyCFunction)__pyx_pf_6bzrlib_16_known_graph_pyx_10KnownGraph_6add_node, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_6bzrlib_16_known_graph_pyx_10KnownGraph_6add_node)},
  {__Pyx_NAMESTR("heads"), (PyCFunction)__pyx_pf_6bzrlib_16_known_graph_pyx_10KnownGraph_7heads, METH_O, __Pyx_DOCSTR(__pyx_doc_6bzrlib_16_known_graph_pyx_10KnownGraph_7heads)},
  {__Pyx_NAMESTR("topo_sort"), (PyCFunction)__pyx_pf_6bzrlib_16_known_graph_pyx_10KnownGraph_8topo_sort, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_6bzrlib_16_known_graph_pyx_10KnownGraph_8topo_sort)},
  {__Pyx_NAMESTR("gc_sort"), (PyCFunction)__pyx_pf_6bzrlib_16_known_graph_pyx_10KnownGraph_9gc_sort, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_6bzrlib_16_known_graph_pyx_10KnownGraph_9gc_sort)},
  {__Pyx_NAMESTR("merge_sort"), (PyCFunction)__pyx_pf_6bzrlib_16_known_graph_pyx_10KnownGraph_10merge_sort, METH_O, __Pyx_DOCSTR(__pyx_doc_6bzrlib_16_known_graph_pyx_10KnownGraph_10merge_sort)},
  {__Pyx_NAMESTR("get_parent_keys"), (PyCFunction)__pyx_pf_6bzrlib_16_known_graph_pyx_10KnownGraph_11get_parent_keys, METH_O, __Pyx_DOCSTR(__pyx_doc_6bzrlib_16_known_graph_pyx_10KnownGraph_11get_parent_keys)},
  {__Pyx_NAMESTR("get_child_keys"), (PyCFunction)__pyx_pf_6bzrlib_16_known_graph_pyx_10KnownGraph_12get_child_keys, METH_O, __Pyx_DOCSTR(__pyx_doc_6bzrlib_16_known_graph_pyx_10KnownGraph_12get_child_keys)},
  {0, 0, 0, 0}
};

static struct PyGetSetDef __pyx_getsets_6bzrlib_16_known_graph_pyx_KnownGraph[] = {
  {(char *)"_nodes", __pyx_getprop_6bzrlib_16_known_graph_pyx_10KnownGraph__nodes, __pyx_setprop_6bzrlib_16_known_graph_pyx_10KnownGraph__nodes, 0, 0},
  {(char *)"_known_heads", __pyx_getprop_6bzrlib_16_known_graph_pyx_10KnownGraph__known_heads, __pyx_setprop_6bzrlib_16_known_graph_pyx_10KnownGraph__known_heads, 0, 0},
  {(char *)"do_cache", __pyx_getprop_6bzrlib_16_known_graph_pyx_10KnownGraph_do_cache, __pyx_setprop_6bzrlib_16_known_graph_pyx_10KnownGraph_do_cache, 0, 0},
  {0, 0, 0, 0, 0}
};

static PyNumberMethods __pyx_tp_as_number_KnownGraph = {
  0, /*nb_add*/
  0, /*nb_subtract*/
  0, /*nb_multiply*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_divide*/
  #endif
  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*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_coerce*/
  #endif
  0, /*nb_int*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_long*/
  #else
  0, /*reserved*/
  #endif
  0, /*nb_float*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_oct*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*nb_hex*/
  #endif
  0, /*nb_inplace_add*/
  0, /*nb_inplace_subtract*/
  0, /*nb_inplace_multiply*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_inplace_divide*/
  #endif
  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_VERSION_HEX >= 0x02050000
  0, /*nb_index*/
  #endif
};

static PySequenceMethods __pyx_tp_as_sequence_KnownGraph = {
  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_KnownGraph = {
  0, /*mp_length*/
  0, /*mp_subscript*/
  0, /*mp_ass_subscript*/
};

static PyBufferProcs __pyx_tp_as_buffer_KnownGraph = {
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getreadbuffer*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getwritebuffer*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getsegcount*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getcharbuffer*/
  #endif
  #if PY_VERSION_HEX >= 0x02060000
  0, /*bf_getbuffer*/
  #endif
  #if PY_VERSION_HEX >= 0x02060000
  0, /*bf_releasebuffer*/
  #endif
};

static PyTypeObject __pyx_type_6bzrlib_16_known_graph_pyx_KnownGraph = {
  PyVarObject_HEAD_INIT(0, 0)
  __Pyx_NAMESTR("bzrlib._known_graph_pyx.KnownGraph"), /*tp_name*/
  sizeof(struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_6bzrlib_16_known_graph_pyx_KnownGraph, /*tp_dealloc*/
  0, /*tp_print*/
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #else
  0, /*reserved*/
  #endif
  0, /*tp_repr*/
  &__pyx_tp_as_number_KnownGraph, /*tp_as_number*/
  &__pyx_tp_as_sequence_KnownGraph, /*tp_as_sequence*/
  &__pyx_tp_as_mapping_KnownGraph, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  &__pyx_tp_as_buffer_KnownGraph, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  __Pyx_DOCSTR("This is a class which assumes we already know the full graph."), /*tp_doc*/
  __pyx_tp_traverse_6bzrlib_16_known_graph_pyx_KnownGraph, /*tp_traverse*/
  __pyx_tp_clear_6bzrlib_16_known_graph_pyx_KnownGraph, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  __pyx_methods_6bzrlib_16_known_graph_pyx_KnownGraph, /*tp_methods*/
  0, /*tp_members*/
  __pyx_getsets_6bzrlib_16_known_graph_pyx_KnownGraph, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  0, /*tp_dictoffset*/
  __pyx_pf_6bzrlib_16_known_graph_pyx_10KnownGraph___init__, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_6bzrlib_16_known_graph_pyx_KnownGraph, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  #if PY_VERSION_HEX >= 0x02060000
  0, /*tp_version_tag*/
  #endif
};
static struct __pyx_vtabstruct_6bzrlib_16_known_graph_pyx__MergeSortNode __pyx_vtable_6bzrlib_16_known_graph_pyx__MergeSortNode;

static PyObject *__pyx_tp_new_6bzrlib_16_known_graph_pyx__MergeSortNode(PyTypeObject *t, PyObject *a, PyObject *k) {
  struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *p;
  PyObject *o = (*t->tp_alloc)(t, 0);
  if (!o) return 0;
  p = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)o);
  p->__pyx_vtab = __pyx_vtabptr_6bzrlib_16_known_graph_pyx__MergeSortNode;
  p->key = Py_None; Py_INCREF(Py_None);
  p->end_of_merge = Py_None; Py_INCREF(Py_None);
  p->left_parent = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)Py_None); Py_INCREF(Py_None);
  p->left_pending_parent = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)Py_None); Py_INCREF(Py_None);
  p->pending_parents = Py_None; Py_INCREF(Py_None);
  return o;
}

static void __pyx_tp_dealloc_6bzrlib_16_known_graph_pyx__MergeSortNode(PyObject *o) {
  struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *p = (struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)o;
  Py_XDECREF(p->key);
  Py_XDECREF(p->end_of_merge);
  Py_XDECREF(((PyObject *)p->left_parent));
  Py_XDECREF(((PyObject *)p->left_pending_parent));
  Py_XDECREF(p->pending_parents);
  (*Py_TYPE(o)->tp_free)(o);
}

static int __pyx_tp_traverse_6bzrlib_16_known_graph_pyx__MergeSortNode(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *p = (struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)o;
  if (p->key) {
    e = (*v)(p->key, a); if (e) return e;
  }
  if (p->end_of_merge) {
    e = (*v)(p->end_of_merge, a); if (e) return e;
  }
  if (p->left_parent) {
    e = (*v)(((PyObject*)p->left_parent), a); if (e) return e;
  }
  if (p->left_pending_parent) {
    e = (*v)(((PyObject*)p->left_pending_parent), a); if (e) return e;
  }
  if (p->pending_parents) {
    e = (*v)(p->pending_parents, a); if (e) return e;
  }
  return 0;
}

static int __pyx_tp_clear_6bzrlib_16_known_graph_pyx__MergeSortNode(PyObject *o) {
  struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *p = (struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)o;
  PyObject* tmp;
  tmp = ((PyObject*)p->key);
  p->key = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->end_of_merge);
  p->end_of_merge = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->left_parent);
  p->left_parent = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)Py_None); Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->left_pending_parent);
  p->left_pending_parent = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)Py_None); Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->pending_parents);
  p->pending_parents = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  return 0;
}

static PyObject *__pyx_getprop_6bzrlib_16_known_graph_pyx_14_MergeSortNode_revno(PyObject *o, void *x) {
  return __pyx_pf_6bzrlib_16_known_graph_pyx_14_MergeSortNode_5revno___get__(o);
}

static PyObject *__pyx_getprop_6bzrlib_16_known_graph_pyx_14_MergeSortNode_key(PyObject *o, void *x) {
  return __pyx_pf_6bzrlib_16_known_graph_pyx_14_MergeSortNode_3key___get__(o);
}

static int __pyx_setprop_6bzrlib_16_known_graph_pyx_14_MergeSortNode_key(PyObject *o, PyObject *v, void *x) {
  if (v) {
    return __pyx_pf_6bzrlib_16_known_graph_pyx_14_MergeSortNode_3key_1__set__(o, v);
  }
  else {
    return __pyx_pf_6bzrlib_16_known_graph_pyx_14_MergeSortNode_3key_2__del__(o);
  }
}

static PyObject *__pyx_getprop_6bzrlib_16_known_graph_pyx_14_MergeSortNode_merge_depth(PyObject *o, void *x) {
  return __pyx_pf_6bzrlib_16_known_graph_pyx_14_MergeSortNode_11merge_depth___get__(o);
}

static int __pyx_setprop_6bzrlib_16_known_graph_pyx_14_MergeSortNode_merge_depth(PyObject *o, PyObject *v, void *x) {
  if (v) {
    return __pyx_pf_6bzrlib_16_known_graph_pyx_14_MergeSortNode_11merge_depth_1__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_6bzrlib_16_known_graph_pyx_14_MergeSortNode_end_of_merge(PyObject *o, void *x) {
  return __pyx_pf_6bzrlib_16_known_graph_pyx_14_MergeSortNode_12end_of_merge___get__(o);
}

static int __pyx_setprop_6bzrlib_16_known_graph_pyx_14_MergeSortNode_end_of_merge(PyObject *o, PyObject *v, void *x) {
  if (v) {
    return __pyx_pf_6bzrlib_16_known_graph_pyx_14_MergeSortNode_12end_of_merge_1__set__(o, v);
  }
  else {
    return __pyx_pf_6bzrlib_16_known_graph_pyx_14_MergeSortNode_12end_of_merge_2__del__(o);
  }
}

static PyMethodDef __pyx_methods_6bzrlib_16_known_graph_pyx__MergeSortNode[] = {
  {0, 0, 0, 0}
};

static struct PyGetSetDef __pyx_getsets_6bzrlib_16_known_graph_pyx__MergeSortNode[] = {
  {(char *)"revno", __pyx_getprop_6bzrlib_16_known_graph_pyx_14_MergeSortNode_revno, 0, 0, 0},
  {(char *)"key", __pyx_getprop_6bzrlib_16_known_graph_pyx_14_MergeSortNode_key, __pyx_setprop_6bzrlib_16_known_graph_pyx_14_MergeSortNode_key, 0, 0},
  {(char *)"merge_depth", __pyx_getprop_6bzrlib_16_known_graph_pyx_14_MergeSortNode_merge_depth, __pyx_setprop_6bzrlib_16_known_graph_pyx_14_MergeSortNode_merge_depth, 0, 0},
  {(char *)"end_of_merge", __pyx_getprop_6bzrlib_16_known_graph_pyx_14_MergeSortNode_end_of_merge, __pyx_setprop_6bzrlib_16_known_graph_pyx_14_MergeSortNode_end_of_merge, 0, 0},
  {0, 0, 0, 0, 0}
};

static PyNumberMethods __pyx_tp_as_number__MergeSortNode = {
  0, /*nb_add*/
  0, /*nb_subtract*/
  0, /*nb_multiply*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_divide*/
  #endif
  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*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_coerce*/
  #endif
  0, /*nb_int*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_long*/
  #else
  0, /*reserved*/
  #endif
  0, /*nb_float*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_oct*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*nb_hex*/
  #endif
  0, /*nb_inplace_add*/
  0, /*nb_inplace_subtract*/
  0, /*nb_inplace_multiply*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_inplace_divide*/
  #endif
  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_VERSION_HEX >= 0x02050000
  0, /*nb_index*/
  #endif
};

static PySequenceMethods __pyx_tp_as_sequence__MergeSortNode = {
  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__MergeSortNode = {
  0, /*mp_length*/
  0, /*mp_subscript*/
  0, /*mp_ass_subscript*/
};

static PyBufferProcs __pyx_tp_as_buffer__MergeSortNode = {
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getreadbuffer*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getwritebuffer*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getsegcount*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getcharbuffer*/
  #endif
  #if PY_VERSION_HEX >= 0x02060000
  0, /*bf_getbuffer*/
  #endif
  #if PY_VERSION_HEX >= 0x02060000
  0, /*bf_releasebuffer*/
  #endif
};

static PyTypeObject __pyx_type_6bzrlib_16_known_graph_pyx__MergeSortNode = {
  PyVarObject_HEAD_INIT(0, 0)
  __Pyx_NAMESTR("bzrlib._known_graph_pyx._MergeSortNode"), /*tp_name*/
  sizeof(struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_6bzrlib_16_known_graph_pyx__MergeSortNode, /*tp_dealloc*/
  0, /*tp_print*/
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #else
  0, /*reserved*/
  #endif
  __pyx_pf_6bzrlib_16_known_graph_pyx_14_MergeSortNode_1__repr__, /*tp_repr*/
  &__pyx_tp_as_number__MergeSortNode, /*tp_as_number*/
  &__pyx_tp_as_sequence__MergeSortNode, /*tp_as_sequence*/
  &__pyx_tp_as_mapping__MergeSortNode, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  &__pyx_tp_as_buffer__MergeSortNode, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  __Pyx_DOCSTR("Tracks information about a node during the merge_sort operation."), /*tp_doc*/
  __pyx_tp_traverse_6bzrlib_16_known_graph_pyx__MergeSortNode, /*tp_traverse*/
  __pyx_tp_clear_6bzrlib_16_known_graph_pyx__MergeSortNode, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  __pyx_methods_6bzrlib_16_known_graph_pyx__MergeSortNode, /*tp_methods*/
  0, /*tp_members*/
  __pyx_getsets_6bzrlib_16_known_graph_pyx__MergeSortNode, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  0, /*tp_dictoffset*/
  __pyx_pf_6bzrlib_16_known_graph_pyx_14_MergeSortNode___init__, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_6bzrlib_16_known_graph_pyx__MergeSortNode, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  #if PY_VERSION_HEX >= 0x02060000
  0, /*tp_version_tag*/
  #endif
};

static PyMethodDef __pyx_methods[] = {
  {0, 0, 0, 0}
};

#if PY_MAJOR_VERSION >= 3
static struct PyModuleDef __pyx_moduledef = {
    PyModuleDef_HEAD_INIT,
    __Pyx_NAMESTR("_known_graph_pyx"),
    __Pyx_DOCSTR(__pyx_k_14), /* m_doc */
    -1, /* m_size */
    __pyx_methods /* m_methods */,
    NULL, /* m_reload */
    NULL, /* m_traverse */
    NULL, /* m_clear */
    NULL /* m_free */
};
#endif

static __Pyx_StringTabEntry __pyx_string_tab[] = {
  {&__pyx_kp_s_1, __pyx_k_1, sizeof(__pyx_k_1), 0, 0, 1, 0},
  {&__pyx_kp_s_10, __pyx_k_10, sizeof(__pyx_k_10), 0, 0, 1, 0},
  {&__pyx_kp_s_11, __pyx_k_11, sizeof(__pyx_k_11), 0, 0, 1, 0},
  {&__pyx_n_s_12, __pyx_k_12, sizeof(__pyx_k_12), 0, 0, 1, 1},
  {&__pyx_kp_s_13, __pyx_k_13, sizeof(__pyx_k_13), 0, 0, 1, 0},
  {&__pyx_n_s_15, __pyx_k_15, sizeof(__pyx_k_15), 0, 0, 1, 1},
  {&__pyx_kp_s_2, __pyx_k_2, sizeof(__pyx_k_2), 0, 0, 1, 0},
  {&__pyx_kp_s_5, __pyx_k_5, sizeof(__pyx_k_5), 0, 0, 1, 0},
  {&__pyx_kp_s_7, __pyx_k_7, sizeof(__pyx_k_7), 0, 0, 1, 0},
  {&__pyx_kp_s_8, __pyx_k_8, sizeof(__pyx_k_8), 0, 0, 1, 0},
  {&__pyx_kp_s_9, __pyx_k_9, sizeof(__pyx_k_9), 0, 0, 1, 0},
  {&__pyx_n_s__GraphCycleError, __pyx_k__GraphCycleError, sizeof(__pyx_k__GraphCycleError), 0, 0, 1, 1},
  {&__pyx_n_s__KeyError, __pyx_k__KeyError, sizeof(__pyx_k__KeyError), 0, 0, 1, 1},
  {&__pyx_n_s__NULL_REVISION, __pyx_k__NULL_REVISION, sizeof(__pyx_k__NULL_REVISION), 0, 0, 1, 1},
  {&__pyx_n_s__RuntimeError, __pyx_k__RuntimeError, sizeof(__pyx_k__RuntimeError), 0, 0, 1, 1},
  {&__pyx_n_s__TypeError, __pyx_k__TypeError, sizeof(__pyx_k__TypeError), 0, 0, 1, 1},
  {&__pyx_n_s__ValueError, __pyx_k__ValueError, sizeof(__pyx_k__ValueError), 0, 0, 1, 1},
  {&__pyx_n_s____class__, __pyx_k____class__, sizeof(__pyx_k____class__), 0, 0, 1, 1},
  {&__pyx_n_s____main__, __pyx_k____main__, sizeof(__pyx_k____main__), 0, 0, 1, 1},
  {&__pyx_n_s____name__, __pyx_k____name__, sizeof(__pyx_k____name__), 0, 0, 1, 1},
  {&__pyx_n_s____test__, __pyx_k____test__, sizeof(__pyx_k____test__), 0, 0, 1, 1},
  {&__pyx_n_s___depth_first_stack, __pyx_k___depth_first_stack, sizeof(__pyx_k___depth_first_stack), 0, 0, 1, 1},
  {&__pyx_n_s___find_gdfo, __pyx_k___find_gdfo, sizeof(__pyx_k___find_gdfo), 0, 0, 1, 1},
  {&__pyx_n_s___find_tails, __pyx_k___find_tails, sizeof(__pyx_k___find_tails), 0, 0, 1, 1},
  {&__pyx_n_s___find_tips, __pyx_k___find_tips, sizeof(__pyx_k___find_tips), 0, 0, 1, 1},
  {&__pyx_n_s___get_ms_node, __pyx_k___get_ms_node, sizeof(__pyx_k___get_ms_node), 0, 0, 1, 1},
  {&__pyx_n_s___get_or_create_node, __pyx_k___get_or_create_node, sizeof(__pyx_k___get_or_create_node), 0, 0, 1, 1},
  {&__pyx_n_s___initialize_nodes, __pyx_k___initialize_nodes, sizeof(__pyx_k___initialize_nodes), 0, 0, 1, 1},
  {&__pyx_n_s___known_heads, __pyx_k___known_heads, sizeof(__pyx_k___known_heads), 0, 0, 1, 1},
  {&__pyx_n_s___last_stack_item, __pyx_k___last_stack_item, sizeof(__pyx_k___last_stack_item), 0, 0, 1, 1},
  {&__pyx_n_s___nodes, __pyx_k___nodes, sizeof(__pyx_k___nodes), 0, 0, 1, 1},
  {&__pyx_n_s___pop_node, __pyx_k___pop_node, sizeof(__pyx_k___pop_node), 0, 0, 1, 1},
  {&__pyx_n_s___populate_parents, __pyx_k___populate_parents, sizeof(__pyx_k___populate_parents), 0, 0, 1, 1},
  {&__pyx_n_s___push_node, __pyx_k___push_node, sizeof(__pyx_k___push_node), 0, 0, 1, 1},
  {&__pyx_n_s___revno, __pyx_k___revno, sizeof(__pyx_k___revno), 0, 0, 1, 1},
  {&__pyx_n_s___revno_first, __pyx_k___revno_first, sizeof(__pyx_k___revno_first), 0, 0, 1, 1},
  {&__pyx_n_s___revno_last, __pyx_k___revno_last, sizeof(__pyx_k___revno_last), 0, 0, 1, 1},
  {&__pyx_n_s___revno_second, __pyx_k___revno_second, sizeof(__pyx_k___revno_second), 0, 0, 1, 1},
  {&__pyx_n_s___schedule_stack, __pyx_k___schedule_stack, sizeof(__pyx_k___schedule_stack), 0, 0, 1, 1},
  {&__pyx_n_s___scheduled_nodes, __pyx_k___scheduled_nodes, sizeof(__pyx_k___scheduled_nodes), 0, 0, 1, 1},
  {&__pyx_n_s__append, __pyx_k__append, sizeof(__pyx_k__append), 0, 0, 1, 1},
  {&__pyx_n_s__bzrlib, __pyx_k__bzrlib, sizeof(__pyx_k__bzrlib), 0, 0, 1, 1},
  {&__pyx_n_s__child_keys, __pyx_k__child_keys, sizeof(__pyx_k__child_keys), 0, 0, 1, 1},
  {&__pyx_n_s__children, __pyx_k__children, sizeof(__pyx_k__children), 0, 0, 1, 1},
  {&__pyx_n_s__clear, __pyx_k__clear, sizeof(__pyx_k__clear), 0, 0, 1, 1},
  {&__pyx_n_s__clear_references, __pyx_k__clear_references, sizeof(__pyx_k__clear_references), 0, 0, 1, 1},
  {&__pyx_n_s__collections, __pyx_k__collections, sizeof(__pyx_k__collections), 0, 0, 1, 1},
  {&__pyx_n_s__completed, __pyx_k__completed, sizeof(__pyx_k__completed), 0, 0, 1, 1},
  {&__pyx_n_s__deque, __pyx_k__deque, sizeof(__pyx_k__deque), 0, 0, 1, 1},
  {&__pyx_n_s__do_cache, __pyx_k__do_cache, sizeof(__pyx_k__do_cache), 0, 0, 1, 1},
  {&__pyx_n_s__end_of_merge, __pyx_k__end_of_merge, sizeof(__pyx_k__end_of_merge), 0, 0, 1, 1},
  {&__pyx_n_s__errors, __pyx_k__errors, sizeof(__pyx_k__errors), 0, 0, 1, 1},
  {&__pyx_n_s__extend, __pyx_k__extend, sizeof(__pyx_k__extend), 0, 0, 1, 1},
  {&__pyx_n_s__extra, __pyx_k__extra, sizeof(__pyx_k__extra), 0, 0, 1, 1},
  {&__pyx_n_s__gc, __pyx_k__gc, sizeof(__pyx_k__gc), 0, 0, 1, 1},
  {&__pyx_n_s__gdfo, __pyx_k__gdfo, sizeof(__pyx_k__gdfo), 0, 0, 1, 1},
  {&__pyx_n_s__get_key, __pyx_k__get_key, sizeof(__pyx_k__get_key), 0, 0, 1, 1},
  {&__pyx_n_s__graph, __pyx_k__graph, sizeof(__pyx_k__graph), 0, 0, 1, 1},
  {&__pyx_n_s__has_pending_parents, __pyx_k__has_pending_parents, sizeof(__pyx_k__has_pending_parents), 0, 0, 1, 1},
  {&__pyx_n_s__is_first_child, __pyx_k__is_first_child, sizeof(__pyx_k__is_first_child), 0, 0, 1, 1},
  {&__pyx_n_s__key, __pyx_k__key, sizeof(__pyx_k__key), 0, 0, 1, 1},
  {&__pyx_n_s__known_graph, __pyx_k__known_graph, sizeof(__pyx_k__known_graph), 0, 0, 1, 1},
  {&__pyx_n_s__left_parent, __pyx_k__left_parent, sizeof(__pyx_k__left_parent), 0, 0, 1, 1},
  {&__pyx_n_s__left_pending_parent, __pyx_k__left_pending_parent, sizeof(__pyx_k__left_pending_parent), 0, 0, 1, 1},
  {&__pyx_n_s__merge_depth, __pyx_k__merge_depth, sizeof(__pyx_k__merge_depth), 0, 0, 1, 1},
  {&__pyx_n_s__parent_keys, __pyx_k__parent_keys, sizeof(__pyx_k__parent_keys), 0, 0, 1, 1},
  {&__pyx_n_s__parent_map, __pyx_k__parent_map, sizeof(__pyx_k__parent_map), 0, 0, 1, 1},
  {&__pyx_n_s__parents, __pyx_k__parents, sizeof(__pyx_k__parents), 0, 0, 1, 1},
  {&__pyx_n_s__pending_parents, __pyx_k__pending_parents, sizeof(__pyx_k__pending_parents), 0, 0, 1, 1},
  {&__pyx_n_s__pop, __pyx_k__pop, sizeof(__pyx_k__pop), 0, 0, 1, 1},
  {&__pyx_n_s__popleft, __pyx_k__popleft, sizeof(__pyx_k__popleft), 0, 0, 1, 1},
  {&__pyx_n_s__reverse, __pyx_k__reverse, sizeof(__pyx_k__reverse), 0, 0, 1, 1},
  {&__pyx_n_s__revision, __pyx_k__revision, sizeof(__pyx_k__revision), 0, 0, 1, 1},
  {&__pyx_n_s__seen, __pyx_k__seen, sizeof(__pyx_k__seen), 0, 0, 1, 1},
  {&__pyx_n_s__seen_by_child, __pyx_k__seen_by_child, sizeof(__pyx_k__seen_by_child), 0, 0, 1, 1},
  {&__pyx_n_s__sort, __pyx_k__sort, sizeof(__pyx_k__sort), 0, 0, 1, 1},
  {&__pyx_n_s__sorted, __pyx_k__sorted, sizeof(__pyx_k__sorted), 0, 0, 1, 1},
  {&__pyx_n_s__tip_key, __pyx_k__tip_key, sizeof(__pyx_k__tip_key), 0, 0, 1, 1},
  {&__pyx_n_s__topo_order, __pyx_k__topo_order, sizeof(__pyx_k__topo_order), 0, 0, 1, 1},
  {0, 0, 0, 0, 0, 0, 0}
};
static int __Pyx_InitCachedBuiltins(void) {
  __pyx_builtin_TypeError = __Pyx_GetName(__pyx_b, __pyx_n_s__TypeError); if (!__pyx_builtin_TypeError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 156; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_builtin_ValueError = __Pyx_GetName(__pyx_b, __pyx_n_s__ValueError); if (!__pyx_builtin_ValueError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 378; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_builtin_KeyError = __Pyx_GetName(__pyx_b, __pyx_n_s__KeyError); if (!__pyx_builtin_KeyError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 444; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_builtin_sorted = __Pyx_GetName(__pyx_b, __pyx_n_s__sorted); if (!__pyx_builtin_sorted) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 592; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_builtin_RuntimeError = __Pyx_GetName(__pyx_b, __pyx_n_s__RuntimeError); if (!__pyx_builtin_RuntimeError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 714; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  return 0;
  __pyx_L1_error:;
  return -1;
}

static int __Pyx_InitCachedConstants(void) {
  __Pyx_RefNannySetupContext("__Pyx_InitCachedConstants");

  /* "bzrlib/_known_graph_pyx.pyx":156
 *     is_tuple = PyTuple_CheckExact(lst_or_tpl)
 *     if not (is_tuple or PyList_CheckExact(lst_or_tpl)):
 *         raise TypeError('lst_or_tpl must be a list or tuple.')             # <<<<<<<<<<<<<<
 *     length = len(lst_or_tpl)
 *     if length == 0 or length == 1:
 */
  __pyx_k_tuple_3 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 156; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_3));
  __Pyx_INCREF(((PyObject *)__pyx_kp_s_2));
  PyTuple_SET_ITEM(__pyx_k_tuple_3, 0, ((PyObject *)__pyx_kp_s_2));
  __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_2));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_3));

  /* "bzrlib/_known_graph_pyx.pyx":273
 * 
 *         if not PyDict_CheckExact(parent_map):
 *             raise TypeError('parent_map should be a dict of {key:parent_keys}')             # <<<<<<<<<<<<<<
 *         # for key, parent_keys in parent_map.iteritems():
 *         pos = 0
 */
  __pyx_k_tuple_6 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 273; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_6));
  __Pyx_INCREF(((PyObject *)__pyx_kp_s_5));
  PyTuple_SET_ITEM(__pyx_k_tuple_6, 0, ((PyObject *)__pyx_kp_s_5));
  __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_5));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_6));
  __Pyx_RefNannyFinishContext();
  return 0;
  __pyx_L1_error:;
  __Pyx_RefNannyFinishContext();
  return -1;
}

static int __Pyx_InitGlobals(void) {
  #if PY_VERSION_HEX < 0x02040000
  if (unlikely(__Pyx_Py23SetsImport() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  #endif
  if (__Pyx_InitStrings(__pyx_string_tab) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __pyx_int_0 = PyInt_FromLong(0); if (unlikely(!__pyx_int_0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __pyx_int_1 = PyInt_FromLong(1); if (unlikely(!__pyx_int_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  return 0;
  __pyx_L1_error:;
  return -1;
}

#if PY_MAJOR_VERSION < 3
PyMODINIT_FUNC init_known_graph_pyx(void); /*proto*/
PyMODINIT_FUNC init_known_graph_pyx(void)
#else
PyMODINIT_FUNC PyInit__known_graph_pyx(void); /*proto*/
PyMODINIT_FUNC PyInit__known_graph_pyx(void)
#endif
{
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  #if CYTHON_REFNANNY
  void* __pyx_refnanny = NULL;
  __Pyx_RefNanny = __Pyx_RefNannyImportAPI("refnanny");
  if (!__Pyx_RefNanny) {
      PyErr_Clear();
      __Pyx_RefNanny = __Pyx_RefNannyImportAPI("Cython.Runtime.refnanny");
      if (!__Pyx_RefNanny)
          Py_FatalError("failed to import 'refnanny' module");
  }
  __pyx_refnanny = __Pyx_RefNanny->SetupContext("PyMODINIT_FUNC PyInit__known_graph_pyx(void)", __LINE__, __FILE__);
  #endif
  __pyx_empty_tuple = PyTuple_New(0); if (unlikely(!__pyx_empty_tuple)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_empty_bytes = PyBytes_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_bytes)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  #ifdef __pyx_binding_PyCFunctionType_USED
  if (__pyx_binding_PyCFunctionType_init() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  #endif
  /*--- Library function declarations ---*/
  /*--- Threads initialization code ---*/
  #if defined(__PYX_FORCE_INIT_THREADS) && __PYX_FORCE_INIT_THREADS
  #ifdef WITH_THREAD /* Python build with threading support? */
  PyEval_InitThreads();
  #endif
  #endif
  /*--- Module creation code ---*/
  #if PY_MAJOR_VERSION < 3
  __pyx_m = Py_InitModule4(__Pyx_NAMESTR("_known_graph_pyx"), __pyx_methods, __Pyx_DOCSTR(__pyx_k_14), 0, PYTHON_API_VERSION);
  #else
  __pyx_m = PyModule_Create(&__pyx_moduledef);
  #endif
  if (!__pyx_m) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  #if PY_MAJOR_VERSION < 3
  Py_INCREF(__pyx_m);
  #endif
  __pyx_b = PyImport_AddModule(__Pyx_NAMESTR(__Pyx_BUILTIN_MODULE_NAME));
  if (!__pyx_b) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  if (__Pyx_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  /*--- Initialize various global constants etc. ---*/
  if (unlikely(__Pyx_InitGlobals() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_module_is_main_bzrlib___known_graph_pyx) {
    if (__Pyx_SetAttrString(__pyx_m, "__name__", __pyx_n_s____main__) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  }
  /*--- Builtin init code ---*/
  if (unlikely(__Pyx_InitCachedBuiltins() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  /*--- Constants init code ---*/
  if (unlikely(__Pyx_InitCachedConstants() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  /*--- Global init code ---*/
  __pyx_v_6bzrlib_16_known_graph_pyx_NULL_REVISION = Py_None; Py_INCREF(Py_None);
  /*--- Function export code ---*/
  /*--- Type init code ---*/
  __pyx_vtabptr_6bzrlib_16_known_graph_pyx__KnownGraphNode = &__pyx_vtable_6bzrlib_16_known_graph_pyx__KnownGraphNode;
  __pyx_vtable_6bzrlib_16_known_graph_pyx__KnownGraphNode.clear_references = (PyObject *(*)(struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *))__pyx_f_6bzrlib_16_known_graph_pyx_15_KnownGraphNode_clear_references;
  if (PyType_Ready(&__pyx_type_6bzrlib_16_known_graph_pyx__KnownGraphNode) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__Pyx_SetVtable(__pyx_type_6bzrlib_16_known_graph_pyx__KnownGraphNode.tp_dict, __pyx_vtabptr_6bzrlib_16_known_graph_pyx__KnownGraphNode) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__Pyx_SetAttrString(__pyx_m, "_KnownGraphNode", (PyObject *)&__pyx_type_6bzrlib_16_known_graph_pyx__KnownGraphNode) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_6bzrlib_16_known_graph_pyx__KnownGraphNode = &__pyx_type_6bzrlib_16_known_graph_pyx__KnownGraphNode;
  __pyx_vtabptr_6bzrlib_16_known_graph_pyx__MergeSorter = &__pyx_vtable_6bzrlib_16_known_graph_pyx__MergeSorter;
  __pyx_vtable_6bzrlib_16_known_graph_pyx__MergeSorter._get_ms_node = (struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *(*)(struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSorter *, struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *))__pyx_f_6bzrlib_16_known_graph_pyx_12_MergeSorter__get_ms_node;
  __pyx_vtable_6bzrlib_16_known_graph_pyx__MergeSorter._push_node = (PyObject *(*)(struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSorter *, struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *, long))__pyx_f_6bzrlib_16_known_graph_pyx_12_MergeSorter__push_node;
  __pyx_vtable_6bzrlib_16_known_graph_pyx__MergeSorter._pop_node = (PyObject *(*)(struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSorter *))__pyx_f_6bzrlib_16_known_graph_pyx_12_MergeSorter__pop_node;
  __pyx_vtable_6bzrlib_16_known_graph_pyx__MergeSorter._schedule_stack = (PyObject *(*)(struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSorter *))__pyx_f_6bzrlib_16_known_graph_pyx_12_MergeSorter__schedule_stack;
  __pyx_vtable_6bzrlib_16_known_graph_pyx__MergeSorter.topo_order = (PyObject *(*)(struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSorter *))__pyx_f_6bzrlib_16_known_graph_pyx_12_MergeSorter_topo_order;
  if (PyType_Ready(&__pyx_type_6bzrlib_16_known_graph_pyx__MergeSorter) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 724; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__Pyx_SetVtable(__pyx_type_6bzrlib_16_known_graph_pyx__MergeSorter.tp_dict, __pyx_vtabptr_6bzrlib_16_known_graph_pyx__MergeSorter) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 724; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__Pyx_SetAttrString(__pyx_m, "_MergeSorter", (PyObject *)&__pyx_type_6bzrlib_16_known_graph_pyx__MergeSorter) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 724; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_6bzrlib_16_known_graph_pyx__MergeSorter = &__pyx_type_6bzrlib_16_known_graph_pyx__MergeSorter;
  __pyx_vtabptr_6bzrlib_16_known_graph_pyx_KnownGraph = &__pyx_vtable_6bzrlib_16_known_graph_pyx_KnownGraph;
  __pyx_vtable_6bzrlib_16_known_graph_pyx_KnownGraph._get_or_create_node = (struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *(*)(struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *, PyObject *))__pyx_f_6bzrlib_16_known_graph_pyx_10KnownGraph__get_or_create_node;
  __pyx_vtable_6bzrlib_16_known_graph_pyx_KnownGraph._populate_parents = (PyObject *(*)(struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *, struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *, PyObject *))__pyx_f_6bzrlib_16_known_graph_pyx_10KnownGraph__populate_parents;
  if (PyType_Ready(&__pyx_type_6bzrlib_16_known_graph_pyx_KnownGraph) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 192; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  {
    PyObject *wrapper = __Pyx_GetAttrString((PyObject *)&__pyx_type_6bzrlib_16_known_graph_pyx_KnownGraph, "__init__"); if (unlikely(!wrapper)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 192; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (Py_TYPE(wrapper) == &PyWrapperDescr_Type) {
      __pyx_wrapperbase_6bzrlib_16_known_graph_pyx_10KnownGraph___init__ = *((PyWrapperDescrObject *)wrapper)->d_base;
      __pyx_wrapperbase_6bzrlib_16_known_graph_pyx_10KnownGraph___init__.doc = __pyx_doc_6bzrlib_16_known_graph_pyx_10KnownGraph___init__;
      ((PyWrapperDescrObject *)wrapper)->d_base = &__pyx_wrapperbase_6bzrlib_16_known_graph_pyx_10KnownGraph___init__;
    }
  }
  if (__Pyx_SetVtable(__pyx_type_6bzrlib_16_known_graph_pyx_KnownGraph.tp_dict, __pyx_vtabptr_6bzrlib_16_known_graph_pyx_KnownGraph) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 192; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__Pyx_SetAttrString(__pyx_m, "KnownGraph", (PyObject *)&__pyx_type_6bzrlib_16_known_graph_pyx_KnownGraph) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 192; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_6bzrlib_16_known_graph_pyx_KnownGraph = &__pyx_type_6bzrlib_16_known_graph_pyx_KnownGraph;
  __pyx_vtabptr_6bzrlib_16_known_graph_pyx__MergeSortNode = &__pyx_vtable_6bzrlib_16_known_graph_pyx__MergeSortNode;
  __pyx_vtable_6bzrlib_16_known_graph_pyx__MergeSortNode.has_pending_parents = (int (*)(struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *))__pyx_f_6bzrlib_16_known_graph_pyx_14_MergeSortNode_has_pending_parents;
  __pyx_vtable_6bzrlib_16_known_graph_pyx__MergeSortNode._revno = (PyObject *(*)(struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *))__pyx_f_6bzrlib_16_known_graph_pyx_14_MergeSortNode__revno;
  if (PyType_Ready(&__pyx_type_6bzrlib_16_known_graph_pyx__MergeSortNode) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 666; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__Pyx_SetVtable(__pyx_type_6bzrlib_16_known_graph_pyx__MergeSortNode.tp_dict, __pyx_vtabptr_6bzrlib_16_known_graph_pyx__MergeSortNode) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 666; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__Pyx_SetAttrString(__pyx_m, "_MergeSortNode", (PyObject *)&__pyx_type_6bzrlib_16_known_graph_pyx__MergeSortNode) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 666; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_6bzrlib_16_known_graph_pyx__MergeSortNode = &__pyx_type_6bzrlib_16_known_graph_pyx__MergeSortNode;
  /*--- Type import code ---*/
  /*--- Function import code ---*/
  /*--- Execution code ---*/

  /* "bzrlib/_known_graph_pyx.pyx":54
 *     void Py_INCREF(object)
 * 
 * from collections import deque             # <<<<<<<<<<<<<<
 * import gc
 * 
 */
  __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_1));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__deque));
  PyList_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_n_s__deque));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__deque));
  __pyx_t_2 = __Pyx_Import(((PyObject *)__pyx_n_s__collections), ((PyObject *)__pyx_t_1)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __pyx_t_1 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__deque); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__deque, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "bzrlib/_known_graph_pyx.pyx":55
 * 
 * from collections import deque
 * import gc             # <<<<<<<<<<<<<<
 * 
 * from bzrlib import errors, revision
 */
  __pyx_t_2 = __Pyx_Import(((PyObject *)__pyx_n_s__gc), 0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__gc, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "bzrlib/_known_graph_pyx.pyx":57
 * import gc
 * 
 * from bzrlib import errors, revision             # <<<<<<<<<<<<<<
 * 
 * cdef object NULL_REVISION
 */
  __pyx_t_2 = PyList_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_2));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__errors));
  PyList_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_n_s__errors));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__errors));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__revision));
  PyList_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_n_s__revision));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__revision));
  __pyx_t_1 = __Pyx_Import(((PyObject *)__pyx_n_s__bzrlib), ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__errors); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__errors, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__revision); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__revision, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "bzrlib/_known_graph_pyx.pyx":60
 * 
 * cdef object NULL_REVISION
 * NULL_REVISION = revision.NULL_REVISION             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__revision); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__NULL_REVISION); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_GOTREF(__pyx_v_6bzrlib_16_known_graph_pyx_NULL_REVISION);
  __Pyx_DECREF(__pyx_v_6bzrlib_16_known_graph_pyx_NULL_REVISION);
  __Pyx_GIVEREF(__pyx_t_2);
  __pyx_v_6bzrlib_16_known_graph_pyx_NULL_REVISION = __pyx_t_2;
  __pyx_t_2 = 0;

  /* "bzrlib/_known_graph_pyx.pyx":138
 * 
 * 
 * def get_key(node):             # <<<<<<<<<<<<<<
 *     cdef _KnownGraphNode real_node
 *     real_node = node
 */
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_6bzrlib_16_known_graph_pyx_get_key, NULL, __pyx_n_s_15); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 138; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__get_key, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 138; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "bzrlib/_known_graph_pyx.pyx":199
 *     cdef public int do_cache
 * 
 *     def __init__(self, parent_map, do_cache=True):             # <<<<<<<<<<<<<<
 *         """Create a new KnownGraph instance.
 * 
 */
  __pyx_t_2 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 199; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_k_4 = __pyx_t_2;
  __Pyx_GIVEREF(__pyx_t_2);
  __pyx_t_2 = 0;

  /* "bzrlib/_known_graph_pyx.pyx":1
 * # Copyright (C) 2009, 2010 Canonical Ltd             # <<<<<<<<<<<<<<
 * #
 * # This program is free software; you can redistribute it and/or modify
 */
  __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_2));
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s____test__, ((PyObject *)__pyx_t_2)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  if (__pyx_m) {
    __Pyx_AddTraceback("init bzrlib._known_graph_pyx");
    Py_DECREF(__pyx_m); __pyx_m = 0;
  } else if (!PyErr_Occurred()) {
    PyErr_SetString(PyExc_ImportError, "init bzrlib._known_graph_pyx");
  }
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  #if PY_MAJOR_VERSION < 3
  return;
  #else
  return __pyx_m;
  #endif
}

/* Runtime support code */

static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name) {
    PyObject *result;
    result = PyObject_GetAttr(dict, name);
    if (!result)
        PyErr_SetObject(PyExc_NameError, name);
    return result;
}

static void __Pyx_RaiseDoubleKeywordsError(
    const char* func_name,
    PyObject* kw_name)
{
    PyErr_Format(PyExc_TypeError,
        #if PY_MAJOR_VERSION >= 3
        "%s() got multiple values for keyword argument '%U'", func_name, kw_name);
        #else
        "%s() got multiple values for keyword argument '%s'", func_name,
        PyString_AS_STRING(kw_name));
        #endif
}

static int __Pyx_ParseOptionalKeywords(
    PyObject *kwds,
    PyObject **argnames[],
    PyObject *kwds2,
    PyObject *values[],
    Py_ssize_t num_pos_args,
    const char* function_name)
{
    PyObject *key = 0, *value = 0;
    Py_ssize_t pos = 0;
    PyObject*** name;
    PyObject*** first_kw_arg = argnames + num_pos_args;

    while (PyDict_Next(kwds, &pos, &key, &value)) {
        name = first_kw_arg;
        while (*name && (**name != key)) name++;
        if (*name) {
            values[name-argnames] = value;
        } else {
            #if PY_MAJOR_VERSION < 3
            if (unlikely(!PyString_CheckExact(key)) && unlikely(!PyString_Check(key))) {
            #else
            if (unlikely(!PyUnicode_CheckExact(key)) && unlikely(!PyUnicode_Check(key))) {
            #endif
                goto invalid_keyword_type;
            } else {
                for (name = first_kw_arg; *name; name++) {
                    #if PY_MAJOR_VERSION >= 3
                    if (PyUnicode_GET_SIZE(**name) == PyUnicode_GET_SIZE(key) &&
                        PyUnicode_Compare(**name, key) == 0) break;
                    #else
                    if (PyString_GET_SIZE(**name) == PyString_GET_SIZE(key) &&
                        _PyString_Eq(**name, key)) break;
                    #endif
                }
                if (*name) {
                    values[name-argnames] = value;
                } else {
                    /* unexpected keyword found */
                    for (name=argnames; name != first_kw_arg; name++) {
                        if (**name == key) goto arg_passed_twice;
                        #if PY_MAJOR_VERSION >= 3
                        if (PyUnicode_GET_SIZE(**name) == PyUnicode_GET_SIZE(key) &&
                            PyUnicode_Compare(**name, key) == 0) goto arg_passed_twice;
                        #else
                        if (PyString_GET_SIZE(**name) == PyString_GET_SIZE(key) &&
                            _PyString_Eq(**name, key)) goto arg_passed_twice;
                        #endif
                    }
                    if (kwds2) {
                        if (unlikely(PyDict_SetItem(kwds2, key, value))) goto bad;
                    } else {
                        goto invalid_keyword;
                    }
                }
            }
        }
    }
    return 0;
arg_passed_twice:
    __Pyx_RaiseDoubleKeywordsError(function_name, **name);
    goto bad;
invalid_keyword_type:
    PyErr_Format(PyExc_TypeError,
        "%s() keywords must be strings", function_name);
    goto bad;
invalid_keyword:
    PyErr_Format(PyExc_TypeError,
    #if PY_MAJOR_VERSION < 3
        "%s() got an unexpected keyword argument '%s'",
        function_name, PyString_AsString(key));
    #else
        "%s() got an unexpected keyword argument '%U'",
        function_name, key);
    #endif
bad:
    return -1;
}

static void __Pyx_RaiseArgtupleInvalid(
    const char* func_name,
    int exact,
    Py_ssize_t num_min,
    Py_ssize_t num_max,
    Py_ssize_t num_found)
{
    Py_ssize_t num_expected;
    const char *number, *more_or_less;

    if (num_found < num_min) {
        num_expected = num_min;
        more_or_less = "at least";
    } else {
        num_expected = num_max;
        more_or_less = "at most";
    }
    if (exact) {
        more_or_less = "exactly";
    }
    number = (num_expected == 1) ? "" : "s";
    PyErr_Format(PyExc_TypeError,
        #if PY_VERSION_HEX < 0x02050000
            "%s() takes %s %d positional argument%s (%d given)",
        #else
            "%s() takes %s %zd positional argument%s (%zd given)",
        #endif
        func_name, more_or_less, num_expected, number, num_found);
}

static CYTHON_INLINE int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type) {
    if (unlikely(!type)) {
        PyErr_Format(PyExc_SystemError, "Missing type object");
        return 0;
    }
    if (likely(PyObject_TypeCheck(obj, type)))
        return 1;
    PyErr_Format(PyExc_TypeError, "Cannot convert %.200s to %.200s",
                 Py_TYPE(obj)->tp_name, type->tp_name);
    return 0;
}

static CYTHON_INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *value, PyObject *tb) {
    PyObject *tmp_type, *tmp_value, *tmp_tb;
    PyThreadState *tstate = PyThreadState_GET();

    tmp_type = tstate->curexc_type;
    tmp_value = tstate->curexc_value;
    tmp_tb = tstate->curexc_traceback;
    tstate->curexc_type = type;
    tstate->curexc_value = value;
    tstate->curexc_traceback = tb;
    Py_XDECREF(tmp_type);
    Py_XDECREF(tmp_value);
    Py_XDECREF(tmp_tb);
}

static CYTHON_INLINE void __Pyx_ErrFetch(PyObject **type, PyObject **value, PyObject **tb) {
    PyThreadState *tstate = PyThreadState_GET();
    *type = tstate->curexc_type;
    *value = tstate->curexc_value;
    *tb = tstate->curexc_traceback;

    tstate->curexc_type = 0;
    tstate->curexc_value = 0;
    tstate->curexc_traceback = 0;
}


#if PY_MAJOR_VERSION < 3
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 {
                type = 0;
                PyErr_SetString(PyExc_TypeError,
                    "raise: exception must be an old-style class or instance");
                goto raise_error;
            }
        #else
            type = (PyObject*) Py_TYPE(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
    }

    __Pyx_ErrRestore(type, value, tb);
    return;
raise_error:
    Py_XDECREF(value);
    Py_XDECREF(type);
    Py_XDECREF(tb);
    return;
}

#else /* Python 3+ */

static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb) {
    if (tb == Py_None) {
        tb = 0;
    } else if (tb && !PyTraceBack_Check(tb)) {
        PyErr_SetString(PyExc_TypeError,
            "raise: arg 3 must be a traceback or None");
        goto bad;
    }
    if (value == Py_None)
        value = 0;

    if (PyExceptionInstance_Check(type)) {
        if (value) {
            PyErr_SetString(PyExc_TypeError,
                "instance exception may not have a separate value");
            goto bad;
        }
        value = type;
        type = (PyObject*) Py_TYPE(value);
    } else if (!PyExceptionClass_Check(type)) {
        PyErr_SetString(PyExc_TypeError,
            "raise: exception class must be a subclass of BaseException");
        goto bad;
    }

    PyErr_SetObject(type, value);

    if (tb) {
        PyThreadState *tstate = PyThreadState_GET();
        PyObject* tmp_tb = tstate->curexc_traceback;
        if (tb != tmp_tb) {
            Py_INCREF(tb);
            tstate->curexc_traceback = tb;
            Py_XDECREF(tmp_tb);
        }
    }

bad:
    return;
}
#endif


static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list) {
    PyObject *py_import = 0;
    PyObject *empty_list = 0;
    PyObject *module = 0;
    PyObject *global_dict = 0;
    PyObject *empty_dict = 0;
    PyObject *list;
    py_import = __Pyx_GetAttrString(__pyx_b, "__import__");
    if (!py_import)
        goto bad;
    if (from_list)
        list = from_list;
    else {
        empty_list = PyList_New(0);
        if (!empty_list)
            goto bad;
        list = empty_list;
    }
    global_dict = PyModule_GetDict(__pyx_m);
    if (!global_dict)
        goto bad;
    empty_dict = PyDict_New();
    if (!empty_dict)
        goto bad;
    module = PyObject_CallFunctionObjArgs(py_import,
        name, global_dict, empty_dict, list, NULL);
bad:
    Py_XDECREF(empty_list);
    Py_XDECREF(py_import);
    Py_XDECREF(empty_dict);
    return module;
}

static CYTHON_INLINE unsigned char __Pyx_PyInt_AsUnsignedChar(PyObject* x) {
    const unsigned char neg_one = (unsigned char)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(unsigned char) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(unsigned char)val)) {
            if (!unlikely(val == -1 && PyErr_Occurred())) {
                PyErr_SetString(PyExc_OverflowError,
                    (is_unsigned && unlikely(val < 0)) ?
                    "can't convert negative value to unsigned char" :
                    "value too large to convert to unsigned char");
            }
            return (unsigned char)-1;
        }
        return (unsigned char)val;
    }
    return (unsigned char)__Pyx_PyInt_AsUnsignedLong(x);
}

static CYTHON_INLINE unsigned short __Pyx_PyInt_AsUnsignedShort(PyObject* x) {
    const unsigned short neg_one = (unsigned short)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(unsigned short) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(unsigned short)val)) {
            if (!unlikely(val == -1 && PyErr_Occurred())) {
                PyErr_SetString(PyExc_OverflowError,
                    (is_unsigned && unlikely(val < 0)) ?
                    "can't convert negative value to unsigned short" :
                    "value too large to convert to unsigned short");
            }
            return (unsigned short)-1;
        }
        return (unsigned short)val;
    }
    return (unsigned short)__Pyx_PyInt_AsUnsignedLong(x);
}

static CYTHON_INLINE unsigned int __Pyx_PyInt_AsUnsignedInt(PyObject* x) {
    const unsigned int neg_one = (unsigned int)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(unsigned int) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(unsigned int)val)) {
            if (!unlikely(val == -1 && PyErr_Occurred())) {
                PyErr_SetString(PyExc_OverflowError,
                    (is_unsigned && unlikely(val < 0)) ?
                    "can't convert negative value to unsigned int" :
                    "value too large to convert to unsigned int");
            }
            return (unsigned int)-1;
        }
        return (unsigned int)val;
    }
    return (unsigned int)__Pyx_PyInt_AsUnsignedLong(x);
}

static CYTHON_INLINE char __Pyx_PyInt_AsChar(PyObject* x) {
    const char neg_one = (char)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(char) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(char)val)) {
            if (!unlikely(val == -1 && PyErr_Occurred())) {
                PyErr_SetString(PyExc_OverflowError,
                    (is_unsigned && unlikely(val < 0)) ?
                    "can't convert negative value to char" :
                    "value too large to convert to char");
            }
            return (char)-1;
        }
        return (char)val;
    }
    return (char)__Pyx_PyInt_AsLong(x);
}

static CYTHON_INLINE short __Pyx_PyInt_AsShort(PyObject* x) {
    const short neg_one = (short)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(short) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(short)val)) {
            if (!unlikely(val == -1 && PyErr_Occurred())) {
                PyErr_SetString(PyExc_OverflowError,
                    (is_unsigned && unlikely(val < 0)) ?
                    "can't convert negative value to short" :
                    "value too large to convert to short");
            }
            return (short)-1;
        }
        return (short)val;
    }
    return (short)__Pyx_PyInt_AsLong(x);
}

static CYTHON_INLINE int __Pyx_PyInt_AsInt(PyObject* x) {
    const int neg_one = (int)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(int) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(int)val)) {
            if (!unlikely(val == -1 && PyErr_Occurred())) {
                PyErr_SetString(PyExc_OverflowError,
                    (is_unsigned && unlikely(val < 0)) ?
                    "can't convert negative value to int" :
                    "value too large to convert to int");
            }
            return (int)-1;
        }
        return (int)val;
    }
    return (int)__Pyx_PyInt_AsLong(x);
}

static CYTHON_INLINE signed char __Pyx_PyInt_AsSignedChar(PyObject* x) {
    const signed char neg_one = (signed char)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(signed char) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(signed char)val)) {
            if (!unlikely(val == -1 && PyErr_Occurred())) {
                PyErr_SetString(PyExc_OverflowError,
                    (is_unsigned && unlikely(val < 0)) ?
                    "can't convert negative value to signed char" :
                    "value too large to convert to signed char");
            }
            return (signed char)-1;
        }
        return (signed char)val;
    }
    return (signed char)__Pyx_PyInt_AsSignedLong(x);
}

static CYTHON_INLINE signed short __Pyx_PyInt_AsSignedShort(PyObject* x) {
    const signed short neg_one = (signed short)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(signed short) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(signed short)val)) {
            if (!unlikely(val == -1 && PyErr_Occurred())) {
                PyErr_SetString(PyExc_OverflowError,
                    (is_unsigned && unlikely(val < 0)) ?
                    "can't convert negative value to signed short" :
                    "value too large to convert to signed short");
            }
            return (signed short)-1;
        }
        return (signed short)val;
    }
    return (signed short)__Pyx_PyInt_AsSignedLong(x);
}

static CYTHON_INLINE signed int __Pyx_PyInt_AsSignedInt(PyObject* x) {
    const signed int neg_one = (signed int)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(signed int) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(signed int)val)) {
            if (!unlikely(val == -1 && PyErr_Occurred())) {
                PyErr_SetString(PyExc_OverflowError,
                    (is_unsigned && unlikely(val < 0)) ?
                    "can't convert negative value to signed int" :
                    "value too large to convert to signed int");
            }
            return (signed int)-1;
        }
        return (signed int)val;
    }
    return (signed int)__Pyx_PyInt_AsSignedLong(x);
}

static CYTHON_INLINE int __Pyx_PyInt_AsLongDouble(PyObject* x) {
    const int neg_one = (int)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(int) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(int)val)) {
            if (!unlikely(val == -1 && PyErr_Occurred())) {
                PyErr_SetString(PyExc_OverflowError,
                    (is_unsigned && unlikely(val < 0)) ?
                    "can't convert negative value to int" :
                    "value too large to convert to int");
            }
            return (int)-1;
        }
        return (int)val;
    }
    return (int)__Pyx_PyInt_AsLong(x);
}

static CYTHON_INLINE unsigned long __Pyx_PyInt_AsUnsignedLong(PyObject* x) {
    const unsigned long neg_one = (unsigned long)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
#if PY_VERSION_HEX < 0x03000000
    if (likely(PyInt_Check(x))) {
        long val = PyInt_AS_LONG(x);
        if (is_unsigned && unlikely(val < 0)) {
            PyErr_SetString(PyExc_OverflowError,
                            "can't convert negative value to unsigned long");
            return (unsigned long)-1;
        }
        return (unsigned long)val;
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
            if (unlikely(Py_SIZE(x) < 0)) {
                PyErr_SetString(PyExc_OverflowError,
                                "can't convert negative value to unsigned long");
                return (unsigned long)-1;
            }
            return PyLong_AsUnsignedLong(x);
        } else {
            return PyLong_AsLong(x);
        }
    } else {
        unsigned long val;
        PyObject *tmp = __Pyx_PyNumber_Int(x);
        if (!tmp) return (unsigned long)-1;
        val = __Pyx_PyInt_AsUnsignedLong(tmp);
        Py_DECREF(tmp);
        return val;
    }
}

static CYTHON_INLINE unsigned PY_LONG_LONG __Pyx_PyInt_AsUnsignedLongLong(PyObject* x) {
    const unsigned PY_LONG_LONG neg_one = (unsigned PY_LONG_LONG)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
#if PY_VERSION_HEX < 0x03000000
    if (likely(PyInt_Check(x))) {
        long val = PyInt_AS_LONG(x);
        if (is_unsigned && unlikely(val < 0)) {
            PyErr_SetString(PyExc_OverflowError,
                            "can't convert negative value to unsigned PY_LONG_LONG");
            return (unsigned PY_LONG_LONG)-1;
        }
        return (unsigned PY_LONG_LONG)val;
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
            if (unlikely(Py_SIZE(x) < 0)) {
                PyErr_SetString(PyExc_OverflowError,
                                "can't convert negative value to unsigned PY_LONG_LONG");
                return (unsigned PY_LONG_LONG)-1;
            }
            return PyLong_AsUnsignedLongLong(x);
        } else {
            return PyLong_AsLongLong(x);
        }
    } else {
        unsigned PY_LONG_LONG val;
        PyObject *tmp = __Pyx_PyNumber_Int(x);
        if (!tmp) return (unsigned PY_LONG_LONG)-1;
        val = __Pyx_PyInt_AsUnsignedLongLong(tmp);
        Py_DECREF(tmp);
        return val;
    }
}

static CYTHON_INLINE long __Pyx_PyInt_AsLong(PyObject* x) {
    const long neg_one = (long)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
#if PY_VERSION_HEX < 0x03000000
    if (likely(PyInt_Check(x))) {
        long val = PyInt_AS_LONG(x);
        if (is_unsigned && unlikely(val < 0)) {
            PyErr_SetString(PyExc_OverflowError,
                            "can't convert negative value to long");
            return (long)-1;
        }
        return (long)val;
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
            if (unlikely(Py_SIZE(x) < 0)) {
                PyErr_SetString(PyExc_OverflowError,
                                "can't convert negative value to long");
                return (long)-1;
            }
            return PyLong_AsUnsignedLong(x);
        } else {
            return PyLong_AsLong(x);
        }
    } else {
        long val;
        PyObject *tmp = __Pyx_PyNumber_Int(x);
        if (!tmp) return (long)-1;
        val = __Pyx_PyInt_AsLong(tmp);
        Py_DECREF(tmp);
        return val;
    }
}

static CYTHON_INLINE PY_LONG_LONG __Pyx_PyInt_AsLongLong(PyObject* x) {
    const PY_LONG_LONG neg_one = (PY_LONG_LONG)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
#if PY_VERSION_HEX < 0x03000000
    if (likely(PyInt_Check(x))) {
        long val = PyInt_AS_LONG(x);
        if (is_unsigned && unlikely(val < 0)) {
            PyErr_SetString(PyExc_OverflowError,
                            "can't convert negative value to PY_LONG_LONG");
            return (PY_LONG_LONG)-1;
        }
        return (PY_LONG_LONG)val;
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
            if (unlikely(Py_SIZE(x) < 0)) {
                PyErr_SetString(PyExc_OverflowError,
                                "can't convert negative value to PY_LONG_LONG");
                return (PY_LONG_LONG)-1;
            }
            return PyLong_AsUnsignedLongLong(x);
        } else {
            return PyLong_AsLongLong(x);
        }
    } else {
        PY_LONG_LONG val;
        PyObject *tmp = __Pyx_PyNumber_Int(x);
        if (!tmp) return (PY_LONG_LONG)-1;
        val = __Pyx_PyInt_AsLongLong(tmp);
        Py_DECREF(tmp);
        return val;
    }
}

static CYTHON_INLINE signed long __Pyx_PyInt_AsSignedLong(PyObject* x) {
    const signed long neg_one = (signed long)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
#if PY_VERSION_HEX < 0x03000000
    if (likely(PyInt_Check(x))) {
        long val = PyInt_AS_LONG(x);
        if (is_unsigned && unlikely(val < 0)) {
            PyErr_SetString(PyExc_OverflowError,
                            "can't convert negative value to signed long");
            return (signed long)-1;
        }
        return (signed long)val;
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
            if (unlikely(Py_SIZE(x) < 0)) {
                PyErr_SetString(PyExc_OverflowError,
                                "can't convert negative value to signed long");
                return (signed long)-1;
            }
            return PyLong_AsUnsignedLong(x);
        } else {
            return PyLong_AsLong(x);
        }
    } else {
        signed long val;
        PyObject *tmp = __Pyx_PyNumber_Int(x);
        if (!tmp) return (signed long)-1;
        val = __Pyx_PyInt_AsSignedLong(tmp);
        Py_DECREF(tmp);
        return val;
    }
}

static CYTHON_INLINE signed PY_LONG_LONG __Pyx_PyInt_AsSignedLongLong(PyObject* x) {
    const signed PY_LONG_LONG neg_one = (signed PY_LONG_LONG)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
#if PY_VERSION_HEX < 0x03000000
    if (likely(PyInt_Check(x))) {
        long val = PyInt_AS_LONG(x);
        if (is_unsigned && unlikely(val < 0)) {
            PyErr_SetString(PyExc_OverflowError,
                            "can't convert negative value to signed PY_LONG_LONG");
            return (signed PY_LONG_LONG)-1;
        }
        return (signed PY_LONG_LONG)val;
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
            if (unlikely(Py_SIZE(x) < 0)) {
                PyErr_SetString(PyExc_OverflowError,
                                "can't convert negative value to signed PY_LONG_LONG");
                return (signed PY_LONG_LONG)-1;
            }
            return PyLong_AsUnsignedLongLong(x);
        } else {
            return PyLong_AsLongLong(x);
        }
    } else {
        signed PY_LONG_LONG val;
        PyObject *tmp = __Pyx_PyNumber_Int(x);
        if (!tmp) return (signed PY_LONG_LONG)-1;
        val = __Pyx_PyInt_AsSignedLongLong(tmp);
        Py_DECREF(tmp);
        return val;
    }
}

static void __Pyx_WriteUnraisable(const char *name) {
    PyObject *old_exc, *old_val, *old_tb;
    PyObject *ctx;
    __Pyx_ErrFetch(&old_exc, &old_val, &old_tb);
    #if PY_MAJOR_VERSION < 3
    ctx = PyString_FromString(name);
    #else
    ctx = PyUnicode_FromString(name);
    #endif
    __Pyx_ErrRestore(old_exc, old_val, old_tb);
    if (!ctx) {
        PyErr_WriteUnraisable(Py_None);
    } else {
        PyErr_WriteUnraisable(ctx);
        Py_DECREF(ctx);
    }
}

static int __Pyx_SetVtable(PyObject *dict, void *vtable) {
#if PY_VERSION_HEX >= 0x02070000 && !(PY_MAJOR_VERSION==3&&PY_MINOR_VERSION==0)
    PyObject *ob = PyCapsule_New(vtable, 0, 0);
#else
    PyObject *ob = PyCObject_FromVoidPtr(vtable, 0);
#endif
    if (!ob)
        goto bad;
    if (PyDict_SetItemString(dict, "__pyx_vtable__", ob) < 0)
        goto bad;
    Py_DECREF(ob);
    return 0;
bad:
    Py_XDECREF(ob);
    return -1;
}

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

static void __Pyx_AddTraceback(const char *funcname) {
    PyObject *py_srcfile = 0;
    PyObject *py_funcname = 0;
    PyObject *py_globals = 0;
    PyCodeObject *py_code = 0;
    PyFrameObject *py_frame = 0;

    #if PY_MAJOR_VERSION < 3
    py_srcfile = PyString_FromString(__pyx_filename);
    #else
    py_srcfile = PyUnicode_FromString(__pyx_filename);
    #endif
    if (!py_srcfile) goto bad;
    if (__pyx_clineno) {
        #if PY_MAJOR_VERSION < 3
        py_funcname = PyString_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, __pyx_clineno);
        #else
        py_funcname = PyUnicode_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, __pyx_clineno);
        #endif
    }
    else {
        #if PY_MAJOR_VERSION < 3
        py_funcname = PyString_FromString(funcname);
        #else
        py_funcname = PyUnicode_FromString(funcname);
        #endif
    }
    if (!py_funcname) goto bad;
    py_globals = PyModule_GetDict(__pyx_m);
    if (!py_globals) goto bad;
    py_code = PyCode_New(
        0,            /*int argcount,*/
        #if PY_MAJOR_VERSION >= 3
        0,            /*int kwonlyargcount,*/
        #endif
        0,            /*int nlocals,*/
        0,            /*int stacksize,*/
        0,            /*int flags,*/
        __pyx_empty_bytes, /*PyObject *code,*/
        __pyx_empty_tuple,  /*PyObject *consts,*/
        __pyx_empty_tuple,  /*PyObject *names,*/
        __pyx_empty_tuple,  /*PyObject *varnames,*/
        __pyx_empty_tuple,  /*PyObject *freevars,*/
        __pyx_empty_tuple,  /*PyObject *cellvars,*/
        py_srcfile,   /*PyObject *filename,*/
        py_funcname,  /*PyObject *name,*/
        __pyx_lineno,   /*int firstlineno,*/
        __pyx_empty_bytes  /*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(py_code);
    Py_XDECREF(py_frame);
}

static int __Pyx_InitStrings(__Pyx_StringTabEntry *t) {
    while (t->p) {
        #if PY_MAJOR_VERSION < 3
        if (t->is_unicode) {
            *t->p = PyUnicode_DecodeUTF8(t->s, t->n - 1, NULL);
        } else if (t->intern) {
            *t->p = PyString_InternFromString(t->s);
        } else {
            *t->p = PyString_FromStringAndSize(t->s, t->n - 1);
        }
        #else  /* Python 3+ has unicode identifiers */
        if (t->is_unicode | t->is_str) {
            if (t->intern) {
                *t->p = PyUnicode_InternFromString(t->s);
            } else if (t->encoding) {
                *t->p = PyUnicode_Decode(t->s, t->n - 1, t->encoding, NULL);
            } else {
                *t->p = PyUnicode_FromStringAndSize(t->s, t->n - 1);
            }
        } else {
            *t->p = PyBytes_FromStringAndSize(t->s, t->n - 1);
        }
        #endif
        if (!*t->p)
            return -1;
        ++t;
    }
    return 0;
}

/* Type Conversion Functions */

static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject* x) {
   int is_true = x == Py_True;
   if (is_true | (x == Py_False) | (x == Py_None)) return is_true;
   else return PyObject_IsTrue(x);
}

static CYTHON_INLINE PyObject* __Pyx_PyNumber_Int(PyObject* x) {
  PyNumberMethods *m;
  const char *name = NULL;
  PyObject *res = NULL;
#if PY_VERSION_HEX < 0x03000000
  if (PyInt_Check(x) || PyLong_Check(x))
#else
  if (PyLong_Check(x))
#endif
    return Py_INCREF(x), x;
  m = Py_TYPE(x)->tp_as_number;
#if PY_VERSION_HEX < 0x03000000
  if (m && m->nb_int) {
    name = "int";
    res = PyNumber_Int(x);
  }
  else if (m && m->nb_long) {
    name = "long";
    res = PyNumber_Long(x);
  }
#else
  if (m && m->nb_int) {
    name = "int";
    res = PyNumber_Long(x);
  }
#endif
  if (res) {
#if PY_VERSION_HEX < 0x03000000
    if (!PyInt_Check(res) && !PyLong_Check(res)) {
#else
    if (!PyLong_Check(res)) {
#endif
      PyErr_Format(PyExc_TypeError,
                   "__%s__ returned non-%s (type %.200s)",
                   name, name, Py_TYPE(res)->tp_name);
      Py_DECREF(res);
      return NULL;
    }
  }
  else if (!PyErr_Occurred()) {
    PyErr_SetString(PyExc_TypeError,
                    "an integer is required");
  }
  return res;
}

static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject* b) {
  Py_ssize_t ival;
  PyObject* x = PyNumber_Index(b);
  if (!x) return -1;
  ival = PyInt_AsSsize_t(x);
  Py_DECREF(x);
  return ival;
}

static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t ival) {
#if PY_VERSION_HEX < 0x02050000
   if (ival <= LONG_MAX)
       return PyInt_FromLong((long)ival);
   else {
       unsigned char *bytes = (unsigned char *) &ival;
       int one = 1; int little = (int)*(unsigned char*)&one;
       return _PyLong_FromByteArray(bytes, sizeof(size_t), little, 0);
   }
#else
   return PyInt_FromSize_t(ival);
#endif
}

static CYTHON_INLINE size_t __Pyx_PyInt_AsSize_t(PyObject* x) {
   unsigned PY_LONG_LONG val = __Pyx_PyInt_AsUnsignedLongLong(x);
   if (unlikely(val == (unsigned PY_LONG_LONG)-1 && PyErr_Occurred())) {
       return (size_t)-1;
   } else if (unlikely(val != (unsigned PY_LONG_LONG)(size_t)val)) {
       PyErr_SetString(PyExc_OverflowError,
                       "value too large to convert to size_t");
       return (size_t)-1;
   }
   return (size_t)val;
}


#endif /* Py_PYTHON_H */
