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

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


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

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

static char __pyx_mdoc[] = "Implementation of Graph algorithms when we have already loaded everything.\n";

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

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

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

static PyObject *__Pyx_GetItemInt(PyObject *o, Py_ssize_t i); /*proto*/

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

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

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

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

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

/* Declarations from bzrlib._known_graph_pyx */


/* Declarations from implementation of bzrlib._known_graph_pyx */

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;
};

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;
};

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;
};

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;
};


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;


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;


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;


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;

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;
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*/

static char __pyx_k1[] = "append";
static char __pyx_k2[] = "%s(%s  gdfo:%s par:%s child:%s)";
static char __pyx_k3[] = "__class__";
static char __pyx_k4[] = "__name__";
static char __pyx_k5[] = "lst_or_tpl must be a list or tuple.";
static char __pyx_k6[] = "sort";
static char __pyx_k7[] = "key";
static char __pyx_k8[] = "get_key";
static char __pyx_k9[] = "reverse";
static char __pyx_k10[] = "_initialize_nodes";
static char __pyx_k11[] = "_find_gdfo";
static char __pyx_k12[] = "parent_map should be a dict of {key:parent_keys}";
static char __pyx_k13[] = "_find_tails";
static char __pyx_k14[] = "clear";
static char __pyx_k15[] = "Parent key mismatch, existing node %s has parents of %s not %s";
static char __pyx_k16[] = "deque";
static char __pyx_k17[] = "popleft";
static char __pyx_k18[] = "frozenset";
static char __pyx_k19[] = "key %s not in nodes";
static char __pyx_k20[] = "pop";
static char __pyx_k21[] = "extend";
static char __pyx_k22[] = "errors";
static char __pyx_k23[] = "GraphCycleError";
static char __pyx_k24[] = "_find_tips";
static char __pyx_k25[] = "";
static char __pyx_k26[] = "sorted";
static char __pyx_k27[] = "parent_keys";
static char __pyx_k28[] = "child_keys";
static char __pyx_k29[] = "%s(%s depth:%s rev:%s,%s,%s first:%s seen:%s)";
static char __pyx_k30[] = "Something wrong with: %s";
static char __pyx_k31[] = "ghost nodes should not be pushed onto the stack: %s";
static char __pyx_k32[] = "collections";
static char __pyx_k33[] = "gc";
static char __pyx_k34[] = "bzrlib";
static char __pyx_k35[] = "revision";
static char __pyx_k36[] = "NULL_REVISION";

static PyObject *__pyx_n_GraphCycleError;
static PyObject *__pyx_n_NULL_REVISION;
static PyObject *__pyx_n___class__;
static PyObject *__pyx_n___name__;
static PyObject *__pyx_n__find_gdfo;
static PyObject *__pyx_n__find_tails;
static PyObject *__pyx_n__find_tips;
static PyObject *__pyx_n__initialize_nodes;
static PyObject *__pyx_n_append;
static PyObject *__pyx_n_bzrlib;
static PyObject *__pyx_n_child_keys;
static PyObject *__pyx_n_clear;
static PyObject *__pyx_n_collections;
static PyObject *__pyx_n_deque;
static PyObject *__pyx_n_errors;
static PyObject *__pyx_n_extend;
static PyObject *__pyx_n_frozenset;
static PyObject *__pyx_n_gc;
static PyObject *__pyx_n_get_key;
static PyObject *__pyx_n_key;
static PyObject *__pyx_n_parent_keys;
static PyObject *__pyx_n_pop;
static PyObject *__pyx_n_popleft;
static PyObject *__pyx_n_reverse;
static PyObject *__pyx_n_revision;
static PyObject *__pyx_n_sort;
static PyObject *__pyx_n_sorted;

static PyObject *__pyx_k2p;
static PyObject *__pyx_k5p;
static PyObject *__pyx_k12p;
static PyObject *__pyx_k15p;
static PyObject *__pyx_k19p;
static PyObject *__pyx_k25p;
static PyObject *__pyx_k29p;
static PyObject *__pyx_k30p;
static PyObject *__pyx_k31p;

static __Pyx_StringTabEntry __pyx_string_tab[] = {
  {&__pyx_n_GraphCycleError, 1, __pyx_k23, sizeof(__pyx_k23)},
  {&__pyx_n_NULL_REVISION, 1, __pyx_k36, sizeof(__pyx_k36)},
  {&__pyx_n___class__, 1, __pyx_k3, sizeof(__pyx_k3)},
  {&__pyx_n___name__, 1, __pyx_k4, sizeof(__pyx_k4)},
  {&__pyx_n__find_gdfo, 1, __pyx_k11, sizeof(__pyx_k11)},
  {&__pyx_n__find_tails, 1, __pyx_k13, sizeof(__pyx_k13)},
  {&__pyx_n__find_tips, 1, __pyx_k24, sizeof(__pyx_k24)},
  {&__pyx_n__initialize_nodes, 1, __pyx_k10, sizeof(__pyx_k10)},
  {&__pyx_n_append, 1, __pyx_k1, sizeof(__pyx_k1)},
  {&__pyx_n_bzrlib, 1, __pyx_k34, sizeof(__pyx_k34)},
  {&__pyx_n_child_keys, 1, __pyx_k28, sizeof(__pyx_k28)},
  {&__pyx_n_clear, 1, __pyx_k14, sizeof(__pyx_k14)},
  {&__pyx_n_collections, 1, __pyx_k32, sizeof(__pyx_k32)},
  {&__pyx_n_deque, 1, __pyx_k16, sizeof(__pyx_k16)},
  {&__pyx_n_errors, 1, __pyx_k22, sizeof(__pyx_k22)},
  {&__pyx_n_extend, 1, __pyx_k21, sizeof(__pyx_k21)},
  {&__pyx_n_frozenset, 1, __pyx_k18, sizeof(__pyx_k18)},
  {&__pyx_n_gc, 1, __pyx_k33, sizeof(__pyx_k33)},
  {&__pyx_n_get_key, 1, __pyx_k8, sizeof(__pyx_k8)},
  {&__pyx_n_key, 1, __pyx_k7, sizeof(__pyx_k7)},
  {&__pyx_n_parent_keys, 1, __pyx_k27, sizeof(__pyx_k27)},
  {&__pyx_n_pop, 1, __pyx_k20, sizeof(__pyx_k20)},
  {&__pyx_n_popleft, 1, __pyx_k17, sizeof(__pyx_k17)},
  {&__pyx_n_reverse, 1, __pyx_k9, sizeof(__pyx_k9)},
  {&__pyx_n_revision, 1, __pyx_k35, sizeof(__pyx_k35)},
  {&__pyx_n_sort, 1, __pyx_k6, sizeof(__pyx_k6)},
  {&__pyx_n_sorted, 1, __pyx_k26, sizeof(__pyx_k26)},
  {&__pyx_k2p, 0, __pyx_k2, sizeof(__pyx_k2)},
  {&__pyx_k5p, 0, __pyx_k5, sizeof(__pyx_k5)},
  {&__pyx_k12p, 0, __pyx_k12, sizeof(__pyx_k12)},
  {&__pyx_k15p, 0, __pyx_k15, sizeof(__pyx_k15)},
  {&__pyx_k19p, 0, __pyx_k19, sizeof(__pyx_k19)},
  {&__pyx_k25p, 0, __pyx_k25, sizeof(__pyx_k25)},
  {&__pyx_k29p, 0, __pyx_k29, sizeof(__pyx_k29)},
  {&__pyx_k30p, 0, __pyx_k30, sizeof(__pyx_k30)},
  {&__pyx_k31p, 0, __pyx_k31, sizeof(__pyx_k31)},
  {0, 0, 0, 0}
};

static PyObject *__pyx_d1;


/* Implementation of bzrlib._known_graph_pyx */

static int __pyx_f_6bzrlib_16_known_graph_pyx_15_KnownGraphNode___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_f_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_1 = 0;
  static char *__pyx_argnames[] = {"key",0};
  if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "O", __pyx_argnames, &__pyx_v_key)) return -1;
  Py_INCREF(__pyx_v_self);
  Py_INCREF(__pyx_v_key);

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":74 */
  Py_INCREF(__pyx_v_key);
  Py_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;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":75 */
  Py_INCREF(Py_None);
  Py_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;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":77 */
  __pyx_1 = PyList_New(0); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 77; goto __pyx_L1;}
  Py_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 = __pyx_1;
  __pyx_1 = 0;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":79 */
  ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_v_self)->gdfo = (-1);

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":80 */
  ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_v_self)->seen = 0;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":81 */
  Py_INCREF(Py_None);
  Py_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:;
  Py_XDECREF(__pyx_1);
  __Pyx_AddTraceback("bzrlib._known_graph_pyx._KnownGraphNode.__init__");
  __pyx_r = -1;
  __pyx_L0:;
  Py_DECREF(__pyx_v_self);
  Py_DECREF(__pyx_v_key);
  return __pyx_r;
}

static PyObject *__pyx_f_6bzrlib_16_known_graph_pyx_15_KnownGraphNode_10child_keys___get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_f_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;
  PyObject *__pyx_1 = 0;
  PyObject *__pyx_2 = 0;
  int __pyx_3;
  Py_INCREF(__pyx_v_self);
  __pyx_v_child = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)Py_None); Py_INCREF(Py_None);
  __pyx_v_keys = Py_None; Py_INCREF(Py_None);

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":87 */
  __pyx_1 = PyList_New(0); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 87; goto __pyx_L1;}
  Py_DECREF(__pyx_v_keys);
  __pyx_v_keys = __pyx_1;
  __pyx_1 = 0;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":88 */
  __pyx_1 = PyObject_GetIter(((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_v_self)->children); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 88; goto __pyx_L1;}
  for (;;) {
    __pyx_2 = PyIter_Next(__pyx_1);
    if (!__pyx_2) {
      if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 88; goto __pyx_L1;}
      break;
    }
    if (!__Pyx_TypeTest(__pyx_2, __pyx_ptype_6bzrlib_16_known_graph_pyx__KnownGraphNode)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 88; goto __pyx_L1;}
    Py_DECREF(((PyObject *)__pyx_v_child));
    __pyx_v_child = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_2);
    __pyx_2 = 0;
    __pyx_3 = PyList_Append(__pyx_v_keys,__pyx_v_child->key); if (__pyx_3 == (-1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 89; goto __pyx_L1;}
  }
  Py_DECREF(__pyx_1); __pyx_1 = 0;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":90 */
  Py_INCREF(__pyx_v_keys);
  __pyx_r = __pyx_v_keys;
  goto __pyx_L0;

  __pyx_r = Py_None; Py_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_1);
  Py_XDECREF(__pyx_2);
  __Pyx_AddTraceback("bzrlib._known_graph_pyx._KnownGraphNode.child_keys.__get__");
  __pyx_r = 0;
  __pyx_L0:;
  Py_DECREF(__pyx_v_child);
  Py_DECREF(__pyx_v_keys);
  Py_DECREF(__pyx_v_self);
  return __pyx_r;
}

static PyObject *__pyx_f_6bzrlib_16_known_graph_pyx_15_KnownGraphNode_11parent_keys___get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_f_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;
  int __pyx_1;
  PyObject *__pyx_2 = 0;
  PyObject *__pyx_3 = 0;
  Py_INCREF(__pyx_v_self);
  __pyx_v_parent = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)Py_None); Py_INCREF(Py_None);
  __pyx_v_keys = Py_None; Py_INCREF(Py_None);

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":94 */
  __pyx_1 = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_v_self)->parents == Py_None;
  if (__pyx_1) {
    Py_INCREF(Py_None);
    __pyx_r = Py_None;
    goto __pyx_L0;
    goto __pyx_L2;
  }
  __pyx_L2:;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":99 */
  __pyx_2 = PyList_New(0); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 99; goto __pyx_L1;}
  Py_DECREF(__pyx_v_keys);
  __pyx_v_keys = __pyx_2;
  __pyx_2 = 0;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":100 */
  __pyx_2 = PyObject_GetIter(((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_v_self)->parents); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 100; goto __pyx_L1;}
  for (;;) {
    __pyx_3 = PyIter_Next(__pyx_2);
    if (!__pyx_3) {
      if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 100; goto __pyx_L1;}
      break;
    }
    if (!__Pyx_TypeTest(__pyx_3, __pyx_ptype_6bzrlib_16_known_graph_pyx__KnownGraphNode)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 100; goto __pyx_L1;}
    Py_DECREF(((PyObject *)__pyx_v_parent));
    __pyx_v_parent = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_3);
    __pyx_3 = 0;
    __pyx_1 = PyList_Append(__pyx_v_keys,__pyx_v_parent->key); if (__pyx_1 == (-1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 101; goto __pyx_L1;}
  }
  Py_DECREF(__pyx_2); __pyx_2 = 0;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":102 */
  Py_INCREF(__pyx_v_keys);
  __pyx_r = __pyx_v_keys;
  goto __pyx_L0;

  __pyx_r = Py_None; Py_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_2);
  Py_XDECREF(__pyx_3);
  __Pyx_AddTraceback("bzrlib._known_graph_pyx._KnownGraphNode.parent_keys.__get__");
  __pyx_r = 0;
  __pyx_L0:;
  Py_DECREF(__pyx_v_parent);
  Py_DECREF(__pyx_v_keys);
  Py_DECREF(__pyx_v_self);
  return __pyx_r;
}

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;
  Py_INCREF(__pyx_v_self);

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":105 */
  Py_INCREF(Py_None);
  Py_DECREF(__pyx_v_self->parents);
  __pyx_v_self->parents = Py_None;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":106 */
  Py_INCREF(Py_None);
  Py_DECREF(__pyx_v_self->children);
  __pyx_v_self->children = Py_None;

  __pyx_r = Py_None; Py_INCREF(Py_None);
  Py_DECREF(__pyx_v_self);
  return __pyx_r;
}

static PyObject *__pyx_f_6bzrlib_16_known_graph_pyx_15_KnownGraphNode___repr__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_f_6bzrlib_16_known_graph_pyx_15_KnownGraphNode___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;
  PyObject *__pyx_1 = 0;
  int __pyx_2;
  PyObject *__pyx_3 = 0;
  PyObject *__pyx_4 = 0;
  PyObject *__pyx_5 = 0;
  Py_INCREF(__pyx_v_self);
  __pyx_v_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)Py_None); Py_INCREF(Py_None);
  __pyx_v_parent_keys = Py_None; Py_INCREF(Py_None);
  __pyx_v_child_keys = Py_None; Py_INCREF(Py_None);

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":111 */
  __pyx_1 = PyList_New(0); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 111; goto __pyx_L1;}
  Py_DECREF(__pyx_v_parent_keys);
  __pyx_v_parent_keys = __pyx_1;
  __pyx_1 = 0;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":112 */
  __pyx_2 = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_v_self)->parents != Py_None;
  if (__pyx_2) {
    __pyx_1 = PyObject_GetIter(((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_v_self)->parents); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 113; goto __pyx_L1;}
    for (;;) {
      __pyx_3 = PyIter_Next(__pyx_1);
      if (!__pyx_3) {
        if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 113; goto __pyx_L1;}
        break;
      }
      if (!__Pyx_TypeTest(__pyx_3, __pyx_ptype_6bzrlib_16_known_graph_pyx__KnownGraphNode)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 113; goto __pyx_L1;}
      Py_DECREF(((PyObject *)__pyx_v_node));
      __pyx_v_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_3);
      __pyx_3 = 0;
      __pyx_3 = PyObject_GetAttr(__pyx_v_parent_keys, __pyx_n_append); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 114; goto __pyx_L1;}
      __pyx_4 = PyTuple_New(1); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 114; goto __pyx_L1;}
      Py_INCREF(__pyx_v_node->key);
      PyTuple_SET_ITEM(__pyx_4, 0, __pyx_v_node->key);
      __pyx_5 = PyObject_CallObject(__pyx_3, __pyx_4); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 114; goto __pyx_L1;}
      Py_DECREF(__pyx_3); __pyx_3 = 0;
      Py_DECREF(__pyx_4); __pyx_4 = 0;
      Py_DECREF(__pyx_5); __pyx_5 = 0;
    }
    Py_DECREF(__pyx_1); __pyx_1 = 0;
    goto __pyx_L2;
  }
  __pyx_L2:;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":115 */
  __pyx_3 = PyList_New(0); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 115; goto __pyx_L1;}
  Py_DECREF(__pyx_v_child_keys);
  __pyx_v_child_keys = __pyx_3;
  __pyx_3 = 0;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":116 */
  __pyx_2 = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_v_self)->children != Py_None;
  if (__pyx_2) {
    __pyx_4 = PyObject_GetIter(((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_v_self)->children); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 117; goto __pyx_L1;}
    for (;;) {
      __pyx_5 = PyIter_Next(__pyx_4);
      if (!__pyx_5) {
        if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 117; goto __pyx_L1;}
        break;
      }
      if (!__Pyx_TypeTest(__pyx_5, __pyx_ptype_6bzrlib_16_known_graph_pyx__KnownGraphNode)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 117; goto __pyx_L1;}
      Py_DECREF(((PyObject *)__pyx_v_node));
      __pyx_v_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_5);
      __pyx_5 = 0;
      __pyx_1 = PyObject_GetAttr(__pyx_v_child_keys, __pyx_n_append); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 118; goto __pyx_L1;}
      __pyx_3 = PyTuple_New(1); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 118; goto __pyx_L1;}
      Py_INCREF(__pyx_v_node->key);
      PyTuple_SET_ITEM(__pyx_3, 0, __pyx_v_node->key);
      __pyx_5 = PyObject_CallObject(__pyx_1, __pyx_3); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 118; goto __pyx_L1;}
      Py_DECREF(__pyx_1); __pyx_1 = 0;
      Py_DECREF(__pyx_3); __pyx_3 = 0;
      Py_DECREF(__pyx_5); __pyx_5 = 0;
    }
    Py_DECREF(__pyx_4); __pyx_4 = 0;
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":119 */
  __pyx_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n___class__); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 120; goto __pyx_L1;}
  __pyx_3 = PyObject_GetAttr(__pyx_1, __pyx_n___name__); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 120; goto __pyx_L1;}
  Py_DECREF(__pyx_1); __pyx_1 = 0;
  __pyx_5 = PyInt_FromLong(((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_v_self)->gdfo); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 120; goto __pyx_L1;}
  __pyx_4 = PyTuple_New(5); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 120; goto __pyx_L1;}
  PyTuple_SET_ITEM(__pyx_4, 0, __pyx_3);
  Py_INCREF(((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_v_self)->key);
  PyTuple_SET_ITEM(__pyx_4, 1, ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_v_self)->key);
  PyTuple_SET_ITEM(__pyx_4, 2, __pyx_5);
  Py_INCREF(__pyx_v_parent_keys);
  PyTuple_SET_ITEM(__pyx_4, 3, __pyx_v_parent_keys);
  Py_INCREF(__pyx_v_child_keys);
  PyTuple_SET_ITEM(__pyx_4, 4, __pyx_v_child_keys);
  __pyx_3 = 0;
  __pyx_5 = 0;
  __pyx_1 = PyNumber_Remainder(__pyx_k2p, __pyx_4); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 119; goto __pyx_L1;}
  Py_DECREF(__pyx_4); __pyx_4 = 0;
  __pyx_r = __pyx_1;
  __pyx_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; Py_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_1);
  Py_XDECREF(__pyx_3);
  Py_XDECREF(__pyx_4);
  Py_XDECREF(__pyx_5);
  __Pyx_AddTraceback("bzrlib._known_graph_pyx._KnownGraphNode.__repr__");
  __pyx_r = 0;
  __pyx_L0:;
  Py_DECREF(__pyx_v_node);
  Py_DECREF(__pyx_v_parent_keys);
  Py_DECREF(__pyx_v_child_keys);
  Py_DECREF(__pyx_v_self);
  return __pyx_r;
}

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;
  Py_INCREF(__pyx_v_lst);

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":127 */
  __pyx_v_temp_node = PyList_GET_ITEM(__pyx_v_lst,__pyx_v_pos);

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":128 */
  Py_INCREF(((PyObject *)__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); Py_INCREF(Py_None);
  __pyx_L0:;
  Py_DECREF(__pyx_v_lst);
  return __pyx_r;
}

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;
  Py_INCREF(__pyx_v_tpl);

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":134 */
  __pyx_v_temp_node = PyTuple_GET_ITEM(__pyx_v_tpl,__pyx_v_pos);

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":135 */
  Py_INCREF(((PyObject *)__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); Py_INCREF(Py_None);
  __pyx_L0:;
  Py_DECREF(__pyx_v_tpl);
  return __pyx_r;
}

