parameters: (base_config, config_changes, config_path)
return_statement: return (patch, base_checksum, base_hashes)
docstring: Takes the base config file and the changes and generates a patch.
  
    Args:
      base_config: The whole contents of the base config file.
      config_changes: The new config string. This will replace the part of the
          base config file that starts with "config = {" and ends with "}".
      config_path: Path to the config file to use.
  
    Returns:
      A triple with the patch string, the base md5 checksum, and the "base
      hashes", which normally might contain checksums for multiple files, but
      in our case just contains the base checksum and base filename.
docstring_summary: Takes the base config file and the changes and generates a patch.
docstring_tokens: Takes the base config file and the changes and generates a patch .
function: def _CreatePatch(base_config, config_changes, config_path):
    """Takes the base config file and the changes and generates a patch.
  
    Args:
      base_config: The whole contents of the base config file.
      config_changes: The new config string. This will replace the part of the
          base config file that starts with "config = {" and ends with "}".
      config_path: Path to the config file to use.
  
    Returns:
      A triple with the patch string, the base md5 checksum, and the "base
      hashes", which normally might contain checksums for multiple files, but
      in our case just contains the base checksum and base filename.
    """
    # Compute git SHA1 hashes for both the original and new config. See:
    # http://git-scm.com/book/en/Git-Internals-Git-Objects#Object-Storage
    base_checksum = hashlib.md5(base_config).hexdigest()
    base_hashes = '%s:%s' % (base_checksum, config_path)
    base_header = 'blob %d\0' % len(base_config)
    base_sha = hashlib.sha1(base_header + base_config).hexdigest()
  
    # Replace part of the base config to get the new config.
    new_config = (base_config[:base_config.rfind('config')] +
                  config_changes +
                  base_config[base_config.rfind('}') + 2:])
  
    # The client sometimes adds extra '\r' chars; remove them.
    new_config = new_config.replace('\r', '')
    new_header = 'blob %d\0' % len(new_config)
    new_sha = hashlib.sha1(new_header + new_config).hexdigest()
    diff = difflib.unified_diff(base_config.split('\n'),
                                new_config.split('\n'),
                                'a/%s' % config_path,
                                'b/%s' % config_path,
                                lineterm='')
    patch_header = _PATCH_HEADER % {
        'filename': config_path,
        'filename_a': config_path,
        'filename_b': config_path,
        'hash_a': base_sha,
        'hash_b': new_sha,
    }
    patch = patch_header + '\n'.join(diff)
    patch = patch.rstrip() + '\n'
    return (patch, base_checksum, base_hashes)
function_tokens: def _CreatePatch ( base_config , config_changes , config_path ) : # Compute git SHA1 hashes for both the original and new config. See: # http://git-scm.com/book/en/Git-Internals-Git-Objects#Object-Storage base_checksum = hashlib . md5 ( base_config ) . hexdigest ( ) base_hashes = '%s:%s' % ( base_checksum , config_path ) base_header = 'blob %d\0' % len ( base_config ) base_sha = hashlib . sha1 ( base_header + base_config ) . hexdigest ( ) # Replace part of the base config to get the new config. new_config = ( base_config [ : base_config . rfind ( 'config' ) ] + config_changes + base_config [ base_config . rfind ( '}' ) + 2 : ] ) # The client sometimes adds extra '\r' chars; remove them. new_config = new_config . replace ( '\r' , '' ) new_header = 'blob %d\0' % len ( new_config ) new_sha = hashlib . sha1 ( new_header + new_config ) . hexdigest ( ) diff = difflib . unified_diff ( base_config . split ( '\n' ) , new_config . split ( '\n' ) , 'a/%s' % config_path , 'b/%s' % config_path , lineterm = '' ) patch_header = _PATCH_HEADER % { 'filename' : config_path , 'filename_a' : config_path , 'filename_b' : config_path , 'hash_a' : base_sha , 'hash_b' : new_sha , } patch = patch_header + '\n' . join ( diff ) patch = patch . rstrip ( ) + '\n' return ( patch , base_checksum , base_hashes )