git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 1/2] Repository.rev_parse: support commits, trees, and blobs

From
GHGustav Hållberg <gustav@gmail.com>
Date
May 24, 2010, 18:52 UTC
Message-ID
<20100524185219.30884.66896.stgit@sambuntu>
In-Reply-To
<20100524184908.30884.65042.stgit@sambuntu>
---
 stgit/lib/git.py |   10 ++++++----
 1 files changed, 6 insertions(+), 4 deletions(-)
diff --git a/stgit/lib/git.py b/stgit/lib/git.py
index 65d2a6c..899c1a2 100644
--- a/stgit/lib/git.py
+++ b/stgit/lib/git.py
@@ -581,13 +581,15 @@ class Repository(RunWithEnv):
     refs = property(lambda self: self.__refs)
     def cat_object(self, sha1):
         return self.run(['git', 'cat-file', '-p', sha1]).raw_output()
-    def rev_parse(self, rev, discard_stderr = False):
+    def rev_parse(self, rev, discard_stderr = False, object_type = 'commit'):
+        assert object_type in ('commit', 'tree', 'blob')
+        getter = getattr(self, 'get_' + object_type)
         try:
-            return self.get_commit(self.run(
-                    ['git', 'rev-parse', '%s^{commit}' % rev]
+            return getter(self.run(
+                    ['git', 'rev-parse', '%s^{%s}' % (rev, object_type)]
                     ).discard_stderr(discard_stderr).output_one_line())
         except run.RunException:
-            raise RepositoryException('%s: No such revision' % rev)
+            raise RepositoryException('%s: No such %s' % (rev, object_type))
     def get_blob(self, sha1):
         return self.__blobs[sha1]
     def get_tree(self, sha1):
Previous: Gustav HållbergNext: Gustav Hållberg
Message 12 of 16 in “edit: Allow setting git tree SHA1 of a patch”
  1. edit: Allow setting git tree SHA1 of a patchGustav Hållberg, May 16, 2010
  2. Karl WibergMay 17, 2010
  3. Catalin MarinasMay 21, 2010
  4. David KågedalMay 21, 2010
  5. Catalin MarinasMay 21, 2010
  6. David KågedalMay 21, 2010
  7. Gustav HållbergMay 21, 2010
  8. Catalin MarinasMay 21, 2010
  9. David KågedalMay 21, 2010
  10. Gustav HållbergMay 21, 2010
  11. 0/2 Setting git tree of a patch (improved version)Gustav Hållberg, May 24, 2010
  12. 1/2 Repository.rev_parse: support commits, trees, and blobsGustav Hållberg, May 24, 2010
  13. 2/2 edit: Allow setting git tree of a patchGustav Hållberg, May 24, 2010
  14. Catalin MarinasMay 25, 2010
  15. Gustav HållbergMay 26, 2010
  16. Catalin MarinasMay 26, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.