Jelmer Vernooij 16 лет назад
Родитель
Сommit
9dbda24705
2 измененных файлов с 47 добавлено и 1 удалено
  1. 27 0
      bin/dulwich
  2. 20 1
      dulwich/repo.py

+ 27 - 0
bin/dulwich

@@ -45,6 +45,32 @@ def cmd_fetch_pack(args):
 		f.close()
 		raise
 
+
+def cmd_log(args):
+	from dulwich.repo import Repo
+	opts, args = getopt(args, "", [])
+	r = Repo(".")
+	todo = [r.head()]
+	done = set()
+	while todo:
+		sha = todo.pop()
+		assert isinstance(sha, str)
+		if sha in done:
+			continue
+		done.add(sha)
+		commit = r.commit(sha)
+		print "-" * 50
+		print "commit: %s" % sha
+		if len(commit.parents) > 1:
+			print "merge: %s" % "...".join(commit.parents[1:])
+		print "author: %s" % commit.author
+		print "committer: %s" % commit.committer
+		print ""
+		print commit.message
+		print ""
+		todo.extend([p for p in commit.parents if p not in done])
+
+
 def cmd_dump_pack(args):
 	from dulwich.errors import ApplyDeltaError
 	from dulwich.pack import Pack, sha_to_hex
@@ -75,6 +101,7 @@ def cmd_dump_pack(args):
 commands = {
 	"fetch-pack": cmd_fetch_pack,
 	"dump-pack": cmd_dump_pack,
+	"log": cmd_log,
 	}
 
 if len(sys.argv) < 2:

+ 20 - 1
dulwich/repo.py

@@ -269,6 +269,7 @@ class ObjectStore(object):
 
     @property
     def packs(self):
+        """List with pack objects."""
         if self._packs is None:
             self._packs = list(load_packs(self.pack_dir()))
         return self._packs
@@ -283,6 +284,11 @@ class ObjectStore(object):
         return None
 
     def get_raw(self, sha):
+        """Obtain the raw text for an object.
+        
+        :param sha: Sha for the object.
+        :return: tuple with object type and object contents.
+        """
         for pack in self.packs:
             if sha in pack:
                 return pack.get_raw(sha, self.get_raw)
@@ -302,13 +308,26 @@ class ObjectStore(object):
         return ShaFile.from_raw_string(type, uncomp)
 
     def move_in_pack(self, path):
+        """Move a specific file containing a pack into the pack directory.
+
+        :note: The file should be on the same file system as the 
+            packs directory.
+
+        :param path: Path to the pack file.
+        """
         p = PackData(path)
         entries = p.sorted_entries(self.get_raw)
-        basename = os.path.join(self.pack_dir(), "pack-%s" % iter_sha1(entry[0] for entry in entries))
+        basename = os.path.join(self.pack_dir(), 
+            "pack-%s" % iter_sha1(entry[0] for entry in entries))
         write_pack_index_v2(basename+".idx", entries, p.calculate_checksum())
         os.rename(path, basename + ".pack")
 
     def add_pack(self):
+        """Add a new pack to this object store. 
+
+        :return: Fileobject to write to and a commit function to 
+            call when the pack is finished.
+        """
         fd, path = tempfile.mkstemp(dir=self.pack_dir(), suffix=".pack")
         f = os.fdopen(fd, 'w')
         def commit():