<commit_before>#!/usr/bin/python
#
# Copyright 2015 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

"""Gets list of revisions between two commits and their commit positions.

Example usage:
  ./fetch_intervening_revisions.py 343b531d31 7b43807df3
"""

import argparse
import json
import os
import re
import sys
import urllib2

_GITILES_PADDING = ')]}\'\n'

# Gitiles paginates the list of commits; since we want to get all of the
# commits at once, the page size should be larger than the largest revision
# range that we expect to get.
_PAGE_SIZE = 2048


def fetch_intervening_revisions(min_rev, max_rev):
  """Fetches a list of revision in between two commits.

  Args:
    min_rev (str): A git commit hash in the Chromium src repository.
    max_rev (str): Another git commit hash, after min_rev.

  Returns:
    A list of pairs (commit hash, commit position), from earliest to latest,
    for all commits in between the two given commits, not including either
    of the given commits.

  Raises:
    urllib2.URLError: The request to gitiles failed.
    ValueError: The response wasn't valid JSON.
    KeyError: The JSON didn't contain the expected data.
  """
  base_url= 'https://chromium.googlesource.com/chromium/src/+log/'
  url = base_url + '%s..%s?format=json' % (min_rev, max_rev)
  url += '&n=' + _PAGE_SIZE
  response = urllib2.urlopen(url).read()
  response_json = response[len(_GITILES_PADDING):]  # Remove padding.
  response_dict = json.loads(response_json)
  intervening_revisions = response_dict['log'][1:]
  return [(r['commit'], _commit_position_from_message(r['message']))
          for r in reversed(intervening_revisions)]


def _commit_position_from_message(message):
  for line in reversed(message.splitlines()):
    if line.startswith('Cr-Commit-Position:'):
      return line.split('#')[1].split('}')[0]
  return None


def main():
  parser = argparse.ArgumentParser()<commit_msg>Fix mistake in fetch_intervening_revisions.py<commit_after>#!/usr/bin/python
#
# Copyright 2015 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

"""Gets list of revisions between two commits and their commit positions.

Example usage:
  ./fetch_intervening_revisions.py 343b531d31 7b43807df3
"""

import argparse
import json
import os
import re
import sys
import urllib2

_GITILES_PADDING = ')]}\'\n'

# Gitiles paginates the list of commits; since we want to get all of the
# commits at once, the page size should be larger than the largest revision
# range that we expect to get.
_PAGE_SIZE = 2048


def fetch_intervening_revisions(min_rev, max_rev):
  """Fetches a list of revision in between two commits.

  Args:
    min_rev (str): A git commit hash in the Chromium src repository.
    max_rev (str): Another git commit hash, after min_rev.

  Returns:
    A list of pairs (commit hash, commit position), from earliest to latest,
    for all commits in between the two given commits, not including either
    of the given commits.

  Raises:
    urllib2.URLError: The request to gitiles failed.
    ValueError: The response wasn't valid JSON.
    KeyError: The JSON didn't contain the expected data.
  """
  base_url= 'https://chromium.googlesource.com/chromium/src/+log/'
  url = base_url + '%s..%s?format=json' % (min_rev, max_rev)
  url += '&n=%d' % _PAGE_SIZE
  response = urllib2.urlopen(url).read()
  response_json = response[len(_GITILES_PADDING):]  # Remove padding.
  response_dict = json.loads(response_json)
  intervening_revisions = response_dict['log'][1:]
  return [(r['commit'], _commit_position_from_message(r['message']))
          for r in reversed(intervening_revisions)]


def _commit_position_from_message(message):
  for line in reversed(message.splitlines()):
    if line.startswith('Cr-Commit-Position:'):
      return line.split('#')[1].split('}')[0]
  return None


def main():
  parser = argparse.ArgumentParser()
{'fraction_non_alphanumeric': 0.09975308641975308, 'fraction_numerical': 0.014320987654320988, 'mean_word_length': 4.254215304798962, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6544564', 'n_tokens_mistral': 1356, 'n_tokens_neox': 1266, 'n_words': 438}