Permalink
Browse files

Merge commit 'jwiegley/master'

  • Loading branch information...
2 parents ccd521d + 3a0ed4b commit 41b84099e772e5d6b72a70d3832f2166127b59ba @ktf committed Aug 7, 2008
Showing with 161 additions and 97 deletions.
  1. +43 −51 git-issues
  2. +63 −27 gitshelve.py
  3. +55 −19 t_gitshelve.py
View
94 git-issues
@@ -994,8 +994,8 @@ if __name__ == '__main__':
######################################################################
- # jww (2008-05-12): Pick the appropriate IssueSet to used based on what we
- # find in our environment.
+ # jww (2008-05-12): Pick the appropriate IssueSet to use based on the
+ # environment.
issueSet = GitIssueSet().load_state()
@@ -1060,55 +1060,47 @@ if __name__ == '__main__':
issueSet.get_comment(comment[0:7]).comment)
for comment in issue.comments])
if command == "show":
- sys.stdout.write("""
- Title: %s
- Summary: %s
-
- Description: %s
-
- Author: %s
- Reporter: %s
- Owner: %s
- Assigned: %s
- Cc: %s
-
- Type: %s
- Status: %s
- Resolution: %s
- Components: %s
- Version: %s
- Milestone: %s
- Severity: %s
- Priority: %s
- Tags: %s
-
- Created: %s
- Modified: %s
- %s
-""" % (issue.title,
- format_long_text(issue.summary),
-
- format_long_text(issue.description),
-
- issue.author,
- format_people_list(issue.reporters),
- format_people_list(issue.owners),
- format_people_list(issue.assigned),
- format_people_list(issue.carbons),
-
- issue.issue_type,
- issue.status,
- issue.resolution or "",
- issue.components or "",
- issue.version or "",
- issue.milestone or "",
- issue.severity,
- issue.priority,
- issue.tags or "",
-
- issue.created,
- issue.modified,
- comments))
+ if issue.title:
+ print " Title:", issue.title
+ if issue.summary:
+ print " Summary:", format_long_text(issue.summary)
+ print
+ if issue.description:
+ print " Description:", format_long_text(issue.description)
+ print
+ if issue.author:
+ print " Author:", issue.author
+ if issue.reporters:
+ print " Reporter(s):", format_people_list(issue.reporters)
+ if issue.owners:
+ print " Owner(s):", format_people_list(issue.owners)
+ if issue.assigned:
+ print " Assigned:", format_people_list(issue.assigned)
+ if issue.carbons:
+ print " Cc:", format_people_list(issue.carbons)
+
+ if issue.issue_type:
+ print " Type:", issue.issue_type
+ if issue.status:
+ print " Status:", issue.status
+ if issue.resolution:
+ print " Resolution:", issue.resolution
+ if issue.components:
+ print " Components:", issue.components
+ if issue.version:
+ print " Version:", issue.version
+ if issue.milestone:
+ print " Milestone:", issue.milestone
+ if issue.severity:
+ print " Severity:", issue.severity
+ if issue.priority:
+ print " Priority:", issue.priority
+ if issue.tags:
+ print " Tags:", issue.tags
+
+ print " Created:", issue.created
+ if issue.modified:
+ print " Modified:", issue.modified
else:
write_object(issue)
View
90 gitshelve.py
@@ -66,10 +66,10 @@ def __init__(self, cmd, args, kwargs, stderr = None):
def __str__(self):
if self.stderr:
- return "Git command failed: git-%s %s: %s" % \
+ return "Git command failed: git %s %s: %s" % \
(self.cmd, self.args, self.stderr)
else:
- return "Git command failed: git-%s %s" % (self.cmd, self.args)
+ return "Git command failed: git %s %s" % (self.cmd, self.args)
def git(cmd, *args, **kwargs):
restart = True
@@ -79,7 +79,7 @@ def git(cmd, *args, **kwargs):
stdin_mode = PIPE
if verbose:
- print "Command: git-%s %s" % (cmd, join(args, ' '))
+ print "Command: git %s %s" % (cmd, join(args, ' '))
if kwargs.has_key('input'):
print "Input: <<EOF"
print kwargs['input'],
@@ -92,12 +92,12 @@ def git(cmd, *args, **kwargs):
git_dir = environ['GIT_DIR']
if not os.path.isdir(git_dir):
- proc = Popen('git-init', env = environ,
+ proc = Popen(('git', 'init'), env = environ,
stdout = PIPE, stderr = PIPE)
if proc.wait() != 0:
raise GitError('init', [], {}, proc.stderr.read())
- proc = Popen(('git-' + cmd,) + args, env = environ,
+ proc = Popen(('git', cmd) + args, env = environ,
stdin = stdin_mode,
stdout = PIPE,
stderr = PIPE)
@@ -171,17 +171,18 @@ class gitshelve(dict):
This implementation uses a dictionary of gitbook objects, since we don't
really want to use Pickling within a Git repository (it's not friendly to
other Git users, nor does it support merging)."""
- ls_tree_pat = re.compile('(040000 tree|100644 blob) ([0-9a-f]{40})\t(start|(.+))$')
+ ls_tree_pat = re.compile('((\d{6}) (tree|blob)) ([0-9a-f]{40})\t(start|(.+))$')
head = None
dirty = False
objects = None
def __init__(self, branch = 'master', repository = None,
- book_type = gitbook):
- self.branch = branch
- self.repository = repository
- self.book_type = book_type
+ keep_history = True, book_type = gitbook):
+ self.branch = branch
+ self.repository = repository
+ self.keep_history = keep_history
+ self.book_type = book_type
self.init_data()
dict.__init__(self)
@@ -225,8 +226,9 @@ def read_repository(self):
assert match
treep = match.group(1) == "040000 tree"
- name = match.group(2)
- path = match.group(3)
+ perm = match.group(2)
+ name = match.group(4)
+ path = match.group(5)
parts = split(path, os.sep)
d = self.objects
@@ -236,13 +238,21 @@ def read_repository(self):
d = d[part]
if treep:
- d['__root__'] = name
+ if perm == '040000' :
+ d['__root__'] = name
+ else :
+ raise GitError('read_repository', [], {},
+ 'Invalid mode for %s : 040000 required, %s found' %(path, perm))
else:
- d['__book__'] = self.book_type(self, path, name)
+ if perm == '100644' :
+ d['__book__'] = self.book_type(self, path, name)
+ else :
+ raise GitError('read_repository', [], {},
+ 'Invalid mode for %s : 100644 required, %s found' %(path, perm))
def open(cls, branch = 'master', repository = None,
- book_type = gitbook):
- shelf = gitshelve(branch, repository, book_type)
+ keep_history = True, book_type = gitbook):
+ shelf = gitshelve(branch, repository, keep_history, book_type)
shelf.read_repository()
return shelf
@@ -304,9 +314,9 @@ def make_tree(self, objects, comment_accumulator = None):
def make_commit(self, tree_name, comment):
if not comment: comment = ""
- if self.head:
+ if self.head and self.keep_history:
name = self.git('commit-tree', tree_name, '-p', self.head,
- input = comment)
+ input = comment)
else:
name = self.git('commit-tree', tree_name, input = comment)
@@ -379,22 +389,47 @@ def get_tree(self, path, make_dirs = False):
d = d[part]
return d
+ def get(self, key):
+ path = '%s/%s' % (key[:2], key[2:])
+ d = None
+ try:
+ d = self.get_tree(path)
+ except KeyError:
+ raise KeyError(key)
+ if not d or not d.has_key('__book__'):
+ raise KeyError(key)
+ return d['__book__'].get_data()
+
+ def put(self, data):
+ book = self.book_type(self, '__unknown__')
+ book.data = data
+ book.name = self.make_blob(book.serialize_data(book.data))
+ book.dirty = False # the blob was just written!
+ book.path = '%s/%s' % (book.name[:2], book.name[2:])
+
+ d = self.get_tree(book.path, make_dirs = True)
+ d.clear()
+ d['__book__'] = book
+ self.dirty = True
+
+ return book.name
+
def __getitem__(self, path):
+ d = None
try:
d = self.get_tree(path)
except KeyError:
raise KeyError(path)
- if len(d.keys()) == 1:
+ if d and d.has_key('__book__'):
return d['__book__'].get_data()
- raise KeyError(path)
+ else:
+ raise KeyError(path)
def __setitem__(self, path, data):
- try:
- d = self.get_tree(path, make_dirs = True)
- except KeyError:
- raise KeyError(path)
- if len(d.keys()) == 0:
+ d = self.get_tree(path, make_dirs = True)
+ if not d.has_key('__book__'):
+ d.clear()
d['__book__'] = self.book_type(self, path)
d['__book__'].set_data(data)
self.dirty = True
@@ -473,7 +508,8 @@ def __setstate__(self, ndict):
self.read_repository()
-def open(branch = 'master', repository = None, book_type = gitbook):
- return gitshelve.open(branch, repository, book_type)
+def open(branch = 'master', repository = None, keep_history = True,
+ book_type = gitbook):
+ return gitshelve.open(branch, repository, keep_history, book_type)
# gitshelve.py ends here
View
74 t_gitshelve.py
@@ -59,10 +59,10 @@ def testInsertion(self):
text = "Hello, this is a test\n"
shelf['foo/bar/baz.c'] = text
- buffer = StringIO()
- shelf.dump_objects(buffer)
+ buf = StringIO()
+ shelf.dump_objects(buf)
- self.assertEqual(buffer.getvalue(), """tree: foo
+ self.assertEqual(buf.getvalue(), """tree: foo
tree: bar
blob: baz.c
""")
@@ -71,14 +71,14 @@ def testInsertion(self):
hash2 = shelf.commit('second\n')
self.assertEqual(hash1, hash2)
- buffer = StringIO()
- shelf.dump_objects(buffer)
+ buf = StringIO()
+ shelf.dump_objects(buf)
self.assertEqual("""tree ca37be3e31987d8ece35001301c0b8f1fccbb888
tree 95b790693f3b5934c63d10b8b007e4758f6134a9: foo
tree c03cdd65fa74c272bed2e9a48e3ed19402576e19: bar
blob ea93d5cc5f34e13d2a55a5866b75e2c58993d253: baz.c
-""", buffer.getvalue())
+""", buf.getvalue())
hash3 = shelf.current_head()
self.assertEqual(hash1, hash3)
@@ -98,7 +98,7 @@ def testInsertion(self):
tree 95b790693f3b5934c63d10b8b007e4758f6134a9: foo
tree c03cdd65fa74c272bed2e9a48e3ed19402576e19: bar
blob ea93d5cc5f34e13d2a55a5866b75e2c58993d253: baz.c
-""", buffer.getvalue())
+""", buf.getvalue())
self.assertEqual(text, shelf['foo/bar/baz.c'])
del shelf
@@ -110,55 +110,55 @@ def testIterator(self):
shelf['alpha/beta/baz2.c'] = text
shelf['apple/orange/baz3.c'] = text
- buffer = StringIO()
+ buf = StringIO()
keys = shelf.keys()
keys.sort()
for path in keys:
- buffer.write("path: (%s)\n" % path)
+ buf.write("path: (%s)\n" % path)
self.assertEqual("""path: (alpha/beta/baz2.c)
path: (apple/orange/baz3.c)
path: (foo/bar/baz1.c)
-""", buffer.getvalue())
+""", buf.getvalue())
def testVersioning(self):
shelf = gitshelve.open('test')
text = "Hello, this is a test\n"
shelf['foo/bar/baz1.c'] = text
shelf.sync()
- buffer = StringIO()
- shelf.dump_objects(buffer)
+ buf = StringIO()
+ shelf.dump_objects(buf)
self.assertEqual("""tree 073629aeb0ef56a50a6cfcaf56da9b8393604b56
tree ce9d91f2da4ab3aa920cd5763be48b9aef76f999: foo
tree 2e626f2ae629ea77618e84e79e1bfae1c473452e: bar
blob ea93d5cc5f34e13d2a55a5866b75e2c58993d253: baz1.c
-""", buffer.getvalue())
+""", buf.getvalue())
text = "Hello, this is a change\n"
shelf['foo/bar/baz1.c'] = text
shelf['foo/bar/baz2.c'] = text
shelf.sync()
- buffer = StringIO()
- shelf.dump_objects(buffer)
+ buf = StringIO()
+ shelf.dump_objects(buf)
self.assertEqual("""tree c7c6fd4368460c645d0953349d5577d32f46115a
tree 3936ea8daffe9eef0451b43205d6530374f8ffa3: foo
tree 8f7bfca3bc33c93fb1a878bc79c2bb93d8f41730: bar
blob fb54a7573d864d4b57ffcc8af37e7565e2ba4608: baz1.c
blob fb54a7573d864d4b57ffcc8af37e7565e2ba4608: baz2.c
-""", buffer.getvalue())
+""", buf.getvalue())
del shelf
shelf = gitshelve.open('test')
- buffer = StringIO()
- shelf.dump_objects(buffer)
+ buf = StringIO()
+ shelf.dump_objects(buf)
self.assertEqual("""tree 3936ea8daffe9eef0451b43205d6530374f8ffa3: foo
tree 8f7bfca3bc33c93fb1a878bc79c2bb93d8f41730: bar
blob fb54a7573d864d4b57ffcc8af37e7565e2ba4608: baz1.c
blob fb54a7573d864d4b57ffcc8af37e7565e2ba4608: baz2.c
-""", buffer.getvalue())
+""", buf.getvalue())
self.assertEqual(text, shelf['foo/bar/baz1.c'])
self.assertEqual(text, shelf['foo/bar/baz2.c'])
@@ -200,6 +200,42 @@ def testDetachedRepo(self):
if os.path.isdir('/tmp/repo-test'):
shutil.rmtree('/tmp/repo-test')
+ def testBlobStore(self):
+ """Test use a gitshelve as a generic blob store."""
+ try:
+ shelf = gitshelve.open(repository = '/tmp/blobs', keep_history = False)
+ text = "This is just some sample text.\n"
+ hash = shelf.put(text)
+
+ buf = StringIO()
+ shelf.dump_objects(buf)
+ self.assertEqual("""tree: ac
+ blob acd291ce81136338a729a30569da2034d918e057: d291ce81136338a729a30569da2034d918e057
+""", buf.getvalue())
+
+ self.assertEqual(text, shelf.get(hash))
+
+ shelf.sync()
+ buf = StringIO()
+ shelf.dump_objects(buf)
+ self.assertEqual("""tree 127093ef9a92ebb1f49caa5ecee9ff7139db3a6c
+ tree 6c6167149ccc5bf60892b65b84322c1943f5f7da: ac
+ blob acd291ce81136338a729a30569da2034d918e057: d291ce81136338a729a30569da2034d918e057
+""", buf.getvalue())
+ del shelf
+
+ shelf = gitshelve.open(repository = '/tmp/blobs', keep_history = False)
+ buf = StringIO()
+ shelf.dump_objects(buf)
+ self.assertEqual("""tree 6c6167149ccc5bf60892b65b84322c1943f5f7da: ac
+ blob acd291ce81136338a729a30569da2034d918e057: d291ce81136338a729a30569da2034d918e057
+""", buf.getvalue())
+
+ self.assertEqual(text, shelf.get(hash))
+ del shelf
+ finally:
+ if os.path.isdir('/tmp/blobs'):
+ shutil.rmtree('/tmp/blobs')
def suite():
return unittest.TestLoader().loadTestsFromTestCase(t_gitshelve)

0 comments on commit 41b8409

Please sign in to comment.