tools/symsrc/source_index.py
def ExtractGitInfo(local_filename):
  """Checks if a file is coming from a git repository and if so returns some
  information about it.

  Args:
    local_filename: The name of the file that we want to check.

  Returns:
    None if the file doesn't come from a git repository, otherwise it returns a
    RevisionInfo tuple.
  """
  # Starts by checking if this file is coming from a git repository. For that
  # we'll start by calling 'git info' on this file; for this to work we need to
  # make sure that the current working directory is correctly cased. It turns
  # out that even on Windows the casing of the path passed in the |cwd| argument
  # of subprocess.Popen matters and if it's not correctly cased then 'git info'
  # will return None even if the file is coming from a git repository. This
  # is not the case if we're just interested in checking if the path containing
  # |local_filename| is coming from a git repository, in this case the casing
  # doesn't matter.
  local_filename = GetCasedFilePath(local_filename)
  local_file_basename = os.path.basename(local_filename)
  local_file_dir = os.path.dirname(local_filename)
  file_info = RunCommand('git.bat', 'log', '-n', '1', local_file_basename,
                          cwd=local_file_dir, raise_on_failure=False)

  if not file_info:
    return

  # Get the revision of the master branch.
  rev = RunCommand('git.bat', 'rev-parse', 'HEAD', cwd=local_file_dir)

  # Get the url of the remote repository.
  repo = RunCommand('git.bat', 'config', '--get', 'remote.origin.url',
      cwd=local_file_dir)
  # If the repository point to a local directory then we need to run this
  # command one more time from this directory to get the repository url.
  if os.path.isdir(repo):
    repo = RunCommand('git.bat', 'config', '--get', 'remote.origin.url',
        cwd=repo)

  # Don't use the authenticated path.
  repo = repo.replace('googlesource.com/a/', 'googlesource.com/')

  # Get the relative file path for this file in the git repository.
  git_path = RunCommand('git.bat', 'ls-tree', '--full-name', '--name-only',
      'HEAD', local_file_basename, cwd=local_file_dir).replace('/','\\')

  if not git_path:
    return

  git_root_path = local_filename.replace(git_path, '')

  if repo not in REPO_MAP:
    # Automatically adds the project coming from a git GoogleCode or Github
    # repository to the repository map.
    if urlparse(repo).netloc.endswith('.googlesource.com'):
      # The files from these repositories are accessible via gitiles in a
      # base64 encoded format.
      REPO_MAP[repo] = {
          'url': '%s/+/{revision}/{file_path}?format=TEXT' % repo,
          'base64': True
      }
    elif urlparse(repo).netloc.endswith('github.com'):
      raw_url = '%s/{revision}/{file_path}' % repo.replace('.git', '').replace(
          'github.com', 'raw.githubusercontent.com')
      REPO_MAP[repo] = {
          'url': raw_url,
          'base64': False
      }

  # Get the list of files coming from this repository.
  git_file_list = RunCommand('git.bat', 'ls-tree', '--full-name', '--name-only',
      'HEAD', '-r', cwd=git_root_path)

  file_list = [x for x in git_file_list.splitlines() if len(x) != 0]

  return RevisionInfo(repo=repo, rev=rev, files=file_list,
      root_path=git_root_path, path_prefix=None)
Checks if a file is coming from a git repository and if so returns some
  information about it.

  Args:
    local_filename: The name of the file that we want to check.

  Returns:
    None if the file doesn't come from a git repository, otherwise it returns a
    RevisionInfo tuple.
  
Checks if a file is coming from a git repository and if so returns some
information about it.
Checks if a file is coming from a git repository and if so returns some information about it .
def ExtractGitInfo(local_filename):
  local_filename = GetCasedFilePath(local_filename)
  local_file_basename = os.path.basename(local_filename)
  local_file_dir = os.path.dirname(local_filename)
  file_info = RunCommand('git.bat', 'log', '-n', '1', local_file_basename,
                          cwd=local_file_dir, raise_on_failure=False)
  if not file_info:
    return
  rev = RunCommand('git.bat', 'rev-parse', 'HEAD', cwd=local_file_dir)
  repo = RunCommand('git.bat', 'config', '--get', 'remote.origin.url',
      cwd=local_file_dir)
  if os.path.isdir(repo):
    repo = RunCommand('git.bat', 'config', '--get', 'remote.origin.url',
        cwd=repo)
  repo = repo.replace('googlesource.com/a/', 'googlesource.com/')
  git_path = RunCommand('git.bat', 'ls-tree', '--full-name', '--name-only',
      'HEAD', local_file_basename, cwd=local_file_dir).replace('/','\\')
  if not git_path:
    return
  git_root_path = local_filename.replace(git_path, '')
  if repo not in REPO_MAP:
    if urlparse(repo).netloc.endswith('.googlesource.com'):
      REPO_MAP[repo] = {
          'url': '%s/+/{revision}/{file_path}?format=TEXT' % repo,
          'base64': True
      }
    elif urlparse(repo).netloc.endswith('github.com'):
      raw_url = '%s/{revision}/{file_path}' % repo.replace('.git', '').replace(
          'github.com', 'raw.githubusercontent.com')
      REPO_MAP[repo] = {
          'url': raw_url,
          'base64': False
      }
  git_file_list = RunCommand('git.bat', 'ls-tree', '--full-name', '--name-only',
      'HEAD', '-r', cwd=git_root_path)
  file_list = [x for x in git_file_list.splitlines() if len(x) != 0]
  return RevisionInfo(repo=repo, rev=rev, files=file_list,
      root_path=git_root_path, path_prefix=None)
