def kwdiff(orig, repo, *args, **kwargs):
    """Monkeypatch patch.diff to avoid expansion."""
    kwt = getattr(repo, '_keywordkwt', None)
    if kwt:
        restrict = kwt.restrict
        kwt.restrict = True
    try:
        for chunk in orig(repo, *args, **kwargs):
            yield chunk
    finally:
        if kwt:
            kwt.restrict = restrict
