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

Public Member Functions

def __init__ (self, options, repo_dir)
 
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

 repo_dir
 
 subdir
 
 base_rev
 
- Public Attributes inherited from upload.VersionControlSystem
 options
 

Detailed Description

Implementation of the VersionControlSystem interface for Mercurial.

Definition at line 1057 of file upload.py.

Constructor & Destructor Documentation

◆ __init__()

def upload.MercurialVCS.__init__ (   self,
  options,
  repo_dir 
)
Constructor.

Args:
  options: Command line options.

Reimplemented from upload.VersionControlSystem.

Definition at line 1060 of file upload.py.

1060 def __init__(self, options, repo_dir):
1061 super(MercurialVCS, self).__init__(options)
1062 # Absolute path to repository (we can be in a subdir)
1063 self.repo_dir = os.path.normpath(repo_dir)
1064 # Compute the subdir
1065 cwd = os.path.normpath(os.getcwd())
1066 assert cwd.startswith(self.repo_dir)
1067 self.subdir = cwd[len(self.repo_dir):].lstrip(r"\/")
1068 if self.options.revision:
1069 self.base_rev = self.options.revision
1070 else:
1071 self.base_rev = RunShell(["hg", "parent", "-q"]).split(':')[1].strip()
1072
const std::vector< std::string > split(const std::string &s, char c)
Definition: helpers.h:43
def RunShell(command, silent_ok=False, universal_newlines=True, print_output=False)
Definition: upload.py:593

Member Function Documentation

◆ GenerateDiff()

def upload.MercurialVCS.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 1079 of file upload.py.

1079 def GenerateDiff(self, extra_args):
1080 # If no file specified, restrict to the current subdir
1081 extra_args = extra_args or ["."]
1082 cmd = ["hg", "diff", "--git", "-r", self.base_rev] + extra_args
1083 data = RunShell(cmd, silent_ok=True)
1084 svndiff = []
1085 filecount = 0
1086 for line in data.splitlines():
1087 m = re.match("diff --git a/(\S+) b/(\S+)", line)
1088 if m:
1089 # Modify line to make it look like as it comes from svn diff.
1090 # With this modification no changes on the server side are required
1091 # to make upload.py work with Mercurial repos.
1092 # NOTE: for proper handling of moved/copied files, we have to use
1093 # the second filename.
1094 filename = m.group(2)
1095 svndiff.append("Index: %s" % filename)
1096 svndiff.append("=" * 67)
1097 filecount += 1
1098 logging.info(line)
1099 else:
1100 svndiff.append(line)
1101 if not filecount:
1102 ErrorExit("No valid patches found in output from hg diff")
1103 return "\n".join(svndiff) + "\n"
1104
def ErrorExit(msg)
Definition: upload.py:124

◆ GetBaseFile()

def upload.MercurialVCS.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 1117 of file upload.py.

1117 def GetBaseFile(self, filename):
1118 # "hg status" and "hg cat" both take a path relative to the current subdir
1119 # rather than to the repo root, but "hg diff" has given us the full path
1120 # to the repo root.
1121 base_content = ""
1122 new_content = None
1123 is_binary = False
1124 oldrelpath = relpath = self._GetRelPath(filename)
1125 # "hg status -C" returns two lines for moved/copied files, one otherwise
1126 out = RunShell(["hg", "status", "-C", "--rev", self.base_rev, relpath])
1127 out = out.splitlines()
1128 # HACK: strip error message about missing file/directory if it isn't in
1129 # the working copy
1130 if out[0].startswith('%s: ' % relpath):
1131 out = out[1:]
1132 if len(out) > 1:
1133 # Moved/copied => considered as modified, use old filename to
1134 # retrieve base contents
1135 oldrelpath = out[1].strip()
1136 status = "M"
1137 else:
1138 status, _ = out[0].split(' ', 1)
1139 if status != "A":
1140 base_content = RunShell(["hg", "cat", "-r", self.base_rev, oldrelpath],
1141 silent_ok=True)
1142 is_binary = "\0" in base_content # Mercurial's heuristic
1143 if status != "R":
1144 new_content = open(relpath, "rb").read()
1145 is_binary = is_binary or "\0" in new_content
1146 if is_binary and base_content:
1147 # Fetch again without converting newlines
1148 base_content = RunShell(["hg", "cat", "-r", self.base_rev, oldrelpath],
1149 silent_ok=True, universal_newlines=False)
1150 if not is_binary or not self.IsImage(relpath):
1151 new_content = None
1152 return base_content, new_content, is_binary, status
1153
1154
1155# NOTE: The SplitPatch function is duplicated in engine.py, keep them in sync.

◆ GetUnknownFiles()

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

Reimplemented from upload.VersionControlSystem.

Definition at line 1105 of file upload.py.

1105 def GetUnknownFiles(self):
1106 """Return a list of files unknown to the VCS."""
1107 args = []
1108 status = RunShell(["hg", "status", "--rev", self.base_rev, "-u", "."],
1109 silent_ok=True)
1110 unknown_files = []
1111 for line in status.splitlines():
1112 st, fn = line.split(" ", 1)
1113 if st == "?":
1114 unknown_files.append(fn)
1115 return unknown_files
1116

Member Data Documentation

◆ base_rev

upload.MercurialVCS.base_rev

Definition at line 1069 of file upload.py.

◆ repo_dir

upload.MercurialVCS.repo_dir

Definition at line 1063 of file upload.py.

◆ subdir

upload.MercurialVCS.subdir

Definition at line 1067 of file upload.py.


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