githelper.git / githelper.pike

version» Context lines:

githelper.git/githelper.pike:46:   array(string) split_lf(string data)   {    array(string) a = data / "\n";    if (sizeof(a) && a[-1] == "")    a = a[..sizeof(a)-2];    return a;   }      string run_git_ex(int max_exitcode, string ... args)   { -  mapping res = Process.run(({"git"})+args); -  if (res->exitcode > max_exitcode) { -  werror(res->stderr); -  fail("git exited with code %d\n", res->exitcode); +  Stdio.File mystdout = Stdio.File(); +  Stdio.File mystderr = Stdio.File(); +  Process.Process p = Process.Process (({"git"})+args, ([ +  "stdout":mystdout->pipe(), +  "stderr":mystderr->pipe(), +  ])); +  string gotstdout="", gotstderr=""; +  mystdout->set_read_callback( lambda( mixed i, string data) { +  gotstdout += data; +  } ); +  mystderr->set_read_callback( lambda( mixed i, string data) { +  gotstderr += data; +  } ); +  while( !p->status() || p->status() == 1 ) +  Pike.DefaultBackend( 1.0 ); +  +  mystdout->set_read_callback(0); +  mystderr->set_read_callback(0); +  +  gotstdout += mystdout->read(); +  gotstderr += mystderr->read(); +  +  int exitcode = p->wait(); +  +  if (exitcode > max_exitcode) { +  werror(gotstderr); +  fail("git exited with code %d\n", exitcode);    } -  return res->stdout; +  return gotstdout;   }      string run_git(string ... args)   {    return run_git_ex(0, @args);   }      string get_staged_file(string filename, int|void allow_empty)   {    string blob;