git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* java diffs show no method context
@ 2018-04-25 12:53 Ulrich Windl
  2018-04-25 15:05 ` Alban Gruin
  0 siblings, 1 reply; 4+ messages in thread
From: Ulrich Windl @ 2018-04-25 12:53 UTC (permalink / raw)
  To: git

Hi!

This is for git 2.13.6, and it may be an FAQ or frequent feature request. Anyway:
I'm new to Java, and writing my first project using Git, I found that "git diff" only reports the class in the diff context, but not the method (as seen for C, for example).
I'd wish to have the method where the diff is located. Here is an example chunk:


@@ -100,6 +119,8 @@ public class PdfParser {
        PdfObject obj, value;
        PdfObjectName name;
        for ( int pos = startIndex; pos < endIndex; pos += 2 ) {
+           if ( (obj = objects.get(pos)).type != PdfObject.Type.Name )
+               exception("Name expected");
            name = (PdfObjectName) obj;
            if ( pos + 1 == endIndex )
                exception("missing value");

The corrsponding definition of the method is like this:

    /**
     * Populate Dictionary with parsed objects
     * @param dict Dictionary to fill
     * @param startIndex Position of first item to add
     * @param endIndex Position of first item not to add
     */
    private void populateDictionary(PdfObjectDictionary dict, int startIndex, in
t endIndex)
    {
...

Regards,
Ulrich





^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: java diffs show no method context
  2018-04-25 12:53 java diffs show no method context Ulrich Windl
@ 2018-04-25 15:05 ` Alban Gruin
  2018-04-26  6:30   ` Antw: " Ulrich Windl
  0 siblings, 1 reply; 4+ messages in thread
From: Alban Gruin @ 2018-04-25 15:05 UTC (permalink / raw)
  To: Ulrich Windl, git

Le 25/04/2018 à 14:53, Ulrich Windl a écrit :
> Hi!
> 
> This is for git 2.13.6, and it may be an FAQ or frequent feature request. Anyway:
> I'm new to Java, and writing my first project using Git, I found that "git diff" only reports the class in the diff context, but not the method (as seen for C, for example).
> I'd wish to have the method where the diff is located.

Hi,

to achieve this behaviour, you have to create a file named
".gitattributes" at the root of your project, containing this line:

*.java diff=java

.gitattributes allows you to configure other things, as described in the
documentation[1].

I hope it helps.

[1] https://www.git-scm.com/docs/gitattributes

Cheers,
Alban

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Antw: Re: java diffs show no method context
  2018-04-25 15:05 ` Alban Gruin
@ 2018-04-26  6:30   ` Ulrich Windl
  2018-04-26  7:43     ` Ævar Arnfjörð Bjarmason
  0 siblings, 1 reply; 4+ messages in thread
From: Ulrich Windl @ 2018-04-26  6:30 UTC (permalink / raw)
  To: Alban Gruin, git

Hi!

Thanks for that. It sounds plausible, but I wonder why it works automagically
for C, but not for Java (Politcal reasons put aside): Using ".c" for C is about
as common as using ".java" for Java ;-)

Regards,
Ulrich

>>> Alban Gruin <alban.gruin@gmail.com> schrieb am 25.04.2018 um 17:05 in
Nachricht
<aae8d748-101d-1eb2-f8e8-9da2e53e2388@gmail.com>:
> Le 25/04/2018 à 14:53, Ulrich Windl a écrit :
>> Hi!
>> 
>> This is for git 2.13.6, and it may be an FAQ or frequent feature request. 
> Anyway:
>> I'm new to Java, and writing my first project using Git, I found that "git

> diff" only reports the class in the diff context, but not the method (as
seen 
> for C, for example).
>> I'd wish to have the method where the diff is located.
> 
> Hi,
> 
> to achieve this behaviour, you have to create a file named
> ".gitattributes" at the root of your project, containing this line:
> 
> *.java diff=java
> 
> .gitattributes allows you to configure other things, as described in the
> documentation[1].
> 
> I hope it helps.
> 
> [1] https://www.git-scm.com/docs/gitattributes 
> 
> Cheers,
> Alban




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Antw: Re: java diffs show no method context
  2018-04-26  6:30   ` Antw: " Ulrich Windl
@ 2018-04-26  7:43     ` Ævar Arnfjörð Bjarmason
  0 siblings, 0 replies; 4+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2018-04-26  7:43 UTC (permalink / raw)
  To: Ulrich Windl; +Cc: Alban Gruin, git


On Thu, Apr 26 2018, Ulrich Windl wrote:

> Thanks for that. It sounds plausible, but I wonder why it works automagically
> for C, but not for Java (Politcal reasons put aside): Using ".c" for C is about
> as common as using ".java" for Java ;-)

It has a bit to do with it being in C, but not in the way you think. By
default Git doesn't enable the "cpp" driver either for *.c, but it just
so happens to do the right thing more of the time because the default
heuristic is basically to search for a nearby line that doesn't start
with whitespace for context.

This doesn't work for Java because your methods tend to be indented
since they're part of the class you're working on.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2018-04-26  7:44 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-25 12:53 java diffs show no method context Ulrich Windl
2018-04-25 15:05 ` Alban Gruin
2018-04-26  6:30   ` Antw: " Ulrich Windl
2018-04-26  7:43     ` Ævar Arnfjörð Bjarmason

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).