From 478d15f7f4bb48a8442e54d8ab08aaade39e5270 Mon Sep 17 00:00:00 2001 From: Timothee Cour Date: Thu, 28 Jan 2021 22:51:12 -0800 Subject: [PATCH] improve code in categories.nim; add std/private/gitutils; fix flakyness in nim CI (cloneDependency in deps.nim) (#16856) * improve code in categories.nim; gitutils; fix flakyness in deps.nim * cleanups --- lib/std/private/gitutils.nim | 40 ++++++++++++++++++++++ testament/categories.nim | 64 ++++++++++++------------------------ tools/deps.nim | 31 +++++++---------- 3 files changed, 73 insertions(+), 62 deletions(-) create mode 100644 lib/std/private/gitutils.nim diff --git a/lib/std/private/gitutils.nim b/lib/std/private/gitutils.nim new file mode 100644 index 0000000000..bf5e7cb1ff --- /dev/null +++ b/lib/std/private/gitutils.nim @@ -0,0 +1,40 @@ +##[ +internal API for now, API subject to change +]## + +# xxx move other git utilities here; candidate for stdlib. + +import std/[os, osproc, strutils] + +const commitHead* = "HEAD" + +template retryCall*(maxRetry = 3, backoffDuration = 1.0, call: untyped): bool = + ## Retry `call` up to `maxRetry` times with exponential backoff and initial + ## duraton of `backoffDuration` seconds. + ## This is in particular useful for network commands that can fail. + runnableExamples: + doAssert not retryCall(maxRetry = 2, backoffDuration = 0.1, false) + var i = 0 + doAssert: retryCall(maxRetry = 3, backoffDuration = 0.1, (i.inc; i >= 3)) + doAssert retryCall(call = true) + var result = false + var t = backoffDuration + for i in 0..