File: commit.rb

package info (click to toggle)
ruby-rugged 0.27.4%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 740 kB
  • sloc: ansic: 8,401; ruby: 659; makefile: 4
file content (59 lines) | stat: -rw-r--r-- 1,559 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# Copyright (C) the Rugged contributors.  All rights reserved.
#
# This file is part of Rugged, distributed under the MIT license.
# For full terms see the included LICENSE file.

module Rugged
  class Commit

    def self.prettify_message(msg, strip_comments = true)
      Rugged::prettify_message(msg, strip_comments)
    end

    def inspect
      "#<Rugged::Commit:#{object_id} {message: #{message.inspect}, tree: #{tree.inspect}, parents: #{parent_oids}}>"
    end

    def header_field?(field)
      !!header_field(field)
    end

    # Return a diff between this commit and its first parent or another commit or tree.
    #
    # See Rugged::Tree#diff for more details.
    def diff(*args)
      args.unshift(parents.first) if args.size == 1 && args.first.is_a?(Hash)
      self.tree.diff(*args)
    end

    # Return a diff between this commit and the workdir.
    #
    # See Rugged::Tree#diff_workdir for more details.
    def diff_workdir(options = {})
      self.tree.diff_workdir(options)
    end

    # The time when this commit was made effective. This is the same value
    # as the +:time+ attribute for +commit.committer+.
    #
    # Returns a Time object
    def time
      @time ||= Time.at(self.epoch_time)
    end

    def to_hash
      {
        :message => message,
        :committer => committer,
        :author => author,
        :tree => tree,
        :parents => parents,
      }
    end

    def modify(new_args, update_ref=nil)
      args = self.to_hash.merge(new_args)
      Commit.create(args, update_ref)
    end
  end
end