def GenerateGerritChangeId(message):
    'Returns Ixxxxxx...xxx change id.\n\n  Works the same way as\n  https://gerrit-review.googlesource.com/tools/hooks/commit-msg\n  but can be called on demand on all platforms.\n\n  The basic idea is to generate git hash of a state of the tree, original commit\n  message, author/committer info and timestamps.\n  '
    lines = []
    tree_hash = RunGitSilent(['write-tree'])
    lines.append(('tree %s' % tree_hash.strip()))
    (code, parent) = RunGitWithCode(['rev-parse', 'HEAD~0'], suppress_stderr=False)
    if (code == 0):
        lines.append(('parent %s' % parent.strip()))
    author = RunGitSilent(['var', 'GIT_AUTHOR_IDENT'])
    lines.append(('author %s' % author.strip()))
    committer = RunGitSilent(['var', 'GIT_COMMITTER_IDENT'])
    lines.append(('committer %s' % committer.strip()))
    lines.append('')
    lines.append(message)
    change_hash = RunCommand(['git', 'hash-object', '-t', 'commit', '--stdin'], stdin='\n'.join(lines))
    return ('I%s' % change_hash.strip())
Returns Ixxxxxx...xxx change id.

Works the same way as
https://gerrit-review.googlesource.com/tools/hooks/commit-msg
but can be called on demand on all platforms.

The basic idea is to generate git hash of a state of the tree, original commit
message, author/committer info and timestamps.
def GenerateGerritChangeId(message):
    'Returns Ixxxxxx...xxx change id.\n\n  Works the same way as\n  https://gerrit-review.googlesource.com/tools/hooks/commit-msg\n  but can be called on demand on all platforms.\n\n  The basic idea is to generate git hash of a state of the tree, original commit\n  message, author/committer info and timestamps.\n  '
    lines = []
    tree_hash = RunGitSilent(['write-tree'])
    lines.append(('tree %s' % tree_hash.strip()))
    (code, parent) = RunGitWithCode(['rev-parse', 'HEAD~0'], suppress_stderr=False)
    if (code == 0):
        lines.append(('parent %s' % parent.strip()))
    author = RunGitSilent(['var', 'GIT_AUTHOR_IDENT'])
    lines.append(('author %s' % author.strip()))
    committer = RunGitSilent(['var', 'GIT_COMMITTER_IDENT'])
    lines.append(('committer %s' % committer.strip()))
    lines.append()
    lines.append(message)
    change_hash = RunCommand(['git', 'hash-object', '-t', 'commit', '--stdin'], stdin='\n'.join(lines))
    return ('I%s' % change_hash.strip())