MCPcopy
hub / github.com/jisaacks/GitGutter / execute_async

Method execute_async

modules/handler.py:782–840  ·  view source on GitHub ↗

Execute a git command asynchronously and return a Promise. Arguments: args (list): The command line arguments used to run git. decode (bool): If True the git's output is decoded assuming utf-8 which is the default output encoding of git.

(self, args, decode=True)

Source from the content-addressed store, hash-verified

780 return Promise(executor)
781
782 def execute_async(self, args, decode=True):
783 """Execute a git command asynchronously and return a Promise.
784
785 Arguments:
786 args (list): The command line arguments used to run git.
787 decode (bool): If True the git's output is decoded assuming utf-8
788 which is the default output encoding of git.
789
790 Returns:
791 Promise: A promise to return the git output in the future.
792 """
793 try:
794 proc = self.popen(args)
795 except Exception as error:
796 utils.log_message(str(error))
797 return Promise.resolve(None)
798
799 # inject some attributes into the proc object
800 setattr(proc, 'buffer', b'')
801
802 def poll(proc, resolve, decode):
803 """Poll the process and resolve promise if finished.
804
805 Arguments:
806 proc (subprocess.Popen):
807 The running process' object to quiery for completion
808 resolve (callable):
809 The function to be called to resolve the Promise.
810 decode (bool):
811 True to decode the binary output to text.
812 """
813 chunk = proc.stdout.read(_BUFSIZE)
814 if chunk:
815 # need to read from stdout as process won't exit if buffer
816 # is full.
817 proc.buffer += chunk
818 if len(chunk) == _BUFSIZE:
819 # git is still busy, come here later again
820 set_timeout(functools.partial(
821 poll, proc, resolve, decode), 20)
822 return
823
824 if not proc.buffer and self.settings.get('debug'):
825 proc.wait()
826 # 0 = ok, 128 = file not found
827 if proc.returncode not in (0, 128):
828 utils.log_message('%s failed with "%s"' % (
829 ' '.join(args), proc.stderr.read().decode('utf-8').strip()))
830
831 # return decoded ouptut using utf-8 or binary output
832 if decode and proc.buffer is not None:
833 return resolve(proc.buffer.decode('utf-8').strip())
834 return resolve(proc.buffer)
835
836 def executor(resolve):
837 """Start polling the process to query for its finish."""
838 set_timeout(functools.partial(poll, proc, resolve, decode), 20)
839

Callers 11

_run_diffMethod · 0.95
untrackedMethod · 0.95
ignoredMethod · 0.95
git_commitsMethod · 0.95
git_file_commitsMethod · 0.95
git_branchesMethod · 0.95
git_tagsMethod · 0.95
git_branch_nameMethod · 0.95
git_branch_statusMethod · 0.95
git_compare_commitMethod · 0.95
git_blameMethod · 0.95

Calls 3

popenMethod · 0.95
PromiseClass · 0.85
resolveMethod · 0.80

Tested by

no test coverage detected