瀏覽代碼

Add format_reflog_line.

Jelmer Vernooij 9 年之前
父節點
當前提交
ef233fbac1
共有 4 個文件被更改,包括 98 次插入1 次删除
  1. 42 0
      dulwich/reflog.py
  2. 1 0
      dulwich/tests/__init__.py
  3. 55 0
      dulwich/tests/test_reflog.py
  4. 0 1
      relicensing-apachev2.txt

+ 42 - 0
dulwich/reflog.py

@@ -0,0 +1,42 @@
+# reflog.py -- Parsing and writing reflog files
+# Copyright (C) 2015 Jelmer Vernooij and others.
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; version 2
+# of the License or (at your option) a later version of the License.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+# MA  02110-1301, USA.
+
+"""Utilities for reading and generating reflogs.
+"""
+
+from dulwich.objects import (
+    format_timezone,
+    ZERO_SHA,
+    )
+
+
+def format_reflog_line(old_sha, new_sha, committer, timestamp, timezone, message):
+    """Generate a single reflog line.
+
+    :param old_sha: Old Commit SHA
+    :param new_sha: New Commit SHA
+    :param committer: Committer name and e-mail
+    :param timestamp: Timestamp
+    :param timezone: Timezone
+    :param message: Message
+    """
+    if old_sha is None:
+        old_sha = ZERO_SHA
+    return (old_sha + b' ' + new_sha + b' ' + committer + b' ' +
+            str(timestamp).encode('ascii') + b' ' +
+            format_timezone(timezone).encode('ascii') + b'\t' + message)

+ 1 - 0
dulwich/tests/__init__.py

@@ -135,6 +135,7 @@ def self_test_suite():
         'patch',
         'porcelain',
         'protocol',
+        'reflog',
         'refs',
         'repository',
         'server',

+ 55 - 0
dulwich/tests/test_reflog.py

@@ -0,0 +1,55 @@
+# test_reflog.py -- tests for reflog.py
+# encoding: utf-8
+# Copyright (C) 2015 Jelmer Vernooij <jelmer@samba.org>
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; version 2
+# of the License or (at your option) any later version of
+# the License.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+# MA  02110-1301, USA.
+
+"""Tests for dulwich.reflog."""
+
+
+from dulwich.reflog import format_reflog_line
+
+from dulwich.tests import (
+    TestCase,
+    )
+
+
+class FormatReflogLineTests(TestCase):
+
+    def test_valid(self):
+        self.assertEqual(
+            b'0000000000000000000000000000000000000000 '
+            b'49030649db3dfec5a9bc03e5dde4255a14499f16 Jelmer Vernooij '
+            b'<jelmer@jelmer.uk> 1446552482 +0000	'
+            b'clone: from git://jelmer.uk/samba',
+            format_reflog_line(
+                b'0000000000000000000000000000000000000000',
+                b'49030649db3dfec5a9bc03e5dde4255a14499f16',
+                b'Jelmer Vernooij <jelmer@jelmer.uk>',
+                1446552482, 0, b'clone: from git://jelmer.uk/samba'))
+
+        self.assertEqual(
+            b'0000000000000000000000000000000000000000 '
+            b'49030649db3dfec5a9bc03e5dde4255a14499f16 Jelmer Vernooij '
+            b'<jelmer@jelmer.uk> 1446552482 +0000	'
+            b'clone: from git://jelmer.uk/samba',
+            format_reflog_line(
+                None,
+                b'49030649db3dfec5a9bc03e5dde4255a14499f16',
+                b'Jelmer Vernooij <jelmer@jelmer.uk>',
+                1446552482, 0, b'clone: from git://jelmer.uk/samba'))
+

+ 0 - 1
relicensing-apachev2.txt

@@ -16,7 +16,6 @@ alone. Code written by the following contributors has not (yet) been relicensed
 under dual Apachev2/GPLv2:
 
 Artem Tikhomirov <artem.tikhomirov@syntevo.com>
-Dmitriy <dkomarov@gmail.com>
 Gary van der Merwé <garyvdm@gmail.com>
 Risto Kankkunen <risto.kankkunen@f-secure.com> <risto.kankkunen@iki.fi>