def ExtractGitInfo ( local_filename ) : local_filename = GetCasedFilePath ( local_filename ) local_file_basename = os . path . basename ( local_filename ) local_file_dir = os . path . dirname ( local_filename ) file_info = RunCommand ( 'git.bat' , 'log' , '-n' , '1' , local_file_basename , cwd = local_file_dir , raise_on_failure = False ) if not file_info : return rev = RunCommand ( 'git.bat' , 'rev-parse' , 'HEAD' , cwd = local_file_dir ) repo = RunCommand ( 'git.bat' , 'config' , '--get' , 'remote.origin.url' , cwd = local_file_dir ) if os . path . isdir ( repo ) : repo = RunCommand ( 'git.bat' , 'config' , '--get' , 'remote.origin.url' , cwd = repo ) repo = repo . replace ( 'googlesource.com/a/' , 'googlesource.com/' ) git_path = RunCommand ( 'git.bat' , 'ls-tree' , '--full-name' , '--name-only' , 'HEAD' , local_file_basename , cwd = local_file_dir ) . replace ( '/' , '\\' ) if not git_path : return git_root_path = local_filename . replace ( git_path , '' ) if repo not in REPO_MAP : if urlparse ( repo ) . netloc . endswith ( '.googlesource.com' ) : REPO_MAP [ repo ] = { 'url' : '%s/+/{revision}/{file_path}?format=TEXT' % repo , 'base64' : True } elif urlparse ( repo ) . netloc . endswith ( 'github.com' ) : raw_url = '%s/{revision}/{file_path}' % repo . replace ( '.git' , '' ) . replace ( 'github.com' , 'raw.githubusercontent.com' ) REPO_MAP [ repo ] = { 'url' : raw_url , 'base64' : False } git_file_list = RunCommand ( 'git.bat' , 'ls-tree' , '--full-name' , '--name-only' , 'HEAD' , '-r' , cwd = git_root_path ) file_list = [ x for x in git_file_list . splitlines ( ) if len ( x ) != 0 ] return RevisionInfo ( repo = repo , rev = rev , files = file_list , root_path = git_root_path , path_prefix = None )
Checks if a file is coming from a git repository and if so returns some
information about it.
Checks if a file is coming from a git repository and if so returns some information about it .
"""Checks if a file is coming from a git repository and if so returns some
  information about it.

  Args:
    local_filename: The name of the file that we want to check.

  Returns:
    None if the file doesn't come from a git repository, otherwise it returns a
    RevisionInfo tuple.
  """ # Starts by checking if this file is coming from a git repository. For that # we'll start by calling 'git info' on this file; for this to work we need to # make sure that the current working directory is correctly cased. It turns # out that even on Windows the casing of the path passed in the |cwd| argument # of subprocess.Popen matters and if it's not correctly cased then 'git info' # will return None even if the file is coming from a git repository. This # is not the case if we're just interested in checking if the path containing # |local_filename| is coming from a git repository, in this case the casing # doesn't matter. # Get the revision of the master branch. # Get the url of the remote repository. # If the repository point to a local directory then we need to run this # command one more time from this directory to get the repository url. # Don't use the authenticated path. # Get the relative file path for this file in the git repository. # Automatically adds the project coming from a git GoogleCode or Github # repository to the repository map. # The files from these repositories are accessible via gitiles in a # base64 encoded format. # Get the list of files coming from this repository.
None if the file doesn't come from a git repository, otherwise it returns a
RevisionInfo tuple.
None if the file doesn ' t come from a git repository otherwise it returns a RevisionInfo tuple .
local_filename
The name of the file that we want to check.
The name of the file that we want to check .