Ejemplo n.º 1
0
def _fmt_cmd_for_log(cmd):
    """
    Join the git_cmd, quoting individual segments first so that
    it's relatively easy to see if there were whitespace issues or
    not.
    """
    return ' '.join(['"%s"' % util.utf8(seg) for seg in cmd])
Ejemplo n.º 2
0
def _write_to_stdout(str_or_unicode):
    """
    Write `str_or_unicode` to stdout, encoding to utf-8 if it's
    unicode.

    No extra newline is written.
    """
    sys.stdout.write(util.utf8(str_or_unicode))
Ejemplo n.º 3
0
def _write_to_stdout(str_or_unicode):
    """
    Write `str_or_unicode` to stdout, encoding to utf-8 if it's
    unicode.

    No extra newline is written.
    """
    sys.stdout.write(util.utf8(str_or_unicode))
Ejemplo n.º 4
0
def test_git_cmd_returns_std_out():
    with fleeting_repo() as test_repo:
        commit_msg = 'I remain committed.'
        test_repo.commit([('test.txt', 'testing\n')],
                         commit_msg=commit_msg)

        with git_cmd(["log"], cwd=test_repo.repo_root) as output_f:
            ok_(commit_msg in util.utf8(output_f.read()))
Ejemplo n.º 5
0
 def _wrap(fname, log_entry):
     with tempfile.TemporaryFile() as fil:
         fil.write('\0'.join(
             [util.utf8(x) for x in [fname] + list(log_entry)]))
         fil.flush()
         fil.seek(0)
         with util.wrap_popen(list_or_str, stdin_fil=fil) as out_fil:
             return out_fil.read()
Ejemplo n.º 6
0
 def _wrap(fname, log_entry):
     with tempfile.TemporaryFile() as fil:
         fil.write('\0'.join([util.utf8(x)
                              for x
                              in [fname] + list(log_entry)]))
         fil.flush()
         fil.seek(0)
         with util.wrap_popen(list_or_str, stdin_fil=fil) as out_fil:
             return out_fil.read()
Ejemplo n.º 7
0
def _parse_log_entry(raw_log_entry):
    """
    Parse a single git log entry into a LogEntry, or return None
    if it can't be parsed.
    """
    # A note on the encodings.  Git doesn't give us a way to get at
    # the encodings of the files / diffs (short of .gitattributes,
    # which has to be set by the original producers of the repo).  We
    # assume that the encoding is UTF-8, and just replace everything
    # else with that lovely question mark thing, to do the parsing /
    # manipulation, and then convert that utf-8 to unicode for the
    # returned LogEntry.
    utf8_log_entry = util.utf8(raw_log_entry)

    # attempt to split the header from the diff.
    split_log_entry = _split_entry_header(utf8_log_entry)
    if split_log_entry is None:
        return None
    header_lines, diff_lines = split_log_entry

    diff = '\n'.join(diff_lines)

    if not diff.strip():
        log.debug("Diff appeared to be empty.")
        return None

    author = _parse_header('Author: ', header_lines)
    if not author:
        log.debug("Could not parse author.")
        return None

    parsed_author = parse_name_and_email(author)
    if not parsed_author:
        log.debug("Could not parse author name / email.")
        return None
    author_name, author_email = parsed_author

    commit = _parse_header('commit ', header_lines)
    if not commit:
        log.debug("Could not parse commit.")
        return None

    log_msg = '\n'.join(_parse_log_msg(header_lines))

    return LogEntry(author_name=util.uc(author_name),
                    author_email=util.uc(author_email),
                    commit=util.uc(commit),
                    log_msg=util.uc(log_msg),
                    diff=util.uc(diff),
                    raw_log=raw_log_entry)
