# Path: dgitcore/helper.py
# def run(cmd):
#     """
#     Run a shell command
#     """
#     cmd = [pipes.quote(c) for c in cmd]
#     cmd = " ".join(cmd)
#     cmd += "; exit 0"
#     # print("Running {} in {}".format(cmd, os.getcwd()))
#     try:
#         output = subprocess.check_output(cmd,
#                                          stderr=subprocess.STDOUT,
#                                          shell=True)
#     except subprocess.CalledProcessError as e:
#             output = e.output
# 
#     output = output.decode('utf-8')
#     output = output.strip()
#     return output
# 
# class cd:
#     """Context manager for changing the current working directory"""
#     def __init__(self, newPath):
#         self.newPath = os.path.expanduser(newPath)
# 
#     def __enter__(self):
#         self.savedPath = os.getcwd()
#         os.chdir(self.newPath)
# 
#     def __exit__(self, etype, value, traceback):
#         os.chdir(self.savedPath)
# 
# Path: dgitcore/plugins/common.py
# def plugins_get_mgr():
#     """
#     Get the global plugin manager
#     """
#     global pluginmgr
#     return pluginmgr


import os, sys, parse, shutil 
import traceback 
import subprocess, pipes
import tempfile 
import json
import daff
from collections import OrderedDict
from ..helper import run, cd
from ..plugins.common import plugins_get_mgr
                        cmd = ['tar', 'xvf', 'checkout.tar']
                        output = run(cmd) 
                        if 'fatal' in output: 
                            print("Cleaning up - fatal 1", temp1)
                            shutil.rmtree(temp1)
                            continue 

                # Check to make sure that 
                path1 = os.path.join(temp1, v1_hex, path) 
                path2 = os.path.join(temp1, v2_hex, path) 
                if not os.path.exists(path1) or not os.path.exists(path2): 
                    # print("One of the two output files is missing") 
                    shutil.rmtree(temp1)
                    continue 

                #print(path1, path2) 

                # Now call the handler
                diff = handler.get_diff(path1, path2)

                # print("Inserting diff", diff)
                c['diff'] = diff

            except Exception as e: 
                #traceback.print_exc() 
                #print("Cleaning up - Exception ", temp1)
                shutil.rmtree(temp1)

def get_history(gitdir="."):


# Path: dgitcore/helper.py
# def run(cmd):
#     """
#     Run a shell command
#     """
#     cmd = [pipes.quote(c) for c in cmd]
#     cmd = " ".join(cmd)
#     cmd += "; exit 0"
#     # print("Running {} in {}".format(cmd, os.getcwd()))
#     try:
#         output = subprocess.check_output(cmd,
#                                          stderr=subprocess.STDOUT,
#                                          shell=True)
#     except subprocess.CalledProcessError as e:
#             output = e.output
# 
#     output = output.decode('utf-8')
#     output = output.strip()
#     return output
# 
# class cd:
#     """Context manager for changing the current working directory"""
#     def __init__(self, newPath):
#         self.newPath = os.path.expanduser(newPath)
# 
#     def __enter__(self):
#         self.savedPath = os.getcwd()
#         os.chdir(self.newPath)
# 
#     def __exit__(self, etype, value, traceback):
#         os.chdir(self.savedPath)
# 
# Path: dgitcore/plugins/common.py
# def plugins_get_mgr():
#     """
#     Get the global plugin manager
#     """
#     global pluginmgr
#     return pluginmgr


# Path: dgitcore/datasets/history.py
import os, sys, parse, shutil 
import traceback 
import subprocess, pipes
import tempfile 
import json
import daff
from collections import OrderedDict
from ..helper import run, cd
from ..plugins.common import plugins_get_mgr

                        cmd = ['tar', 'xvf', 'checkout.tar']
                        output = run(cmd) 
                        if 'fatal' in output: 
                            print("Cleaning up - fatal 1", temp1)
                            shutil.rmtree(temp1)
                            continue 

                # Check to make sure that 
                path1 = os.path.join(temp1, v1_hex, path) 
                path2 = os.path.join(temp1, v2_hex, path) 
                if not os.path.exists(path1) or not os.path.exists(path2): 
                    # print("One of the two output files is missing") 
                    shutil.rmtree(temp1)
                    continue 

                #print(path1, path2) 

                # Now call the handler
                diff = handler.get_diff(path1, path2)

                # print("Inserting diff", diff)
                c['diff'] = diff

            except Exception as e: 
                #traceback.print_exc() 
                #print("Cleaning up - Exception ", temp1)
                shutil.rmtree(temp1)

def get_history(gitdir="."):


    with cd(gitdir):