def GetUpstream(git_dir, branch): """Returns the name of the upstream for a branch Args: git_dir: Git directory containing repo branch: Name of branch Returns: Tuple: Name of upstream branch (e.g. 'upstream/master') or None if none Warning/error message, or None if none """ try: remote = command.OutputOneLine('git', '--git-dir', git_dir, 'config', 'branch.%s.remote' % branch) merge = command.OutputOneLine('git', '--git-dir', git_dir, 'config', 'branch.%s.merge' % branch) except: upstream, msg = GuessUpstream(git_dir, branch) return upstream, msg if remote == '.': return merge, None elif remote and merge: leaf = merge.split('/')[-1] return '%s/%s' % (remote, leaf), None else: raise ValueError("Cannot determine upstream branch for branch " "'%s' remote='%s', merge='%s'" % (branch, remote, merge))
def GetHead(): """Get the hash of the current HEAD Returns: Hash of HEAD """ return command.OutputOneLine('git', 'show', '-s', '--pretty=format:%H')
def CheckSuppressCCConfig(): """Check if sendemail.suppresscc is configured correctly. Returns: True if the option is configured correctly, False otherwise. """ suppresscc = command.OutputOneLine('git', 'config', 'sendemail.suppresscc', raise_on_error=False) # Other settings should be fine. if suppresscc == 'all' or suppresscc == 'cccmd': col = terminal.Color() print((col.Color(col.RED, "error") + ": git config sendemail.suppresscc set to %s\n" % (suppresscc)) + " patman needs --cc-cmd to be run to set the cc list.\n" + " Please run:\n" + " git config --unset sendemail.suppresscc\n" + " Or read the man page:\n" + " git send-email --help\n" + " and set an option that runs --cc-cmd\n") return False return True
def LocateArchUrl(self, fetch_arch): """Find a toolchain available online Look in standard places for available toolchains. At present the only standard place is at kernel.org. Args: arch: Architecture to look for, or 'list' for all Returns: If fetch_arch is 'list', a tuple: Machine architecture (e.g. x86_64) List of toolchains else URL containing this toolchain, if avaialble, else None """ arch = command.OutputOneLine('uname', '-m') if arch == 'aarch64': arch = 'arm64' base = 'https://www.kernel.org/pub/tools/crosstool/files/bin' versions = ['11.1.0', '9.2.0', '7.3.0', '6.4.0', '4.9.4'] links = [] for version in versions: url = '%s/%s/%s/' % (base, arch, version) print('Checking: %s' % url) response = urllib.request.urlopen(url) html = tools.ToString(response.read()) parser = MyHTMLParser(fetch_arch) parser.feed(html) if fetch_arch == 'list': links += parser.links elif parser.arch_link: return url + parser.arch_link if fetch_arch == 'list': return arch, links return None
def GetDefaultUserEmail(): """Gets the user.email from the global .gitconfig file. Returns: User's email found in .gitconfig file, or None if none """ uemail = command.OutputOneLine('git', 'config', '--global', 'user.email') return uemail
def GetDefaultUserName(): """Gets the user.name from .gitconfig file. Returns: User name found in .gitconfig file, or None if none """ uname = command.OutputOneLine('git', 'config', '--global', 'user.name') return uname
def GetDefaultSubjectPrefix(): """Gets the format.subjectprefix from local .git/config file. Returns: Subject prefix found in local .git/config file, or None if none """ sub_prefix = command.OutputOneLine('git', 'config', 'format.subjectprefix', raise_on_error=False) return sub_prefix
def GetAliasFile(): """Gets the name of the git alias file. Returns: Filename of git alias file, or None if none """ fname = command.OutputOneLine('git', 'config', 'sendemail.aliasesfile', raise_on_error=False) if fname: fname = os.path.join(GetTopLevel(), fname.strip()) return fname
def GetTopLevel(): """Return name of top-level directory for this git repo. Returns: Full path to git top-level directory This test makes sure that we are running tests in the right subdir >>> os.path.realpath(os.path.dirname(__file__)) == \ os.path.join(GetTopLevel(), 'tools', 'patman') True """ return command.OutputOneLine('git', 'rev-parse', '--show-toplevel')