Page MenuHomePhorge

Raw use of "git diff" provides insufficient Diff Context
Open, Needs TriagePublic

Description

Some users prefer to create revisions using raw diffs. This workflow is convenient because it does not require installation of arcanist. Users are required to specify the repository for which this diff is intended.

Unfortunately Revisions created with such method have a serious drawback - very few unchanged lines are visible, so maintainers can't gather the context of the change. This creates a need for a maintainer to have a full source code of a file open somewhere to review the change. We often end up asking our contributors to regenerate the diff with git diff -U99999 so maintainers can see the entire file.

Given that users specify the repository and diff contains file names - it seem that it should be possible for Phorge to show all surrounding unchanged lines without needing to do git diff -U99999

Secondly, if this is really impossible to do we should at least show users correct commands. The tooltip at https://reviews.freebsd.org/differential/diff/create says:

You can also paste a diff above, or upload a file containing a diff (for example, from svn diff, git diff or hg diff --git).

where we should at least be saying something like:

You can also paste a diff above, or upload a file containing a diff (for example git diff -U9999). Pls-pls make sure your patch has as many unchanged lines as possible..

These are the context buttons that are not shown in Differentials when pasting a git diff:

Differentials context.png (497×1 px, 92 KB)

Trying to understand what happens

This is simply an attempt to understand the current situation to help future hackers:

/**
 * This function calculates a lot of stuff we need to know to display
 * the diff:
 *
 * Gaps - compute gaps in the visible display diff, where we will render
 * "Show more context" spacers. If a gap is smaller than the context size,
 * we just display it. Otherwise, we record it into $gaps and will render a
 * "show more context" element instead of diff text below. A given $gap
 * is a tuple of $gap_line_number_start and $gap_length.
 *
 * Mask - compute the actual lines that need to be shown (because they
 * are near changes lines, near inline comments, or the request has
 * explicitly asked for them, i.e. resulting from the user clicking
 * "show more"). The $mask returned is a sparsely populated dictionary
 * of $visible_line_number => true.
 *
 * @return array($gaps, $mask)
 */
private function calculateGapsAndMask(
  ...
}

Also note:

Event Timeline

ton created this object in space S1 Public.

Hi, thanks for this interesting question.

I don't understand if the preamble here is "let's improve git diff to provide more context, since we don't use Arcanist (that also fixes the context)".

I'm not arguing, I'm trying to figure out what is the margin of contribution I can make here.

By the way it seems that - for any frontend string - your local Administrators can override a message from the Phorge/Phabricator Config page.

For example, in Phorge the Config page is here (but I cannot see that - I'm not an Admin):

https://we.phorge.it/config/edit/translation.override/

Man page:

You can use 'translation.override' if you don't want to create a full translation to give users an option for switching to it and you just want to override some strings in the default translation.
Example:

{"some string": "my alternative"}

I tried it locally and it works really well. Try with:

{"You can also paste a diff above, or upload a file containing a diff (for example, from %s, %s or %s).": "Whaaaaaait WHAAAT? GIVE UP, PIRATE! ONLY WITH ARCANIST WILL YOU BE ABLE TO UNDERSTAND HOW TO CONTRIBUTE HERE! - AH-AH!"}
NOTE: I've found that message string using grep in the source code of Phorge. The full file is here: https://we.phorge.it/source/phorge/browse/master/src/applications/differential/controller/DifferentialDiffCreateController.php$122-123

Example integration:

Config Override example.png (785×1 px, 60 KB)

Holy sky, this feature is damn awesome. Thank you for let me discovering this in this moment.

what's frustrating here is the fact that Phorge has the source code, so it should know the context.
But by not providing the context itself, it can also not know when a Diff has diverged and can no longer be landed without (manual) intervention.

So if I understand correctly:

  1. most FreeBSD users share a Diff but is usually just a git patch
    • → first problem: Phorge was intended to use arc diff for best experience, so that to create a git patch, create the Diff, and assign that Diff to the right Repository, run Lint, and run Unit tests
    • → but sharing a raw git patch is really OK and reasonable, I understand that Arcanist is a pain for new users, but:
  2. the user also does not want to prefill the Repository field in the Diff page
    • → Current situation: at the moment the FreeBSD maintainers try to be nice with code proposer that do not prefill Repository field. They try to guess the repo from the full git context - when available - or they also try to apply that patch in some repo, until finding the correct one.
      • → I understand that this is really frustrating.
    • Question: Do you know why code proposers do not fill at least the Repository field? I mean: typing in the Repository field probably consumes 2 seconds for a general code proposer, but it saves 10 minutes to every maintainer. Probably this should be encouraged. So, they are free to do not use Arcanist (that does that), but at least they should help maintainers in sharing their full context, populating the Repository field by hand. (I don't want to convince your users to do that - I'm just curious in this, since it seems reasonable to me to ask for that.)
    • → Proposed improvement for Phorge: we can allow to prefill the Repository from an URL. So, if you just have 5-10 repositories, you can have a menu on the website with "Share Patch for Repo A", prefilling that field. Probably is not possible now, but seems very reasonable to me to implement.

Thanks for this discussion

valerio.bozzolan renamed this task from Insufficient Diff Context to Raw use of "git diff" provides insufficient Diff Context.Apr 14 2023, 08:25

Feel free to say to me that I probably didn't understand shit as usual :D

As an alternative to using the "upload raw diff" option, see also https://secure.phabricator.com/T5000, and in specific the "magic ref" stuff in T15096#2329 and https://secure.phabricator.com/D9599.

By the way, it seems to me that the reporter is saying that these buttons are sometime not available (when the user does not use Arcanist):

Differentials context.png (497×1 px, 92 KB)

But, to me, I have an additional problem: on my production server and on Phorge I see them everywhere correctly (example: https://we.phorge.it/D25120#toc · https://gitpull.it/D100#toc etc).

But, in my local test installation, I never see these buttons, whenever I pasted with git diff, or whenever I used Arc diff. (Yes, I've set the correct Repository field in both local cases). So there are still some things that could be clarified.

@ton: Can you please confirm that at least sometime you see the above buttons in Differential (for example when somebody used Arcanist)?

Edited:

Anyway I can reproduce in my production:

So if I understand correctly:

  1. most FreeBSD users share a Diff but is usually just a git patch
    • → first problem: Phorge was intended to use arc diff for best experience, so that to create a git patch, create the Diff, and assign that Diff to the right Repository, run Lint, and run Unit tests
    • → but sharing a raw git patch is really OK and reasonable, I understand that Arcanist is a pain for new users, but:

indeed it's not most users, but definitely most new users, and most external contributors

external contributors will struggle to see the benefit of setting up and learning arcanist if without a commit bit they don't get access to more than half the functionality

@valerio.bozzolan yes, https://gitpull.it/D110 demonstrates the point I was trying to communicate. No buttons available to expand the context.

Arcanist internally generates a diff that includes a similar suggested parameter to account for the entire file contents being present in the resulting diff.

If the diff contents reference the commit the change was made to it would be possible for Phorge to generate the full context for the resulting diff. Even with the changeset in the diff there’s a non-zero chance that Phorge might not know of that commit, e.g. someone uploads a diff that is on top of another local commit that doesn’t exist in Phorge.

Generally speaking the web server account doesn’t have access, or at least not write access, to repositories. Additionally this would likely be more complex to properly handle clustered environments.

Rather than trying to address these scenarios I think @avivey is right that it would likely be better to address https://secure.phabricator.com/T5000