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

Public Member Functions

def __init__ (self, options)
 
def GuessBase (self, required)
 
def GenerateDiff (self, args)
 
def GetUnknownFiles (self)
 
def ReadFile (self, filename)
 
def GetStatus (self, filename)
 
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

 rev_start
 
 rev_end
 
 svnls_cache
 
 svn_base
 
- Public Attributes inherited from upload.VersionControlSystem
 options
 

Detailed Description

Implementation of the VersionControlSystem interface for Subversion.

Definition at line 736 of file upload.py.

Constructor & Destructor Documentation

◆ __init__()

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

Args:
  options: Command line options.

Reimplemented from upload.VersionControlSystem.

Definition at line 739 of file upload.py.

739 def __init__(self, options):
740 super(SubversionVCS, self).__init__(options)
741 if self.options.revision:
742 match = re.match(r"(\d+)(:(\d+))?", self.options.revision)
743 if not match:
744 ErrorExit("Invalid Subversion revision %s." % self.options.revision)
745 self.rev_start = match.group(1)
746 self.rev_end = match.group(3)
747 else:
748 self.rev_start = self.rev_end = None
749 # Cache output from "svn list -r REVNO dirname".
750 # Keys: dirname, Values: 2-tuple (output for start rev and end rev).
751 self.svnls_cache = {}
752 # SVN base URL is required to fetch files deleted in an older revision.
753 # Result is cached to not guess it over and over again in GetBaseFile().
754 required = self.options.download_base or self.options.revision is not None
755 self.svn_base = self._GuessBase(required)
756
def ErrorExit(msg)
Definition: upload.py:124

Member Function Documentation

◆ GenerateDiff()

def upload.SubversionVCS.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 805 of file upload.py.

805 def GenerateDiff(self, args):
806 cmd = ["svn", "diff"]
807 if self.options.revision:
808 cmd += ["-r", self.options.revision]
809 cmd.extend(args)
810 data = RunShell(cmd)
811 count = 0
812 for line in data.splitlines():
813 if line.startswith("Index:") or line.startswith("Property changes on:"):
814 count += 1
815 logging.info(line)
816 if not count:
817 ErrorExit("No valid patches found in output from svn diff")
818 return data
819
def RunShell(command, silent_ok=False, universal_newlines=True, print_output=False)
Definition: upload.py:593

◆ GetBaseFile()

def upload.SubversionVCS.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 913 of file upload.py.

913 def GetBaseFile(self, filename):
914 status = self.GetStatus(filename)
915 base_content = None
916 new_content = None
917
918 # If a file is copied its status will be "A +", which signifies
919 # "addition-with-history". See "svn st" for more information. We need to
920 # upload the original file or else diff parsing will fail if the file was
921 # edited.
922 if status[0] == "A" and status[3] != "+":
923 # We'll need to upload the new content if we're adding a binary file
924 # since diff's output won't contain it.
925 mimetype = RunShell(["svn", "propget", "svn:mime-type", filename],
926 silent_ok=True)
927 base_content = ""
928 is_binary = mimetype and not mimetype.startswith("text/")
929 if is_binary and self.IsImage(filename):
930 new_content = self.ReadFile(filename)
931 elif (status[0] in ("M", "D", "R") or
932 (status[0] == "A" and status[3] == "+") or # Copied file.
933 (status[0] == " " and status[1] == "M")): # Property change.
934 args = []
935 if self.options.revision:
936 url = "%s/%s@%s" % (self.svn_base, filename, self.rev_start)
937 else:
938 # Don't change filename, it's needed later.
939 url = filename
940 args += ["-r", "BASE"]
941 cmd = ["svn"] + args + ["propget", "svn:mime-type", url]
942 mimetype, returncode = RunShellWithReturnCode(cmd)
943 if returncode:
944 # File does not exist in the requested revision.
945 # Reset mimetype, it contains an error message.
946 mimetype = ""
947 get_base = False
948 is_binary = mimetype and not mimetype.startswith("text/")
949 if status[0] == " ":
950 # Empty base content just to force an upload.
951 base_content = ""
952 elif is_binary:
953 if self.IsImage(filename):
954 get_base = True
955 if status[0] == "M":
956 if not self.rev_end:
957 new_content = self.ReadFile(filename)
958 else:
959 url = "%s/%s@%s" % (self.svn_base, filename, self.rev_end)
960 new_content = RunShell(["svn", "cat", url],
961 universal_newlines=True, silent_ok=True)
962 else:
963 base_content = ""
964 else:
965 get_base = True
966
967 if get_base:
968 if is_binary:
969 universal_newlines = False
970 else:
971 universal_newlines = True
972 if self.rev_start:
973 # "svn cat -r REV delete_file.txt" doesn't work. cat requires
974 # the full URL with "@REV" appended instead of using "-r" option.
975 url = "%s/%s@%s" % (self.svn_base, filename, self.rev_start)
976 base_content = RunShell(["svn", "cat", url],
977 universal_newlines=universal_newlines,
978 silent_ok=True)
979 else:
980 base_content = RunShell(["svn", "cat", filename],
981 universal_newlines=universal_newlines,
982 silent_ok=True)
983 if not is_binary:
984 args = []
985 if self.rev_start:
986 url = "%s/%s@%s" % (self.svn_base, filename, self.rev_start)
987 else:
988 url = filename
989 args += ["-r", "BASE"]
990 cmd = ["svn"] + args + ["propget", "svn:keywords", url]
991 keywords, returncode = RunShellWithReturnCode(cmd)
992 if keywords and not returncode:
993 base_content = self._CollapseKeywords(base_content, keywords)
994 else:
995 StatusUpdate("svn status returned unexpected output: %s" % status)
996 sys.exit(1)
997 return base_content, new_content, is_binary, status[0:5]
998
999
def RunShellWithReturnCode(command, print_output=False, universal_newlines=True)
Definition: upload.py:557
def StatusUpdate(msg)
Definition: upload.py:112

