<commit_before>from django.contrib import messages
from django.template import RequestContext
from django.shortcuts import render_to_response

from vcs.exceptions import VCSError
from vcs.utils.diffs import get_udiff, DiffProcessor
from vcs.web.simplevcs.utils import get_repository

def diff_file(request, file_path, template_name, repository=None,
        repository_path=None, repository_alias=None, revision1=None,
        revision2=None, extra_context={}):
    """
    Generic repository browser view.

    **Required arguments:**

    - Either ``repository`` or (``repository_path`` *and* ``repository_alias``
      is required

    - ``file_path``: relative location of the file node in the repository.

    - ``revision1``: object identifying changeset on a backend.

    - ``revision2``: object identifying changeset on a backend.

    - ``template_name``: The full name of a template to use in rendering the
      page.

    **Optional arguments:**

    - ``extra_context``: A dictionary of values to add to the template context.
      By default, this is an empty dictionary.

    **Template context:**

    In addition to ``extra_context``, the template's context will be:

    - ``repository``: same what was given or computed from ``repository_path``
      and ``repository_alias``

    - ``file1``: ``FileNode`` retrieved by backend for given ``revision1`` param

    - ``file2``: ``FileNode`` retrieved by backend for given ``revision2`` param

    - ``diff_content``: unified diff for retrieved ``file1`` and ``file2``
      contents

    """
    context = {}
    for key, value in extra_context.items():
        context[key] = callable(value) and value() or value

    try:
        repository = get_repository(repository, repository_path,
            repository_alias)
        file1 = repository.request(file_path, revision1)
        file2 = repository.request(file_path, revision2)
        diff_content = get_udiff(file1, file2)

        context.update(dict(
            repository = repository,
            file1 = file1,
            file2 = file2,
            diff_content = diff_content,
            differ = DiffProcessor(diff_content),
        ))
    except VCSError, err:
        messages.error(request, str(err))

    return render_to_response(template_name, context, RequestContext(request))
<commit_msg>Little update at simplevcs's diff view<commit_after>from django.contrib import messages
from django.template import RequestContext
from django.shortcuts import render_to_response

from vcs.exceptions import VCSError
from vcs.utils.diffs import get_udiff, DiffProcessor
from vcs.web.simplevcs.utils import get_repository

def diff_file(request, file_path, template_name, repository=None,
        repository_path=None, repository_alias=None, revision_old=None,
        revision_new=None, extra_context={}):
    """
    Generic repository browser view.

    **Required arguments:**

    - Either ``repository`` or (``repository_path`` *and* ``repository_alias``
      is required

    - ``file_path``: relative location of the file node in the repository.

    - ``revision_old``: object identifying changeset at backend.

    - ``revision_new``: object identifying changeset at backend.

    - ``template_name``: The full name of a template to use in rendering the
      page.

    **Optional arguments:**

    - ``extra_context``: A dictionary of values to add to the template context.
      By default, this is an empty dictionary.

    **Template context:**

    In addition to ``extra_context``, the template's context will be:

    - ``repository``: same what was given or computed from ``repository_path``
      and ``repository_alias``

    - ``file_old``: ``FileNode`` retrieved by backend for given ``revision_old``
      param

    - ``file_new``: ``FileNode`` retrieved by backend for given ``revision_new``
      param

    - ``diff_content``: unified diff for retrieved ``file_old`` and ``file_new``
      contents

    """
    context = {}
    for key, value in extra_context.items():
        context[key] = callable(value) and value() or value

    try:
        repository = get_repository(repository, repository_path,
            repository_alias)
        file_old = repository.request(file_path, revision_old)
        file_new = repository.request(file_path, revision_new)
        diff_content = get_udiff(file_old, file_new)

        context.update(dict(
            repository = repository,
            file_old = file_old,
            file_new = file_new,
            diff_content = diff_content,
            differ = DiffProcessor(diff_content),
        ))
    except VCSError, err:
        messages.error(request, str(err))

    return render_to_response(template_name, context, RequestContext(request))

{'fraction_non_alphanumeric': 0.09947423764458464, 'fraction_numerical': 0.004206098843322818, 'mean_word_length': 3.284684684684685, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, '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': '7567600', 'n_tokens_mistral': 1323, 'n_tokens_neox': 1268, 'n_words': 405}