File: raw_object.rb

package info (click to toggle)
ruby-grit 2.8.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 336 kB
  • sloc: ruby: 3,643; makefile: 4
file content (44 lines) | stat: -rw-r--r-- 859 bytes parent folder | download | duplicates (5)
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
#
# converted from the gitrb project
#
# authors:
#    Matthias Lederhofer <matled@gmx.net>
#    Simon 'corecode' Schubert <corecode@fs.ei.tum.de>
#
# provides native ruby access to git objects and pack files
#

require 'digest/sha1'

module Grit
  module GitRuby
    module Internal
      OBJ_NONE = 0
      OBJ_COMMIT = 1
      OBJ_TREE = 2
      OBJ_BLOB = 3
      OBJ_TAG = 4

      OBJ_TYPES = [nil, :commit, :tree, :blob, :tag].freeze

      class RawObject
        attr_accessor :type, :content
        def initialize(type, content)
          @type = type
          @content = content
        end

        def sha1
          Digest::SHA1.digest("%s %d\0" % [@type, @content.length] + @content)
        end

        def to_hash
          {
            :type => @type,
            :content => @content
          }
        end
      end
    end
  end
end