# std/private/gitutils

Theme:

- Manual
- Standard library
- Index
- Compiler docs
- Fusion docs
- devel, stable

Search:
Source Edit

internal API for now, API subject to change

# Imports

os, paths, osproc, strutils, tempfiles, assertions, syncio

# Consts

    commitHead = "HEAD"

  Source Edit

# Procs

    proc diffFiles(path1, path2: string): tuple[output: string, same: bool] {.
        ...raises: [OSError, IOError, ValueError],
        tags: [ExecIOEffect, ReadIOEffect, RootEffect], forbids: [].}

  Returns a human readable diff of files `path1`, `path2`, the exact form of which is implementation defined. Source Edit

    proc diffStrings(a, b: string): tuple[output: string, same: bool] {.
        ...raises: [IOError, OSError, ValueError], tags: [ReadEnvEffect, ReadIOEffect,
        WriteIOEffect, WriteDirEffect, ExecIOEffect, RootEffect], forbids: [].}

  Returns a human readable diff of `a`, `b`, the exact form of which is implementation defined. See also `experimental.diff`.

  Example:

      let a = "ok1\nok2\nok3\n"
      let b = "ok1\nok2 alt\nok3\nok4\n"
      let (c, same) = diffStrings(a, b)
      doAssert not same
      let (c2, same2) = diffStrings(a, a)
      doAssert same2

  Example: cmd: -r:off

      let a = "ok1\nok2\nok3\n"
      let b = "ok1\nok2 alt\nok3\nok4\n"
      echo diffStrings(a, b).output

  Source Edit

    proc isGitRepo(dir: string): bool {....raises: [], tags: [ReadDirEffect],
                                        forbids: [].}

  Avoid calling git since it depends on /bin/sh existing and fails in Nix. Source Edit

# Templates

    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.

  Example:

      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)

  Source Edit