static PyObject *__pyx_f_6bzrlib_16_known_graph_pyx_get_key(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_f_6bzrlib_16_known_graph_pyx_get_key(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_node = 0;
  struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *__pyx_v_real_node;
  PyObject *__pyx_r;
  static char *__pyx_argnames[] = {"node",0};
  if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "O", __pyx_argnames, &__pyx_v_node)) return 0;
  Py_INCREF(__pyx_v_node);
  __pyx_v_real_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)Py_None); Py_INCREF(Py_None);

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":140 */
  if (!__Pyx_TypeTest(__pyx_v_node, __pyx_ptype_6bzrlib_16_known_graph_pyx__KnownGraphNode)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 140; goto __pyx_L1;}
  Py_INCREF(__pyx_v_node);
  Py_DECREF(((PyObject *)__pyx_v_real_node));
  __pyx_v_real_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_v_node);

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":141 */
  Py_INCREF(__pyx_v_real_node->key);
  __pyx_r = __pyx_v_real_node->key;
  goto __pyx_L0;

  __pyx_r = Py_None; Py_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1:;
  __Pyx_AddTraceback("bzrlib._known_graph_pyx.get_key");
  __pyx_r = 0;
  __pyx_L0:;
  Py_DECREF(__pyx_v_real_node);
  Py_DECREF(__pyx_v_node);
  return __pyx_r;
}

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;
  int __pyx_1;
  int __pyx_2;
  PyObject *__pyx_3 = 0;
  PyObject *__pyx_4 = 0;
  Py_ssize_t __pyx_5;
  PyObject *__pyx_6 = 0;
  PyObject *__pyx_7 = 0;
  Py_INCREF(__pyx_v_lst_or_tpl);
  __pyx_v_node1 = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)Py_None); Py_INCREF(Py_None);
  __pyx_v_node2 = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)Py_None); Py_INCREF(Py_None);

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":154 */
  __pyx_v_is_tuple = PyTuple_CheckExact(__pyx_v_lst_or_tpl);

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":155 */
  __pyx_1 = __pyx_v_is_tuple;
  if (!__pyx_1) {
    __pyx_1 = PyList_CheckExact(__pyx_v_lst_or_tpl);
  }
  __pyx_2 = (!__pyx_1);
  if (__pyx_2) {
    __pyx_3 = PyTuple_New(1); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 156; goto __pyx_L1;}
    Py_INCREF(__pyx_k5p);
    PyTuple_SET_ITEM(__pyx_3, 0, __pyx_k5p);
    __pyx_4 = PyObject_CallObject(PyExc_TypeError, __pyx_3); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 156; goto __pyx_L1;}
    Py_DECREF(__pyx_3); __pyx_3 = 0;
    __Pyx_Raise(__pyx_4, 0, 0);
    Py_DECREF(__pyx_4); __pyx_4 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 156; goto __pyx_L1;}
    goto __pyx_L2;
  }
  __pyx_L2:;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":157 */
  __pyx_5 = PyObject_Length(__pyx_v_lst_or_tpl); if (__pyx_5 == -1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 157; goto __pyx_L1;}
  __pyx_v_length = __pyx_5;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":158 */
  __pyx_1 = (__pyx_v_length == 0);
  if (!__pyx_1) {
    __pyx_1 = (__pyx_v_length == 1);
  }
  if (__pyx_1) {
    Py_INCREF(__pyx_v_lst_or_tpl);
    __pyx_r = __pyx_v_lst_or_tpl;
    goto __pyx_L0;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":160 */
  __pyx_2 = (__pyx_v_length == 2);
  if (__pyx_2) {

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":161 */
    __pyx_1 = __pyx_v_is_tuple;
    if (__pyx_1) {

      /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":162 */
      __pyx_3 = ((PyObject *)__pyx_f_6bzrlib_16_known_graph_pyx__get_tuple_node(__pyx_v_lst_or_tpl,0)); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 162; goto __pyx_L1;}
      Py_DECREF(((PyObject *)__pyx_v_node1));
      __pyx_v_node1 = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_3);
      __pyx_3 = 0;

      /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":163 */
      __pyx_4 = ((PyObject *)__pyx_f_6bzrlib_16_known_graph_pyx__get_tuple_node(__pyx_v_lst_or_tpl,1)); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 163; goto __pyx_L1;}
      Py_DECREF(((PyObject *)__pyx_v_node2));
      __pyx_v_node2 = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_4);
      __pyx_4 = 0;
      goto __pyx_L5;
    }
    /*else*/ {

      /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":165 */
      __pyx_3 = ((PyObject *)__pyx_f_6bzrlib_16_known_graph_pyx__get_list_node(__pyx_v_lst_or_tpl,0)); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 165; goto __pyx_L1;}
      Py_DECREF(((PyObject *)__pyx_v_node1));
      __pyx_v_node1 = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_3);
      __pyx_3 = 0;

      /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":166 */
      __pyx_4 = ((PyObject *)__pyx_f_6bzrlib_16_known_graph_pyx__get_list_node(__pyx_v_lst_or_tpl,1)); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 166; goto __pyx_L1;}
      Py_DECREF(((PyObject *)__pyx_v_node2));
      __pyx_v_node2 = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_4);
      __pyx_4 = 0;
    }
    __pyx_L5:;

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":167 */
    __pyx_2 = __pyx_v_reverse;
    if (__pyx_2) {
      __pyx_v_do_swap = PyObject_RichCompareBool(__pyx_v_node1->key,__pyx_v_node2->key,Py_LT);
      goto __pyx_L6;
    }
    /*else*/ {
      __pyx_v_do_swap = PyObject_RichCompareBool(__pyx_v_node2->key,__pyx_v_node1->key,Py_LT);
    }
    __pyx_L6:;

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":171 */
    __pyx_1 = (!__pyx_v_do_swap);
    if (__pyx_1) {
      Py_INCREF(__pyx_v_lst_or_tpl);
      __pyx_r = __pyx_v_lst_or_tpl;
      goto __pyx_L0;
      goto __pyx_L7;
    }
    __pyx_L7:;

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":173 */
    __pyx_2 = __pyx_v_is_tuple;
    if (__pyx_2) {
      __pyx_3 = PyTuple_New(2); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 174; goto __pyx_L1;}
      Py_INCREF(((PyObject *)__pyx_v_node2));
      PyTuple_SET_ITEM(__pyx_3, 0, ((PyObject *)__pyx_v_node2));
      Py_INCREF(((PyObject *)__pyx_v_node1));
      PyTuple_SET_ITEM(__pyx_3, 1, ((PyObject *)__pyx_v_node1));
      __pyx_r = __pyx_3;
      __pyx_3 = 0;
      goto __pyx_L0;
      goto __pyx_L8;
    }
    /*else*/ {

      /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":177 */
      Py_INCREF(((PyObject *)__pyx_v_node1));

      /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":178 */
      __pyx_1 = PyList_SetItem(__pyx_v_lst_or_tpl,1,((PyObject *)__pyx_v_node1)); if (__pyx_1 == (-1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 178; goto __pyx_L1;}

      /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":179 */
      Py_INCREF(((PyObject *)__pyx_v_node2));

      /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":180 */
      __pyx_2 = PyList_SetItem(__pyx_v_lst_or_tpl,0,((PyObject *)__pyx_v_node2)); if (__pyx_2 == (-1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 180; goto __pyx_L1;}

      /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":181 */
      Py_INCREF(__pyx_v_lst_or_tpl);
      __pyx_r = __pyx_v_lst_or_tpl;
      goto __pyx_L0;
    }
    __pyx_L8:;
    goto __pyx_L4;
  }
  __pyx_L4:;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":183 */
  __pyx_1 = __pyx_v_is_tuple;
  if (__pyx_1) {
    __pyx_4 = PyTuple_New(1); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 185; goto __pyx_L1;}
    Py_INCREF(__pyx_v_lst_or_tpl);
    PyTuple_SET_ITEM(__pyx_4, 0, __pyx_v_lst_or_tpl);
    __pyx_3 = PyObject_CallObject(((PyObject *)(&PyList_Type)), __pyx_4); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 185; goto __pyx_L1;}
    Py_DECREF(__pyx_4); __pyx_4 = 0;
    Py_DECREF(__pyx_v_lst_or_tpl);
    __pyx_v_lst_or_tpl = __pyx_3;
    __pyx_3 = 0;
    goto __pyx_L9;
  }
  __pyx_L9:;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":186 */
  __pyx_4 = PyObject_GetAttr(__pyx_v_lst_or_tpl, __pyx_n_sort); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 186; goto __pyx_L1;}
  __pyx_3 = PyTuple_New(0); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 186; goto __pyx_L1;}
  __pyx_6 = PyDict_New(); if (!__pyx_6) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 186; goto __pyx_L1;}
  __pyx_7 = __Pyx_GetName(__pyx_m, __pyx_n_get_key); if (!__pyx_7) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 186; goto __pyx_L1;}
  if (PyDict_SetItem(__pyx_6, __pyx_n_key, __pyx_7) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 186; goto __pyx_L1;}
  Py_DECREF(__pyx_7); __pyx_7 = 0;
  __pyx_7 = PyInt_FromLong(__pyx_v_reverse); if (!__pyx_7) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 186; goto __pyx_L1;}
  if (PyDict_SetItem(__pyx_6, __pyx_n_reverse, __pyx_7) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 186; goto __pyx_L1;}
  Py_DECREF(__pyx_7); __pyx_7 = 0;
  __pyx_7 = PyEval_CallObjectWithKeywords(__pyx_4, __pyx_3, __pyx_6); if (!__pyx_7) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 186; goto __pyx_L1;}
  Py_DECREF(__pyx_4); __pyx_4 = 0;
  Py_DECREF(__pyx_3); __pyx_3 = 0;
  Py_DECREF(__pyx_6); __pyx_6 = 0;
  Py_DECREF(__pyx_7); __pyx_7 = 0;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":187 */
  Py_INCREF(__pyx_v_lst_or_tpl);
  __pyx_r = __pyx_v_lst_or_tpl;
  goto __pyx_L0;

  __pyx_r = Py_None; Py_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_3);
  Py_XDECREF(__pyx_4);
  Py_XDECREF(__pyx_6);
  Py_XDECREF(__pyx_7);
  __Pyx_AddTraceback("bzrlib._known_graph_pyx._sort_list_nodes");
  __pyx_r = 0;
  __pyx_L0:;
  Py_DECREF(__pyx_v_node1);
  Py_DECREF(__pyx_v_node2);
  Py_DECREF(__pyx_v_lst_or_tpl);
  return __pyx_r;
}

static int __pyx_f_6bzrlib_16_known_graph_pyx_10KnownGraph___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_f_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_1 = 0;
  PyObject *__pyx_2 = 0;
  int __pyx_3;
  PyObject *__pyx_4 = 0;
  static char *__pyx_argnames[] = {"parent_map","do_cache",0};
  __pyx_v_do_cache = __pyx_d1;
  if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "O|O", __pyx_argnames, &__pyx_v_parent_map, &__pyx_v_do_cache)) return -1;
  Py_INCREF(__pyx_v_self);
  Py_INCREF(__pyx_v_parent_map);
  Py_INCREF(__pyx_v_do_cache);

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":205 */
  __pyx_1 = PyDict_New(); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 205; goto __pyx_L1;}
  Py_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_1;
  __pyx_1 = 0;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":207 */
  __pyx_1 = PyDict_New(); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 207; goto __pyx_L1;}
  Py_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_1;
  __pyx_1 = 0;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":208 */
  __pyx_1 = PyTuple_New(1); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 208; goto __pyx_L1;}
  Py_INCREF(__pyx_v_do_cache);
  PyTuple_SET_ITEM(__pyx_1, 0, __pyx_v_do_cache);
  __pyx_2 = PyObject_CallObject(((PyObject *)(&PyInt_Type)), __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 208; goto __pyx_L1;}
  Py_DECREF(__pyx_1); __pyx_1 = 0;
  __pyx_3 = PyInt_AsLong(__pyx_2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 208; goto __pyx_L1;}
  Py_DECREF(__pyx_2); __pyx_2 = 0;
  ((struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *)__pyx_v_self)->do_cache = __pyx_3;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":212 */
  __pyx_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n__initialize_nodes); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 212; goto __pyx_L1;}
  __pyx_2 = PyTuple_New(1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 212; goto __pyx_L1;}
  Py_INCREF(__pyx_v_parent_map);
  PyTuple_SET_ITEM(__pyx_2, 0, __pyx_v_parent_map);
  __pyx_4 = PyObject_CallObject(__pyx_1, __pyx_2); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 212; goto __pyx_L1;}
  Py_DECREF(__pyx_1); __pyx_1 = 0;
  Py_DECREF(__pyx_2); __pyx_2 = 0;
  Py_DECREF(__pyx_4); __pyx_4 = 0;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":213 */
  __pyx_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n__find_gdfo); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 213; goto __pyx_L1;}
  __pyx_2 = PyObject_CallObject(__pyx_1, 0); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 213; goto __pyx_L1;}
  Py_DECREF(__pyx_1); __pyx_1 = 0;
  Py_DECREF(__pyx_2); __pyx_2 = 0;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_1);
  Py_XDECREF(__pyx_2);
  Py_XDECREF(__pyx_4);
  __Pyx_AddTraceback("bzrlib._known_graph_pyx.KnownGraph.__init__");
  __pyx_r = -1;
  __pyx_L0:;
  Py_DECREF(__pyx_v_self);
  Py_DECREF(__pyx_v_parent_map);
  Py_DECREF(__pyx_v_do_cache);
  return __pyx_r;
}

static void __pyx_f_6bzrlib_16_known_graph_pyx_10KnownGraph___dealloc__(PyObject *__pyx_v_self); /*proto*/
static void __pyx_f_6bzrlib_16_known_graph_pyx_10KnownGraph___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;
  int __pyx_1;
  PyObject *__pyx_2 = 0;
  Py_INCREF(__pyx_v_self);
  __pyx_v_child = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)Py_None); Py_INCREF(Py_None);

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":220 */
  while (1) {
    __pyx_1 = PyDict_Next(((struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *)__pyx_v_self)->_nodes,(&__pyx_v_pos),NULL,(&__pyx_v_temp_node));
    if (!__pyx_1) break;

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":221 */
    Py_INCREF(((PyObject *)__pyx_v_temp_node));
    Py_DECREF(((PyObject *)__pyx_v_child));
    __pyx_v_child = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_v_temp_node);

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":222 */
    __pyx_2 = ((struct __pyx_vtabstruct_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_v_child->__pyx_vtab)->clear_references(__pyx_v_child); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 222; goto __pyx_L1;}
    Py_DECREF(__pyx_2); __pyx_2 = 0;
  }

  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_2);
  __Pyx_AddTraceback("bzrlib._known_graph_pyx.KnownGraph.__dealloc__");
  __pyx_L0:;
  Py_DECREF(__pyx_v_child);
  Py_DECREF(__pyx_v_self);
}

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;
  int __pyx_1;
  PyObject *__pyx_2 = 0;
  PyObject *__pyx_3 = 0;
  Py_INCREF(__pyx_v_self);
  Py_INCREF(__pyx_v_key);
  __pyx_v_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)Py_None); Py_INCREF(Py_None);

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":228 */
  __pyx_v_temp_node = PyDict_GetItem(__pyx_v_self->_nodes,__pyx_v_key);

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":229 */
  __pyx_1 = (__pyx_v_temp_node == NULL);
  if (__pyx_1) {

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":230 */
    __pyx_2 = PyTuple_New(1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 230; goto __pyx_L1;}
    Py_INCREF(__pyx_v_key);
    PyTuple_SET_ITEM(__pyx_2, 0, __pyx_v_key);
    __pyx_3 = PyObject_CallObject(((PyObject *)__pyx_ptype_6bzrlib_16_known_graph_pyx__KnownGraphNode), __pyx_2); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 230; goto __pyx_L1;}
    Py_DECREF(__pyx_2); __pyx_2 = 0;
    Py_DECREF(((PyObject *)__pyx_v_node));
    __pyx_v_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_3);
    __pyx_3 = 0;

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":231 */
    __pyx_1 = PyDict_SetItem(__pyx_v_self->_nodes,__pyx_v_key,((PyObject *)__pyx_v_node)); if (__pyx_1 == (-1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 231; goto __pyx_L1;}
    goto __pyx_L2;
  }
  /*else*/ {
    Py_INCREF(((PyObject *)__pyx_v_temp_node));
    Py_DECREF(((PyObject *)__pyx_v_node));
    __pyx_v_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_v_temp_node);
  }
  __pyx_L2:;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":234 */
  Py_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); Py_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_2);
  Py_XDECREF(__pyx_3);
  __Pyx_AddTraceback("bzrlib._known_graph_pyx.KnownGraph._get_or_create_node");
  __pyx_r = 0;
  __pyx_L0:;
  Py_DECREF(__pyx_v_node);
  Py_DECREF(__pyx_v_self);
  Py_DECREF(__pyx_v_key);
  return __pyx_r;
}

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;
  Py_ssize_t __pyx_1;
  PyObject *__pyx_2 = 0;
  PyObject *__pyx_3 = 0;
  int __pyx_4;
  Py_INCREF(__pyx_v_self);
  Py_INCREF(__pyx_v_node);
  Py_INCREF(__pyx_v_parent_keys);
  __pyx_v_parent_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)Py_None); Py_INCREF(Py_None);
  __pyx_v_parent_nodes = Py_None; Py_INCREF(Py_None);

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":240 */
  __pyx_1 = PyObject_Length(__pyx_v_parent_keys); if (__pyx_1 == -1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 240; goto __pyx_L1;}
  __pyx_v_num_parent_keys = __pyx_1;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":242 */
  __pyx_2 = PyTuple_New(__pyx_v_num_parent_keys); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 242; goto __pyx_L1;}
  Py_DECREF(__pyx_v_parent_nodes);
  __pyx_v_parent_nodes = __pyx_2;
  __pyx_2 = 0;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":243 */
  for (__pyx_v_pos = 0; __pyx_v_pos < __pyx_v_num_parent_keys; ++__pyx_v_pos) {

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":251 */
    __pyx_2 = __Pyx_GetItemInt(__pyx_v_parent_keys, __pyx_v_pos); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 251; goto __pyx_L1;}
    __pyx_3 = ((PyObject *)((struct __pyx_vtabstruct_6bzrlib_16_known_graph_pyx_KnownGraph *)__pyx_v_self->__pyx_vtab)->_get_or_create_node(__pyx_v_self,__pyx_2)); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 251; goto __pyx_L1;}
    Py_DECREF(__pyx_2); __pyx_2 = 0;
    Py_DECREF(((PyObject *)__pyx_v_parent_node));
    __pyx_v_parent_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_3);
    __pyx_3 = 0;

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":253 */
    Py_INCREF(((PyObject *)__pyx_v_parent_node));

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":254 */
    PyTuple_SET_ITEM(__pyx_v_parent_nodes,__pyx_v_pos,((PyObject *)__pyx_v_parent_node));

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":255 */
    __pyx_4 = PyList_Append(__pyx_v_parent_node->children,((PyObject *)__pyx_v_node)); if (__pyx_4 == (-1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 255; goto __pyx_L1;}
  }

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":256 */
  Py_INCREF(__pyx_v_parent_nodes);
  Py_DECREF(__pyx_v_node->parents);
  __pyx_v_node->parents = __pyx_v_parent_nodes;

  __pyx_r = Py_None; Py_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_2);
  Py_XDECREF(__pyx_3);
  __Pyx_AddTraceback("bzrlib._known_graph_pyx.KnownGraph._populate_parents");
  __pyx_r = 0;
  __pyx_L0:;
  Py_DECREF(__pyx_v_parent_node);
  Py_DECREF(__pyx_v_parent_nodes);
  Py_DECREF(__pyx_v_self);
  Py_DECREF(__pyx_v_node);
  Py_DECREF(__pyx_v_parent_keys);
  return __pyx_r;
}

static PyObject *__pyx_f_6bzrlib_16_known_graph_pyx_10KnownGraph__initialize_nodes(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_6bzrlib_16_known_graph_pyx_10KnownGraph__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_f_6bzrlib_16_known_graph_pyx_10KnownGraph__initialize_nodes(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_parent_map = 0;
  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;
  int __pyx_1;
  PyObject *__pyx_2 = 0;
  PyObject *__pyx_3 = 0;
  static char *__pyx_argnames[] = {"parent_map",0};
  if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "O", __pyx_argnames, &__pyx_v_parent_map)) return 0;
  Py_INCREF(__pyx_v_self);
  Py_INCREF(__pyx_v_parent_map);
  __pyx_v_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)Py_None); Py_INCREF(Py_None);
  __pyx_v_key = Py_None; Py_INCREF(Py_None);
  __pyx_v_parent_keys = Py_None; Py_INCREF(Py_None);

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":272 */
  __pyx_1 = (!PyDict_CheckExact(__pyx_v_parent_map));
  if (__pyx_1) {
    __pyx_2 = PyTuple_New(1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 273; goto __pyx_L1;}
    Py_INCREF(__pyx_k12p);
    PyTuple_SET_ITEM(__pyx_2, 0, __pyx_k12p);
    __pyx_3 = PyObject_CallObject(PyExc_TypeError, __pyx_2); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 273; goto __pyx_L1;}
    Py_DECREF(__pyx_2); __pyx_2 = 0;
    __Pyx_Raise(__pyx_3, 0, 0);
    Py_DECREF(__pyx_3); __pyx_3 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 273; goto __pyx_L1;}
    goto __pyx_L2;
  }
  __pyx_L2:;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":275 */
  __pyx_v_pos = 0;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":276 */
  while (1) {
    __pyx_1 = PyDict_Next(__pyx_v_parent_map,(&__pyx_v_pos),(&__pyx_v_temp_key),(&__pyx_v_temp_parent_keys));
    if (!__pyx_1) break;

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":277 */
    Py_INCREF(((PyObject *)__pyx_v_temp_key));
    Py_DECREF(__pyx_v_key);
    __pyx_v_key = ((PyObject *)__pyx_v_temp_key);

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":278 */
    Py_INCREF(((PyObject *)__pyx_v_temp_parent_keys));
    Py_DECREF(__pyx_v_parent_keys);
    __pyx_v_parent_keys = ((PyObject *)__pyx_v_temp_parent_keys);

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":279 */
    __pyx_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 (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 279; goto __pyx_L1;}
    Py_DECREF(((PyObject *)__pyx_v_node));
    __pyx_v_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_2);
    __pyx_2 = 0;

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":280 */
    __pyx_3 = ((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 (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 280; goto __pyx_L1;}
    Py_DECREF(__pyx_3); __pyx_3 = 0;
  }

  __pyx_r = Py_None; Py_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_2);
  Py_XDECREF(__pyx_3);
  __Pyx_AddTraceback("bzrlib._known_graph_pyx.KnownGraph._initialize_nodes");
  __pyx_r = 0;
  __pyx_L0:;
  Py_DECREF(__pyx_v_node);
  Py_DECREF(__pyx_v_key);
  Py_DECREF(__pyx_v_parent_keys);
  Py_DECREF(__pyx_v_self);
  Py_DECREF(__pyx_v_parent_map);
  return __pyx_r;
}

static PyObject *__pyx_f_6bzrlib_16_known_graph_pyx_10KnownGraph__find_tails(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_f_6bzrlib_16_known_graph_pyx_10KnownGraph__find_tails(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  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;
  PyObject *__pyx_1 = 0;
  int __pyx_2;
  static char *__pyx_argnames[] = {0};
  if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "", __pyx_argnames)) return 0;
  Py_INCREF(__pyx_v_self);
  __pyx_v_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)Py_None); Py_INCREF(Py_None);
  __pyx_v_tails = Py_None; Py_INCREF(Py_None);

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":287 */
  __pyx_1 = PyList_New(0); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 287; goto __pyx_L1;}
  Py_DECREF(__pyx_v_tails);
  __pyx_v_tails = __pyx_1;
  __pyx_1 = 0;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":288 */
  __pyx_v_pos = 0;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":289 */
  while (1) {
    __pyx_2 = PyDict_Next(((struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *)__pyx_v_self)->_nodes,(&__pyx_v_pos),NULL,(&__pyx_v_temp_node));
    if (!__pyx_2) break;

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":290 */
    Py_INCREF(((PyObject *)__pyx_v_temp_node));
    Py_DECREF(((PyObject *)__pyx_v_node));
    __pyx_v_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_v_temp_node);

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":291 */
    __pyx_2 = __pyx_v_node->parents == Py_None;
    if (!__pyx_2) {
      __pyx_2 = (PyTuple_GET_SIZE(__pyx_v_node->parents) == 0);
    }
    if (__pyx_2) {

      /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":292 */
      __pyx_v_node->gdfo = 1;

      /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":293 */
      __pyx_2 = PyList_Append(__pyx_v_tails,((PyObject *)__pyx_v_node)); if (__pyx_2 == (-1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 293; goto __pyx_L1;}
      goto __pyx_L4;
    }
    __pyx_L4:;
  }

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":294 */
  Py_INCREF(__pyx_v_tails);
  __pyx_r = __pyx_v_tails;
  goto __pyx_L0;

  __pyx_r = Py_None; Py_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_1);
  __Pyx_AddTraceback("bzrlib._known_graph_pyx.KnownGraph._find_tails");
  __pyx_r = 0;
  __pyx_L0:;
  Py_DECREF(__pyx_v_node);
  Py_DECREF(__pyx_v_tails);
  Py_DECREF(__pyx_v_self);
  return __pyx_r;
}

static PyObject *__pyx_f_6bzrlib_16_known_graph_pyx_10KnownGraph__find_tips(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_f_6bzrlib_16_known_graph_pyx_10KnownGraph__find_tips(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  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;
  PyObject *__pyx_1 = 0;
  int __pyx_2;
  static char *__pyx_argnames[] = {0};
  if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "", __pyx_argnames)) return 0;
  Py_INCREF(__pyx_v_self);
  __pyx_v_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)Py_None); Py_INCREF(Py_None);
  __pyx_v_tips = Py_None; Py_INCREF(Py_None);

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":301 */
  __pyx_1 = PyList_New(0); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 301; goto __pyx_L1;}
  Py_DECREF(__pyx_v_tips);
  __pyx_v_tips = __pyx_1;
  __pyx_1 = 0;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":302 */
  __pyx_v_pos = 0;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":303 */
  while (1) {
    __pyx_2 = PyDict_Next(((struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *)__pyx_v_self)->_nodes,(&__pyx_v_pos),NULL,(&__pyx_v_temp_node));
    if (!__pyx_2) break;

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":304 */
    Py_INCREF(((PyObject *)__pyx_v_temp_node));
    Py_DECREF(((PyObject *)__pyx_v_node));
    __pyx_v_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_v_temp_node);

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":305 */
    __pyx_2 = (PyList_GET_SIZE(__pyx_v_node->children) == 0);
    if (__pyx_2) {
      __pyx_2 = PyList_Append(__pyx_v_tips,((PyObject *)__pyx_v_node)); if (__pyx_2 == (-1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 306; goto __pyx_L1;}
      goto __pyx_L4;
    }
    __pyx_L4:;
  }

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":307 */
  Py_INCREF(__pyx_v_tips);
  __pyx_r = __pyx_v_tips;
  goto __pyx_L0;

  __pyx_r = Py_None; Py_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_1);
  __Pyx_AddTraceback("bzrlib._known_graph_pyx.KnownGraph._find_tips");
  __pyx_r = 0;
  __pyx_L0:;
  Py_DECREF(__pyx_v_node);
  Py_DECREF(__pyx_v_tips);
  Py_DECREF(__pyx_v_self);
  return __pyx_r;
}

static PyObject *__pyx_f_6bzrlib_16_known_graph_pyx_10KnownGraph__find_gdfo(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_f_6bzrlib_16_known_graph_pyx_10KnownGraph__find_gdfo(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  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;
  PyObject *__pyx_1 = 0;
  PyObject *__pyx_2 = 0;
  int __pyx_3;
  Py_ssize_t __pyx_4;
  static char *__pyx_argnames[] = {0};
  if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "", __pyx_argnames)) return 0;
  Py_INCREF(__pyx_v_self);
  __pyx_v_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)Py_None); Py_INCREF(Py_None);
  __pyx_v_child = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)Py_None); Py_INCREF(Py_None);
  __pyx_v_pending = Py_None; Py_INCREF(Py_None);

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":318 */
  __pyx_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n__find_tails); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 318; goto __pyx_L1;}
  __pyx_2 = PyObject_CallObject(__pyx_1, 0); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 318; goto __pyx_L1;}
  Py_DECREF(__pyx_1); __pyx_1 = 0;
  Py_DECREF(__pyx_v_pending);
  __pyx_v_pending = __pyx_2;
  __pyx_2 = 0;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":320 */
  __pyx_v_last_item = (PyList_GET_SIZE(__pyx_v_pending) - 1);

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":321 */
  while (1) {
    __pyx_3 = (__pyx_v_last_item >= 0);
    if (!__pyx_3) break;

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":324 */
    __pyx_1 = ((PyObject *)__pyx_f_6bzrlib_16_known_graph_pyx__get_list_node(__pyx_v_pending,__pyx_v_last_item)); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 324; goto __pyx_L1;}
    Py_DECREF(((PyObject *)__pyx_v_node));
    __pyx_v_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_1);
    __pyx_1 = 0;

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":325 */
    __pyx_v_last_item = (__pyx_v_last_item - 1);

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":326 */
    __pyx_v_next_gdfo = (__pyx_v_node->gdfo + 1);

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":327 */
    __pyx_4 = PyList_GET_SIZE(__pyx_v_node->children);
    for (__pyx_v_pos = 0; __pyx_v_pos < __pyx_4; ++__pyx_v_pos) {

      /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":328 */
      __pyx_2 = ((PyObject *)__pyx_f_6bzrlib_16_known_graph_pyx__get_list_node(__pyx_v_node->children,__pyx_v_pos)); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 328; goto __pyx_L1;}
      Py_DECREF(((PyObject *)__pyx_v_child));
      __pyx_v_child = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_2);
      __pyx_2 = 0;

      /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":329 */
      __pyx_3 = (__pyx_v_next_gdfo > __pyx_v_child->gdfo);
      if (__pyx_3) {
        __pyx_v_child->gdfo = __pyx_v_next_gdfo;
        goto __pyx_L6;
      }
      __pyx_L6:;

      /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":331 */
      __pyx_v_child->seen = (__pyx_v_child->seen + 1);

      /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":332 */
      __pyx_3 = (__pyx_v_child->seen == PyTuple_GET_SIZE(__pyx_v_child->parents));
      if (__pyx_3) {

        /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":334 */
        __pyx_v_last_item = (__pyx_v_last_item + 1);

        /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":335 */
        __pyx_3 = (__pyx_v_last_item < PyList_GET_SIZE(__pyx_v_pending));
        if (__pyx_3) {

          /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":336 */
          Py_INCREF(((PyObject *)__pyx_v_child));

          /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":337 */
          __pyx_3 = PyList_SetItem(__pyx_v_pending,__pyx_v_last_item,((PyObject *)__pyx_v_child)); if (__pyx_3 == (-1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 337; goto __pyx_L1;}
          goto __pyx_L8;
        }
        /*else*/ {
          __pyx_3 = PyList_Append(__pyx_v_pending,((PyObject *)__pyx_v_child)); if (__pyx_3 == (-1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 339; goto __pyx_L1;}
        }
        __pyx_L8:;

        /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":342 */
        __pyx_v_child->seen = 0;
        goto __pyx_L7;
      }
      __pyx_L7:;
    }
  }

  __pyx_r = Py_None; Py_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_1);
  Py_XDECREF(__pyx_2);
  __Pyx_AddTraceback("bzrlib._known_graph_pyx.KnownGraph._find_gdfo");
  __pyx_r = 0;
  __pyx_L0:;
  Py_DECREF(__pyx_v_node);
  Py_DECREF(__pyx_v_child);
  Py_DECREF(__pyx_v_pending);
  Py_DECREF(__pyx_v_self);
  return __pyx_r;
}

static PyObject *__pyx_f_6bzrlib_16_known_graph_pyx_10KnownGraph_add_node(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_6bzrlib_16_known_graph_pyx_10KnownGraph_add_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_f_6bzrlib_16_known_graph_pyx_10KnownGraph_add_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;
  int __pyx_1;
  PyObject *__pyx_2 = 0;
  PyObject *__pyx_3 = 0;
  PyObject *__pyx_4 = 0;
  PyObject *__pyx_5 = 0;
  static char *__pyx_argnames[] = {"key","parent_keys",0};
  if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "OO", __pyx_argnames, &__pyx_v_key, &__pyx_v_parent_keys)) return 0;
  Py_INCREF(__pyx_v_self);
  Py_INCREF(__pyx_v_key);
  Py_INCREF(__pyx_v_parent_keys);
  __pyx_v_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)Py_None); Py_INCREF(Py_None);
  __pyx_v_parent_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)Py_None); Py_INCREF(Py_None);
  __pyx_v_child_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)Py_None); Py_INCREF(Py_None);
  __pyx_v_existing_parent_keys = Py_None; Py_INCREF(Py_None);
  __pyx_v_pending = Py_None; Py_INCREF(Py_None);
  __pyx_v_pending_popleft = Py_None; Py_INCREF(Py_None);
  __pyx_v_pending_append = Py_None; Py_INCREF(Py_None);

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":359 */
  __pyx_v_maybe_node = PyDict_GetItem(((struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *)__pyx_v_self)->_nodes,__pyx_v_key);

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

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":361 */
    Py_INCREF(((PyObject *)__pyx_v_maybe_node));
    Py_DECREF(((PyObject *)__pyx_v_node));
    __pyx_v_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_v_maybe_node);

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":362 */
    __pyx_1 = __pyx_v_node->parents == Py_None;
    if (__pyx_1) {

      /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":364 */
      __pyx_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 (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 364; goto __pyx_L1;}
      Py_DECREF(__pyx_2); __pyx_2 = 0;

      /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":366 */
      __pyx_2 = PyObject_GetAttr(((struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *)__pyx_v_self)->_known_heads, __pyx_n_clear); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 366; goto __pyx_L1;}
      __pyx_3 = PyObject_CallObject(__pyx_2, 0); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 366; goto __pyx_L1;}
      Py_DECREF(__pyx_2); __pyx_2 = 0;
      Py_DECREF(__pyx_3); __pyx_3 = 0;
      goto __pyx_L3;
    }
    /*else*/ {

      /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":368 */
      __pyx_2 = PyList_New(0); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 368; goto __pyx_L1;}
      Py_DECREF(__pyx_v_existing_parent_keys);
      __pyx_v_existing_parent_keys = __pyx_2;
      __pyx_2 = 0;

      /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":369 */
      __pyx_3 = PyObject_GetIter(__pyx_v_node->parents); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 369; goto __pyx_L1;}
      for (;;) {
        __pyx_2 = PyIter_Next(__pyx_3);
        if (!__pyx_2) {
          if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 369; goto __pyx_L1;}
          break;
        }
        if (!__Pyx_TypeTest(__pyx_2, __pyx_ptype_6bzrlib_16_known_graph_pyx__KnownGraphNode)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 369; goto __pyx_L1;}
        Py_DECREF(((PyObject *)__pyx_v_parent_node));
        __pyx_v_parent_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_2);
        __pyx_2 = 0;
        __pyx_2 = PyObject_GetAttr(__pyx_v_existing_parent_keys, __pyx_n_append); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 370; goto __pyx_L1;}
        __pyx_4 = PyTuple_New(1); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 370; goto __pyx_L1;}
        Py_INCREF(__pyx_v_parent_node->key);
        PyTuple_SET_ITEM(__pyx_4, 0, __pyx_v_parent_node->key);
        __pyx_5 = PyObject_CallObject(__pyx_2, __pyx_4); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 370; goto __pyx_L1;}
        Py_DECREF(__pyx_2); __pyx_2 = 0;
        Py_DECREF(__pyx_4); __pyx_4 = 0;
        Py_DECREF(__pyx_5); __pyx_5 = 0;
      }
      Py_DECREF(__pyx_3); __pyx_3 = 0;

      /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":373 */
      __pyx_2 = PyTuple_New(1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 373; goto __pyx_L1;}
      Py_INCREF(__pyx_v_parent_keys);
      PyTuple_SET_ITEM(__pyx_2, 0, __pyx_v_parent_keys);
      __pyx_4 = PyObject_CallObject(((PyObject *)(&PyList_Type)), __pyx_2); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 373; goto __pyx_L1;}
      Py_DECREF(__pyx_2); __pyx_2 = 0;
      Py_DECREF(__pyx_v_parent_keys);
      __pyx_v_parent_keys = __pyx_4;
      __pyx_4 = 0;

      /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":374 */
      if (PyObject_Cmp(__pyx_v_existing_parent_keys, __pyx_v_parent_keys, &__pyx_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 374; goto __pyx_L1;}
      __pyx_1 = __pyx_1 == 0;
      if (__pyx_1) {
        __pyx_r = Py_None; Py_INCREF(Py_None);
        goto __pyx_L0;
        goto __pyx_L6;
      }
      /*else*/ {
        __pyx_5 = PyTuple_New(3); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 380; goto __pyx_L1;}
        Py_INCREF(__pyx_v_key);
        PyTuple_SET_ITEM(__pyx_5, 0, __pyx_v_key);
        Py_INCREF(__pyx_v_existing_parent_keys);
        PyTuple_SET_ITEM(__pyx_5, 1, __pyx_v_existing_parent_keys);
        Py_INCREF(__pyx_v_parent_keys);
        PyTuple_SET_ITEM(__pyx_5, 2, __pyx_v_parent_keys);
        __pyx_3 = PyNumber_Remainder(__pyx_k15p, __pyx_5); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 380; goto __pyx_L1;}
        Py_DECREF(__pyx_5); __pyx_5 = 0;
        __pyx_2 = PyTuple_New(1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 378; goto __pyx_L1;}
        PyTuple_SET_ITEM(__pyx_2, 0, __pyx_3);
        __pyx_3 = 0;
        __pyx_4 = PyObject_CallObject(PyExc_ValueError, __pyx_2); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 378; goto __pyx_L1;}
        Py_DECREF(__pyx_2); __pyx_2 = 0;
        __Pyx_Raise(__pyx_4, 0, 0);
        Py_DECREF(__pyx_4); __pyx_4 = 0;
        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 378; goto __pyx_L1;}
      }
      __pyx_L6:;
    }
    __pyx_L3:;
    goto __pyx_L2;
  }
  /*else*/ {

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":382 */
    __pyx_5 = PyTuple_New(1); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 382; goto __pyx_L1;}
    Py_INCREF(__pyx_v_key);
    PyTuple_SET_ITEM(__pyx_5, 0, __pyx_v_key);
    __pyx_3 = PyObject_CallObject(((PyObject *)__pyx_ptype_6bzrlib_16_known_graph_pyx__KnownGraphNode), __pyx_5); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 382; goto __pyx_L1;}
    Py_DECREF(__pyx_5); __pyx_5 = 0;
    Py_DECREF(((PyObject *)__pyx_v_node));
    __pyx_v_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_3);
    __pyx_3 = 0;

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":383 */
    __pyx_1 = PyDict_SetItem(((struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *)__pyx_v_self)->_nodes,__pyx_v_key,((PyObject *)__pyx_v_node)); if (__pyx_1 == (-1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 383; goto __pyx_L1;}

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":384 */
    __pyx_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 (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 384; goto __pyx_L1;}
    Py_DECREF(__pyx_2); __pyx_2 = 0;
  }
  __pyx_L2:;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":385 */
  __pyx_v_parent_gdfo = 0;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":386 */
  __pyx_4 = PyObject_GetIter(__pyx_v_node->parents); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 386; goto __pyx_L1;}
  for (;;) {
    __pyx_5 = PyIter_Next(__pyx_4);
    if (!__pyx_5) {
      if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 386; goto __pyx_L1;}
      break;
    }
    if (!__Pyx_TypeTest(__pyx_5, __pyx_ptype_6bzrlib_16_known_graph_pyx__KnownGraphNode)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 386; goto __pyx_L1;}
    Py_DECREF(((PyObject *)__pyx_v_parent_node));
    __pyx_v_parent_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_5);
    __pyx_5 = 0;

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":387 */
    __pyx_1 = (__pyx_v_parent_node->gdfo == (-1));
    if (__pyx_1) {
      __pyx_v_parent_node->gdfo = 1;
      goto __pyx_L9;
    }
    __pyx_L9:;

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":390 */
    __pyx_1 = (__pyx_v_parent_gdfo < __pyx_v_parent_node->gdfo);
    if (__pyx_1) {
      __pyx_v_parent_gdfo = __pyx_v_parent_node->gdfo;
      goto __pyx_L10;
    }
    __pyx_L10:;
  }
  Py_DECREF(__pyx_4); __pyx_4 = 0;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":392 */
  __pyx_v_node->gdfo = (__pyx_v_parent_gdfo + 1);

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":401 */
  __pyx_3 = __Pyx_GetName(__pyx_m, __pyx_n_deque); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 401; goto __pyx_L1;}
  __pyx_2 = PyList_New(1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 401; goto __pyx_L1;}
  Py_INCREF(((PyObject *)__pyx_v_node));
  PyList_SET_ITEM(__pyx_2, 0, ((PyObject *)__pyx_v_node));
  __pyx_5 = PyTuple_New(1); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 401; goto __pyx_L1;}
  PyTuple_SET_ITEM(__pyx_5, 0, __pyx_2);
  __pyx_2 = 0;
  __pyx_4 = PyObject_CallObject(__pyx_3, __pyx_5); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 401; goto __pyx_L1;}
  Py_DECREF(__pyx_3); __pyx_3 = 0;
  Py_DECREF(__pyx_5); __pyx_5 = 0;
  Py_DECREF(__pyx_v_pending);
  __pyx_v_pending = __pyx_4;
  __pyx_4 = 0;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":402 */
  __pyx_2 = PyObject_GetAttr(__pyx_v_pending, __pyx_n_popleft); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 402; goto __pyx_L1;}
  Py_DECREF(__pyx_v_pending_popleft);
  __pyx_v_pending_popleft = __pyx_2;
  __pyx_2 = 0;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":403 */
  __pyx_3 = PyObject_GetAttr(__pyx_v_pending, __pyx_n_append); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 403; goto __pyx_L1;}
  Py_DECREF(__pyx_v_pending_append);
  __pyx_v_pending_append = __pyx_3;
  __pyx_3 = 0;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":404 */
  while (1) {
    __pyx_1 = PyObject_IsTrue(__pyx_v_pending); if (__pyx_1 < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 404; goto __pyx_L1;}
    if (!__pyx_1) break;

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":405 */
    __pyx_5 = PyObject_CallObject(__pyx_v_pending_popleft, 0); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 405; goto __pyx_L1;}
    if (!__Pyx_TypeTest(__pyx_5, __pyx_ptype_6bzrlib_16_known_graph_pyx__KnownGraphNode)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 405; goto __pyx_L1;}
    Py_DECREF(((PyObject *)__pyx_v_node));
    __pyx_v_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_5);
    __pyx_5 = 0;

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":406 */
    __pyx_v_next_gdfo = (__pyx_v_node->gdfo + 1);

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":407 */
    __pyx_4 = PyObject_GetIter(__pyx_v_node->children); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 407; goto __pyx_L1;}
    for (;;) {
      __pyx_2 = PyIter_Next(__pyx_4);
      if (!__pyx_2) {
        if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 407; goto __pyx_L1;}
        break;
      }
      if (!__Pyx_TypeTest(__pyx_2, __pyx_ptype_6bzrlib_16_known_graph_pyx__KnownGraphNode)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 407; goto __pyx_L1;}
      Py_DECREF(((PyObject *)__pyx_v_child_node));
      __pyx_v_child_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_2);
      __pyx_2 = 0;
      __pyx_1 = (__pyx_v_child_node->gdfo < __pyx_v_next_gdfo);
      if (__pyx_1) {

        /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":411 */
        __pyx_v_child_node->gdfo = __pyx_v_next_gdfo;

        /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":412 */
        __pyx_3 = PyTuple_New(1); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 412; goto __pyx_L1;}
        Py_INCREF(((PyObject *)__pyx_v_child_node));
        PyTuple_SET_ITEM(__pyx_3, 0, ((PyObject *)__pyx_v_child_node));
        __pyx_5 = PyObject_CallObject(__pyx_v_pending_append, __pyx_3); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 412; goto __pyx_L1;}
        Py_DECREF(__pyx_3); __pyx_3 = 0;
        Py_DECREF(__pyx_5); __pyx_5 = 0;
        goto __pyx_L15;
      }
      __pyx_L15:;
    }
    Py_DECREF(__pyx_4); __pyx_4 = 0;
  }

  __pyx_r = Py_None; Py_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_2);
  Py_XDECREF(__pyx_3);
  Py_XDECREF(__pyx_4);
  Py_XDECREF(__pyx_5);
  __Pyx_AddTraceback("bzrlib._known_graph_pyx.KnownGraph.add_node");
  __pyx_r = 0;
  __pyx_L0:;
  Py_DECREF(__pyx_v_node);
  Py_DECREF(__pyx_v_parent_node);
  Py_DECREF(__pyx_v_child_node);
  Py_DECREF(__pyx_v_existing_parent_keys);
  Py_DECREF(__pyx_v_pending);
  Py_DECREF(__pyx_v_pending_popleft);
  Py_DECREF(__pyx_v_pending_append);
  Py_DECREF(__pyx_v_self);
  Py_DECREF(__pyx_v_key);
  Py_DECREF(__pyx_v_parent_keys);
  return __pyx_r;
}

