Next: , Previous: , Up: Hooks   [Contents][Index]


6.1.10 Attribute Handling

Some files in a project are special; they may require different handling (such as binary or structured files that should always be manually merged – see File Content Conflict), or they may represent executable scripts or programs.

Monotone allows each file (or directory) in a repository to carry arbitrary File Attributes. Persistent attributes are stored in each revision’s manifest. The hooks in this section allow files to be automatically recognised as having certain attributes at the time they’re added, and for custom triggers to be invoked on each file according to its attributes when the workspace is changed.

attr_functions [attribute] (filename, value)

This is not a hook function, but a table of hook functions, indexed by attribute. Each entry in the table attr_functions is a function taking a file name filename and an attribute value value. The function should “apply” the attribute to the file in the file system, possibly in a platform-specific way.

These hooks are called by any command that modifies workspace files, including mtn revert, mtn undrop, mtn update, mtn merge_into_workspace, mtn pluck, mtn clone and mtn checkout.

When called to set an attribute, value is a string representing the value of the attribute.

When called to clear an attribute, value is nil.

This facility can be used to extend monotone’s understanding of files with platform-specific attributes, such as permission bits, access control lists, or special file types.

By default, there is only one entry in this table, for the mtn:execute attribute. It calls platform-specific functions to mark files as executable or not. See Default hooks.

attr_init_functions [attribute] (filename)

This is not a hook function, but a table of hook functions. Each entry in the table attr_init_functions, at table entry attribute, is a function taking a file (or directory) name filename. Each function returns true if the attribute should be set on filename. This table of hook functions is called once for each file during an add.

By default, there are only two entries in this table, for the mtn:execute and mtn:manual_merge attributes. Their definition is:

attr_init_functions["mtn:execute"] =
   function(filename)
      if (is_executable(filename)) then
        return "true"
      else
        return nil
      end
   end
attr_init_functions["mtn:manual_merge"] =
   function(filename)
      if (binary_file(filename)) then
        return "true" -- binary files must be merged manually
      else
        return nil
      end
   end

The binary_file function is also defined as a Lua hook. See Default hooks.


Next: , Previous: , Up: Hooks   [Contents][Index]

Quick Links:     www.monotone.ca    -     Downloads    -     Documentation    -     Wiki    -     Code Forge    -     Build Status