summary refs log tree commit diff stats
path: root/tools/atlas
diff options
context:
space:
mode:
authorAntonis Geralis <43617260+planetis-m@users.noreply.github.com>2021-07-18 16:29:49 +0300
committerGitHub <noreply@github.com>2021-07-18 15:29:49 +0200
commit220b55c5d7c40aa93df7879ebc6c9f71147c3eda (patch)
tree997a4e76930d9ca439d7aba3638dacd275210cbb /tools/atlas
parent99c4b69097638aca8377ea3746e52cc19c24ced8 (diff)
downloadNim-220b55c5d7c40aa93df7879ebc6c9f71147c3eda.tar.gz
attempt to support short commit hashes (#18514)
* attempt to support short commit hashes

Not sure if that's the correct way and what happens when the short hash matches "head"

* need to remove #

* Output needs to be stripped of newlines
Diffstat (limited to 'tools/atlas')
-rw-r--r--tools/atlas/atlas.nim21
1 files changed, 16 insertions, 5 deletions
diff --git a/tools/atlas/atlas.nim b/tools/atlas/atlas.nim
index bc1cc6ae3..371a1c13f 100644
--- a/tools/atlas/atlas.nim
+++ b/tools/atlas/atlas.nim
@@ -123,8 +123,12 @@ proc versionToCommit(d: Dependency): string =
 
   return ""
 
+proc shortToCommit(short: string): string =
+  let (cc, status) = osproc.execCmdEx("git rev-parse " & quoteShell(short))
+  result = if status == 0: strutils.strip(cc) else: ""
+
 proc checkoutGitCommit(c: var AtlasContext; p: PackageName; commit: string) =
-  let (outp, status) = osproc.execCmdEx("git checkout " & quoteShell(commit))
+  let (_, status) = osproc.execCmdEx("git checkout " & quoteShell(commit))
   if status != 0:
     error(c, p, "could not checkout commit", commit)
 
@@ -169,17 +173,23 @@ proc toName(p: string): PackageName =
 proc needsCommitLookup(commit: string): bool {.inline} =
   '.' in commit or commit == InvalidCommit
 
+proc isShortCommitHash(commit: string): bool {.inline.} =
+  commit.len >= 4 and commit.len < 40
+
 proc checkoutCommit(c: var AtlasContext; w: Dependency) =
   let dir = c.workspace / w.name.string
   withDir dir:
-    if w.commit.len == 0 or cmpIgnoreCase(w.commit, "#head") == 0:
+    if w.commit.len == 0 or cmpIgnoreCase(w.commit, "head") == 0:
       gitPull(c, w.name)
     else:
       let err = isCleanGit(dir)
       if err != "":
         warn c, w.name, err
       else:
-        let requiredCommit = if needsCommitLookup(w.commit): versionToCommit(w) else: w.commit
+        let requiredCommit =
+          if needsCommitLookup(w.commit): versionToCommit(w)
+          elif isShortCommitHash(w.commit): shortToCommit(w.commit)
+          else: w.commit
         let (cc, status) = osproc.execCmdEx("git log -n 1 --format=%H")
         let currentCommit = strutils.strip(cc)
         if requiredCommit == "" or status != 0:
@@ -191,8 +201,9 @@ proc checkoutCommit(c: var AtlasContext; w: Dependency) =
           if currentCommit != requiredCommit:
             # checkout the later commit:
             # git merge-base --is-ancestor <commit> <commit>
-            let (mergeBase, status) = osproc.execCmdEx("git merge-base " &
+            let (cc, status) = osproc.execCmdEx("git merge-base " &
                 currentCommit.quoteShell & " " & requiredCommit.quoteShell)
+            let mergeBase = strutils.strip(cc)
             if status == 0 and (mergeBase == currentCommit or mergeBase == requiredCommit):
               # conflict resolution: pick the later commit:
               if mergeBase == currentCommit:
@@ -242,7 +253,7 @@ proc collectNewDeps(c: var AtlasContext; work: var seq[Dependency];
         tokens.add InvalidCommit
       elif tokens.len == 2 and tokens[1].startsWith("#"):
         # Dependencies can also look like 'requires "sdl2#head"
-        var commit = tokens[1]
+        var commit = tokens[1][1 .. ^1]
         tokens[1] = "=="
         tokens.add commit