static PyObject *__pyx_f_6bzrlib_16_known_graph_pyx_10KnownGraph_heads(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_6bzrlib_16_known_graph_pyx_10KnownGraph_heads[] = "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_f_6bzrlib_16_known_graph_pyx_10KnownGraph_heads(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_keys = 0;
  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;
  PyObject *__pyx_v_parent_node;
  PyObject *__pyx_v_heads;
  PyObject *__pyx_r;
  PyObject *__pyx_1 = 0;
  PyObject *__pyx_2 = 0;
  PyObject *__pyx_3 = 0;
  int __pyx_4;
  int __pyx_5;
  Py_ssize_t __pyx_6;
  static char *__pyx_argnames[] = {"keys",0};
  if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "O", __pyx_argnames, &__pyx_v_keys)) return 0;
  Py_INCREF(__pyx_v_self);
  Py_INCREF(__pyx_v_keys);
  __pyx_v_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)Py_None); Py_INCREF(Py_None);
  __pyx_v_heads_key = Py_None; Py_INCREF(Py_None);
  __pyx_v_candidate_nodes = Py_None; Py_INCREF(Py_None);
  __pyx_v_key = Py_None; Py_INCREF(Py_None);
  __pyx_v_cleanup = Py_None; Py_INCREF(Py_None);
  __pyx_v_pending = Py_None; Py_INCREF(Py_None);
  __pyx_v_parent_node = Py_None; Py_INCREF(Py_None);
  __pyx_v_heads = Py_None; Py_INCREF(Py_None);

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":435 */
  __pyx_1 = __Pyx_GetName(__pyx_b, __pyx_n_frozenset); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 435; goto __pyx_L1;}
  __pyx_2 = PyTuple_New(1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 435; goto __pyx_L1;}
  Py_INCREF(__pyx_v_keys);
  PyTuple_SET_ITEM(__pyx_2, 0, __pyx_v_keys);
  __pyx_3 = PyObject_CallObject(__pyx_1, __pyx_2); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 435; goto __pyx_L1;}
  Py_DECREF(__pyx_1); __pyx_1 = 0;
  Py_DECREF(__pyx_2); __pyx_2 = 0;
  Py_DECREF(__pyx_v_heads_key);
  __pyx_v_heads_key = __pyx_3;
  __pyx_3 = 0;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":436 */
  __pyx_v_maybe_heads = PyDict_GetItem(((struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *)__pyx_v_self)->_known_heads,__pyx_v_heads_key);

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":437 */
  __pyx_4 = (__pyx_v_maybe_heads != NULL);
  if (__pyx_4) {
    Py_INCREF(((PyObject *)__pyx_v_maybe_heads));
    __pyx_r = ((PyObject *)__pyx_v_maybe_heads);
    goto __pyx_L0;
    goto __pyx_L2;
  }
  __pyx_L2:;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":440 */
  __pyx_1 = PyDict_New(); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 440; goto __pyx_L1;}
  Py_DECREF(__pyx_v_candidate_nodes);
  __pyx_v_candidate_nodes = __pyx_1;
  __pyx_1 = 0;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":441 */
  __pyx_2 = PyObject_GetIter(__pyx_v_keys); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 441; goto __pyx_L1;}
  for (;;) {
    __pyx_3 = PyIter_Next(__pyx_2);
    if (!__pyx_3) {
      if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 441; goto __pyx_L1;}
      break;
    }
    Py_DECREF(__pyx_v_key);
    __pyx_v_key = __pyx_3;
    __pyx_3 = 0;

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":442 */
    __pyx_v_maybe_node = PyDict_GetItem(((struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *)__pyx_v_self)->_nodes,__pyx_v_key);

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":443 */
    __pyx_4 = (__pyx_v_maybe_node == NULL);
    if (__pyx_4) {
      __pyx_1 = PyTuple_New(1); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 444; goto __pyx_L1;}
      Py_INCREF(__pyx_v_key);
      PyTuple_SET_ITEM(__pyx_1, 0, __pyx_v_key);
      __pyx_3 = PyNumber_Remainder(__pyx_k19p, __pyx_1); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 444; goto __pyx_L1;}
      Py_DECREF(__pyx_1); __pyx_1 = 0;
      __pyx_1 = PyTuple_New(1); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 444; goto __pyx_L1;}
      PyTuple_SET_ITEM(__pyx_1, 0, __pyx_3);
      __pyx_3 = 0;
      __pyx_3 = PyObject_CallObject(PyExc_KeyError, __pyx_1); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 444; goto __pyx_L1;}
      Py_DECREF(__pyx_1); __pyx_1 = 0;
      __Pyx_Raise(__pyx_3, 0, 0);
      Py_DECREF(__pyx_3); __pyx_3 = 0;
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 444; goto __pyx_L1;}
      goto __pyx_L5;
    }
    __pyx_L5:;

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":445 */
    __pyx_4 = PyDict_SetItem(__pyx_v_candidate_nodes,__pyx_v_key,((PyObject *)__pyx_v_maybe_node)); if (__pyx_4 == (-1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 445; goto __pyx_L1;}
  }
  Py_DECREF(__pyx_2); __pyx_2 = 0;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":446 */
  __pyx_v_maybe_node = PyDict_GetItem(__pyx_v_candidate_nodes,__pyx_v_6bzrlib_16_known_graph_pyx_NULL_REVISION);

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":447 */
  __pyx_4 = (__pyx_v_maybe_node != NULL);
  if (__pyx_4) {

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":449 */
    __pyx_1 = PyObject_GetAttr(__pyx_v_candidate_nodes, __pyx_n_pop); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 449; goto __pyx_L1;}
    __pyx_3 = PyTuple_New(1); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 449; goto __pyx_L1;}
    Py_INCREF(__pyx_v_6bzrlib_16_known_graph_pyx_NULL_REVISION);
    PyTuple_SET_ITEM(__pyx_3, 0, __pyx_v_6bzrlib_16_known_graph_pyx_NULL_REVISION);
    __pyx_2 = PyObject_CallObject(__pyx_1, __pyx_3); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 449; goto __pyx_L1;}
    Py_DECREF(__pyx_1); __pyx_1 = 0;
    Py_DECREF(__pyx_3); __pyx_3 = 0;
    Py_DECREF(__pyx_2); __pyx_2 = 0;

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":450 */
    __pyx_4 = PyObject_IsTrue(__pyx_v_candidate_nodes); if (__pyx_4 < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 450; goto __pyx_L1;}
    __pyx_5 = (!__pyx_4);
    if (__pyx_5) {
      __pyx_1 = __Pyx_GetName(__pyx_b, __pyx_n_frozenset); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 451; goto __pyx_L1;}
      __pyx_3 = PyList_New(1); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 451; goto __pyx_L1;}
      Py_INCREF(__pyx_v_6bzrlib_16_known_graph_pyx_NULL_REVISION);
      PyList_SET_ITEM(__pyx_3, 0, __pyx_v_6bzrlib_16_known_graph_pyx_NULL_REVISION);
      __pyx_2 = PyTuple_New(1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 451; goto __pyx_L1;}
      PyTuple_SET_ITEM(__pyx_2, 0, __pyx_3);
      __pyx_3 = 0;
      __pyx_3 = PyObject_CallObject(__pyx_1, __pyx_2); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 451; goto __pyx_L1;}
      Py_DECREF(__pyx_1); __pyx_1 = 0;
      Py_DECREF(__pyx_2); __pyx_2 = 0;
      __pyx_r = __pyx_3;
      __pyx_3 = 0;
      goto __pyx_L0;
      goto __pyx_L7;
    }
    __pyx_L7:;

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":453 */
    __pyx_1 = __Pyx_GetName(__pyx_b, __pyx_n_frozenset); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 453; goto __pyx_L1;}
    __pyx_2 = PyTuple_New(1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 453; goto __pyx_L1;}
    Py_INCREF(__pyx_v_candidate_nodes);
    PyTuple_SET_ITEM(__pyx_2, 0, __pyx_v_candidate_nodes);
    __pyx_3 = PyObject_CallObject(__pyx_1, __pyx_2); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 453; goto __pyx_L1;}
    Py_DECREF(__pyx_1); __pyx_1 = 0;
    Py_DECREF(__pyx_2); __pyx_2 = 0;
    Py_DECREF(__pyx_v_heads_key);
    __pyx_v_heads_key = __pyx_3;
    __pyx_3 = 0;
    goto __pyx_L6;
  }
  __pyx_L6:;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":454 */
  __pyx_6 = PyDict_Size(__pyx_v_candidate_nodes); if (__pyx_6 == (-1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 454; goto __pyx_L1;}
  __pyx_4 = (__pyx_6 < 2);
  if (__pyx_4) {
    Py_INCREF(__pyx_v_heads_key);
    __pyx_r = __pyx_v_heads_key;
    goto __pyx_L0;
    goto __pyx_L8;
  }
  __pyx_L8:;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":457 */
  __pyx_1 = PyList_New(0); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 457; goto __pyx_L1;}
  Py_DECREF(__pyx_v_cleanup);
  __pyx_v_cleanup = __pyx_1;
  __pyx_1 = 0;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":458 */
  __pyx_2 = PyList_New(0); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 458; goto __pyx_L1;}
  Py_DECREF(__pyx_v_pending);
  __pyx_v_pending = __pyx_2;
  __pyx_2 = 0;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":460 */
  __pyx_6 = PyDict_Size(((struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *)__pyx_v_self)->_nodes); if (__pyx_6 == (-1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 460; goto __pyx_L1;}
  __pyx_v_min_gdfo = (__pyx_6 + 1);

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":463 */
  __pyx_v_pos = 0;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":464 */
  while (1) {
    __pyx_5 = PyDict_Next(__pyx_v_candidate_nodes,(&__pyx_v_pos),NULL,(&__pyx_v_temp_node));
    if (!__pyx_5) break;

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":465 */
    Py_INCREF(((PyObject *)__pyx_v_temp_node));
    Py_DECREF(((PyObject *)__pyx_v_node));
    __pyx_v_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_v_temp_node);

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":466 */
    __pyx_4 = __pyx_v_node->parents != Py_None;
    if (__pyx_4) {
      __pyx_3 = PyObject_GetAttr(__pyx_v_pending, __pyx_n_extend); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 467; goto __pyx_L1;}
      __pyx_1 = PyTuple_New(1); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 467; goto __pyx_L1;}
      Py_INCREF(__pyx_v_node->parents);
      PyTuple_SET_ITEM(__pyx_1, 0, __pyx_v_node->parents);
      __pyx_2 = PyObject_CallObject(__pyx_3, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 467; goto __pyx_L1;}
      Py_DECREF(__pyx_3); __pyx_3 = 0;
      Py_DECREF(__pyx_1); __pyx_1 = 0;
      Py_DECREF(__pyx_2); __pyx_2 = 0;
      goto __pyx_L11;
    }
    __pyx_L11:;

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":468 */
    __pyx_5 = (__pyx_v_node->gdfo < __pyx_v_min_gdfo);
    if (__pyx_5) {
      __pyx_v_min_gdfo = __pyx_v_node->gdfo;
      goto __pyx_L12;
    }
    __pyx_L12:;
  }

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":472 */
  __pyx_v_last_item = (PyList_GET_SIZE(__pyx_v_pending) - 1);

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":473 */
  while (1) {
    __pyx_4 = (__pyx_v_last_item >= 0);
    if (!__pyx_4) break;

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":474 */
    __pyx_3 = ((PyObject *)__pyx_f_6bzrlib_16_known_graph_pyx__get_list_node(__pyx_v_pending,__pyx_v_last_item)); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 474; goto __pyx_L1;}
    Py_DECREF(((PyObject *)__pyx_v_node));
    __pyx_v_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_3);
    __pyx_3 = 0;

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":475 */
    __pyx_v_last_item = (__pyx_v_last_item - 1);

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":476 */
    __pyx_5 = __pyx_v_node->seen;
    if (__pyx_5) {
      goto __pyx_L13;
      goto __pyx_L15;
    }
    __pyx_L15:;

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":479 */
    __pyx_4 = PyList_Append(__pyx_v_cleanup,((PyObject *)__pyx_v_node)); if (__pyx_4 == (-1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 479; goto __pyx_L1;}

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":480 */
    __pyx_v_node->seen = 1;

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":481 */
    __pyx_5 = (__pyx_v_node->gdfo <= __pyx_v_min_gdfo);
    if (__pyx_5) {
      goto __pyx_L13;
      goto __pyx_L16;
    }
    __pyx_L16:;

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":483 */
    __pyx_4 = __pyx_v_node->parents != Py_None;
    if (__pyx_4) {
      __pyx_4 = (PyTuple_GET_SIZE(__pyx_v_node->parents) > 0);
    }
    if (__pyx_4) {
      __pyx_6 = PyTuple_GET_SIZE(__pyx_v_node->parents);
      for (__pyx_v_pos = 0; __pyx_v_pos < __pyx_6; ++__pyx_v_pos) {

        /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":485 */
        __pyx_1 = ((PyObject *)__pyx_f_6bzrlib_16_known_graph_pyx__get_tuple_node(__pyx_v_node->parents,__pyx_v_pos)); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 485; goto __pyx_L1;}
        Py_DECREF(__pyx_v_parent_node);
        __pyx_v_parent_node = __pyx_1;
        __pyx_1 = 0;

        /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":486 */
        __pyx_v_last_item = (__pyx_v_last_item + 1);

        /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":487 */
        __pyx_5 = (__pyx_v_last_item < PyList_GET_SIZE(__pyx_v_pending));
        if (__pyx_5) {

          /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":488 */
          Py_INCREF(__pyx_v_parent_node);

          /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":489 */
          __pyx_4 = PyList_SetItem(__pyx_v_pending,__pyx_v_last_item,__pyx_v_parent_node); if (__pyx_4 == (-1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 489; goto __pyx_L1;}
          goto __pyx_L20;
        }
        /*else*/ {
          __pyx_5 = PyList_Append(__pyx_v_pending,__pyx_v_parent_node); if (__pyx_5 == (-1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 491; goto __pyx_L1;}
        }
        __pyx_L20:;
      }
      goto __pyx_L17;
    }
    __pyx_L17:;
    __pyx_L13:;
  }

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":492 */
  __pyx_2 = PyList_New(0); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 492; goto __pyx_L1;}
  Py_DECREF(__pyx_v_heads);
  __pyx_v_heads = __pyx_2;
  __pyx_2 = 0;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":493 */
  __pyx_v_pos = 0;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":494 */
  while (1) {
    __pyx_4 = PyDict_Next(__pyx_v_candidate_nodes,(&__pyx_v_pos),NULL,(&__pyx_v_temp_node));
    if (!__pyx_4) break;

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":495 */
    Py_INCREF(((PyObject *)__pyx_v_temp_node));
    Py_DECREF(((PyObject *)__pyx_v_node));
    __pyx_v_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_v_temp_node);

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":496 */
    __pyx_5 = (!__pyx_v_node->seen);
    if (__pyx_5) {
      __pyx_4 = PyList_Append(__pyx_v_heads,__pyx_v_node->key); if (__pyx_4 == (-1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 497; goto __pyx_L1;}
      goto __pyx_L23;
    }
    __pyx_L23:;
  }

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":498 */
  __pyx_3 = __Pyx_GetName(__pyx_b, __pyx_n_frozenset); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 498; goto __pyx_L1;}
  __pyx_1 = PyTuple_New(1); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 498; goto __pyx_L1;}
  Py_INCREF(__pyx_v_heads);
  PyTuple_SET_ITEM(__pyx_1, 0, __pyx_v_heads);
  __pyx_2 = PyObject_CallObject(__pyx_3, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 498; goto __pyx_L1;}
  Py_DECREF(__pyx_3); __pyx_3 = 0;
  Py_DECREF(__pyx_1); __pyx_1 = 0;
  Py_DECREF(__pyx_v_heads);
  __pyx_v_heads = __pyx_2;
  __pyx_2 = 0;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":499 */
  __pyx_6 = PyList_GET_SIZE(__pyx_v_cleanup);
  for (__pyx_v_pos = 0; __pyx_v_pos < __pyx_6; ++__pyx_v_pos) {

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":500 */
    __pyx_3 = ((PyObject *)__pyx_f_6bzrlib_16_known_graph_pyx__get_list_node(__pyx_v_cleanup,__pyx_v_pos)); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 500; goto __pyx_L1;}
    Py_DECREF(((PyObject *)__pyx_v_node));
    __pyx_v_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_3);
    __pyx_3 = 0;

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":501 */
    __pyx_v_node->seen = 0;
  }

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":502 */
  __pyx_5 = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *)__pyx_v_self)->do_cache;
  if (__pyx_5) {
    __pyx_4 = PyDict_SetItem(((struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *)__pyx_v_self)->_known_heads,__pyx_v_heads_key,__pyx_v_heads); if (__pyx_4 == (-1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 503; goto __pyx_L1;}
    goto __pyx_L26;
  }
  __pyx_L26:;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":504 */
  Py_INCREF(__pyx_v_heads);
  __pyx_r = __pyx_v_heads;
  goto __pyx_L0;

  __pyx_r = Py_None; Py_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_1);
  Py_XDECREF(__pyx_2);
  Py_XDECREF(__pyx_3);
  __Pyx_AddTraceback("bzrlib._known_graph_pyx.KnownGraph.heads");
  __pyx_r = 0;
  __pyx_L0:;
  Py_DECREF(__pyx_v_node);
  Py_DECREF(__pyx_v_heads_key);
  Py_DECREF(__pyx_v_candidate_nodes);
  Py_DECREF(__pyx_v_key);
  Py_DECREF(__pyx_v_cleanup);
  Py_DECREF(__pyx_v_pending);
  Py_DECREF(__pyx_v_parent_node);
  Py_DECREF(__pyx_v_heads);
  Py_DECREF(__pyx_v_self);
  Py_DECREF(__pyx_v_keys);
  return __pyx_r;
}

