# Path: pigeon/xerblin/btree.py
# def items(node):
#     '''
#     Iterate in order over the (key, value) pairs in a tree.
#     '''
#     if not node:
#         return
# 
#     key, value, lower, higher = node
#     
#     for kv in items(lower):
#         yield kv
#     
#     yield key, value
#     
#     for kv in items(higher):
#         yield kv


import pickle, logging, sys
from os.path import exists, join
from dulwich.repo import Repo, NotGitRepository
from pigeon.xerblin.btree import items
  from pigeon.xerblin.world import ROOT
#
#    Pigeon Computer is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with Pigeon Computer.  If not, see <http://www.gnu.org/licenses/>.
#


def make_commit_thing(path, files):
  log = logging.getLogger('COMMIT')
  try:
    repo = Repo(path)
  except NotGitRepository:
    log.critical("%r isn't a repository!", path)
    raise ValueError("%r isn't a repository!" % (path,))

  # Note that we bind the args as defaults rather than via a closure so
  # you can override them later if you want.
  def commit(message, files=files, repo=repo, log=log):
    repo.stage(files)
    commit_sha = repo.do_commit(message)
    log.info('commit %s %s', commit_sha, message[:100])

  return commit


def list_words(dictionary):

# Path: pigeon/xerblin/btree.py
# def items(node):
#     '''
#     Iterate in order over the (key, value) pairs in a tree.
#     '''
#     if not node:
#         return
# 
#     key, value, lower, higher = node
#     
#     for kv in items(lower):
#         yield kv
#     
#     yield key, value
#     
#     for kv in items(higher):
#         yield kv


# Path: pigeon/xerblin/gitstore.py
import pickle, logging, sys
from os.path import exists, join
from dulwich.repo import Repo, NotGitRepository
from pigeon.xerblin.btree import items
  from pigeon.xerblin.world import ROOT

#
#    Pigeon Computer is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with Pigeon Computer.  If not, see <http://www.gnu.org/licenses/>.
#


def make_commit_thing(path, files):
  log = logging.getLogger('COMMIT')
  try:
    repo = Repo(path)
  except NotGitRepository:
    log.critical("%r isn't a repository!", path)
    raise ValueError("%r isn't a repository!" % (path,))

  # Note that we bind the args as defaults rather than via a closure so
  # you can override them later if you want.
  def commit(message, files=files, repo=repo, log=log):
    repo.stage(files)
    commit_sha = repo.do_commit(message)
    log.info('commit %s %s', commit_sha, message[:100])

  return commit


def list_words(dictionary):

  words = sorted(name for name, value in items(dictionary))