Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor: use git log -S ... -p ... and strip diffs #2

Open
Kraymer opened this issue Nov 16, 2020 · 0 comments
Open

Refactor: use git log -S ... -p ... and strip diffs #2

Kraymer opened this issue Nov 16, 2020 · 0 comments

Comments

@Kraymer
Copy link
Owner

Kraymer commented Nov 16, 2020

ublame is pretty close of what git log -S ... -p ... do : its diff is more concise and readable but it is way slower.

This refactoring consists in capturing git log -S ... -p ... output and stripping it to achieve current ublame output :

Algo would be :

  • extract diff by regex capturing text between @ and @ / commit hexa lines
  • if diff contain token keep it, otherwise discard it
❯ git log -G "ublame_cli" -p ublame/__init__.py
commit 90e286119ac29090f54115bc5a908f1488d0d98b
Author: Fabrice Laporte <fabrice@yescapa.com>
Date:   Sun Nov 15 10:25:49 2020 +0100

    feat: accept multiple patterns as input

───────────────────────────────────────────────────────────────────────────────
modified: ublame/__init__.py
───────────────────────────────────────────────────────────────────────────────
@ ublame/__init__.py:41 @ def repo_path_for(filename):
            return filename


def trim_diff(diff, token, context=3):
def trim_diff(diff, patterns, context=3):
    """Keep only context surrounding searched token."""
    if token in diff:
[...]
    return any(diffs) or found
 

@click.argument("patterns", nargs=-1, required=True)
def ublame_cli(filename, patterns):
    filename = os.path.abspath(filename)
    repo_path = repo_path_for(filename)
[...]

───────────────────────────────────────────────────────────────────────────────
added: ublame/__init__.py
───────────────────────────────────────────────────────────────────────────────
@ ublame/__init__.py:4 @
import blessed
import os
import click
from pydriller import RepositoryMining, GitRepository
 
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant