---@class ow.Git.Revision ---@field stage 0|1|2|3? ---@field path string? ---@field base string? local Revision = {} Revision.__index = Revision ---@return string function Revision:format() if self.stage then return ":" .. self.stage .. ":" .. self.path elseif self.path then return self.base .. ":" .. self.path end return self.base or error("Revision:format: empty Revision") end ---@param parts { stage?: integer, base?: string, path?: string } ---@return ow.Git.Revision function Revision.new(parts) return setmetatable(parts, Revision) end ---@param str string ---@return ow.Git.Revision function Revision.parse(str) local stage, path = str:match("^:([0123]):(.+)$") if stage then return Revision.new({ stage = tonumber(stage) --[[@as (0|1|2|3)?]], path = path, }) end path = str:match("^:([^:]+)$") if path then return Revision.new({ stage = 0, path = path }) end local base, p = str:match("^([^:]+):(.+)$") if base then return Revision.new({ base = base, path = p }) end return Revision.new({ base = str }) end return Revision