parameters: (filename, line_ranges, revision=None,
                           binary='clang-format', style=None)
return_statement: return convert_string(stdout).rstrip('\r\n')
docstring: Run clang-format on the given file and save the result to a git blob.
  
    Runs on the file in `revision` if not None, or on the file in the working
    directory if `revision` is None.
  
    Returns the object ID (SHA-1) of the created blob.
docstring_summary: Run clang-format on the given file and save the result to a git blob.
docstring_tokens: Run clang - format on the given file and save the result to a git blob .
function: def clang_format_to_blob(filename, line_ranges, revision=None,
                           binary='clang-format', style=None):
    """Run clang-format on the given file and save the result to a git blob.
  
    Runs on the file in `revision` if not None, or on the file in the working
    directory if `revision` is None.
  
    Returns the object ID (SHA-1) of the created blob."""
    clang_format_cmd = [binary]
    if style:
      clang_format_cmd.extend(['-style='+style])
    clang_format_cmd.extend([
        '-lines=%s:%s' % (start_line, start_line+line_count-1)
        for start_line, line_count in line_ranges])
    if revision:
      clang_format_cmd.extend(['-assume-filename='+filename])
      git_show_cmd = ['git', 'cat-file', 'blob', '%s:%s' % (revision, filename)]
      git_show = subprocess.Popen(git_show_cmd, stdin=subprocess.PIPE,
                                  stdout=subprocess.PIPE)
      git_show.stdin.close()
      clang_format_stdin = git_show.stdout
    else:
      clang_format_cmd.extend([filename])
      git_show = None
      clang_format_stdin = subprocess.PIPE
    try:
      clang_format = subprocess.Popen(clang_format_cmd, stdin=clang_format_stdin,
                                      stdout=subprocess.PIPE)
      if clang_format_stdin == subprocess.PIPE:
        clang_format_stdin = clang_format.stdin
    except OSError as e:
      if e.errno == errno.ENOENT:
        die('cannot find executable "%s"' % binary)
      else:
        raise
    clang_format_stdin.close()
    hash_object_cmd = ['git', 'hash-object', '-w', '--path='+filename, '--stdin']
    hash_object = subprocess.Popen(hash_object_cmd, stdin=clang_format.stdout,
                                   stdout=subprocess.PIPE)
    clang_format.stdout.close()
    stdout = hash_object.communicate()[0]
    if hash_object.returncode != 0:
      die('`%s` failed' % ' '.join(hash_object_cmd))
    if clang_format.wait() != 0:
      die('`%s` failed' % ' '.join(clang_format_cmd))
    if git_show and git_show.wait() != 0:
      die('`%s` failed' % ' '.join(git_show_cmd))
    return convert_string(stdout).rstrip('\r\n')
function_tokens: def clang_format_to_blob ( filename , line_ranges , revision = None , binary = 'clang-format' , style = None ) : clang_format_cmd = [ binary ] if style : clang_format_cmd . extend ( [ '-style=' + style ] ) clang_format_cmd . extend ( [ '-lines=%s:%s' % ( start_line , start_line + line_count - 1 ) for start_line , line_count in line_ranges ] ) if revision : clang_format_cmd . extend ( [ '-assume-filename=' + filename ] ) git_show_cmd = [ 'git' , 'cat-file' , 'blob' , '%s:%s' % ( revision , filename ) ] git_show = subprocess . Popen ( git_show_cmd , stdin = subprocess . PIPE , stdout = subprocess . PIPE ) git_show . stdin . close ( ) clang_format_stdin = git_show . stdout else : clang_format_cmd . extend ( [ filename ] ) git_show = None clang_format_stdin = subprocess . PIPE try : clang_format = subprocess . Popen ( clang_format_cmd , stdin = clang_format_stdin , stdout = subprocess . PIPE ) if clang_format_stdin == subprocess . PIPE : clang_format_stdin = clang_format . stdin except OSError as e : if e . errno == errno . ENOENT : die ( 'cannot find executable "%s"' % binary ) else : raise clang_format_stdin . close ( ) hash_object_cmd = [ 'git' , 'hash-object' , '-w' , '--path=' + filename , '--stdin' ] hash_object = subprocess . Popen ( hash_object_cmd , stdin = clang_format . stdout , stdout = subprocess . PIPE ) clang_format . stdout . close ( ) stdout = hash_object . communicate ( ) [ 0 ] if hash_object . returncode != 0 : die ( '`%s` failed' % ' ' . join ( hash_object_cmd ) ) if clang_format . wait ( ) != 0 : die ( '`%s` failed' % ' ' . join ( clang_format_cmd ) ) if git_show and git_show . wait ( ) != 0 : die ( '`%s` failed' % ' ' . join ( git_show_cmd ) ) return convert_string ( stdout ) . rstrip ( '\r\n' )