tesseract v5.3.3.20231005
upload.GitVCS Class Reference
Inheritance diagram for upload.GitVCS:
upload.VersionControlSystem

Public Member Functions

def __init__ (self, options)
 
def GenerateDiff (self, extra_args)
 
def GetUnknownFiles (self)
 
def GetBaseFile (self, filename)
 
- Public Member Functions inherited from upload.VersionControlSystem
def __init__ (self, options)
 
def GenerateDiff (self, args)
 
def GetUnknownFiles (self)
 
def CheckForUnknownFiles (self)
 
def GetBaseFile (self, filename)
 
def GetBaseFiles (self, diff)
 
def UploadBaseFiles (self, issue, rpc_server, patch_list, patchset, options, files)
 
def IsImage (self, filename)
 

Public Attributes

 base_hashes
 
- Public Attributes inherited from upload.VersionControlSystem
 options
 

Detailed Description

Implementation of the VersionControlSystem interface for Git.

Definition at line 1000 of file upload.py.

Constructor & Destructor Documentation

◆ __init__()

def upload.GitVCS.__init__ (   self,
  options 
)
Constructor.

Args:
  options: Command line options.

Reimplemented from upload.VersionControlSystem.

Definition at line 1003 of file upload.py.

1003 def __init__(self, options):
1004 super(GitVCS, self).__init__(options)
1005 # Map of filename -> hash of base file.
1006 self.base_hashes = {}
1007

Member Function Documentation

◆ GenerateDiff()

def upload.GitVCS.GenerateDiff (   self,
  args 
)
Return the current diff as a string.

Args:
  args: Extra arguments to pass to the diff command.

Reimplemented from upload.VersionControlSystem.

Definition at line 1008 of file upload.py.

1008 def GenerateDiff(self, extra_args):
1009 # This is more complicated than svn's GenerateDiff because we must convert
1010 # the diff output to include an svn-style "Index:" line as well as record
1011 # the hashes of the base files, so we can upload them along with our diff.
1012 if self.options.revision:
1013 extra_args = [self.options.revision] + extra_args
1014 gitdiff = RunShell(["git", "diff", "--full-index"] + extra_args)
1015 svndiff = []
1016 filecount = 0
1017 filename = None
1018 for line in gitdiff.splitlines():
1019 match = re.match(r"diff --git a/(.*) b/.*$", line)
1020 if match:
1021 filecount += 1
1022 filename = match.group(1)
1023 svndiff.append("Index: %s\n" % filename)
1024 else:
1025 # The "index" line in a git diff looks like this (long hashes elided):
1026 # index 82c0d44..b2cee3f 100755
1027 # We want to save the left hash, as that identifies the base file.
1028 match = re.match(r"index (\w+)\.\.", line)
1029 if match:
1030 self.base_hashes[filename] = match.group(1)
1031 svndiff.append(line + "\n")
1032 if not filecount:
1033 ErrorExit("No valid patches found in output from git diff")
1034 return "".join(svndiff)
1035
def ErrorExit(msg)
Definition: upload.py:124
def RunShell(command, silent_ok=False, universal_newlines=True, print_output=False)
Definition: upload.py:593

◆ GetBaseFile()

def upload.GitVCS.GetBaseFile (   self,
  filename 
)
Get the content of the upstream version of a file.

Returns:
  A tuple (base_content, new_content, is_binary, status)
    base_content: The contents of the base file.
    new_content: For text files, this is empty.  For binary files, this is
      the contents of the new file, since the diff output won't contain
      information to reconstruct the current file.
    is_binary: True iff the file is binary.
    status: The status of the file.

Reimplemented from upload.VersionControlSystem.

Definition at line 1041 of file upload.py.

1041 def GetBaseFile(self, filename):
1042 hash = self.base_hashes[filename]
1043 base_content = None
1044 new_content = None
1045 is_binary = False
1046 if hash == "0" * 40: # All-zero hash indicates no base file.
1047 status = "A"
1048 base_content = ""
1049 else:
1050 status = "M"
1051 base_content, returncode = RunShellWithReturnCode(["git", "show", hash])
1052 if returncode:
1053 ErrorExit("Got error status from 'git show %s'" % hash)
1054 return (base_content, new_content, is_binary, status)
1055
1056
def RunShellWithReturnCode(command, print_output=False, universal_newlines=True)
Definition: upload.py:557

◆ GetUnknownFiles()

def upload.GitVCS.GetUnknownFiles (   self)
Return a list of files unknown to the VCS.

Reimplemented from upload.VersionControlSystem.

Definition at line 1036 of file upload.py.

1036 def GetUnknownFiles(self):
1037 status = RunShell(["git", "ls-files", "--exclude-standard", "--others"],
1038 silent_ok=True)
1039 return status.splitlines()
1040

Member Data Documentation

◆ base_hashes

upload.GitVCS.base_hashes

Definition at line 1006 of file upload.py.


The documentation for this class was generated from the following file: