@@ -141,6 +141,9 @@ pub trait OplogExt {
141141 /// This is useful to show what has changed in this particular snapshot
142142 fn snapshot_diff ( & self , sha : git2:: Oid ) -> Result < Vec < TreeChange > > ;
143143
144+ /// Gets a specific snapshot by its commit sha.
145+ fn get_snapshot ( & self , sha : git2:: Oid ) -> Result < Snapshot > ;
146+
144147 /// Gets the sha of the last snapshot commit if present.
145148 fn oplog_head ( & self ) -> Result < Option < git2:: Oid > > ;
146149}
@@ -169,6 +172,26 @@ impl OplogExt for CommandContext {
169172 commit_snapshot ( self . project ( ) , tree_id, details, perm)
170173 }
171174
175+ #[ instrument( skip( self ) , err( Debug ) ) ]
176+ fn get_snapshot ( & self , sha : git2:: Oid ) -> Result < Snapshot > {
177+ let repo = self . project ( ) . open_for_merging ( ) ?;
178+ let commit = repo. find_commit ( sha. to_gix ( ) ) ?;
179+ let commit_time = gix_time_to_git2 ( commit. time ( ) ?) ;
180+ let details = commit
181+ . message_raw ( ) ?
182+ . to_str ( )
183+ . ok ( )
184+ . and_then ( |msg| SnapshotDetails :: from_str ( msg) . ok ( ) )
185+ . ok_or ( anyhow ! ( "Commit is not a snapshot" ) ) ?;
186+
187+ let snapshot = Snapshot {
188+ commit_id : sha,
189+ created_at : commit_time,
190+ details : Some ( details) ,
191+ } ;
192+ Ok ( snapshot)
193+ }
194+
172195 #[ instrument( skip( self ) , err( Debug ) ) ]
173196 fn list_snapshots (
174197 & self ,
0 commit comments