Difference between revisions of "Repository snapshot objects"

From Software Heritage Wiki
Jump to navigation Jump to search
Line 15: Line 15:
  
 
<pre>
 
<pre>
 +
  # create repo with some commits, branches, and tags
 
$ git init test
 
$ git init test
Initialized empty Git repository in /home/zack/test/.git/
 
 
$ cd test/
 
$ cd test/
 
$ echo foo > foo.txt
 
$ echo foo > foo.txt
 
$ git add foo.txt  
 
$ git add foo.txt  
 
$ git commit -m 'checkin foo'
 
$ git commit -m 'checkin foo'
[master (root-commit) 502cb84] checkin foo
 
1 file changed, 1 insertion(+)
 
create mode 100644 foo.txt
 
 
$ git branch foo
 
$ git branch foo
 
$ echo bar >> foo.txt  
 
$ echo bar >> foo.txt  
 
$ git commit -a -m 'add bar'
 
$ git commit -a -m 'add bar'
[master a9ae6b8] add bar
 
1 file changed, 1 insertion(+)
 
 
$ git tag bar
 
$ git tag bar
 
$ echo baz >> foo.txt  
 
$ echo baz >> foo.txt  
 
$ git commit -a -m 'add baz'
 
$ git commit -a -m 'add baz'
[master 2982e6b] add baz
 
1 file changed, 1 insertion(+)
 
  
$ # ASSUMPTION: the output of git show-ref is sorted by ref name using
+
  # ASSUMPTION: the output of git show-ref is sorted by ref name using
$ # the usual Git sort algorithm for textual object manifests. This is
+
  # the usual Git sort algorithm for textual object manifests. This is
$ # currently the case as of Git 2.8.1, but it is not documented
+
  # currently the case as of Git 2.8.1, but it is not documented
$ # behavior in git-show-ref(1).
+
  # behavior in git-show-ref(1).
  
$ # object content in full (the manifest)
+
  # repository object in full (the manifest)
$ git show-ref > snapshot-object.txt
+
$ git show-ref
$ sha1sum snapshot-object.txt | cut -f 1 -d' ' > snapshot-object.id.txt
+
585f6e27f540012af621a18d0155aae2a8ec0276 refs/heads/foo
 +
6d976a397fe0b28a5bc59540e64f7f36a861af68 refs/heads/master
 +
521cb6d728f9fa3d6c4d73ddd309c0796ddf6995 refs/tags/bar
  
$ # object ID (the Git SHA1 of the manifest)
+
  # repository object ID, as a Git SHA1
$ cat snapshot-object.id.txt
+
$ git show-ref | git hash-object -w --stdin --literally -t snapshot
11ef7425e723ae003eaa120cc0a5d5f9b6274457
+
7e78262ed2b2998244864284fbbc7b770bce2951
  
$ cat snapshot-object.txt
+
  # raw content of the repository object, including Git header
502cb84dca18c16658fe9341a2a2b2301bba2777 refs/heads/foo
+
$ zlib-flate -uncompress < .git/objects/7e/78262ed2b2998244864284fbbc7b770bce2951
2982e6bd42c65ddbc6023861ccab67300aed41c8 refs/heads/master
+
snapshot 170585f6e27f540012af621a18d0155aae2a8ec0276 refs/heads/foo
a9ae6b8e315d71b5a8aaef1e7bc5d588b2426f0e refs/tags/bar
+
6d976a397fe0b28a5bc59540e64f7f36a861af68 refs/heads/master
 +
521cb6d728f9fa3d6c4d73ddd309c0796ddf6995 refs/tags/bar
 +
 
 +
  # i.e., a 170-byte long object of type "snapshot"
 
</pre>
 
</pre>

Revision as of 15:32, 9 August 2016

Repository snapshot objects

A repository snapshot object is a Merkle DAG node used to capture the state of a VCS repository.

Conceptually, a snapshot object is a map from branch names to revision identifiers.
Practically, the map is serialized as an association list sorted by branch name.

Object ID

Each snapshot object has as its snapshot object ID the cryptographic has value of a textual serialization of the <branch name, revision ID> association list.

Git repository snapshot objects

In the spirit of other Git objects, snapshot object for Git repositories can be implemented as follows.

  # create repo with some commits, branches, and tags
$ git init test
$ cd test/
$ echo foo > foo.txt
$ git add foo.txt 
$ git commit -m 'checkin foo'
$ git branch foo
$ echo bar >> foo.txt 
$ git commit -a -m 'add bar'
$ git tag bar
$ echo baz >> foo.txt 
$ git commit -a -m 'add baz'

  # ASSUMPTION: the output of git show-ref is sorted by ref name using
  # the usual Git sort algorithm for textual object manifests. This is
  # currently the case as of Git 2.8.1, but it is not documented
  # behavior in git-show-ref(1).

  # repository object in full (the manifest)
$ git show-ref
585f6e27f540012af621a18d0155aae2a8ec0276 refs/heads/foo
6d976a397fe0b28a5bc59540e64f7f36a861af68 refs/heads/master
521cb6d728f9fa3d6c4d73ddd309c0796ddf6995 refs/tags/bar

  # repository object ID, as a Git SHA1
$ git show-ref | git hash-object -w --stdin --literally -t snapshot
7e78262ed2b2998244864284fbbc7b770bce2951

  # raw content of the repository object, including Git header
$ zlib-flate -uncompress < .git/objects/7e/78262ed2b2998244864284fbbc7b770bce2951 
snapshot 170585f6e27f540012af621a18d0155aae2a8ec0276 refs/heads/foo
6d976a397fe0b28a5bc59540e64f7f36a861af68 refs/heads/master
521cb6d728f9fa3d6c4d73ddd309c0796ddf6995 refs/tags/bar

  # i.e., a 170-byte long object of type "snapshot"