Hi all!
I’m currently working on a project that involves Git. What I have to do is that I have to compare the changes in a pull request using a webhook and build the particular modified components in the Jenkins server.
I have already posted a blogpost on how to create a webhook based on particular events, which is in my case the ‘pull request’ event. According to the JSON payload that I receive, I have to extract the diff url and check for the modified components. Since there are not much information on the git diff format, I thought of writing a post about it from what I have learned.
This is a sample output of a diff url. Let us examine what each and every line does in this diff format.
COMPARISON OUTPUT
This line shows the input sources of the diff. b/… file is the newly modified one. b/… file is being compared with a/… file.
META DATA
This line diplays some meta data. The numbers in this output correlate with hash identifiers of the files. In the example given above compares a previous file with the newly modified file. The output is something like,
index d82cbb23b..58f6f39a6 100644
It compares the changes between two hashes. If it is a newly created file, the output will be something like this.
new file mode 100644 index 000000000..43d88e9d6
As you can see, it compares the new file hash with 000000000 and has a new line called new file mode 100644.
- 100644 stands for a normal file.
- 100755 stands for an executable file.
- 120000 specifies a symbolic link.
MARKERS FOR CHANGES
This line shows how it assigns symbols to each diff input source. In this case, changes from a/… are marked with a — and the changes from b/… are marked with a +++ symbol.
DIFF OUTPUT
The remaining diff output is a list of ‘diff chunks’. A diff only displays the sections of the file that have changes. In our example, we have 5 chunks as we are working with a simple scenario.
@@ -17,3 +17,5 @@ -org.wso2.carbon.throttle.module.* -org.wso2.carbon.throttle.core.impl.ipbase.* -org.wso2.uri.template.parser.* +-*.stub* +-*.stub_
The first line is the chunk header. Each chunk is added on by a header surrounded within @@ symbols. This header contains the summary of changes made to the file. According to our example, 3 lines have been changed starting from 17th line. In addition to that, 5 lines have been added starting from line number 17.
Each changed line is prepended with + or – symbol indicating which version of the diff input the changes come from. -17,3 indicates that 3 lines have been changed starting from 17th line in a/… file.
That’s it about Git diff. Stay tuned for more cool stuff! 🙂
Great post. Keep up the good work
LikeLiked by 1 person
Thank you!! :*)
LikeLike