git-off

git off handles large files in git repos
git clone https://noulin.net/git/git-off.git
Log | Files | Refs | README

proxy.coffee (849B)


      1 
      2 child_process = require 'child_process'
      3 
      4 
      5 # Use 0.12 native functionality when available (instead of emulated blocking)
      6 #
      7 # @param cmd String command to execute
      8 # @param max_wait Number millisecond timeout value
      9 # @param options Object child_process.execSync options (like: encoding)
     10 #
     11 # @return Object identical to emulated: {stderr, stdout, status}
     12 
     13 module.exports = (cmd, max_wait, options) ->
     14 
     15   options.timeout = max_wait
     16   stdout = stderr = ''
     17   status = 0
     18 
     19   t0 = Date.now()
     20 
     21   orig_write = process.stderr.write
     22   process.stderr.write = ->
     23   try
     24     stdout = child_process.execSync cmd, options
     25     process.stderr.write = orig_write
     26   catch err
     27     process.stderr.write = orig_write
     28     if err.signal is 'SIGTERM' and t0 <= Date.now() - max_wait
     29       throw new Error 'Timeout'
     30     {stdout, stderr, status} = err
     31 
     32   {stdout, stderr, status}