static PyObject *__pyx_f_6bzrlib_16_known_graph_pyx_10KnownGraph_topo_sort(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_6bzrlib_16_known_graph_pyx_10KnownGraph_topo_sort[] = "Return the nodes in topological order.\n\n        All parents must occur before all children.\n        ";
static PyObject *__pyx_f_6bzrlib_16_known_graph_pyx_10KnownGraph_topo_sort(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  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;
  PyObject *__pyx_1 = 0;
  PyObject *__pyx_2 = 0;
  int __pyx_3;
  Py_ssize_t __pyx_4;
  PyObject *__pyx_5 = 0;
  static char *__pyx_argnames[] = {0};
  if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "", __pyx_argnames)) return 0;
  Py_INCREF(__pyx_v_self);
  __pyx_v_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)Py_None); Py_INCREF(Py_None);
  __pyx_v_child = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)Py_None); Py_INCREF(Py_None);
  __pyx_v_pending = Py_None; Py_INCREF(Py_None);
  __pyx_v_topo_order = Py_None; Py_INCREF(Py_None);

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":523 */
  __pyx_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n__find_tails); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 523; goto __pyx_L1;}
  __pyx_2 = PyObject_CallObject(__pyx_1, 0); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 523; goto __pyx_L1;}
  Py_DECREF(__pyx_1); __pyx_1 = 0;
  Py_DECREF(__pyx_v_pending);
  __pyx_v_pending = __pyx_2;
  __pyx_2 = 0;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":524 */
  __pyx_3 = (PyList_GET_SIZE(__pyx_v_pending) == 0);
  if (__pyx_3) {
    __pyx_4 = PyObject_Length(((struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *)__pyx_v_self)->_nodes); if (__pyx_4 == -1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 524; goto __pyx_L1;}
    __pyx_3 = (__pyx_4 > 0);
  }
  if (__pyx_3) {
    __pyx_1 = __Pyx_GetName(__pyx_m, __pyx_n_errors); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 525; goto __pyx_L1;}
    __pyx_2 = PyObject_GetAttr(__pyx_1, __pyx_n_GraphCycleError); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 525; goto __pyx_L1;}
    Py_DECREF(__pyx_1); __pyx_1 = 0;
    __pyx_1 = PyTuple_New(1); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 525; goto __pyx_L1;}
    Py_INCREF(((struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *)__pyx_v_self)->_nodes);
    PyTuple_SET_ITEM(__pyx_1, 0, ((struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *)__pyx_v_self)->_nodes);
    __pyx_5 = PyObject_CallObject(__pyx_2, __pyx_1); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 525; goto __pyx_L1;}
    Py_DECREF(__pyx_2); __pyx_2 = 0;
    Py_DECREF(__pyx_1); __pyx_1 = 0;
    __Pyx_Raise(__pyx_5, 0, 0);
    Py_DECREF(__pyx_5); __pyx_5 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 525; goto __pyx_L1;}
    goto __pyx_L2;
  }
  __pyx_L2:;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":527 */
  __pyx_2 = PyList_New(0); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 527; goto __pyx_L1;}
  Py_DECREF(__pyx_v_topo_order);
  __pyx_v_topo_order = __pyx_2;
  __pyx_2 = 0;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":529 */
  __pyx_v_last_item = (PyList_GET_SIZE(__pyx_v_pending) - 1);

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":530 */
  while (1) {
    __pyx_3 = (__pyx_v_last_item >= 0);
    if (!__pyx_3) break;

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":533 */
    __pyx_1 = ((PyObject *)__pyx_f_6bzrlib_16_known_graph_pyx__get_list_node(__pyx_v_pending,__pyx_v_last_item)); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 533; goto __pyx_L1;}
    Py_DECREF(((PyObject *)__pyx_v_node));
    __pyx_v_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_1);
    __pyx_1 = 0;

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":534 */
    __pyx_v_last_item = (__pyx_v_last_item - 1);

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":535 */
    __pyx_3 = __pyx_v_node->parents != Py_None;
    if (__pyx_3) {
      __pyx_3 = PyList_Append(__pyx_v_topo_order,__pyx_v_node->key); if (__pyx_3 == (-1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 537; goto __pyx_L1;}
      goto __pyx_L5;
    }
    __pyx_L5:;

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":538 */
    __pyx_4 = PyList_GET_SIZE(__pyx_v_node->children);
    for (__pyx_v_pos = 0; __pyx_v_pos < __pyx_4; ++__pyx_v_pos) {

      /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":539 */
      __pyx_5 = ((PyObject *)__pyx_f_6bzrlib_16_known_graph_pyx__get_list_node(__pyx_v_node->children,__pyx_v_pos)); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 539; goto __pyx_L1;}
      Py_DECREF(((PyObject *)__pyx_v_child));
      __pyx_v_child = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_5);
      __pyx_5 = 0;

      /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":540 */
      __pyx_3 = (__pyx_v_child->gdfo == (-1));
      if (__pyx_3) {
        __pyx_2 = __Pyx_GetName(__pyx_m, __pyx_n_errors); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 543; goto __pyx_L1;}
        __pyx_1 = PyObject_GetAttr(__pyx_2, __pyx_n_GraphCycleError); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 543; goto __pyx_L1;}
        Py_DECREF(__pyx_2); __pyx_2 = 0;
        __pyx_5 = PyTuple_New(1); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 543; goto __pyx_L1;}
        Py_INCREF(((struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *)__pyx_v_self)->_nodes);
        PyTuple_SET_ITEM(__pyx_5, 0, ((struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *)__pyx_v_self)->_nodes);
        __pyx_2 = PyObject_CallObject(__pyx_1, __pyx_5); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 543; goto __pyx_L1;}
        Py_DECREF(__pyx_1); __pyx_1 = 0;
        Py_DECREF(__pyx_5); __pyx_5 = 0;
        __Pyx_Raise(__pyx_2, 0, 0);
        Py_DECREF(__pyx_2); __pyx_2 = 0;
        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 543; goto __pyx_L1;}
        goto __pyx_L8;
      }
      __pyx_L8:;

      /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":544 */
      __pyx_v_child->seen = (__pyx_v_child->seen + 1);

      /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":545 */
      __pyx_3 = (__pyx_v_child->seen == PyTuple_GET_SIZE(__pyx_v_child->parents));
      if (__pyx_3) {

        /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":548 */
        __pyx_v_last_item = (__pyx_v_last_item + 1);

        /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":549 */
        __pyx_3 = (__pyx_v_last_item < PyList_GET_SIZE(__pyx_v_pending));
        if (__pyx_3) {

          /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":550 */
          Py_INCREF(((PyObject *)__pyx_v_child));

          /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":551 */
          __pyx_3 = PyList_SetItem(__pyx_v_pending,__pyx_v_last_item,((PyObject *)__pyx_v_child)); if (__pyx_3 == (-1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 551; goto __pyx_L1;}
          goto __pyx_L10;
        }
        /*else*/ {
          __pyx_3 = PyList_Append(__pyx_v_pending,((PyObject *)__pyx_v_child)); if (__pyx_3 == (-1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 553; goto __pyx_L1;}
        }
        __pyx_L10:;

        /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":556 */
        __pyx_v_child->seen = 0;
        goto __pyx_L9;
      }
      __pyx_L9:;
    }
  }

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":558 */
  Py_INCREF(__pyx_v_topo_order);
  __pyx_r = __pyx_v_topo_order;
  goto __pyx_L0;

  __pyx_r = Py_None; Py_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_1);
  Py_XDECREF(__pyx_2);
  Py_XDECREF(__pyx_5);
  __Pyx_AddTraceback("bzrlib._known_graph_pyx.KnownGraph.topo_sort");
  __pyx_r = 0;
  __pyx_L0:;
  Py_DECREF(__pyx_v_node);
  Py_DECREF(__pyx_v_child);
  Py_DECREF(__pyx_v_pending);
  Py_DECREF(__pyx_v_topo_order);
  Py_DECREF(__pyx_v_self);
  return __pyx_r;
}

static PyObject *__pyx_f_6bzrlib_16_known_graph_pyx_10KnownGraph_gc_sort(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_6bzrlib_16_known_graph_pyx_10KnownGraph_gc_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_f_6bzrlib_16_known_graph_pyx_10KnownGraph_gc_sort(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  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;
  PyObject *__pyx_1 = 0;
  PyObject *__pyx_2 = 0;
  Py_ssize_t __pyx_3;
  int __pyx_4;
  Py_ssize_t __pyx_5;
  PyObject *__pyx_6 = 0;
  static char *__pyx_argnames[] = {0};
  if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "", __pyx_argnames)) return 0;
  Py_INCREF(__pyx_v_self);
  __pyx_v_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)Py_None); Py_INCREF(Py_None);
  __pyx_v_parent_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)Py_None); Py_INCREF(Py_None);
  __pyx_v_tips = Py_None; Py_INCREF(Py_None);
  __pyx_v_prefix_tips = Py_None; Py_INCREF(Py_None);
  __pyx_v_prefix = Py_None; Py_INCREF(Py_None);
  __pyx_v_tip_nodes = Py_None; Py_INCREF(Py_None);
  __pyx_v_result = Py_None; Py_INCREF(Py_None);
  __pyx_v_pending = Py_None; Py_INCREF(Py_None);
  __pyx_v_parents = Py_None; Py_INCREF(Py_None);

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":575 */
  __pyx_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n__find_tips); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 575; goto __pyx_L1;}
  __pyx_2 = PyObject_CallObject(__pyx_1, 0); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 575; goto __pyx_L1;}
  Py_DECREF(__pyx_1); __pyx_1 = 0;
  Py_DECREF(__pyx_v_tips);
  __pyx_v_tips = __pyx_2;
  __pyx_2 = 0;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":577 */
  __pyx_1 = PyDict_New(); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 577; goto __pyx_L1;}
  Py_DECREF(__pyx_v_prefix_tips);
  __pyx_v_prefix_tips = __pyx_1;
  __pyx_1 = 0;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":578 */
  __pyx_3 = PyList_GET_SIZE(__pyx_v_tips);
  for (__pyx_v_pos = 0; __pyx_v_pos < __pyx_3; ++__pyx_v_pos) {

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":579 */
    __pyx_2 = ((PyObject *)__pyx_f_6bzrlib_16_known_graph_pyx__get_list_node(__pyx_v_tips,__pyx_v_pos)); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 579; goto __pyx_L1;}
    Py_DECREF(((PyObject *)__pyx_v_node));
    __pyx_v_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_2);
    __pyx_2 = 0;

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":580 */
    __pyx_4 = PyString_CheckExact(__pyx_v_node->key);
    if (!__pyx_4) {
      __pyx_5 = PyObject_Length(__pyx_v_node->key); if (__pyx_5 == -1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 580; goto __pyx_L1;}
      __pyx_4 = (__pyx_5 == 1);
    }
    if (__pyx_4) {
      Py_INCREF(__pyx_k25p);
      Py_DECREF(__pyx_v_prefix);
      __pyx_v_prefix = __pyx_k25p;
      goto __pyx_L4;
    }
    /*else*/ {
      __pyx_1 = __Pyx_GetItemInt(__pyx_v_node->key, 0); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 583; goto __pyx_L1;}
      Py_DECREF(__pyx_v_prefix);
      __pyx_v_prefix = __pyx_1;
      __pyx_1 = 0;
    }
    __pyx_L4:;

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":584 */
    __pyx_v_temp = PyDict_GetItem(__pyx_v_prefix_tips,__pyx_v_prefix);

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":585 */
    __pyx_4 = (__pyx_v_temp == NULL);
    if (__pyx_4) {
      __pyx_2 = PyList_New(1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 586; goto __pyx_L1;}
      Py_INCREF(((PyObject *)__pyx_v_node));
      PyList_SET_ITEM(__pyx_2, 0, ((PyObject *)__pyx_v_node));
      if (PyObject_SetItem(__pyx_v_prefix_tips, __pyx_v_prefix, __pyx_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 586; goto __pyx_L1;}
      Py_DECREF(__pyx_2); __pyx_2 = 0;
      goto __pyx_L5;
    }
    /*else*/ {

      /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":588 */
      Py_INCREF(((PyObject *)__pyx_v_temp));
      Py_DECREF(__pyx_v_tip_nodes);
      __pyx_v_tip_nodes = ((PyObject *)__pyx_v_temp);

      /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":589 */
      __pyx_4 = PyList_Append(__pyx_v_tip_nodes,((PyObject *)__pyx_v_node)); if (__pyx_4 == (-1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 589; goto __pyx_L1;}
    }
    __pyx_L5:;
  }

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":591 */
  __pyx_1 = PyList_New(0); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 591; goto __pyx_L1;}
  Py_DECREF(__pyx_v_result);
  __pyx_v_result = __pyx_1;
  __pyx_1 = 0;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":592 */
  __pyx_2 = __Pyx_GetName(__pyx_b, __pyx_n_sorted); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 592; goto __pyx_L1;}
  __pyx_1 = PyTuple_New(1); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 592; goto __pyx_L1;}
  Py_INCREF(__pyx_v_prefix_tips);
  PyTuple_SET_ITEM(__pyx_1, 0, __pyx_v_prefix_tips);
  __pyx_6 = PyObject_CallObject(__pyx_2, __pyx_1); if (!__pyx_6) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 592; goto __pyx_L1;}
  Py_DECREF(__pyx_2); __pyx_2 = 0;
  Py_DECREF(__pyx_1); __pyx_1 = 0;
  __pyx_2 = PyObject_GetIter(__pyx_6); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 592; goto __pyx_L1;}
  Py_DECREF(__pyx_6); __pyx_6 = 0;
  for (;;) {
    __pyx_1 = PyIter_Next(__pyx_2);
    if (!__pyx_1) {
      if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 592; goto __pyx_L1;}
      break;
    }
    Py_DECREF(__pyx_v_prefix);
    __pyx_v_prefix = __pyx_1;
    __pyx_1 = 0;

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":593 */
    __pyx_v_temp = PyDict_GetItem(__pyx_v_prefix_tips,__pyx_v_prefix);

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

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":595 */
    Py_INCREF(((PyObject *)__pyx_v_temp));
    Py_DECREF(__pyx_v_tip_nodes);
    __pyx_v_tip_nodes = ((PyObject *)__pyx_v_temp);

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":596 */
    __pyx_6 = __pyx_f_6bzrlib_16_known_graph_pyx__sort_list_nodes(__pyx_v_tip_nodes,1); if (!__pyx_6) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 596; goto __pyx_L1;}
    Py_DECREF(__pyx_v_pending);
    __pyx_v_pending = __pyx_6;
    __pyx_6 = 0;

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":597 */
    __pyx_v_last_item = (PyList_GET_SIZE(__pyx_v_pending) - 1);

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":598 */
    while (1) {
      __pyx_4 = (__pyx_v_last_item >= 0);
      if (!__pyx_4) break;

      /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":599 */
      __pyx_1 = ((PyObject *)__pyx_f_6bzrlib_16_known_graph_pyx__get_list_node(__pyx_v_pending,__pyx_v_last_item)); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 599; goto __pyx_L1;}
      Py_DECREF(((PyObject *)__pyx_v_node));
      __pyx_v_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_1);
      __pyx_1 = 0;

      /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":600 */
      __pyx_v_last_item = (__pyx_v_last_item - 1);

      /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":601 */
      __pyx_4 = __pyx_v_node->parents == Py_None;
      if (__pyx_4) {
        goto __pyx_L8;
        goto __pyx_L10;
      }
      __pyx_L10:;

      /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":604 */
      __pyx_4 = PyList_Append(__pyx_v_result,__pyx_v_node->key); if (__pyx_4 == (-1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 604; goto __pyx_L1;}

      /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":611 */
      __pyx_6 = __pyx_f_6bzrlib_16_known_graph_pyx__sort_list_nodes(__pyx_v_node->parents,1); if (!__pyx_6) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 611; goto __pyx_L1;}
      Py_DECREF(__pyx_v_parents);
      __pyx_v_parents = __pyx_6;
      __pyx_6 = 0;

      /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":612 */
      __pyx_5 = PyObject_Length(__pyx_v_parents); if (__pyx_5 == -1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 612; goto __pyx_L1;}
      for (__pyx_v_pos = 0; __pyx_v_pos < __pyx_5; ++__pyx_v_pos) {

        /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":613 */
        __pyx_4 = PyTuple_CheckExact(__pyx_v_parents);
        if (__pyx_4) {
          __pyx_1 = ((PyObject *)__pyx_f_6bzrlib_16_known_graph_pyx__get_tuple_node(__pyx_v_parents,__pyx_v_pos)); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 614; goto __pyx_L1;}
          Py_DECREF(((PyObject *)__pyx_v_parent_node));
          __pyx_v_parent_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_1);
          __pyx_1 = 0;
          goto __pyx_L13;
        }
        /*else*/ {
          __pyx_6 = ((PyObject *)__pyx_f_6bzrlib_16_known_graph_pyx__get_list_node(__pyx_v_parents,__pyx_v_pos)); if (!__pyx_6) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 616; goto __pyx_L1;}
          Py_DECREF(((PyObject *)__pyx_v_parent_node));
          __pyx_v_parent_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_6);
          __pyx_6 = 0;
        }
        __pyx_L13:;

        /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":618 */
        __pyx_v_parent_node->seen = (__pyx_v_parent_node->seen + 1);

        /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":619 */
        __pyx_4 = (__pyx_v_parent_node->seen == PyList_GET_SIZE(__pyx_v_parent_node->children));
        if (__pyx_4) {

          /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":623 */
          __pyx_v_last_item = (__pyx_v_last_item + 1);

          /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":624 */
          __pyx_4 = (__pyx_v_last_item < PyList_GET_SIZE(__pyx_v_pending));
          if (__pyx_4) {

            /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":625 */
            Py_INCREF(((PyObject *)__pyx_v_parent_node));

            /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":626 */
            __pyx_4 = PyList_SetItem(__pyx_v_pending,__pyx_v_last_item,((PyObject *)__pyx_v_parent_node)); if (__pyx_4 == (-1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 626; goto __pyx_L1;}
            goto __pyx_L15;
          }
          /*else*/ {
            __pyx_4 = PyList_Append(__pyx_v_pending,((PyObject *)__pyx_v_parent_node)); if (__pyx_4 == (-1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 628; goto __pyx_L1;}
          }
          __pyx_L15:;

          /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":629 */
          __pyx_v_parent_node->seen = 0;
          goto __pyx_L14;
        }
        __pyx_L14:;
      }
      __pyx_L8:;
    }
  }
  Py_DECREF(__pyx_2); __pyx_2 = 0;

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

  __pyx_r = Py_None; Py_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_1);
  Py_XDECREF(__pyx_2);
  Py_XDECREF(__pyx_6);
  __Pyx_AddTraceback("bzrlib._known_graph_pyx.KnownGraph.gc_sort");
  __pyx_r = 0;
  __pyx_L0:;
  Py_DECREF(__pyx_v_node);
  Py_DECREF(__pyx_v_parent_node);
  Py_DECREF(__pyx_v_tips);
  Py_DECREF(__pyx_v_prefix_tips);
  Py_DECREF(__pyx_v_prefix);
  Py_DECREF(__pyx_v_tip_nodes);
  Py_DECREF(__pyx_v_result);
  Py_DECREF(__pyx_v_pending);
  Py_DECREF(__pyx_v_parents);
  Py_DECREF(__pyx_v_self);
  return __pyx_r;
}

static PyObject *__pyx_f_6bzrlib_16_known_graph_pyx_10KnownGraph_merge_sort(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_6bzrlib_16_known_graph_pyx_10KnownGraph_merge_sort[] = "Compute the merge sorted graph output.";
static PyObject *__pyx_f_6bzrlib_16_known_graph_pyx_10KnownGraph_merge_sort(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_tip_key = 0;
  struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSorter *__pyx_v_sorter;
  PyObject *__pyx_r;
  PyObject *__pyx_1 = 0;
  PyObject *__pyx_2 = 0;
  static char *__pyx_argnames[] = {"tip_key",0};
  if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "O", __pyx_argnames, &__pyx_v_tip_key)) return 0;
  Py_INCREF(__pyx_v_self);
  Py_INCREF(__pyx_v_tip_key);
  __pyx_v_sorter = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSorter *)Py_None); Py_INCREF(Py_None);

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":639 */
  __pyx_1 = PyTuple_New(2); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 639; goto __pyx_L1;}
  Py_INCREF(__pyx_v_self);
  PyTuple_SET_ITEM(__pyx_1, 0, __pyx_v_self);
  Py_INCREF(__pyx_v_tip_key);
  PyTuple_SET_ITEM(__pyx_1, 1, __pyx_v_tip_key);
  __pyx_2 = PyObject_CallObject(((PyObject *)__pyx_ptype_6bzrlib_16_known_graph_pyx__MergeSorter), __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 639; goto __pyx_L1;}
  Py_DECREF(__pyx_1); __pyx_1 = 0;
  Py_DECREF(((PyObject *)__pyx_v_sorter));
  __pyx_v_sorter = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSorter *)__pyx_2);
  __pyx_2 = 0;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":640 */
  __pyx_1 = ((struct __pyx_vtabstruct_6bzrlib_16_known_graph_pyx__MergeSorter *)__pyx_v_sorter->__pyx_vtab)->topo_order(__pyx_v_sorter); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 640; goto __pyx_L1;}
  __pyx_r = __pyx_1;
  __pyx_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; Py_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_1);
  Py_XDECREF(__pyx_2);
  __Pyx_AddTraceback("bzrlib._known_graph_pyx.KnownGraph.merge_sort");
  __pyx_r = 0;
  __pyx_L0:;
  Py_DECREF(__pyx_v_sorter);
  Py_DECREF(__pyx_v_self);
  Py_DECREF(__pyx_v_tip_key);
  return __pyx_r;
}

static PyObject *__pyx_f_6bzrlib_16_known_graph_pyx_10KnownGraph_get_parent_keys(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_6bzrlib_16_known_graph_pyx_10KnownGraph_get_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_f_6bzrlib_16_known_graph_pyx_10KnownGraph_get_parent_keys(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_key = 0;
  PyObject *__pyx_r;
  PyObject *__pyx_1 = 0;
  PyObject *__pyx_2 = 0;
  static char *__pyx_argnames[] = {"key",0};
  if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "O", __pyx_argnames, &__pyx_v_key)) return 0;
  Py_INCREF(__pyx_v_self);
  Py_INCREF(__pyx_v_key);
  __pyx_1 = PyObject_GetItem(((struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *)__pyx_v_self)->_nodes, __pyx_v_key); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 652; goto __pyx_L1;}
  __pyx_2 = PyObject_GetAttr(__pyx_1, __pyx_n_parent_keys); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 652; goto __pyx_L1;}
  Py_DECREF(__pyx_1); __pyx_1 = 0;
  __pyx_r = __pyx_2;
  __pyx_2 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; Py_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_1);
  Py_XDECREF(__pyx_2);
  __Pyx_AddTraceback("bzrlib._known_graph_pyx.KnownGraph.get_parent_keys");
  __pyx_r = 0;
  __pyx_L0:;
  Py_DECREF(__pyx_v_self);
  Py_DECREF(__pyx_v_key);
  return __pyx_r;
}

static PyObject *__pyx_f_6bzrlib_16_known_graph_pyx_10KnownGraph_get_child_keys(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_6bzrlib_16_known_graph_pyx_10KnownGraph_get_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_f_6bzrlib_16_known_graph_pyx_10KnownGraph_get_child_keys(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_key = 0;
  PyObject *__pyx_r;
  PyObject *__pyx_1 = 0;
  PyObject *__pyx_2 = 0;
  static char *__pyx_argnames[] = {"key",0};
  if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "O", __pyx_argnames, &__pyx_v_key)) return 0;
  Py_INCREF(__pyx_v_self);
  Py_INCREF(__pyx_v_key);
  __pyx_1 = PyObject_GetItem(((struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *)__pyx_v_self)->_nodes, __pyx_v_key); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 663; goto __pyx_L1;}
  __pyx_2 = PyObject_GetAttr(__pyx_1, __pyx_n_child_keys); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 663; goto __pyx_L1;}
  Py_DECREF(__pyx_1); __pyx_1 = 0;
  __pyx_r = __pyx_2;
  __pyx_2 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; Py_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_1);
  Py_XDECREF(__pyx_2);
  __Pyx_AddTraceback("bzrlib._known_graph_pyx.KnownGraph.get_child_keys");
  __pyx_r = 0;
  __pyx_L0:;
  Py_DECREF(__pyx_v_self);
  Py_DECREF(__pyx_v_key);
  return __pyx_r;
}

static int __pyx_f_6bzrlib_16_known_graph_pyx_14_MergeSortNode___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_f_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 char *__pyx_argnames[] = {"key",0};
  if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "O", __pyx_argnames, &__pyx_v_key)) return -1;
  Py_INCREF(__pyx_v_self);
  Py_INCREF(__pyx_v_key);

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":687 */
  Py_INCREF(__pyx_v_key);
  Py_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;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":688 */
  ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)__pyx_v_self)->merge_depth = (-1);

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":689 */
  Py_INCREF(Py_None);
  Py_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);

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":690 */
  Py_INCREF(Py_None);
  Py_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);

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":691 */
  Py_INCREF(Py_None);
  Py_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;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":692 */
  ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)__pyx_v_self)->_revno_first = (-1);

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":693 */
  ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)__pyx_v_self)->_revno_second = (-1);

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":694 */
  ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)__pyx_v_self)->_revno_last = (-1);

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":695 */
  ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)__pyx_v_self)->is_first_child = 0;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":696 */
  ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)__pyx_v_self)->seen_by_child = 0;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":697 */
  ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)__pyx_v_self)->completed = 0;

  __pyx_r = 0;
  Py_DECREF(__pyx_v_self);
  Py_DECREF(__pyx_v_key);
  return __pyx_r;
}

