git cl: add python implementation of Change-Id generation.

This allows to generate new IDs on the fly without installing
commit-msg hook and works just fine on Windows.

BUG=579183

Review URL: https://codereview.chromium.org/1757133002

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@299094 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/tests/git_cl_test.py b/tests/git_cl_test.py
index 4015bb3..f5b3257 100755
--- a/tests/git_cl_test.py
+++ b/tests/git_cl_test.py
@@ -746,6 +746,22 @@
     self.assertEquals(5, record_calls.times_called)
     self.assertEquals(0, ret)
 
+  def test_gerrit_change_id(self):
+    self.calls = [
+        ((['git', 'write-tree'], ),
+          'hashtree'),
+        ((['git', 'rev-parse', 'HEAD~0'], ),
+          'branch-parent'),
+        ((['git', 'var', 'GIT_AUTHOR_IDENT'], ),
+          'A B <a@b.org> 1456848326 +0100'),
+        ((['git', 'var', 'GIT_COMMITTER_IDENT'], ),
+          'C D <c@d.org> 1456858326 +0100'),
+        ((['git', 'hash-object', '-t', 'commit', '--stdin'], ),
+          'hashchange'),
+    ]
+    change_id = git_cl.GenerateGerritChangeId('line1\nline2\n')
+    self.assertEqual(change_id, 'Ihashchange')
+
   def test_config_gerrit_download_hook(self):
     self.mock(git_cl, 'FindCodereviewSettingsFile', CodereviewSettingsFileMock)
     def ParseCodereviewSettingsContent(content):