0
# directory 'foo/bar'. Running 'git log' will show the change you made.
0
from StringIO import StringIO
0
from subprocess import Popen, PIPE
0
+from string import split, join
0
######################################################################
0
+ Exception.__init__(self)
0
- return "Git command failed: git-%s %s: %s" % (self.cmd, self.args, self.stderr)
0
+ return "Git command failed: git-%s %s: %s" % \
0
+ (self.cmd, self.args, self.stderr)
0
-
return "Git command failed: git-%s %s" % (self.cmd, self.args)
0
+
return "Git command failed: git-%s %s" % (self.cmd, self.args)
0
def git(cmd, *args, **kwargs):
0
- print "Command: git-%s %s" % (cmd,
string.join(args, ' '))
0
+ print "Command: git-%s %s" % (cmd,
join(args, ' '))
0
if kwargs.has_key('input'):
0
"""Abstracts a reference to a data file within a Git repository. It also
0
maintains knowledge of whether the object has been modified or not."""
0
- def __init__(self, shelf, path,
hash = None):
0
+ def __init__(self, shelf, path,
name = None):
0
- assert self.hash is not None
0
- self.data = self.deserialize_data(self.shelf.get_blob(self.hash))
0
+ assert self.name is not None
0
+ self.data = self.deserialize_data(self.shelf.get_blob(self.name))
0
def set_data(self, data):
0
del odict['dirty'] # remove dirty flag
0
- def __setstate__(self,dict):
0
- self.__dict__.update(dict) # update attributes
0
+ def __setstate__(self, ndict):
0
+ self.__dict__.update(ndict) # update attributes
0
other Git users, nor does it support merging)."""
0
ls_tree_pat = re.compile('(040000 tree|100644 blob) ([0-9a-f]{40})\t(start|(.+))$')
0
def __init__(self, branch, book_type = gitbook):
0
self.book_type = book_type
0
- ls_tree = s
tring.split(git('ls-tree', '-r', '-t', '-z', self.head),
0
+ ls_tree = s
split(git('ls-tree', '-r', '-t', '-z', self.head),
0
match = self.ls_tree_pat.match(line)
0
treep = match.group(1) == "040000 tree"
0
- parts = string.split(path, os.sep)
0
+ parts = split(path, os.sep)
0
- if not dict.has_key(part):
0
+ if not d.has_key(part):
0
- d
ict['__root__'] = hash0
- d
ict['__book__'] = self.book_type(self, path, hash)
0
+ d
['__book__'] = self.book_type(self, path, name)
0
def open(cls, branch, book_type = gitbook):
0
shelf = gitshelve(branch, book_type)
0
open = classmethod(open)
0
- def get_blob(self, hash):
0
- return git('cat-file', 'blob', hash, keep_newline = True)
0
+ def get_blob(self, name):
0
+ return git('cat-file', 'blob', name, keep_newline = True)
0
def make_blob(self, data):
0
return git('hash-object', '-w', '--stdin', input = data)
0
def make_tree(self, objects, comment_accumulator = None):
0
if objects.has_key('__root__'):
0
for path in objects.keys():
0
if path == '__root__': continue
0
- object = objects[path]
0
- assert isinstance(object, dict)
0
+ assert isinstance(obj, dict)
0
- if len(object.keys()) == 1 and object.has_key('__book__'):
0
- book = object['__book__']
0
+ if len(obj.keys()) == 1 and obj.has_key('__book__'):
0
+ book = obj['__book__']
0
if comment_accumulator:
0
comment = book.change_comment()
0
comment_accumulator.write(comment)
0
- book.
hash = self.make_blob(book.serialize_data())
0
+ book.
name = self.make_blob(book.serialize_data())
0
- buf
fer.write("100644 blob %s\t%s\0" % (book.hash, path))
0
+ buf
.write("100644 blob %s\t%s\0" % (book.name, path))
0
- if object.has_key('__root__'):
0
- tree_root = object['__root__']
0
+ if obj.has_key('__root__'):
0
+ tree_root = obj['__root__']
0
- tree_hash = self.make_tree(object, comment_accumulator)
0
- if tree_hash != tree_root:
0
+ tree_name = self.make_tree(obj, comment_accumulator)
0
+ if tree_name != tree_root:
0
- buf
fer.write("040000 tree %s\t%s\0" % (tree_hash, path))
0
+ buf
.write("040000 tree %s\t%s\0" % (tree_name, path))
0
- hash = git('mktree', '-z', input = buffer.getvalue())
0
- objects['__root__'] = hash
0
+ name = git('mktree', '-z', input = buf.getvalue())
0
+ objects['__root__'] = name
0
- def make_commit(self, tree_
hash, comment):
0
+ def make_commit(self, tree_
name, comment):
0
if not comment: comment = ""
0
-
hash = git('commit-tree', tree_hash, '-p', self.head,
0
+
name = git('commit-tree', tree_name, '-p', self.head,
0
-
hash = git('commit-tree', tree_hash, input = comment)
0
+
name = git('commit-tree', tree_name, input = comment)
0
- self.update_head(hash)
0
+ self.update_head(name)
0
def commit(self, comment = None):
0
tree = self.make_tree(self.objects, accumulator)
0
comment = accumulator.getvalue()
0
-
hash = self.make_commit(tree, comment)
0
+
name = self.make_commit(tree, comment)
0
if objects[key].has_key('__book__'):
0
book = objects[key]['__book__']
0
- kind = 'blob ' + book.hash
0
+ kind = 'blob ' + book.name
0
self.dump_objects(fd, indent + 2, objects[key])
0
def get_tree(self, path, make_dirs = False):
0
- parts = string.split(path, os.sep)
0
+ parts = split(path, os.sep)
0
- if make_dirs and not dict.has_key(part):
0
+ if make_dirs and not d.has_key(part):
0
def __getitem__(self, path):
0
- d
ict = self.get_tree(path)
0
+ d
= self.get_tree(path)
0
- if len(dict.keys()) == 1:
0
- return dict['__book__'].get_data()
0
+ if len(d.keys()) == 1:
0
+ return d['__book__'].get_data()
0
def __setitem__(self, path, data):
0
- d
ict = self.get_tree(path, make_dirs = True)
0
+ d
= self.get_tree(path, make_dirs = True)
0
- if len(dict.keys()) == 0:
0
- dict['__book__'] = self.book_type(self, path)
0
- dict['__book__'].set_data(data)
0
+ if len(d.keys()) == 0:
0
+ d['__book__'] = self.book_type(self, path)
0
+ d['__book__'].set_data(data)
0
def prune_tree(self, objects, paths):
0
def __delitem__(self, path):
0
- self.prune_tree(self.objects, s
tring.split(path, os.sep))
0
+ self.prune_tree(self.objects, s
split(path, os.sep))
0
def __contains__(self, path):
0
- dict = self.get_tree(path)
0
- return len(dict.keys()) == 1 and dict.has_key('__book__')
0
+ d = self.get_tree(path)
0
+ return len(d.keys()) == 1 and d.has_key('__book__')
0
def walker(self, kind, objects, path = ''):
0
for item in objects.items():
0
assert isinstance(item[1], dict)
0
- key =
string.join((path, item[0]), os.sep)
0
+ key =
join((path, item[0]), os.sep)
0
- for object in self.walker(kind, item[1], key):
0
+ for obj in self.walker(kind, item[1], key):
0
del odict['dirty'] # remove dirty flag
0
- def __setstate__(self,dict):
0
- self.__dict__.update(dict) # update attributes
0
+ def __setstate__(self, ndict):
0
+ self.__dict__.update(ndict) # update attributes
0
# If the HEAD reference is out of date, throw away all data and
Comments
No one has commented yet.