static PyObject *__pyx_f_6bzrlib_16_known_graph_pyx_14_MergeSortNode___repr__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_f_6bzrlib_16_known_graph_pyx_14_MergeSortNode___repr__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r;
  PyObject *__pyx_1 = 0;
  PyObject *__pyx_2 = 0;
  PyObject *__pyx_3 = 0;
  PyObject *__pyx_4 = 0;
  PyObject *__pyx_5 = 0;
  PyObject *__pyx_6 = 0;
  PyObject *__pyx_7 = 0;
  PyObject *__pyx_8 = 0;
  Py_INCREF(__pyx_v_self);
  __pyx_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n___class__); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 701; goto __pyx_L1;}
  __pyx_2 = PyObject_GetAttr(__pyx_1, __pyx_n___name__); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 701; goto __pyx_L1;}
  Py_DECREF(__pyx_1); __pyx_1 = 0;
  __pyx_1 = PyInt_FromLong(((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)__pyx_v_self)->merge_depth); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 702; goto __pyx_L1;}
  __pyx_3 = PyInt_FromLong(((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)__pyx_v_self)->_revno_first); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 703; goto __pyx_L1;}
  __pyx_4 = PyInt_FromLong(((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)__pyx_v_self)->_revno_second); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 703; goto __pyx_L1;}
  __pyx_5 = PyInt_FromLong(((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)__pyx_v_self)->_revno_last); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 703; goto __pyx_L1;}
  __pyx_6 = PyInt_FromLong(((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)__pyx_v_self)->is_first_child); if (!__pyx_6) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 704; goto __pyx_L1;}
  __pyx_7 = PyInt_FromLong(((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)__pyx_v_self)->seen_by_child); if (!__pyx_7) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 704; goto __pyx_L1;}
  __pyx_8 = PyTuple_New(8); if (!__pyx_8) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 701; goto __pyx_L1;}
  PyTuple_SET_ITEM(__pyx_8, 0, __pyx_2);
  Py_INCREF(((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)__pyx_v_self)->key);
  PyTuple_SET_ITEM(__pyx_8, 1, ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)__pyx_v_self)->key);
  PyTuple_SET_ITEM(__pyx_8, 2, __pyx_1);
  PyTuple_SET_ITEM(__pyx_8, 3, __pyx_3);
  PyTuple_SET_ITEM(__pyx_8, 4, __pyx_4);
  PyTuple_SET_ITEM(__pyx_8, 5, __pyx_5);
  PyTuple_SET_ITEM(__pyx_8, 6, __pyx_6);
  PyTuple_SET_ITEM(__pyx_8, 7, __pyx_7);
  __pyx_2 = 0;
  __pyx_1 = 0;
  __pyx_3 = 0;
  __pyx_4 = 0;
  __pyx_5 = 0;
  __pyx_6 = 0;
  __pyx_7 = 0;
  __pyx_2 = PyNumber_Remainder(__pyx_k29p, __pyx_8); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 700; goto __pyx_L1;}
  Py_DECREF(__pyx_8); __pyx_8 = 0;
  __pyx_r = __pyx_2;
  __pyx_2 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; Py_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_1);
  Py_XDECREF(__pyx_2);
  Py_XDECREF(__pyx_3);
  Py_XDECREF(__pyx_4);
  Py_XDECREF(__pyx_5);
  Py_XDECREF(__pyx_6);
  Py_XDECREF(__pyx_7);
  Py_XDECREF(__pyx_8);
  __Pyx_AddTraceback("bzrlib._known_graph_pyx._MergeSortNode.__repr__");
  __pyx_r = 0;
  __pyx_L0:;
  Py_DECREF(__pyx_v_self);
  return __pyx_r;
}

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;
  PyObject *__pyx_1 = 0;
  int __pyx_2;
  Py_INCREF(__pyx_v_self);

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":707 */
  __pyx_2 = ((PyObject *)__pyx_v_self->left_pending_parent) != Py_None;
  __pyx_1 = PyInt_FromLong(__pyx_2); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 707; goto __pyx_L1;}
  __pyx_2 = PyObject_IsTrue(__pyx_1); if (__pyx_2 < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 707; goto __pyx_L1;}
  if (!__pyx_2) {
    Py_DECREF(__pyx_1); __pyx_1 = 0;
    __pyx_1 = __pyx_v_self->pending_parents;
    Py_INCREF(__pyx_1);
  }
  __pyx_2 = PyObject_IsTrue(__pyx_1); if (__pyx_2 < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 707; goto __pyx_L1;}
  Py_DECREF(__pyx_1); __pyx_1 = 0;
  if (__pyx_2) {
    __pyx_r = 1;
    goto __pyx_L0;
    goto __pyx_L2;
  }
  __pyx_L2:;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":709 */
  __pyx_r = 0;
  goto __pyx_L0;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_1);
  __Pyx_WriteUnraisable("bzrlib._known_graph_pyx._MergeSortNode.has_pending_parents");
  __pyx_r = 0;
  __pyx_L0:;
  Py_DECREF(__pyx_v_self);
  return __pyx_r;
}

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;
  int __pyx_1;
  PyObject *__pyx_2 = 0;
  PyObject *__pyx_3 = 0;
  PyObject *__pyx_4 = 0;
  PyObject *__pyx_5 = 0;
  Py_INCREF(__pyx_v_self);
  __pyx_1 = (__pyx_v_self->_revno_first == (-1));
  if (__pyx_1) {

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":713 */
    __pyx_1 = (__pyx_v_self->_revno_second != (-1));
    if (__pyx_1) {
      __pyx_2 = PyTuple_New(1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 714; goto __pyx_L1;}
      Py_INCREF(((PyObject *)__pyx_v_self));
      PyTuple_SET_ITEM(__pyx_2, 0, ((PyObject *)__pyx_v_self));
      __pyx_3 = PyNumber_Remainder(__pyx_k30p, __pyx_2); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 714; goto __pyx_L1;}
      Py_DECREF(__pyx_2); __pyx_2 = 0;
      __pyx_2 = PyTuple_New(1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 714; goto __pyx_L1;}
      PyTuple_SET_ITEM(__pyx_2, 0, __pyx_3);
      __pyx_3 = 0;
      __pyx_3 = PyObject_CallObject(PyExc_RuntimeError, __pyx_2); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 714; goto __pyx_L1;}
      Py_DECREF(__pyx_2); __pyx_2 = 0;
      __Pyx_Raise(__pyx_3, 0, 0);
      Py_DECREF(__pyx_3); __pyx_3 = 0;
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 714; goto __pyx_L1;}
      goto __pyx_L3;
    }
    __pyx_L3:;

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":715 */
    __pyx_2 = PyInt_FromLong(__pyx_v_self->_revno_last); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 715; goto __pyx_L1;}
    __pyx_3 = PyTuple_New(1); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 715; goto __pyx_L1;}
    PyTuple_SET_ITEM(__pyx_3, 0, __pyx_2);
    __pyx_2 = 0;
    __pyx_r = __pyx_3;
    __pyx_3 = 0;
    goto __pyx_L0;
    goto __pyx_L2;
  }
  /*else*/ {
    __pyx_2 = PyInt_FromLong(__pyx_v_self->_revno_first); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 717; goto __pyx_L1;}
    __pyx_3 = PyInt_FromLong(__pyx_v_self->_revno_second); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 717; goto __pyx_L1;}
    __pyx_4 = PyInt_FromLong(__pyx_v_self->_revno_last); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 717; goto __pyx_L1;}
    __pyx_5 = PyTuple_New(3); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 717; goto __pyx_L1;}
    PyTuple_SET_ITEM(__pyx_5, 0, __pyx_2);
    PyTuple_SET_ITEM(__pyx_5, 1, __pyx_3);
    PyTuple_SET_ITEM(__pyx_5, 2, __pyx_4);
    __pyx_2 = 0;
    __pyx_3 = 0;
    __pyx_4 = 0;
    __pyx_r = __pyx_5;
    __pyx_5 = 0;
    goto __pyx_L0;
  }
  __pyx_L2:;

  __pyx_r = Py_None; Py_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_2);
  Py_XDECREF(__pyx_3);
  Py_XDECREF(__pyx_4);
  Py_XDECREF(__pyx_5);
  __Pyx_AddTraceback("bzrlib._known_graph_pyx._MergeSortNode._revno");
  __pyx_r = 0;
  __pyx_L0:;
  Py_DECREF(__pyx_v_self);
  return __pyx_r;
}

static PyObject *__pyx_f_6bzrlib_16_known_graph_pyx_14_MergeSortNode_5revno___get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_f_6bzrlib_16_known_graph_pyx_14_MergeSortNode_5revno___get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r;
  PyObject *__pyx_1 = 0;
  Py_INCREF(__pyx_v_self);
  __pyx_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 (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 721; goto __pyx_L1;}
  __pyx_r = __pyx_1;
  __pyx_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; Py_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_1);
  __Pyx_AddTraceback("bzrlib._known_graph_pyx._MergeSortNode.revno.__get__");
  __pyx_r = 0;
  __pyx_L0:;
  Py_DECREF(__pyx_v_self);
  return __pyx_r;
}

