{"thread":{"id":"48359","subject":"java diffs show no method context","startedAt":"2018-04-25T13:02:41Z","lastAt":"2018-04-26T07:44:06Z","messageCount":4,"participants":["Ulrich Windl","Alban Gruin","Ævar Arnfjörð Bjarmason"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"345783","messageId":"5AE07A3A020000A10002B5C5@gwsmtp1.uni-regensburg.de","threadId":"48359","inReplyTo":null,"subject":"java diffs show no method context","fromName":"Ulrich Windl","fromEmail":"ulrich.windl@rz.uni-regensburg.de","sentAt":"2018-04-25T12:53:14Z","receivedAt":"2018-04-25T13:02:41Z","isPatch":false,"sender":{"key":"ulrich.windl@rz.uni-regensburg.de","avatar":null},"body":"Hi!\n\nThis is for git 2.13.6, and it may be an FAQ or frequent feature request. Anyway:\nI'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).\nI'd wish to have the method where the diff is located. Here is an example chunk:\n\n\n@@ -100,6 +119,8 @@ public class PdfParser {\n        PdfObject obj, value;\n        PdfObjectName name;\n        for ( int pos = startIndex; pos < endIndex; pos += 2 ) {\n+           if ( (obj = objects.get(pos)).type != PdfObject.Type.Name )\n+               exception(\"Name expected\");\n            name = (PdfObjectName) obj;\n            if ( pos + 1 == endIndex )\n                exception(\"missing value\");\n\nThe corrsponding definition of the method is like this:\n\n    /**\n     * Populate Dictionary with parsed objects\n     * @param dict Dictionary to fill\n     * @param startIndex Position of first item to add\n     * @param endIndex Position of first item not to add\n     */\n    private void populateDictionary(PdfObjectDictionary dict, int startIndex, in\nt endIndex)\n    {\n...\n\nRegards,\nUlrich\n\n\n\n\n"},{"id":"345804","messageId":"aae8d748-101d-1eb2-f8e8-9da2e53e2388@gmail.com","threadId":"48359","inReplyTo":"5AE07A3A020000A10002B5C5@gwsmtp1.uni-regensburg.de","subject":"Re: java diffs show no method context","fromName":"Alban Gruin","fromEmail":"alban.gruin@gmail.com","sentAt":"2018-04-25T15:05:34Z","receivedAt":"2018-04-25T15:05:41Z","isPatch":false,"sender":{"key":"alban.gruin@gmail.com","avatar":"https://avatars.githubusercontent.com/u/6310153?v=4"},"body":"Le 25/04/2018 à 14:53, Ulrich Windl a écrit :\n> Hi!\n> \n> This is for git 2.13.6, and it may be an FAQ or frequent feature request. Anyway:\n> 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).\n> I'd wish to have the method where the diff is located.\n\nHi,\n\nto achieve this behaviour, you have to create a file named\n\".gitattributes\" at the root of your project, containing this line:\n\n*.java diff=java\n\n.gitattributes allows you to configure other things, as described in the\ndocumentation[1].\n\nI hope it helps.\n\n[1] https://www.git-scm.com/docs/gitattributes\n\nCheers,\nAlban\n"},{"id":"345876","messageId":"5AE17203020000A10002B5EF@gwsmtp1.uni-regensburg.de","threadId":"48359","inReplyTo":"aae8d748-101d-1eb2-f8e8-9da2e53e2388@gmail.com","subject":"Antw: Re: java diffs show no method context","fromName":"Ulrich Windl","fromEmail":"ulrich.windl@rz.uni-regensburg.de","sentAt":"2018-04-26T06:30:27Z","receivedAt":"2018-04-26T06:30:34Z","isPatch":false,"sender":{"key":"ulrich.windl@rz.uni-regensburg.de","avatar":null},"body":"Hi!\n\nThanks for that. It sounds plausible, but I wonder why it works automagically\nfor C, but not for Java (Politcal reasons put aside): Using \".c\" for C is about\nas common as using \".java\" for Java ;-)\n\nRegards,\nUlrich\n\n>>> Alban Gruin <alban.gruin@gmail.com> schrieb am 25.04.2018 um 17:05 in\nNachricht\n<aae8d748-101d-1eb2-f8e8-9da2e53e2388@gmail.com>:\n> Le 25/04/2018 à 14:53, Ulrich Windl a écrit :\n>> Hi!\n>> \n>> This is for git 2.13.6, and it may be an FAQ or frequent feature request. \n> Anyway:\n>> I'm new to Java, and writing my first project using Git, I found that \"git\n\n> diff\" only reports the class in the diff context, but not the method (as\nseen \n> for C, for example).\n>> I'd wish to have the method where the diff is located.\n> \n> Hi,\n> \n> to achieve this behaviour, you have to create a file named\n> \".gitattributes\" at the root of your project, containing this line:\n> \n> *.java diff=java\n> \n> .gitattributes allows you to configure other things, as described in the\n> documentation[1].\n> \n> I hope it helps.\n> \n> [1] https://www.git-scm.com/docs/gitattributes \n> \n> Cheers,\n> Alban\n\n\n\n"},{"id":"345877","messageId":"87y3hacszl.fsf@evledraar.gmail.com","threadId":"48359","inReplyTo":"5AE17203020000A10002B5EF@gwsmtp1.uni-regensburg.de","subject":"Re: Antw: Re: java diffs show no method context","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2018-04-26T07:43:58Z","receivedAt":"2018-04-26T07:44:06Z","isPatch":false,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"\nOn Thu, Apr 26 2018, Ulrich Windl wrote:\n\n> Thanks for that. It sounds plausible, but I wonder why it works automagically\n> for C, but not for Java (Politcal reasons put aside): Using \".c\" for C is about\n> as common as using \".java\" for Java ;-)\n\nIt has a bit to do with it being in C, but not in the way you think. By\ndefault Git doesn't enable the \"cpp\" driver either for *.c, but it just\nso happens to do the right thing more of the time because the default\nheuristic is basically to search for a nearby line that doesn't start\nwith whitespace for context.\n\nThis doesn't work for Java because your methods tend to be indented\nsince they're part of the class you're working on.\n"}]}