Class: Amp::Core::Repositories::Git::Index::IndexEntry

Inherits:
Struct
  • Object
show all
Defined in:
lib/amp-git/repo_format/index.rb

Overview

The format of each index entry is as follows:

create_time, 32-bits # in seconds, least-significant bits if rollover
create_time_nanoseconds, 32-bits 
modify_time, 32-bits # in seconds, least-significant bits if rollover
modify_time_nanoseconds, 32-bits
device, 32-bits # device id
inode, 32-bits # inode from the filesystem
mode, 32-bits # permissions/mode from the FS
uid, 32-bits # user ID from the FS
gid, 32-bits # group ID from the FS
size, 32-bits # filesize, least-significant-bits, from FS
hash_id, 20 bytes # sha-1 hash of the data
assume_valid, 1 bit # flag for whether this file should be assumed to be unchanged
update_needed, 1 bit # flag saying the file needs to be refreshed
stage, 2 bits # two flags used for merging
filename_size, 12 bits # the size of the upcoming filename in bytes
filename, N bytes # the name of the file in the index
padding, N bytes # null padding. At least 1 byte, enough to make the block's size a
  multiple of 8 bytes

This class is a big effing struct for this.

Constant Summary collapse

ENTRY_HEADER_FORMAT =
"NNNNNNNNNNa20n"
ENTRY_HEADER_SIZE =
62

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ IndexEntry

Returns a new instance of IndexEntry.



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/amp-git/repo_format/index.rb', line 88

def initialize(*args)
  if args.size > 0 && args[0].kind_of?(IO)
    fp = args.first
    header = fp.read(ENTRY_HEADER_SIZE).unpack(ENTRY_HEADER_FORMAT)
    self.ctime, self.ctime_ns, self.mtime, self.mtime_ns, self.dev, self.inode, 
                self.mode, self.uid, self.gid, self.size, self.hash_id, flags = header
    self.hash_id = NodeId.from_bin(self.hash_id)
    self.assume_valid  = flags & 0x8000 > 0
    self.update_needed = flags & 0x4000 > 0
    self.stage  = (flags & 0x3000) >> 12
    namesize = flags & 0x0FFF
    self.name = fp.read(namesize)
    mod = (ENTRY_HEADER_SIZE + namesize) & 0x7
    padding_len = mod == 0 ? 8 : 8 - mod
    fp.read(padding_len)
  else
    super
  end
end

Instance Attribute Details

#assume_validObject

Returns the value of attribute assume_valid

Returns:

  • (Object)

    the current value of assume_valid



84
85
86
# File 'lib/amp-git/repo_format/index.rb', line 84

def assume_valid
  @assume_valid
end

#ctimeObject

Returns the value of attribute ctime

Returns:

  • (Object)

    the current value of ctime



84
85
86
# File 'lib/amp-git/repo_format/index.rb', line 84

def ctime
  @ctime
end

#ctime_nsObject

Returns the value of attribute ctime_ns

Returns:

  • (Object)

    the current value of ctime_ns



84
85
86
# File 'lib/amp-git/repo_format/index.rb', line 84

def ctime_ns
  @ctime_ns
end

#devObject

Returns the value of attribute dev

Returns:

  • (Object)

    the current value of dev



84
85
86
# File 'lib/amp-git/repo_format/index.rb', line 84

def dev
  @dev
end

#gidObject

Returns the value of attribute gid

Returns:

  • (Object)

    the current value of gid



84
85
86
# File 'lib/amp-git/repo_format/index.rb', line 84

def gid
  @gid
end

#hash_idObject

Returns the value of attribute hash_id

Returns:

  • (Object)

    the current value of hash_id



84
85
86
# File 'lib/amp-git/repo_format/index.rb', line 84

def hash_id
  @hash_id
end

#inodeObject

Returns the value of attribute inode

Returns:

  • (Object)

    the current value of inode



84
85
86
# File 'lib/amp-git/repo_format/index.rb', line 84

def inode
  @inode
end

#modeObject

Returns the value of attribute mode

Returns:

  • (Object)

    the current value of mode



84
85
86
# File 'lib/amp-git/repo_format/index.rb', line 84

def mode
  @mode
end

#mtimeObject

Returns the value of attribute mtime

Returns:

  • (Object)

    the current value of mtime



84
85
86
# File 'lib/amp-git/repo_format/index.rb', line 84

def mtime
  @mtime
end

#mtime_nsObject

Returns the value of attribute mtime_ns

Returns:

  • (Object)

    the current value of mtime_ns



84
85
86
# File 'lib/amp-git/repo_format/index.rb', line 84

def mtime_ns
  @mtime_ns
end

#nameObject

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



84
85
86
# File 'lib/amp-git/repo_format/index.rb', line 84

def name
  @name
end

#sizeObject

Returns the value of attribute size

Returns:

  • (Object)

    the current value of size



84
85
86
# File 'lib/amp-git/repo_format/index.rb', line 84

def size
  @size
end

#stageObject

Returns the value of attribute stage

Returns:

  • (Object)

    the current value of stage



84
85
86
# File 'lib/amp-git/repo_format/index.rb', line 84

def stage
  @stage
end

#uidObject

Returns the value of attribute uid

Returns:

  • (Object)

    the current value of uid



84
85
86
# File 'lib/amp-git/repo_format/index.rb', line 84

def uid
  @uid
end

#update_neededObject

Returns the value of attribute update_needed

Returns:

  • (Object)

    the current value of update_needed



84
85
86
# File 'lib/amp-git/repo_format/index.rb', line 84

def update_needed
  @update_needed
end