◆ GetStatus()

def upload.SubversionVCS.GetStatus (   self,
  filename 
)
Returns the status of a file.

Definition at line 869 of file upload.py.

869 def GetStatus(self, filename):
870 """Returns the status of a file."""
871 if not self.options.revision:
872 status = RunShell(["svn", "status", "--ignore-externals", filename])
873 if not status:
874 ErrorExit("svn status returned no output for %s" % filename)
875 status_lines = status.splitlines()
876 # If file is in a cl, the output will begin with
877 # "\n--- Changelist 'cl_name':\n". See
878 # https://web.archive.org/web/20090918234815/svn.collab.net/repos/svn/trunk/notes/changelist-design.txt
879 if (len(status_lines) == 3 and
880 not status_lines[0] and
881 status_lines[1].startswith("--- Changelist")):
882 status = status_lines[2]
883 else:
884 status = status_lines[0]
885 # If we have a revision to diff against we need to run "svn list"
886 # for the old and the new revision and compare the results to get
887 # the correct status for a file.
888 else:
889 dirname, relfilename = os.path.split(filename)
890 if dirname not in self.svnls_cache:
891 cmd = ["svn", "list", "-r", self.rev_start, dirname or "."]
892 out, returncode = RunShellWithReturnCode(cmd)
893 if returncode:
894 ErrorExit("Failed to get status for %s." % filename)
895 old_files = out.splitlines()
896 args = ["svn", "list"]
897 if self.rev_end:
898 args += ["-r", self.rev_end]
899 cmd = args + [dirname or "."]
900 out, returncode = RunShellWithReturnCode(cmd)
901 if returncode:
902 ErrorExit("Failed to run command %s" % cmd)
903 self.svnls_cache[dirname] = (old_files, out.splitlines())
904 old_files, new_files = self.svnls_cache[dirname]
905 if relfilename in old_files and relfilename not in new_files:
906 status = "D "
907 elif relfilename in old_files and relfilename in new_files:
908 status = "M "
909 else:
910 status = "A "
911 return status
912

◆ GetUnknownFiles()

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

Reimplemented from upload.VersionControlSystem.

Definition at line 851 of file upload.py.

851 def GetUnknownFiles(self):
852 status = RunShell(["svn", "status", "--ignore-externals"], silent_ok=True)
853 unknown_files = []
854 for line in status.split("\n"):
855 if line and line[0] == "?":
856 unknown_files.append(line)
857 return unknown_files
858

◆ GuessBase()

def upload.SubversionVCS.GuessBase (   self,
  required 
)
Wrapper for _GuessBase.

Definition at line 757 of file upload.py.

757 def GuessBase(self, required):
758 """Wrapper for _GuessBase."""
759 return self.svn_base
760

◆ ReadFile()

def upload.SubversionVCS.ReadFile (   self,
  filename 
)
Returns the contents of a file.

Definition at line 859 of file upload.py.

859 def ReadFile(self, filename):
860 """Returns the contents of a file."""
861 file = open(filename, 'rb')
862 result = ""
863 try:
864 result = file.read()
865 finally:
866 file.close()
867 return result
868
std::string ReadFile(const std::string &filename, FileReader reader)

Member Data Documentation

◆ rev_end

upload.SubversionVCS.rev_end

Definition at line 746 of file upload.py.

◆ rev_start

upload.SubversionVCS.rev_start

Definition at line 745 of file upload.py.

◆ svn_base

upload.SubversionVCS.svn_base

Definition at line 755 of file upload.py.

◆ svnls_cache

upload.SubversionVCS.svnls_cache

Definition at line 751 of file upload.py.


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