static int __pyx_f_6bzrlib_16_known_graph_pyx_12_MergeSorter___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_f_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_1 = 0;
  int __pyx_2;
  static char *__pyx_argnames[] = {"known_graph","tip_key",0};
  if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "OO", __pyx_argnames, &__pyx_v_known_graph, &__pyx_v_tip_key)) return -1;
  Py_INCREF(__pyx_v_self);
  Py_INCREF(__pyx_v_known_graph);
  Py_INCREF(__pyx_v_tip_key);
  __pyx_v_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)Py_None); Py_INCREF(Py_None);

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":746 */
  if (!__Pyx_TypeTest(__pyx_v_known_graph, __pyx_ptype_6bzrlib_16_known_graph_pyx_KnownGraph)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 746; goto __pyx_L1;}
  Py_INCREF(__pyx_v_known_graph);
  Py_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);

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":748 */
  __pyx_1 = PyDict_New(); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 748; goto __pyx_L1;}
  Py_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 = __pyx_1;
  __pyx_1 = 0;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":749 */
  __pyx_1 = PyList_New(0); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 749; goto __pyx_L1;}
  Py_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 = __pyx_1;
  __pyx_1 = 0;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":750 */
  ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSorter *)__pyx_v_self)->_last_stack_item = (-1);

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":751 */
  __pyx_1 = PyList_New(0); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 751; goto __pyx_L1;}
  Py_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 = __pyx_1;
  __pyx_1 = 0;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":752 */
  __pyx_2 = __pyx_v_tip_key != Py_None;
  if (__pyx_2) {
    if (PyObject_Cmp(__pyx_v_tip_key, __pyx_v_6bzrlib_16_known_graph_pyx_NULL_REVISION, &__pyx_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 752; goto __pyx_L1;}
    __pyx_2 = __pyx_2 != 0;
    if (__pyx_2) {
      __pyx_1 = PyTuple_New(1); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 753; goto __pyx_L1;}
      Py_INCREF(__pyx_v_6bzrlib_16_known_graph_pyx_NULL_REVISION);
      PyTuple_SET_ITEM(__pyx_1, 0, __pyx_v_6bzrlib_16_known_graph_pyx_NULL_REVISION);
      if (PyObject_Cmp(__pyx_v_tip_key, __pyx_1, &__pyx_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 753; goto __pyx_L1;}
      __pyx_2 = __pyx_2 != 0;
      Py_DECREF(__pyx_1); __pyx_1 = 0;
    }
  }
  if (__pyx_2) {

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":754 */
    __pyx_1 = PyObject_GetItem(((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSorter *)__pyx_v_self)->graph->_nodes, __pyx_v_tip_key); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 754; goto __pyx_L1;}
    if (!__Pyx_TypeTest(__pyx_1, __pyx_ptype_6bzrlib_16_known_graph_pyx__KnownGraphNode)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 754; goto __pyx_L1;}
    Py_DECREF(((PyObject *)__pyx_v_node));
    __pyx_v_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_1);
    __pyx_1 = 0;

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":755 */
    __pyx_1 = ((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 (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 755; goto __pyx_L1;}
    Py_DECREF(__pyx_1); __pyx_1 = 0;
    goto __pyx_L2;
  }
  __pyx_L2:;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_1);
  __Pyx_AddTraceback("bzrlib._known_graph_pyx._MergeSorter.__init__");
  __pyx_r = -1;
  __pyx_L0:;
  Py_DECREF(__pyx_v_node);
  Py_DECREF(__pyx_v_self);
  Py_DECREF(__pyx_v_known_graph);
  Py_DECREF(__pyx_v_tip_key);
  return __pyx_r;
}

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;
  int __pyx_1;
  PyObject *__pyx_2 = 0;
  PyObject *__pyx_3 = 0;
  Py_INCREF(__pyx_v_self);
  Py_INCREF(__pyx_v_node);
  __pyx_v_ms_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)Py_None); Py_INCREF(Py_None);

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":761 */
  __pyx_1 = __pyx_v_node->extra == Py_None;
  if (__pyx_1) {

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":762 */
    __pyx_2 = PyTuple_New(1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 762; goto __pyx_L1;}
    Py_INCREF(__pyx_v_node->key);
    PyTuple_SET_ITEM(__pyx_2, 0, __pyx_v_node->key);
    __pyx_3 = PyObject_CallObject(((PyObject *)__pyx_ptype_6bzrlib_16_known_graph_pyx__MergeSortNode), __pyx_2); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 762; goto __pyx_L1;}
    Py_DECREF(__pyx_2); __pyx_2 = 0;
    Py_DECREF(((PyObject *)__pyx_v_ms_node));
    __pyx_v_ms_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)__pyx_3);
    __pyx_3 = 0;

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":763 */
    Py_INCREF(((PyObject *)__pyx_v_ms_node));
    Py_DECREF(__pyx_v_node->extra);
    __pyx_v_node->extra = ((PyObject *)__pyx_v_ms_node);
    goto __pyx_L2;
  }
  /*else*/ {
    Py_INCREF(__pyx_v_node->extra);
    Py_DECREF(((PyObject *)__pyx_v_ms_node));
    __pyx_v_ms_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)__pyx_v_node->extra);
  }
  __pyx_L2:;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":766 */
  Py_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); Py_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_2);
  Py_XDECREF(__pyx_3);
  __Pyx_AddTraceback("bzrlib._known_graph_pyx._MergeSorter._get_ms_node");
  __pyx_r = 0;
  __pyx_L0:;
  Py_DECREF(__pyx_v_ms_node);
  Py_DECREF(__pyx_v_self);
  Py_DECREF(__pyx_v_node);
  return __pyx_r;
}

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;
  PyObject *__pyx_1 = 0;
  int __pyx_2;
  PyObject *__pyx_3 = 0;
  Py_ssize_t __pyx_4;
  Py_INCREF(__pyx_v_self);
  Py_INCREF(__pyx_v_node);
  __pyx_v_parent_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)Py_None); Py_INCREF(Py_None);
  __pyx_v_ms_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)Py_None); Py_INCREF(Py_None);
  __pyx_v_ms_parent_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)Py_None); Py_INCREF(Py_None);

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":773 */
  __pyx_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 (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 773; goto __pyx_L1;}
  Py_DECREF(((PyObject *)__pyx_v_ms_node));
  __pyx_v_ms_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)__pyx_1);
  __pyx_1 = 0;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":774 */
  __pyx_v_ms_node->merge_depth = __pyx_v_merge_depth;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":775 */
  __pyx_2 = __pyx_v_node->parents == Py_None;
  if (__pyx_2) {
    __pyx_1 = PyTuple_New(1); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 777; goto __pyx_L1;}
    Py_INCREF(((PyObject *)__pyx_v_node));
    PyTuple_SET_ITEM(__pyx_1, 0, ((PyObject *)__pyx_v_node));
    __pyx_3 = PyNumber_Remainder(__pyx_k31p, __pyx_1); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 777; goto __pyx_L1;}
    Py_DECREF(__pyx_1); __pyx_1 = 0;
    __pyx_1 = PyTuple_New(1); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 776; goto __pyx_L1;}
    PyTuple_SET_ITEM(__pyx_1, 0, __pyx_3);
    __pyx_3 = 0;
    __pyx_3 = PyObject_CallObject(PyExc_RuntimeError, __pyx_1); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 776; goto __pyx_L1;}
    Py_DECREF(__pyx_1); __pyx_1 = 0;
    __Pyx_Raise(__pyx_3, 0, 0);
    Py_DECREF(__pyx_3); __pyx_3 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 776; goto __pyx_L1;}
    goto __pyx_L2;
  }
  __pyx_L2:;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":778 */
  __pyx_2 = (PyTuple_GET_SIZE(__pyx_v_node->parents) > 0);
  if (__pyx_2) {

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":779 */
    __pyx_1 = ((PyObject *)__pyx_f_6bzrlib_16_known_graph_pyx__get_tuple_node(__pyx_v_node->parents,0)); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 779; goto __pyx_L1;}
    Py_DECREF(((PyObject *)__pyx_v_parent_node));
    __pyx_v_parent_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_1);
    __pyx_1 = 0;

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":780 */
    Py_INCREF(((PyObject *)__pyx_v_parent_node));
    Py_DECREF(((PyObject *)__pyx_v_ms_node->left_parent));
    __pyx_v_ms_node->left_parent = __pyx_v_parent_node;

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":781 */
    __pyx_2 = __pyx_v_parent_node->parents == Py_None;
    if (__pyx_2) {

      /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":782 */
      Py_INCREF(Py_None);
      Py_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);

      /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":783 */
      Py_INCREF(Py_None);
      Py_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_L4;
    }
    /*else*/ {
      Py_INCREF(((PyObject *)__pyx_v_parent_node));
      Py_DECREF(((PyObject *)__pyx_v_ms_node->left_pending_parent));
      __pyx_v_ms_node->left_pending_parent = __pyx_v_parent_node;
    }
    __pyx_L4:;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":786 */
  __pyx_2 = (PyTuple_GET_SIZE(__pyx_v_node->parents) > 1);
  if (__pyx_2) {

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":787 */
    __pyx_3 = PyList_New(0); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 787; goto __pyx_L1;}
    Py_DECREF(__pyx_v_ms_node->pending_parents);
    __pyx_v_ms_node->pending_parents = __pyx_3;
    __pyx_3 = 0;

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":788 */
    __pyx_4 = PyTuple_GET_SIZE(__pyx_v_node->parents);
    for (__pyx_v_pos = 1; __pyx_v_pos < __pyx_4; ++__pyx_v_pos) {

      /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":789 */
      __pyx_1 = ((PyObject *)__pyx_f_6bzrlib_16_known_graph_pyx__get_tuple_node(__pyx_v_node->parents,__pyx_v_pos)); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 789; goto __pyx_L1;}
      Py_DECREF(((PyObject *)__pyx_v_parent_node));
      __pyx_v_parent_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_1);
      __pyx_1 = 0;

      /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":790 */
      __pyx_2 = __pyx_v_parent_node->parents == Py_None;
      if (__pyx_2) {
        goto __pyx_L6;
        goto __pyx_L8;
      }
      __pyx_L8:;

      /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":792 */
      __pyx_2 = PyList_Append(__pyx_v_ms_node->pending_parents,((PyObject *)__pyx_v_parent_node)); if (__pyx_2 == (-1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 792; goto __pyx_L1;}
      __pyx_L6:;
    }
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":794 */
  __pyx_v_ms_node->is_first_child = 1;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":795 */
  __pyx_2 = ((PyObject *)__pyx_v_ms_node->left_parent) != Py_None;
  if (__pyx_2) {

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":796 */
    __pyx_3 = ((PyObject *)((struct __pyx_vtabstruct_6bzrlib_16_known_graph_pyx__MergeSorter *)__pyx_v_self->__pyx_vtab)->_get_ms_node(__pyx_v_self,__pyx_v_ms_node->left_parent)); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 796; goto __pyx_L1;}
    Py_DECREF(((PyObject *)__pyx_v_ms_parent_node));
    __pyx_v_ms_parent_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)__pyx_3);
    __pyx_3 = 0;

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":797 */
    __pyx_2 = __pyx_v_ms_parent_node->seen_by_child;
    if (__pyx_2) {
      __pyx_v_ms_node->is_first_child = 0;
      goto __pyx_L10;
    }
    __pyx_L10:;

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":799 */
    __pyx_v_ms_parent_node->seen_by_child = 1;
    goto __pyx_L9;
  }
  __pyx_L9:;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":800 */
  __pyx_v_self->_last_stack_item = (__pyx_v_self->_last_stack_item + 1);

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":801 */
  __pyx_2 = (__pyx_v_self->_last_stack_item < PyList_GET_SIZE(__pyx_v_self->_depth_first_stack));
  if (__pyx_2) {

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":802 */
    Py_INCREF(((PyObject *)__pyx_v_node));

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":803 */
    __pyx_2 = PyList_SetItem(__pyx_v_self->_depth_first_stack,__pyx_v_self->_last_stack_item,((PyObject *)__pyx_v_node)); if (__pyx_2 == (-1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 803; goto __pyx_L1;}
    goto __pyx_L11;
  }
  /*else*/ {
    __pyx_2 = PyList_Append(__pyx_v_self->_depth_first_stack,((PyObject *)__pyx_v_node)); if (__pyx_2 == (-1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 806; goto __pyx_L1;}
  }
  __pyx_L11:;

  __pyx_r = Py_None; Py_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_1);
  Py_XDECREF(__pyx_3);
  __Pyx_AddTraceback("bzrlib._known_graph_pyx._MergeSorter._push_node");
  __pyx_r = 0;
  __pyx_L0:;
  Py_DECREF(__pyx_v_parent_node);
  Py_DECREF(__pyx_v_ms_node);
  Py_DECREF(__pyx_v_ms_parent_node);
  Py_DECREF(__pyx_v_self);
  Py_DECREF(__pyx_v_node);
  return __pyx_r;
}

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;
  PyObject *__pyx_v_base_revno;
  PyObject *__pyx_v_branch_count;
  PyObject *__pyx_v_root_count;
  PyObject *__pyx_r;
  PyObject *__pyx_1 = 0;
  int __pyx_2;
  PyObject *__pyx_3 = 0;
  long __pyx_4;
  Py_INCREF(__pyx_v_self);
  __pyx_v_ms_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)Py_None); Py_INCREF(Py_None);
  __pyx_v_ms_parent_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)Py_None); Py_INCREF(Py_None);
  __pyx_v_ms_prev_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)Py_None); Py_INCREF(Py_None);
  __pyx_v_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)Py_None); Py_INCREF(Py_None);
  __pyx_v_prev_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)Py_None); Py_INCREF(Py_None);
  __pyx_v_base_revno = Py_None; Py_INCREF(Py_None);
  __pyx_v_branch_count = Py_None; Py_INCREF(Py_None);
  __pyx_v_root_count = Py_None; Py_INCREF(Py_None);

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":813 */
  __pyx_1 = ((PyObject *)__pyx_f_6bzrlib_16_known_graph_pyx__get_list_node(__pyx_v_self->_depth_first_stack,__pyx_v_self->_last_stack_item)); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 813; goto __pyx_L1;}
  Py_DECREF(((PyObject *)__pyx_v_node));
  __pyx_v_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_1);
  __pyx_1 = 0;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":814 */
  Py_INCREF(__pyx_v_node->extra);
  Py_DECREF(((PyObject *)__pyx_v_ms_node));
  __pyx_v_ms_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)__pyx_v_node->extra);

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":815 */
  __pyx_v_self->_last_stack_item = (__pyx_v_self->_last_stack_item - 1);

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":816 */
  __pyx_2 = ((PyObject *)__pyx_v_ms_node->left_parent) != Py_None;
  if (__pyx_2) {

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":818 */
    Py_INCREF(__pyx_v_ms_node->left_parent->extra);
    Py_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);

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":819 */
    __pyx_2 = __pyx_v_ms_node->is_first_child;
    if (__pyx_2) {

      /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":821 */
      __pyx_v_ms_node->_revno_first = __pyx_v_ms_parent_node->_revno_first;

      /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":822 */
      __pyx_v_ms_node->_revno_second = __pyx_v_ms_parent_node->_revno_second;

      /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":823 */
      __pyx_v_ms_node->_revno_last = (__pyx_v_ms_parent_node->_revno_last + 1);
      goto __pyx_L3;
    }
    /*else*/ {

      /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":827 */
      __pyx_2 = (__pyx_v_ms_parent_node->_revno_first == (-1));
      if (__pyx_2) {
        __pyx_1 = PyInt_FromLong(__pyx_v_ms_parent_node->_revno_last); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 829; goto __pyx_L1;}
        Py_DECREF(__pyx_v_base_revno);
        __pyx_v_base_revno = __pyx_1;
        __pyx_1 = 0;
        goto __pyx_L4;
      }
      /*else*/ {
        __pyx_1 = PyInt_FromLong(__pyx_v_ms_parent_node->_revno_first); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 831; goto __pyx_L1;}
        Py_DECREF(__pyx_v_base_revno);
        __pyx_v_base_revno = __pyx_1;
        __pyx_1 = 0;
      }
      __pyx_L4:;

      /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":832 */
      __pyx_v_temp = PyDict_GetItem(__pyx_v_self->_revno_to_branch_count,__pyx_v_base_revno);

      /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":834 */
      __pyx_2 = (__pyx_v_temp == NULL);
      if (__pyx_2) {
        __pyx_1 = PyInt_FromLong(1); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 835; goto __pyx_L1;}
        Py_DECREF(__pyx_v_branch_count);
        __pyx_v_branch_count = __pyx_1;
        __pyx_1 = 0;
        goto __pyx_L5;
      }
      /*else*/ {
        __pyx_1 = PyInt_FromLong(1); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 837; goto __pyx_L1;}
        __pyx_3 = PyNumber_Add(((PyObject *)__pyx_v_temp), __pyx_1); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 837; goto __pyx_L1;}
        Py_DECREF(__pyx_1); __pyx_1 = 0;
        Py_DECREF(__pyx_v_branch_count);
        __pyx_v_branch_count = __pyx_3;
        __pyx_3 = 0;
      }
      __pyx_L5:;

      /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":838 */
      __pyx_2 = PyDict_SetItem(__pyx_v_self->_revno_to_branch_count,__pyx_v_base_revno,__pyx_v_branch_count); if (__pyx_2 == (-1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 838; goto __pyx_L1;}

      /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":840 */
      __pyx_4 = PyInt_AsLong(__pyx_v_base_revno); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 840; goto __pyx_L1;}
      __pyx_v_ms_node->_revno_first = __pyx_4;

      /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":841 */
      __pyx_4 = PyInt_AsLong(__pyx_v_branch_count); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 841; goto __pyx_L1;}
      __pyx_v_ms_node->_revno_second = __pyx_4;

      /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":842 */
      __pyx_v_ms_node->_revno_last = 1;
    }
    __pyx_L3:;
    goto __pyx_L2;
  }
  /*else*/ {

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":844 */
    __pyx_1 = PyInt_FromLong(0); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 844; goto __pyx_L1;}
    __pyx_v_temp = PyDict_GetItem(__pyx_v_self->_revno_to_branch_count,__pyx_1);
    Py_DECREF(__pyx_1); __pyx_1 = 0;

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":845 */
    __pyx_2 = (__pyx_v_temp == NULL);
    if (__pyx_2) {

      /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":847 */
      __pyx_3 = PyInt_FromLong(0); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 847; goto __pyx_L1;}
      Py_DECREF(__pyx_v_root_count);
      __pyx_v_root_count = __pyx_3;
      __pyx_3 = 0;

      /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":848 */
      __pyx_v_ms_node->_revno_first = (-1);

      /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":849 */
      __pyx_v_ms_node->_revno_second = (-1);

      /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":850 */
      __pyx_v_ms_node->_revno_last = 1;
      goto __pyx_L6;
    }
    /*else*/ {

      /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":852 */
      __pyx_1 = PyInt_FromLong(1); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 852; goto __pyx_L1;}
      __pyx_3 = PyNumber_Add(((PyObject *)__pyx_v_temp), __pyx_1); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 852; goto __pyx_L1;}
      Py_DECREF(__pyx_1); __pyx_1 = 0;
      Py_DECREF(__pyx_v_root_count);
      __pyx_v_root_count = __pyx_3;
      __pyx_3 = 0;

      /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":853 */
      __pyx_v_ms_node->_revno_first = 0;

      /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":854 */
      __pyx_4 = PyInt_AsLong(__pyx_v_root_count); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 854; goto __pyx_L1;}
      __pyx_v_ms_node->_revno_second = __pyx_4;

      /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":855 */
      __pyx_v_ms_node->_revno_last = 1;
    }
    __pyx_L6:;

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":856 */
    __pyx_1 = PyInt_FromLong(0); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 856; goto __pyx_L1;}
    __pyx_2 = PyDict_SetItem(__pyx_v_self->_revno_to_branch_count,__pyx_1,__pyx_v_root_count); if (__pyx_2 == (-1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 856; goto __pyx_L1;}
    Py_DECREF(__pyx_1); __pyx_1 = 0;
  }
  __pyx_L2:;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":857 */
  __pyx_v_ms_node->completed = 1;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":858 */
  __pyx_2 = (PyList_GET_SIZE(__pyx_v_self->_scheduled_nodes) == 0);
  if (__pyx_2) {
    Py_INCREF(Py_True);
    Py_DECREF(__pyx_v_ms_node->end_of_merge);
    __pyx_v_ms_node->end_of_merge = Py_True;
    goto __pyx_L7;
  }
  /*else*/ {

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":862 */
    __pyx_3 = ((PyObject *)__pyx_f_6bzrlib_16_known_graph_pyx__get_list_node(__pyx_v_self->_scheduled_nodes,(PyList_GET_SIZE(__pyx_v_self->_scheduled_nodes) - 1))); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 862; goto __pyx_L1;}
    Py_DECREF(((PyObject *)__pyx_v_prev_node));
    __pyx_v_prev_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_3);
    __pyx_3 = 0;

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":864 */
    Py_INCREF(__pyx_v_prev_node->extra);
    Py_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);

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":865 */
    __pyx_2 = (__pyx_v_ms_prev_node->merge_depth < __pyx_v_ms_node->merge_depth);
    if (__pyx_2) {
      Py_INCREF(Py_True);
      Py_DECREF(__pyx_v_ms_node->end_of_merge);
      __pyx_v_ms_node->end_of_merge = Py_True;
      goto __pyx_L8;
    }
    __pyx_2 = (__pyx_v_ms_prev_node->merge_depth == __pyx_v_ms_node->merge_depth);
    if (__pyx_2) {
      __pyx_2 = PySequence_Contains(__pyx_v_node->parents, ((PyObject *)__pyx_v_prev_node)); if (__pyx_2 < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 870; goto __pyx_L1;}
      __pyx_2 = !__pyx_2;
    }
    if (__pyx_2) {
      Py_INCREF(Py_True);
      Py_DECREF(__pyx_v_ms_node->end_of_merge);
      __pyx_v_ms_node->end_of_merge = Py_True;
      goto __pyx_L8;
    }
    /*else*/ {
      Py_INCREF(Py_False);
      Py_DECREF(__pyx_v_ms_node->end_of_merge);
      __pyx_v_ms_node->end_of_merge = Py_False;
    }
    __pyx_L8:;
  }
  __pyx_L7:;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":875 */
  __pyx_2 = PyList_Append(__pyx_v_self->_scheduled_nodes,((PyObject *)__pyx_v_node)); if (__pyx_2 == (-1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 875; goto __pyx_L1;}

  __pyx_r = Py_None; Py_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_1);
  Py_XDECREF(__pyx_3);
  __Pyx_AddTraceback("bzrlib._known_graph_pyx._MergeSorter._pop_node");
  __pyx_r = 0;
  __pyx_L0:;
  Py_DECREF(__pyx_v_ms_node);
  Py_DECREF(__pyx_v_ms_parent_node);
  Py_DECREF(__pyx_v_ms_prev_node);
  Py_DECREF(__pyx_v_node);
  Py_DECREF(__pyx_v_prev_node);
  Py_DECREF(__pyx_v_base_revno);
  Py_DECREF(__pyx_v_branch_count);
  Py_DECREF(__pyx_v_root_count);
  Py_DECREF(__pyx_v_self);
  return __pyx_r;
}

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;
  PyObject *__pyx_1 = 0;
  int __pyx_2;
  PyObject *__pyx_3 = 0;
  PyObject *__pyx_4 = 0;
  Py_INCREF(__pyx_v_self);
  __pyx_v_last_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)Py_None); Py_INCREF(Py_None);
  __pyx_v_next_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)Py_None); Py_INCREF(Py_None);
  __pyx_v_ms_last_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)Py_None); Py_INCREF(Py_None);
  __pyx_v_ms_next_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)Py_None); Py_INCREF(Py_None);
  __pyx_v_ordered = Py_None; Py_INCREF(Py_None);

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":881 */
  __pyx_1 = PyList_New(0); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 881; goto __pyx_L1;}
  Py_DECREF(__pyx_v_ordered);
  __pyx_v_ordered = __pyx_1;
  __pyx_1 = 0;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":882 */
  while (1) {
    __pyx_2 = (__pyx_v_self->_last_stack_item >= 0);
    if (!__pyx_2) break;

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":884 */
    __pyx_1 = ((PyObject *)__pyx_f_6bzrlib_16_known_graph_pyx__get_list_node(__pyx_v_self->_depth_first_stack,__pyx_v_self->_last_stack_item)); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 884; goto __pyx_L1;}
    Py_DECREF(((PyObject *)__pyx_v_last_node));
    __pyx_v_last_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_1);
    __pyx_1 = 0;

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":886 */
    __pyx_2 = (__pyx_v_last_node->gdfo == (-1));
    if (__pyx_2) {
      __pyx_1 = __Pyx_GetName(__pyx_m, __pyx_n_errors); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 889; goto __pyx_L1;}
      __pyx_3 = PyObject_GetAttr(__pyx_1, __pyx_n_GraphCycleError); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 889; goto __pyx_L1;}
      Py_DECREF(__pyx_1); __pyx_1 = 0;
      __pyx_1 = PyTuple_New(1); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 889; goto __pyx_L1;}
      Py_INCREF(__pyx_v_self->graph->_nodes);
      PyTuple_SET_ITEM(__pyx_1, 0, __pyx_v_self->graph->_nodes);
      __pyx_4 = PyObject_CallObject(__pyx_3, __pyx_1); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 889; goto __pyx_L1;}
      Py_DECREF(__pyx_3); __pyx_3 = 0;
      Py_DECREF(__pyx_1); __pyx_1 = 0;
      __Pyx_Raise(__pyx_4, 0, 0);
      Py_DECREF(__pyx_4); __pyx_4 = 0;
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 889; goto __pyx_L1;}
      goto __pyx_L4;
    }
    __pyx_L4:;

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":890 */
    Py_INCREF(__pyx_v_last_node->extra);
    Py_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);

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":891 */
    __pyx_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_2) {

      /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":893 */
      __pyx_3 = ((struct __pyx_vtabstruct_6bzrlib_16_known_graph_pyx__MergeSorter *)__pyx_v_self->__pyx_vtab)->_pop_node(__pyx_v_self); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 893; goto __pyx_L1;}
      Py_DECREF(__pyx_3); __pyx_3 = 0;

      /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":894 */
      goto __pyx_L2;
      goto __pyx_L5;
    }
    __pyx_L5:;

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":895 */
    while (1) {
      __pyx_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_2) break;

      /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":896 */
      __pyx_2 = ((PyObject *)__pyx_v_ms_last_node->left_pending_parent) != Py_None;
      if (__pyx_2) {

        /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":898 */
        Py_INCREF(((PyObject *)__pyx_v_ms_last_node->left_pending_parent));
        Py_DECREF(((PyObject *)__pyx_v_next_node));
        __pyx_v_next_node = __pyx_v_ms_last_node->left_pending_parent;

        /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":899 */
        Py_INCREF(Py_None);
        Py_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_L8;
      }
      /*else*/ {
        __pyx_1 = PyObject_GetAttr(__pyx_v_ms_last_node->pending_parents, __pyx_n_pop); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 908; goto __pyx_L1;}
        __pyx_4 = PyObject_CallObject(__pyx_1, 0); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 908; goto __pyx_L1;}
        Py_DECREF(__pyx_1); __pyx_1 = 0;
        if (!__Pyx_TypeTest(__pyx_4, __pyx_ptype_6bzrlib_16_known_graph_pyx__KnownGraphNode)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 908; goto __pyx_L1;}
        Py_DECREF(((PyObject *)__pyx_v_next_node));
        __pyx_v_next_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_4);
        __pyx_4 = 0;
      }
      __pyx_L8:;

      /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":909 */
      __pyx_3 = ((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 (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 909; goto __pyx_L1;}
      Py_DECREF(((PyObject *)__pyx_v_ms_next_node));
      __pyx_v_ms_next_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)__pyx_3);
      __pyx_3 = 0;

      /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":910 */
      __pyx_2 = __pyx_v_ms_next_node->completed;
      if (__pyx_2) {
        goto __pyx_L6;
        goto __pyx_L9;
      }
      __pyx_L9:;

      /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":917 */
      __pyx_2 = __pyx_v_next_node == __pyx_v_ms_last_node->left_parent;
      if (__pyx_2) {
        __pyx_v_next_merge_depth = __pyx_v_ms_last_node->merge_depth;
        goto __pyx_L10;
      }
      /*else*/ {
        __pyx_v_next_merge_depth = (__pyx_v_ms_last_node->merge_depth + 1);
      }
      __pyx_L10:;

      /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":921 */
      __pyx_1 = ((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 (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 921; goto __pyx_L1;}
      Py_DECREF(__pyx_1); __pyx_1 = 0;

      /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":924 */
      goto __pyx_L7;
      __pyx_L6:;
    }
    __pyx_L7:;
    __pyx_L2:;
  }

  __pyx_r = Py_None; Py_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_1);
  Py_XDECREF(__pyx_3);
  Py_XDECREF(__pyx_4);
  __Pyx_AddTraceback("bzrlib._known_graph_pyx._MergeSorter._schedule_stack");
  __pyx_r = 0;
  __pyx_L0:;
  Py_DECREF(__pyx_v_last_node);
  Py_DECREF(__pyx_v_next_node);
  Py_DECREF(__pyx_v_ms_last_node);
  Py_DECREF(__pyx_v_ms_next_node);
  Py_DECREF(__pyx_v_ordered);
  Py_DECREF(__pyx_v_self);
  return __pyx_r;
}

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;
  PyObject *__pyx_1 = 0;
  int __pyx_2;
  Py_INCREF(__pyx_v_self);
  __pyx_v_ms_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)Py_None); Py_INCREF(Py_None);
  __pyx_v_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)Py_None); Py_INCREF(Py_None);
  __pyx_v_ordered = Py_None; Py_INCREF(Py_None);

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":936 */
  __pyx_1 = ((struct __pyx_vtabstruct_6bzrlib_16_known_graph_pyx__MergeSorter *)__pyx_v_self->__pyx_vtab)->_schedule_stack(__pyx_v_self); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 936; goto __pyx_L1;}
  Py_DECREF(__pyx_1); __pyx_1 = 0;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":946 */
  __pyx_1 = PyList_New(0); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 946; goto __pyx_L1;}
  Py_DECREF(__pyx_v_ordered);
  __pyx_v_ordered = __pyx_1;
  __pyx_1 = 0;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":948 */
  for (__pyx_v_pos = PyList_GET_SIZE(__pyx_v_self->_scheduled_nodes)-1; __pyx_v_pos >= 0; --__pyx_v_pos) {

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":949 */
    __pyx_1 = ((PyObject *)__pyx_f_6bzrlib_16_known_graph_pyx__get_list_node(__pyx_v_self->_scheduled_nodes,__pyx_v_pos)); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 949; goto __pyx_L1;}
    Py_DECREF(((PyObject *)__pyx_v_node));
    __pyx_v_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_1);
    __pyx_1 = 0;

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":950 */
    Py_INCREF(__pyx_v_node->extra);
    Py_DECREF(((PyObject *)__pyx_v_ms_node));
    __pyx_v_ms_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)__pyx_v_node->extra);

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":951 */
    __pyx_2 = PyList_Append(__pyx_v_ordered,((PyObject *)__pyx_v_ms_node)); if (__pyx_2 == (-1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 951; goto __pyx_L1;}

    /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":952 */
    Py_INCREF(Py_None);
    Py_DECREF(__pyx_v_node->extra);
    __pyx_v_node->extra = Py_None;
  }

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

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":955 */
  Py_INCREF(__pyx_v_ordered);
  __pyx_r = __pyx_v_ordered;
  goto __pyx_L0;

  __pyx_r = Py_None; Py_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_1);
  __Pyx_AddTraceback("bzrlib._known_graph_pyx._MergeSorter.topo_order");
  __pyx_r = 0;
  __pyx_L0:;
  Py_DECREF(__pyx_v_ms_node);
  Py_DECREF(__pyx_v_node);
  Py_DECREF(__pyx_v_ordered);
  Py_DECREF(__pyx_v_self);
  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);
  *(struct __pyx_vtabstruct_6bzrlib_16_known_graph_pyx__KnownGraphNode **)&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);
  (*o->ob_type->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 *t;
  t = p->key; 
  p->key = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(t);
  t = p->parents; 
  p->parents = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(t);
  t = p->children; 
  p->children = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(t);
  t = p->extra; 
  p->extra = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(t);
  return 0;
}

static PyObject *__pyx_getprop_6bzrlib_16_known_graph_pyx_15_KnownGraphNode_child_keys(PyObject *o, void *x) {
  return __pyx_f_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_f_6bzrlib_16_known_graph_pyx_15_KnownGraphNode_11parent_keys___get__(o);
}

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

static struct PyMemberDef __pyx_members_6bzrlib_16_known_graph_pyx__KnownGraphNode[] = {
  {"gdfo", T_LONG, offsetof(struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode, gdfo), 0, 0},
  {0, 0, 0, 0, 0}
};

static struct PyGetSetDef __pyx_getsets_6bzrlib_16_known_graph_pyx__KnownGraphNode[] = {
  {"child_keys", __pyx_getprop_6bzrlib_16_known_graph_pyx_15_KnownGraphNode_child_keys, 0, 0, 0},
  {"parent_keys", __pyx_getprop_6bzrlib_16_known_graph_pyx_15_KnownGraphNode_parent_keys, 0, 0, 0},
  {0, 0, 0, 0, 0}
};

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

static PySequenceMethods __pyx_tp_as_sequence__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 = {
  0, /*bf_getreadbuffer*/
  0, /*bf_getwritebuffer*/
  0, /*bf_getsegcount*/
  0, /*bf_getcharbuffer*/
};