Ejemplo n.º 8
0
def _parse_log_entry(raw_log_entry):
    """
    Parse a single git log entry into a LogEntry, or return None
    if it can't be parsed.
    """
    # A note on the encodings.  Git doesn't give us a way to get at
    # the encodings of the files / diffs (short of .gitattributes,
    # which has to be set by the original producers of the repo).  We
    # assume that the encoding is UTF-8, and just replace everything
    # else with that lovely question mark thing, to do the parsing /
    # manipulation, and then convert that utf-8 to unicode for the
    # returned LogEntry.
    utf8_log_entry = util.utf8(raw_log_entry)

    # attempt to split the header from the diff.
    split_log_entry = _split_entry_header(utf8_log_entry)
    if split_log_entry is None:
        return None
    header_lines, diff_lines = split_log_entry

    diff = '\n'.join(diff_lines)

    if not diff.strip():
        log.debug("Diff appeared to be empty.")
        return None

    author = _parse_header('Author: ', header_lines)
    if not author:
        log.debug("Could not parse author.")
        return None

    parsed_author = parse_name_and_email(author)
    if not parsed_author:
        log.debug("Could not parse author name / email.")
        return None
    author_name, author_email = parsed_author

    commit = _parse_header('commit ', header_lines)
    if not commit:
        log.debug("Could not parse commit.")
        return None

    log_msg = '\n'.join(_parse_log_msg(header_lines))

    return LogEntry(author_name=util.uc(author_name),
                    author_email=util.uc(author_email),
                    commit=util.uc(commit),
                    log_msg=util.uc(log_msg),
                    diff=util.uc(diff),
                    raw_log=raw_log_entry)
Ejemplo n.º 9
0
def _validate_parsed_entry(parsed_entry, commit_info):
    ok_(parsed_entry)
    ok_(util.uc(commit_info.commit_msg) in parsed_entry.log_msg)
    ok_(commit_info.file_body in util.utf8(parsed_entry.diff))
    eq_(util.uc(commit_info.author_name), parsed_entry.author_name)
    eq_(util.uc(commit_info.author_email), parsed_entry.author_email)
Ejemplo n.º 10
0

TEST_COMMIT_ONE = TestCommitInfo(file_body="test file body\n",
                                 commit_msg="test commit msg",
                                 author_name="Testy McTesterson",
                                 author_email="*****@*****.**")


TEST_COMMIT_TWO = TestCommitInfo(file_body="test second file body\n",
                                 commit_msg="test second commit msg",
                                 author_name="Testy Second McTesterson",
                                 author_email="*****@*****.**")


TEST_COMMIT_UNICODE_BODY = TestCommitInfo(
    file_body=util.utf8(u"frosty the \u2603 was a kind soul\n"),
    commit_msg="test commit msg",
    author_name="Testy McTesterson",
    author_email="*****@*****.**")


TEST_COMMIT_UNICODE_MSG = TestCommitInfo(
    file_body="hi unicode msg\n",
    commit_msg=util.utf8(u"test commit \u2603 msg"),
    author_name="Testy McTesterson",
    author_email="*****@*****.**")


TEST_COMMIT_UNICODE_AUTHOR = TestCommitInfo(
    file_body="hi unicode author\n",
    commit_msg="test commit",
Ejemplo n.º 11
0
def _validate_parsed_entry(parsed_entry, commit_info):
    ok_(parsed_entry)
    ok_(util.uc(commit_info.commit_msg) in parsed_entry.log_msg)
    ok_(commit_info.file_body in util.utf8(parsed_entry.diff))
    eq_(util.uc(commit_info.author_name), parsed_entry.author_name)
    eq_(util.uc(commit_info.author_email), parsed_entry.author_email)
Ejemplo n.º 12
0
# purposes of testing log retrieval / parsing
TestCommitInfo = namedtuple('TestCommitInfo',
                            'file_body commit_msg author_name author_email')

TEST_COMMIT_ONE = TestCommitInfo(file_body="test file body\n",
                                 commit_msg="test commit msg",
                                 author_name="Testy McTesterson",
                                 author_email="*****@*****.**")

TEST_COMMIT_TWO = TestCommitInfo(file_body="test second file body\n",
                                 commit_msg="test second commit msg",
                                 author_name="Testy Second McTesterson",
                                 author_email="*****@*****.**")

TEST_COMMIT_UNICODE_BODY = TestCommitInfo(
    file_body=util.utf8(u"frosty the \u2603 was a kind soul\n"),
    commit_msg="test commit msg",
    author_name="Testy McTesterson",
    author_email="*****@*****.**")

TEST_COMMIT_UNICODE_MSG = TestCommitInfo(
    file_body="hi unicode msg\n",
    commit_msg=util.utf8(u"test commit \u2603 msg"),
    author_name="Testy McTesterson",
    author_email="*****@*****.**")

TEST_COMMIT_UNICODE_AUTHOR = TestCommitInfo(
    file_body="hi unicode author\n",
    commit_msg="test commit",
    author_name=util.utf8(u"Testy \u2603 McTesterson"),
    author_email="*****@*****.**")