From aca1e40fa0179bc728f12b86a821a09e3fe5190b Mon Sep 17 00:00:00 2001
From: "Antoine R. Dumont (@ardumont)" <antoine.romain.dumont@gmail.com>
Date: Tue, 22 Mar 2016 18:58:45 +0100
Subject: [PATCH] Use of optional gpgsig in git commit sha1 computation

---
 README-dev.md                       | 35 ++++++++++++++++++-
 swh/model/identifiers.py            |  3 ++
 swh/model/tests/test_identifiers.py | 54 +++++++++++++++++++++++++++++
 3 files changed, 91 insertions(+), 1 deletion(-)

diff --git a/README-dev.md b/README-dev.md
index ac2abc83..97f9fb42 100644
--- a/README-dev.md
+++ b/README-dev.md
@@ -29,7 +29,7 @@ sources:
 - commit_tree_extended: https://github.com/git/git/blob/8d530c4d64ffcc853889f7b385f554d53db375ed/commit.c#L1522
 - commit_tree: https://github.com/git/git/blob/8d530c4d64ffcc853889f7b385f554d53db375ed/commit.c#L1392
 
-Example:
+Examples:
 
 ```sh
 $ cat commit.txt
@@ -48,6 +48,39 @@ $ cat commit.txt | git hash-object -t commit --stdin
 010d34f384fa99d047cdd5e2f41e56e5c2feee45
 ```
 
+commit: 44cc742a8ca17b9c279be4cc195a93a6ef7a320e
+```
+$ git cat-file -p 44cc742a8ca17b9c279be4cc195a93a6ef7a320e
+...
+tree b134f9b7dc434f593c0bab696345548b37de0558
+parent 689664ae944b4692724f13b709a4e4de28b54e57
+parent c888305e1efbaa252d01b4e5e6b778f865a97514
+author Jiang Xin <worldhello.net@gmail.com> 1428538899 +0800
+committer Jiang Xin <worldhello.net@gmail.com> 1428538899 +0800
+gpgsig -----BEGIN PGP SIGNATURE-----
+ Version: GnuPG v1.4.13 (Darwin)
+
+ iQIcBAABAgAGBQJVJcYsAAoJEBiY3kIkQRNJVAUQAJ8/XQIfMqqC5oYeEFfHOPYZ
+ L7qy46bXHVBa9Qd8zAJ2Dou3IbI2ZoF6/Et89K/UggOycMlt5FKV/9toWyuZv4Po
+ L682wonoxX99qvVTHo6+wtnmYO7+G0f82h+qHMErxjP+I6gzRNBvRr+SfY7VlGdK
+ wikMKOMWC5smrScSHITnOq1Ews5pe3N7qDYMzK0XVZmgDoaem4RSWMJs4My/qVLN
+ e0CqYWq2A22GX7sXl6pjneJYQvcAXUX+CAzp24QnPSb+Q22Guj91TcxLFcHCTDdn
+ qgqMsEyMiisoglwrCbO+D+1xq9mjN9tNFWP66SQ48mrrHYTBV5sz9eJyDfroJaLP
+ CWgbDTgq6GzRMehHT3hXfYS5NNatjnhkNISXR7pnVP/obIi/vpWh5ll6Gd8q26z+
+ a/O41UzOaLTeNI365MWT4/cnXohVLRG7iVJbAbCxoQmEgsYMRc/pBAzWJtLfcB2G
+ jdTswYL6+MUdL8sB9pZ82D+BP/YAdHe69CyTu1lk9RT2pYtI/kkfjHubXBCYEJSG
+ +VGllBbYG6idQJpyrOYNRJyrDi9yvDJ2W+S0iQrlZrxzGBVGTB/y65S8C+2WTBcE
+ lf1Qb5GDsQrZWgD+jtWTywOYHtCBwyCKSAXxSARMbNPeak9WPlcW/Jmu+fUcMe2x
+ dg1KdHOa34shrKDaOVzW
+ =od6m
+ -----END PGP SIGNATURE-----
+
+Merge branch 'master' of git://github.com/alexhenrie/git-po
+
+* 'master' of git://github.com/alexhenrie/git-po:
+  l10n: ca.po: update translation
+```
+
 ### directory/tree
 
 sha1 git directory/tree computation:
diff --git a/swh/model/identifiers.py b/swh/model/identifiers.py
index 3d06f9d5..7671ce3b 100644
--- a/swh/model/identifiers.py
+++ b/swh/model/identifiers.py
@@ -265,6 +265,9 @@ def revision_identifier(revision):
     ])
 
     metadata = revision.get('metadata', {})
