<s> """<STR_LIT>""" <EOL> import sys <EOL> import docopt <EOL> import os <EOL> import shutil <EOL> import difflib <EOL> import hashlib <EOL> import json <EOL> import time <EOL> import tempfile <EOL> import subprocess <EOL> def __sha1 ( content ) : <EOL> sha1sum = hashlib . sha1 ( ) <EOL> sha1sum . update ( content ) <EOL> return sha1sum . hexdigest ( ) <EOL> def __read_file ( filename ) : <EOL> with open ( filename ) as my_file : <EOL> return my_file . read ( ) <EOL> def __write_file ( filename , content ) : <EOL> with open ( filename , "<STR_LIT:w>" ) as my_file : <EOL> return my_file . write ( content ) <EOL> def __storedb ( content ) : <EOL> sha1sum = __sha1 ( content ) <EOL> __write_file ( "<STR_LIT>" . format ( sha1sum ) , content ) <EOL> return sha1sum <EOL> def __getdb ( sha1sum ) : <EOL> return __read_file ( "<STR_LIT>" . format ( sha1sum ) ) <EOL> def __content_from_commit ( sha1sum ) : <EOL> return json . loads ( __getdb ( sha1sum ) ) [ "<STR_LIT:content>" ] <EOL> def __get_branches ( ) : <EOL> return os . listdir ( "<STR_LIT>" ) <EOL> def __set_head ( rev ) : <EOL> if rev in __get_branches ( ) : <EOL> __write_file ( "<STR_LIT>" , "<STR_LIT>" . format ( rev ) ) <EOL> else : <EOL> __write_file ( "<STR_LIT>" , rev ) <EOL> def __get_current_branch ( ) : <EOL> head_rev = __read_file ( "<STR_LIT>" ) <EOL> if head_rev [ : <NUM_LIT:4> ] != "<STR_LIT>" : <EOL> return None <EOL> branch_path = head_rev [ <NUM_LIT:4> : ] . strip ( ) <EOL> branch_name = os . path . basename ( branch_path ) <EOL> return branch_name <EOL> def __get_head_commit ( ) : <EOL> branch = __get_current_branch ( ) <EOL> if branch == None : <EOL> return __read_file ( "<STR_LIT>" ) <EOL> else : <EOL> return __read_file ( "<STR_LIT>" . format ( branch ) ) <EOL> def __set_branch_commit ( branch , commit_sha1sum ) : <EOL> __write_file ( "<STR_LIT>" . format ( branch ) , commit_sha1sum ) <EOL> def __get_branch_commit ( branch ) : <EOL> return __read_file ( "<STR_LIT>" . format ( branch ) ) <EOL> def init ( ) : <EOL> os . makedirs ( "<STR_LIT>" ) <EOL> os . makedirs ( "<STR_LIT>" ) <EOL> __set_branch_commit ( "<STR_LIT>" , "<STR_LIT:0>" ) <EOL> __set_head ( "<STR_LIT>" ) <EOL> def branch ( ) : <EOL> current = __get_current_branch ( ) <EOL> for branch in sorted ( __get_branches ( ) ) : <EOL> star = "<STR_LIT:*>" if branch == current else "<STR_LIT:U+0020>" <EOL> print "<STR_LIT>" . format ( star , branch ) <EOL> def __create_commit ( content_sha1sum , parents , msg ) : <EOL> sha1sum_commit = __storedb ( json . dumps ( { <EOL> "<STR_LIT:content>" : content_sha1sum , <EOL> "<STR_LIT>" : parents , <EOL> "<STR_LIT>" : msg , <EOL> "<STR_LIT>" : os . getenv ( "<STR_LIT>" ) , <EOL> "<STR_LIT:time>" : int ( time . time ( ) ) <EOL> } , indent = <NUM_LIT:4> ) ) <EOL> return sha1sum_commit <EOL> def commit ( msg ) : <EOL> branch = __get_current_branch ( ) <EOL> if branch == None : <EOL> print "<STR_LIT>" <EOL> return <EOL> master_rev = __get_branch_commit ( branch ) <EOL> sha1sum_content = __storedb ( __read_file ( "<STR_LIT>" ) ) <EOL> sha1sum_commit = __create_commit ( sha1sum_content , [ master_rev ] , msg ) <EOL> __set_branch_commit ( branch , sha1sum_commit ) <EOL> print sha1sum_commit <EOL> def __is_branch ( start_point ) : <EOL> return start_point in __get_branches ( ) <EOL> def __commit_from_start_point ( start_point ) : <EOL> if __is_branch ( start_point ) : <EOL> return __get_branch_commit ( start_point ) <EOL> return start_point <EOL> def __update_working_copy ( start_point ) : <EOL> commit_sha1sum = __commit_from_start_point ( start_point ) <EOL> content_sha1sum = __content_from_commit ( commit_sha1sum ) <EOL> content = __getdb ( content_sha1sum ) <EOL> __write_file ( "<STR_LIT>" , content ) <EOL> return commit_sha1sum <EOL> def checkout ( start_point , new_branch ) : <EOL> commit_sha1sum = __update_working_copy ( start_point ) <EOL> if new_branch is None : <EOL> __set_head ( start_point ) <EOL> else : <EOL> __set_branch_commit ( new_branch , commit_sha1sum ) <EOL> __set_head ( new_branch ) <EOL> def diff ( ) : <EOL> commit_sha1sum = __get_head_commit ( ) <EOL> content_sha1sum = __content_from_commit ( commit_sha1sum ) <EOL> orig_content = __getdb ( content_sha1sum ) <EOL> orig_content = orig_content . splitlines ( True ) <EOL> curr_content = __read_file ( "<STR_LIT>" ) <EOL> curr_content = curr_content . splitlines ( True ) <EOL> lines = difflib . unified_diff ( orig_content , curr_content , "<STR_LIT>" , "<STR_LIT>" ) <EOL> print ( "<STR_LIT>" . join ( lines ) ) <EOL> def log ( ) : <EOL> commit_sha1sum = __get_head_commit ( ) <EOL> while True : <EOL> commit = json . loads ( __getdb ( commit_sha1sum ) ) <EOL> print commit_sha1sum [ : <NUM_LIT:6> ] , commit [ "<STR_LIT>" ] <EOL> commit_sha1sum = commit [ "<STR_LIT>" ] [ <NUM_LIT:0> ] <EOL> if commit_sha1sum == "<STR_LIT:0>" : <EOL> break <EOL> def merge ( branch ) : <EOL> pass <EOL> def main ( ) : <EOL> args = docopt . docopt ( __doc__ ) <EOL> if args [ "<STR_LIT>" ] : <EOL> commit ( args [ "<STR_LIT>" ] ) <EOL> elif args [ "<STR_LIT>" ] : <EOL> checkout ( args [ "<STR_LIT>" ] , args [ "<STR_LIT>" ] ) <EOL> elif args [ "<STR_LIT>" ] : <EOL> init ( ) <EOL> elif args [ "<STR_LIT>" ] : <EOL> diff ( ) <EOL> elif args [ "<STR_LIT>" ] : <EOL> log ( ) <EOL> elif args [ "<STR_LIT>" ] : <EOL> branch ( ) <EOL> elif args [ "<STR_LIT>" ] : <EOL> merge ( args [ "<STR_LIT>" ] ) <EOL> else : <EOL> pass <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> main ( ) </s>
