reflog.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. # reflog.py -- Parsing and writing reflog files
  2. # Copyright (C) 2015 Jelmer Vernooij and others.
  3. #
  4. # This program is free software; you can redistribute it and/or
  5. # modify it under the terms of the GNU General Public License
  6. # as published by the Free Software Foundation; version 2
  7. # of the License or (at your option) a later version of the License.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program; if not, write to the Free Software
  16. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  17. # MA 02110-1301, USA.
  18. """Utilities for reading and generating reflogs.
  19. """
  20. from dulwich.objects import (
  21. format_timezone,
  22. ZERO_SHA,
  23. )
  24. def format_reflog_line(old_sha, new_sha, committer, timestamp, timezone, message):
  25. """Generate a single reflog line.
  26. :param old_sha: Old Commit SHA
  27. :param new_sha: New Commit SHA
  28. :param committer: Committer name and e-mail
  29. :param timestamp: Timestamp
  30. :param timezone: Timezone
  31. :param message: Message
  32. """
  33. if old_sha is None:
  34. old_sha = ZERO_SHA
  35. return (old_sha + b' ' + new_sha + b' ' + committer + b' ' +
  36. str(timestamp).encode('ascii') + b' ' +
  37. format_timezone(timezone).encode('ascii') + b'\t' + message)