PyTypeObject __pyx_type_6bzrlib_16_known_graph_pyx__KnownGraphNode = {
  PyObject_HEAD_INIT(0)
  0, /*ob_size*/
  "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*/
  0, /*tp_compare*/
  __pyx_f_6bzrlib_16_known_graph_pyx_15_KnownGraphNode___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_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  "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*/
  __pyx_members_6bzrlib_16_known_graph_pyx__KnownGraphNode, /*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_f_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*/
};
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);
  *(struct __pyx_vtabstruct_6bzrlib_16_known_graph_pyx__MergeSorter **)&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);
  (*o->ob_type->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 *t;
  t = ((PyObject *)p->graph); 
  p->graph = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *)Py_None); Py_INCREF(Py_None);
  Py_XDECREF(t);
  t = p->_depth_first_stack; 
  p->_depth_first_stack = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(t);
  t = p->_revno_to_branch_count; 
  p->_revno_to_branch_count = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(t);
  t = p->_scheduled_nodes; 
  p->_scheduled_nodes = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(t);
  return 0;
}

static struct 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*/
  0, /*nb_divide*/
  0, /*nb_remainder*/
  0, /*nb_divmod*/
  0, /*nb_power*/
  0, /*nb_negative*/
  0, /*nb_positive*/
  0, /*nb_absolute*/
  0, /*nb_nonzero*/
  0, /*nb_invert*/
  0, /*nb_lshift*/
  0, /*nb_rshift*/
  0, /*nb_and*/
  0, /*nb_xor*/
  0, /*nb_or*/
  0, /*nb_coerce*/
  0, /*nb_int*/
  0, /*nb_long*/
  0, /*nb_float*/
  0, /*nb_oct*/
  0, /*nb_hex*/
  0, /*nb_inplace_add*/
  0, /*nb_inplace_subtract*/
  0, /*nb_inplace_multiply*/
  0, /*nb_inplace_divide*/
  0, /*nb_inplace_remainder*/
  0, /*nb_inplace_power*/
  0, /*nb_inplace_lshift*/
  0, /*nb_inplace_rshift*/
  0, /*nb_inplace_and*/
  0, /*nb_inplace_xor*/
  0, /*nb_inplace_or*/
  0, /*nb_floor_divide*/
  0, /*nb_true_divide*/
  0, /*nb_inplace_floor_divide*/
  0, /*nb_inplace_true_divide*/
  #if Py_TPFLAGS_DEFAULT & Py_TPFLAGS_HAVE_INDEX
  0, /*nb_index*/
  #endif
};

static PySequenceMethods __pyx_tp_as_sequence__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 = {
  0, /*bf_getreadbuffer*/
  0, /*bf_getwritebuffer*/
  0, /*bf_getsegcount*/
  0, /*bf_getcharbuffer*/
};

PyTypeObject __pyx_type_6bzrlib_16_known_graph_pyx__MergeSorter = {
  PyObject_HEAD_INIT(0)
  0, /*ob_size*/
  "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*/
  0, /*tp_compare*/
  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_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  "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_f_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*/
};
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);
  *(struct __pyx_vtabstruct_6bzrlib_16_known_graph_pyx_KnownGraph **)&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);
    ++o->ob_refcnt;
    __pyx_f_6bzrlib_16_known_graph_pyx_10KnownGraph___dealloc__(o);
    if (PyErr_Occurred()) PyErr_WriteUnraisable(o);
    --o->ob_refcnt;
    PyErr_Restore(etype, eval, etb);
  }
  Py_XDECREF(p->_nodes);
  Py_XDECREF(p->_known_heads);
  (*o->ob_type->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 *t;
  t = p->_nodes; 
  p->_nodes = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(t);
  t = p->_known_heads; 
  p->_known_heads = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(t);
  return 0;
}

static struct PyMethodDef __pyx_methods_6bzrlib_16_known_graph_pyx_KnownGraph[] = {
  {"_initialize_nodes", (PyCFunction)__pyx_f_6bzrlib_16_known_graph_pyx_10KnownGraph__initialize_nodes, METH_VARARGS|METH_KEYWORDS, __pyx_doc_6bzrlib_16_known_graph_pyx_10KnownGraph__initialize_nodes},
  {"_find_tails", (PyCFunction)__pyx_f_6bzrlib_16_known_graph_pyx_10KnownGraph__find_tails, METH_VARARGS|METH_KEYWORDS, 0},
  {"_find_tips", (PyCFunction)__pyx_f_6bzrlib_16_known_graph_pyx_10KnownGraph__find_tips, METH_VARARGS|METH_KEYWORDS, 0},
  {"_find_gdfo", (PyCFunction)__pyx_f_6bzrlib_16_known_graph_pyx_10KnownGraph__find_gdfo, METH_VARARGS|METH_KEYWORDS, 0},
  {"add_node", (PyCFunction)__pyx_f_6bzrlib_16_known_graph_pyx_10KnownGraph_add_node, METH_VARARGS|METH_KEYWORDS, __pyx_doc_6bzrlib_16_known_graph_pyx_10KnownGraph_add_node},
  {"heads", (PyCFunction)__pyx_f_6bzrlib_16_known_graph_pyx_10KnownGraph_heads, METH_VARARGS|METH_KEYWORDS, __pyx_doc_6bzrlib_16_known_graph_pyx_10KnownGraph_heads},
  {"topo_sort", (PyCFunction)__pyx_f_6bzrlib_16_known_graph_pyx_10KnownGraph_topo_sort, METH_VARARGS|METH_KEYWORDS, __pyx_doc_6bzrlib_16_known_graph_pyx_10KnownGraph_topo_sort},
  {"gc_sort", (PyCFunction)__pyx_f_6bzrlib_16_known_graph_pyx_10KnownGraph_gc_sort, METH_VARARGS|METH_KEYWORDS, __pyx_doc_6bzrlib_16_known_graph_pyx_10KnownGraph_gc_sort},
  {"merge_sort", (PyCFunction)__pyx_f_6bzrlib_16_known_graph_pyx_10KnownGraph_merge_sort, METH_VARARGS|METH_KEYWORDS, __pyx_doc_6bzrlib_16_known_graph_pyx_10KnownGraph_merge_sort},
  {"get_parent_keys", (PyCFunction)__pyx_f_6bzrlib_16_known_graph_pyx_10KnownGraph_get_parent_keys, METH_VARARGS|METH_KEYWORDS, __pyx_doc_6bzrlib_16_known_graph_pyx_10KnownGraph_get_parent_keys},
  {"get_child_keys", (PyCFunction)__pyx_f_6bzrlib_16_known_graph_pyx_10KnownGraph_get_child_keys, METH_VARARGS|METH_KEYWORDS, __pyx_doc_6bzrlib_16_known_graph_pyx_10KnownGraph_get_child_keys},
  {0, 0, 0, 0}
};

static struct PyMemberDef __pyx_members_6bzrlib_16_known_graph_pyx_KnownGraph[] = {
  {"_nodes", T_OBJECT, offsetof(struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph, _nodes), 0, 0},
  {"_known_heads", T_OBJECT, offsetof(struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph, _known_heads), 0, 0},
  {"do_cache", T_INT, offsetof(struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph, 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*/
  0, /*nb_divide*/
  0, /*nb_remainder*/
  0, /*nb_divmod*/
  0, /*nb_power*/
  0, /*nb_negative*/
  0, /*nb_positive*/
  0, /*nb_absolute*/
  0, /*nb_nonzero*/
  0, /*nb_invert*/
  0, /*nb_lshift*/
  0, /*nb_rshift*/
  0, /*nb_and*/
  0, /*nb_xor*/
  0, /*nb_or*/
  0, /*nb_coerce*/
  0, /*nb_int*/
  0, /*nb_long*/
  0, /*nb_float*/
  0, /*nb_oct*/
  0, /*nb_hex*/
  0, /*nb_inplace_add*/
  0, /*nb_inplace_subtract*/
  0, /*nb_inplace_multiply*/
  0, /*nb_inplace_divide*/
  0, /*nb_inplace_remainder*/
  0, /*nb_inplace_power*/
  0, /*nb_inplace_lshift*/
  0, /*nb_inplace_rshift*/
  0, /*nb_inplace_and*/
  0, /*nb_inplace_xor*/
  0, /*nb_inplace_or*/
  0, /*nb_floor_divide*/
  0, /*nb_true_divide*/
  0, /*nb_inplace_floor_divide*/
  0, /*nb_inplace_true_divide*/
  #if Py_TPFLAGS_DEFAULT & Py_TPFLAGS_HAVE_INDEX
  0, /*nb_index*/
  #endif
};

static PySequenceMethods __pyx_tp_as_sequence_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 = {
  0, /*bf_getreadbuffer*/
  0, /*bf_getwritebuffer*/
  0, /*bf_getsegcount*/
  0, /*bf_getcharbuffer*/
};

PyTypeObject __pyx_type_6bzrlib_16_known_graph_pyx_KnownGraph = {
  PyObject_HEAD_INIT(0)
  0, /*ob_size*/
  "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*/
  0, /*tp_compare*/
  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_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  "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*/
  __pyx_members_6bzrlib_16_known_graph_pyx_KnownGraph, /*tp_members*/
  0, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  0, /*tp_dictoffset*/
  __pyx_f_6bzrlib_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*/
};
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);
  *(struct __pyx_vtabstruct_6bzrlib_16_known_graph_pyx__MergeSortNode **)&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);
  (*o->ob_type->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 *t;
  t = p->key; 
  p->key = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(t);
  t = p->end_of_merge; 
  p->end_of_merge = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(t);
  t = ((PyObject *)p->left_parent); 
  p->left_parent = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)Py_None); Py_INCREF(Py_None);
  Py_XDECREF(t);
  t = ((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(t);
  t = p->pending_parents; 
  p->pending_parents = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(t);
  return 0;
}

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

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

static struct PyMemberDef __pyx_members_6bzrlib_16_known_graph_pyx__MergeSortNode[] = {
  {"key", T_OBJECT, offsetof(struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode, key), 0, 0},
  {"merge_depth", T_LONG, offsetof(struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode, merge_depth), 0, 0},
  {"end_of_merge", T_OBJECT, offsetof(struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode, end_of_merge), 0, 0},
  {0, 0, 0, 0, 0}
};

static struct PyGetSetDef __pyx_getsets_6bzrlib_16_known_graph_pyx__MergeSortNode[] = {
  {"revno", __pyx_getprop_6bzrlib_16_known_graph_pyx_14_MergeSortNode_revno, 0, 0, 0},
  {0, 0, 0, 0, 0}
};

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

static PySequenceMethods __pyx_tp_as_sequence__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 = {
  0, /*bf_getreadbuffer*/
  0, /*bf_getwritebuffer*/
  0, /*bf_getsegcount*/
  0, /*bf_getcharbuffer*/
};

PyTypeObject __pyx_type_6bzrlib_16_known_graph_pyx__MergeSortNode = {
  PyObject_HEAD_INIT(0)
  0, /*ob_size*/
  "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*/
  0, /*tp_compare*/
  __pyx_f_6bzrlib_16_known_graph_pyx_14_MergeSortNode___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_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  "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*/
  __pyx_members_6bzrlib_16_known_graph_pyx__MergeSortNode, /*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_f_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*/
};

static struct PyMethodDef __pyx_methods[] = {
  {"get_key", (PyCFunction)__pyx_f_6bzrlib_16_known_graph_pyx_get_key, METH_VARARGS|METH_KEYWORDS, 0},
  {0, 0, 0, 0}
};

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

PyMODINIT_FUNC init_known_graph_pyx(void); /*proto*/
PyMODINIT_FUNC init_known_graph_pyx(void) {
  PyObject *__pyx_1 = 0;
  PyObject *__pyx_2 = 0;
  __pyx_init_filenames();
  __pyx_m = Py_InitModule4("_known_graph_pyx", __pyx_methods, __pyx_mdoc, 0, PYTHON_API_VERSION);
  if (!__pyx_m) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 17; goto __pyx_L1;};
  Py_INCREF(__pyx_m);
  __pyx_b = PyImport_AddModule("__builtin__");
  if (!__pyx_b) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 17; goto __pyx_L1;};
  if (PyObject_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 17; goto __pyx_L1;};
  if (__Pyx_InitStrings(__pyx_string_tab) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 17; goto __pyx_L1;};
  __pyx_v_6bzrlib_16_known_graph_pyx_NULL_REVISION = Py_None; Py_INCREF(Py_None);
  __pyx_vtabptr_6bzrlib_16_known_graph_pyx__KnownGraphNode = &__pyx_vtable_6bzrlib_16_known_graph_pyx__KnownGraphNode;
  *(void(**)(void))&__pyx_vtable_6bzrlib_16_known_graph_pyx__KnownGraphNode.clear_references = (void(*)(void))__pyx_f_6bzrlib_16_known_graph_pyx_15_KnownGraphNode_clear_references;
  __pyx_type_6bzrlib_16_known_graph_pyx__KnownGraphNode.tp_free = _PyObject_GC_Del;
  if (PyType_Ready(&__pyx_type_6bzrlib_16_known_graph_pyx__KnownGraphNode) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; goto __pyx_L1;}
  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; goto __pyx_L1;}
  if (PyObject_SetAttrString(__pyx_m, "_KnownGraphNode", (PyObject *)&__pyx_type_6bzrlib_16_known_graph_pyx__KnownGraphNode) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; goto __pyx_L1;}
  __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;
  *(void(**)(void))&__pyx_vtable_6bzrlib_16_known_graph_pyx__MergeSorter._get_ms_node = (void(*)(void))__pyx_f_6bzrlib_16_known_graph_pyx_12_MergeSorter__get_ms_node;
  *(void(**)(void))&__pyx_vtable_6bzrlib_16_known_graph_pyx__MergeSorter._push_node = (void(*)(void))__pyx_f_6bzrlib_16_known_graph_pyx_12_MergeSorter__push_node;
  *(void(**)(void))&__pyx_vtable_6bzrlib_16_known_graph_pyx__MergeSorter._pop_node = (void(*)(void))__pyx_f_6bzrlib_16_known_graph_pyx_12_MergeSorter__pop_node;
  *(void(**)(void))&__pyx_vtable_6bzrlib_16_known_graph_pyx__MergeSorter._schedule_stack = (void(*)(void))__pyx_f_6bzrlib_16_known_graph_pyx_12_MergeSorter__schedule_stack;
  *(void(**)(void))&__pyx_vtable_6bzrlib_16_known_graph_pyx__MergeSorter.topo_order = (void(*)(void))__pyx_f_6bzrlib_16_known_graph_pyx_12_MergeSorter_topo_order;
  __pyx_type_6bzrlib_16_known_graph_pyx__MergeSorter.tp_free = _PyObject_GC_Del;
  if (PyType_Ready(&__pyx_type_6bzrlib_16_known_graph_pyx__MergeSorter) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 724; goto __pyx_L1;}
  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; goto __pyx_L1;}
  if (PyObject_SetAttrString(__pyx_m, "_MergeSorter", (PyObject *)&__pyx_type_6bzrlib_16_known_graph_pyx__MergeSorter) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 724; goto __pyx_L1;}
  __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;
  *(void(**)(void))&__pyx_vtable_6bzrlib_16_known_graph_pyx_KnownGraph._get_or_create_node = (void(*)(void))__pyx_f_6bzrlib_16_known_graph_pyx_10KnownGraph__get_or_create_node;
  *(void(**)(void))&__pyx_vtable_6bzrlib_16_known_graph_pyx_KnownGraph._populate_parents = (void(*)(void))__pyx_f_6bzrlib_16_known_graph_pyx_10KnownGraph__populate_parents;
  __pyx_type_6bzrlib_16_known_graph_pyx_KnownGraph.tp_free = _PyObject_GC_Del;
  if (PyType_Ready(&__pyx_type_6bzrlib_16_known_graph_pyx_KnownGraph) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 192; goto __pyx_L1;}
  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; goto __pyx_L1;}
  if (PyObject_SetAttrString(__pyx_m, "KnownGraph", (PyObject *)&__pyx_type_6bzrlib_16_known_graph_pyx_KnownGraph) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 192; goto __pyx_L1;}
  __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;
  *(void(**)(void))&__pyx_vtable_6bzrlib_16_known_graph_pyx__MergeSortNode.has_pending_parents = (void(*)(void))__pyx_f_6bzrlib_16_known_graph_pyx_14_MergeSortNode_has_pending_parents;
  *(void(**)(void))&__pyx_vtable_6bzrlib_16_known_graph_pyx__MergeSortNode._revno = (void(*)(void))__pyx_f_6bzrlib_16_known_graph_pyx_14_MergeSortNode__revno;
  __pyx_type_6bzrlib_16_known_graph_pyx__MergeSortNode.tp_free = _PyObject_GC_Del;
  if (PyType_Ready(&__pyx_type_6bzrlib_16_known_graph_pyx__MergeSortNode) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 666; goto __pyx_L1;}
  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; goto __pyx_L1;}
  if (PyObject_SetAttrString(__pyx_m, "_MergeSortNode", (PyObject *)&__pyx_type_6bzrlib_16_known_graph_pyx__MergeSortNode) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 666; goto __pyx_L1;}
  __pyx_ptype_6bzrlib_16_known_graph_pyx__MergeSortNode = &__pyx_type_6bzrlib_16_known_graph_pyx__MergeSortNode;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":54 */
  __pyx_1 = PyList_New(1); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 54; goto __pyx_L1;}
  Py_INCREF(__pyx_n_deque);
  PyList_SET_ITEM(__pyx_1, 0, __pyx_n_deque);
  __pyx_2 = __Pyx_Import(__pyx_n_collections, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 54; goto __pyx_L1;}
  Py_DECREF(__pyx_1); __pyx_1 = 0;
  __pyx_1 = PyObject_GetAttr(__pyx_2, __pyx_n_deque); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 54; goto __pyx_L1;}
  if (PyObject_SetAttr(__pyx_m, __pyx_n_deque, __pyx_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 54; goto __pyx_L1;}
  Py_DECREF(__pyx_1); __pyx_1 = 0;
  Py_DECREF(__pyx_2); __pyx_2 = 0;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":55 */
  __pyx_2 = __Pyx_Import(__pyx_n_gc, 0); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 55; goto __pyx_L1;}
  if (PyObject_SetAttr(__pyx_m, __pyx_n_gc, __pyx_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 55; goto __pyx_L1;}
  Py_DECREF(__pyx_2); __pyx_2 = 0;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":57 */
  __pyx_1 = PyList_New(2); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 57; goto __pyx_L1;}
  Py_INCREF(__pyx_n_errors);
  PyList_SET_ITEM(__pyx_1, 0, __pyx_n_errors);
  Py_INCREF(__pyx_n_revision);
  PyList_SET_ITEM(__pyx_1, 1, __pyx_n_revision);
  __pyx_2 = __Pyx_Import(__pyx_n_bzrlib, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 57; goto __pyx_L1;}
  Py_DECREF(__pyx_1); __pyx_1 = 0;
  __pyx_1 = PyObject_GetAttr(__pyx_2, __pyx_n_errors); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 57; goto __pyx_L1;}
  if (PyObject_SetAttr(__pyx_m, __pyx_n_errors, __pyx_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 57; goto __pyx_L1;}
  Py_DECREF(__pyx_1); __pyx_1 = 0;
  __pyx_1 = PyObject_GetAttr(__pyx_2, __pyx_n_revision); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 57; goto __pyx_L1;}
  if (PyObject_SetAttr(__pyx_m, __pyx_n_revision, __pyx_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 57; goto __pyx_L1;}
  Py_DECREF(__pyx_1); __pyx_1 = 0;
  Py_DECREF(__pyx_2); __pyx_2 = 0;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":60 */
  __pyx_2 = __Pyx_GetName(__pyx_m, __pyx_n_revision); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 60; goto __pyx_L1;}
  __pyx_1 = PyObject_GetAttr(__pyx_2, __pyx_n_NULL_REVISION); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 60; goto __pyx_L1;}
  Py_DECREF(__pyx_2); __pyx_2 = 0;
  Py_DECREF(__pyx_v_6bzrlib_16_known_graph_pyx_NULL_REVISION);
  __pyx_v_6bzrlib_16_known_graph_pyx_NULL_REVISION = __pyx_1;
  __pyx_1 = 0;

  /* "/home/vila/src/bzr/releases/prepare-2.2.2/bzrlib/_known_graph_pyx.pyx":199 */
  Py_INCREF(Py_True);
  __pyx_d1 = Py_True;

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

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

/* Runtime support code */

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

static int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type) {
    if (!type) {
        PyErr_Format(PyExc_SystemError, "Missing type object");
        return 0;
    }
    if (obj == Py_None || PyObject_TypeCheck(obj, type))
        return 1;
    PyErr_Format(PyExc_TypeError, "Cannot convert %s to %s",
        obj->ob_type->tp_name, type->tp_name);
    return 0;
}

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

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

static PyObject *__Pyx_GetItemInt(PyObject *o, Py_ssize_t i) {
    PyTypeObject *t = o->ob_type;
    PyObject *r;
    if (t->tp_as_sequence && t->tp_as_sequence->sq_item)
        r = PySequence_GetItem(o, i);
    else {
        PyObject *j = PyInt_FromLong(i);
        if (!j)
            return 0;
        r = PyObject_GetItem(o, j);
        Py_DECREF(j);
    }
    return r;
}

static void __Pyx_WriteUnraisable(char *name) {
    PyObject *old_exc, *old_val, *old_tb;
    PyObject *ctx;
    PyErr_Fetch(&old_exc, &old_val, &old_tb);
    ctx = PyString_FromString(name);
    PyErr_Restore(old_exc, old_val, old_tb);
    if (!ctx)
        ctx = Py_None;
    PyErr_WriteUnraisable(ctx);
}

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

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

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

static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list) {
    PyObject *__import__ = 0;
    PyObject *empty_list = 0;
    PyObject *module = 0;
    PyObject *global_dict = 0;
    PyObject *empty_dict = 0;
    PyObject *list;
    __import__ = PyObject_GetAttrString(__pyx_b, "__import__");
    if (!__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_CallFunction(__import__, "OOOO",
        name, global_dict, empty_dict, list);
bad:
    Py_XDECREF(empty_list);
    Py_XDECREF(__import__);
    Py_XDECREF(empty_dict);
    return module;
}

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

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