1313namespace Gitonomy \Git ;
1414
1515use Gitonomy \Git \Exception \ReferenceNotFoundException ;
16+ use Gitonomy \Git \Exception \InvalidArgumentException ;
1617use Gitonomy \Git \Exception \ProcessException ;
1718
1819/**
@@ -28,44 +29,76 @@ class Revision
2829 /**
2930 * @var string
3031 */
31- protected $ name ;
32+ protected $ revision ;
3233
3334 /**
3435 * @var Commit
3536 */
36- protected $ resolved ;
37+ protected $ commitHash ;
3738
38- public function __construct (Repository $ repository , $ name )
39+ public function __construct (Repository $ repository , $ revision , $ commitHash = null )
3940 {
4041 $ this ->repository = $ repository ;
41- $ this ->name = $ name ;
42+ $ this ->revision = $ revision ;
43+ $ this ->commitHash = $ commitHash ;
4244 }
4345
4446 /**
4547 * @return Log
4648 */
4749 public function getLog ($ paths = null , $ offset = null , $ limit = null )
4850 {
49- return $ this ->repository ->getLog ($ this ->name , $ paths , $ offset , $ limit );
51+ return $ this ->repository ->getLog ($ this ->revision , $ paths , $ offset , $ limit );
5052 }
5153
5254 /**
53- * Resolves the revision to a commit hash .
55+ * Returns the commit associated to the reference .
5456 *
55- * @return Commit
57+ * @return Gitonomy\Git\ Commit
5658 */
57- public function getResolved ()
59+ public function getCommit ()
5860 {
59- if (null !== $ this ->resolved ) {
60- return $ this ->resolved ;
61+ return $ this ->repository ->getCommit ($ this ->getCommitHash ());
62+ }
63+
64+ public function getCommitHash ()
65+ {
66+ if (null !== $ this ->commitHash ) {
67+ return $ this ->commitHash ;
6168 }
6269
6370 try {
64- $ result = $ this ->repository ->run ('rev-parse ' , array ('--verify ' , $ this ->name ));
71+ $ result = $ this ->repository ->run ('rev-parse ' , array ('--verify ' , $ this ->revision ));
6572 } catch (ProcessException $ e ) {
66- throw new ReferenceNotFoundException (sprintf ('Can not find reference "%s" ' , $ this ->name ));
73+ throw new ReferenceNotFoundException (sprintf ('Can not find revision "%s" ' , $ this ->revision ));
6774 }
6875
69- return $ this ->resolved = $ this ->repository ->getCommit (trim ($ result ));
76+ return $ this ->commitHash = trim ($ result );
77+ }
78+
79+ /**
80+ * Returns the last modification date of the reference.
81+ *
82+ * @return DateTime
83+ */
84+ public function getLastModification ()
85+ {
86+ return $ this ->getCommit ()->getAuthorDate ();
87+ }
88+
89+ /**
90+ * @return string
91+ */
92+ public function getRevision ()
93+ {
94+ return $ this ->revision ;
95+ }
96+
97+ /**
98+ * @return Repository
99+ */
100+ public function getRepository ()
101+ {
102+ return $ this ->repository ;
70103 }
71104}
0 commit comments