From 53a54bbb10e75f9ac2e754d9292cfb080f53b69d Mon Sep 17 00:00:00 2001
From: Hisham Muhammad <hisham@gobolinux.org>
Date: Tue, 2 Jan 2018 15:42:57 -0200
Subject: Obtain a unique identifier for a rock version fetched via git

---
 src/luarocks/fetch/git.lua | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

(limited to 'src')

diff --git a/src/luarocks/fetch/git.lua b/src/luarocks/fetch/git.lua
index edc11762..2b8adc78 100644
--- a/src/luarocks/fetch/git.lua
+++ b/src/luarocks/fetch/git.lua
@@ -50,6 +50,17 @@ local function git_supports_shallow_submodules(git_cmd)
    return git_is_at_least(git_cmd, "1.8.4")
 end
 
+local function git_identifier(git_cmd, ver)
+   if not (ver:match("^dev%-%d+$") or ver:match("^scm%-%d+$")) then
+      return nil
+   end
+   local date_hash = util.popen_read(fs.Q(git_cmd).." log --pretty=format:'%ai %h' -n 1")
+   local date, time, tz, hash = date_hash:match("([^%s]+) ([^%s]+) ([^%s]+) ([^%s]+)")
+   date = date:gsub("%-", "")
+   time = time:gsub(":", "")
+   return date .. "." .. time .. "." .. hash
+end
+
 --- Download sources for building a rock, using git.
 -- @param rockspec table: The rockspec table
 -- @param extract boolean: Unused in this module (required for API purposes.)
@@ -122,6 +133,10 @@ function git.get_sources(rockspec, extract, dest_dir, depth)
          return nil, 'Failed to fetch submodules.'
       end
    end
+   
+   if not rockspec.source.tag then
+      rockspec.source.identifier = git_identifier(git_cmd, rockspec.version)
+   end
 
    fs.delete(dir.path(store_dir, module, ".git"))
    fs.delete(dir.path(store_dir, module, ".gitignore"))
-- 
cgit v1.2.3-55-g6feb