+    if 'gpgsig' in metadata:
+        components.extend([b'gpgsig', b' ', metadata['gpgsig'], b'\n'])
+
     if 'extra_headers' in metadata:
         headers = metadata['extra_headers']
         keys = list(headers.keys())
diff --git a/swh/model/tests/test_identifiers.py b/swh/model/tests/test_identifiers.py
index 7864ec69..c1e6201a 100644
--- a/swh/model/tests/test_identifiers.py
+++ b/swh/model/tests/test_identifiers.py
@@ -296,6 +296,51 @@ class RevisionIdentifier(unittest.TestCase):
             }
         }
 
+        self.revision_with_gpgsign = {
+            'id': '44cc742a8ca17b9c279be4cc195a93a6ef7a320e',
+            'directory': 'b134f9b7dc434f593c0bab696345548b37de0558',
+            'parents': ['689664ae944b4692724f13b709a4e4de28b54e57',
+                        'c888305e1efbaa252d01b4e5e6b778f865a97514'],
+            'author': {
+                'name': b'Jiang Xin',
+                'email': b'worldhello.net@gmail.com',
+            },
+            'date': {
+                'timestamp': '1428538899',
+                'offset': 480,
+            },
+            'committer': {
+                'name': b'Jiang Xin',
+                'email': b'worldhello.net@gmail.com',
+            },
+            'committer_date': {
+                'timestamp': '1428538899',
+                'offset': 480,
+            },
+            'metadata': {
+                'gpgsig': b'''-----BEGIN PGP SIGNATURE-----
+ Version: GnuPG v1.4.13 (Darwin)\n \n iQIcBAABAgAGBQJVJcYsAAoJEBiY3kIkQRNJVAUQAJ8/XQIfMqqC5oYeEFfHOPYZ
+ L7qy46bXHVBa9Qd8zAJ2Dou3IbI2ZoF6/Et89K/UggOycMlt5FKV/9toWyuZv4Po
+ L682wonoxX99qvVTHo6+wtnmYO7+G0f82h+qHMErxjP+I6gzRNBvRr+SfY7VlGdK
+ wikMKOMWC5smrScSHITnOq1Ews5pe3N7qDYMzK0XVZmgDoaem4RSWMJs4My/qVLN
+ e0CqYWq2A22GX7sXl6pjneJYQvcAXUX+CAzp24QnPSb+Q22Guj91TcxLFcHCTDdn
+ qgqMsEyMiisoglwrCbO+D+1xq9mjN9tNFWP66SQ48mrrHYTBV5sz9eJyDfroJaLP
+ CWgbDTgq6GzRMehHT3hXfYS5NNatjnhkNISXR7pnVP/obIi/vpWh5ll6Gd8q26z+
+ a/O41UzOaLTeNI365MWT4/cnXohVLRG7iVJbAbCxoQmEgsYMRc/pBAzWJtLfcB2G
+ jdTswYL6+MUdL8sB9pZ82D+BP/YAdHe69CyTu1lk9RT2pYtI/kkfjHubXBCYEJSG
+ +VGllBbYG6idQJpyrOYNRJyrDi9yvDJ2W+S0iQrlZrxzGBVGTB/y65S8C+2WTBcE
+ lf1Qb5GDsQrZWgD+jtWTywOYHtCBwyCKSAXxSARMbNPeak9WPlcW/Jmu+fUcMe2x
+ dg1KdHOa34shrKDaOVzW
+ =od6m
+ -----END PGP SIGNATURE-----'''  # noqa
+            },
+            'message': b'''Merge branch 'master' of git://github.com/alexhenrie/git-po
+
+* 'master' of git://github.com/alexhenrie/git-po:
+  l10n: ca.po: update translation
+'''
+        }
+
     @istest
     def revision_identifier(self):
         self.assertEqual(
@@ -319,6 +364,15 @@ class RevisionIdentifier(unittest.TestCase):
                 self.revision_with_extra_headers['id']),
         )
 
+    @istest
+    def revision_identifier_with_gpgsign(self):
+        self.assertEqual(
+            identifiers.revision_identifier(
+                self.revision_with_gpgsign),
+            identifiers.identifier_to_str(
+                self.revision_with_gpgsign['id']),
+        )
+
 
 class ReleaseIdentifier(unittest.TestCase):
     def setUp(self):
-- 
GitLab