10/6/15

How to Create Patch in Google Summer of Coding | Learn-Fast

In Order to submit Patches for Google Summer of Code , you must be comfortable in reading source code and finding Bugs/issues in them.Well every Organisation will have a Bug Tracker System that has a set of Solved and Unsolved Bugs/Issues which are usually labelled with their difficultly Level ,like first-Timer, Easy, Medium or Hard .In this Post we 'll be covering How to Create a Patch after you detected and worked on some Bugs / Issues .

Learn to Create Patch in Google Summer of Coding


A Patch is simply a file usually a text file that has some additional information that you have added after manipulating your original file .

If you made some changes to your original Code and wanted to share them with the Core Developers of the community (Organisation) then it is very helpful to provide them a Patch file .

Now we know what is a patch , lets create one . Patches can be created in many ways .Some of them which are often used in Google Summer of Coding Contests are listed below :
  • Create Patch using Diff 
  • Create Patch using WinMerge 
  • Create Patch using Git 

Create Patch using Diff :

Diff is simple Linux command that requires two copies of code or a file .The first is the Original code or a file and later is the modified (With some changes you made) Code or a file .

To illustrates this , we put the below code in the Foo.java File .

import java.util.*;
public class Foo {
   public void main(String[] args)
   { 
     System.out.println("Foo");  
   }
}
Next , we modify the above code and save them in Foobar.java .

import java.util.*;
import java.util.*;
public class Foobar {
public void main(String[] args)
{ 
    System.out.println("Foobar Foo");  
}
}

To trace what changes you have made , just type in the Linux terminal

diff -u Foo.java Foobar.java > PatchforFoo.patch
 
The above Code will create patch file called PatchforFoo which shows difference in contents


import java.util.*;
--- Foo.java 2015-10-06 09:40:14.525429605 +0530
+++ Foobar.java 2015-10-06 09:43:29.365427829 +0530
@@ -5,7 +5,7 @@
 public void main(String[] args)
 { 
-System.out.println("Foo");  
+System.out.println("Foobar Foo");  
 }

You can also apply patch in Source Tree or directory .Type in the Linux Terminal

diff -Naur /usr/src/originalfolder  /usr/src/modifiedfolder > patchforgsoc.patch


All those modified differences are placed in patchforgsoc patch file .

Create Patch using WinMerge :

WinMerge is a Simple Open Source GUI based Tool for Windows that is used to compare folder contents and merging. To start with ,first you need to download the WinMerge Software . To create the patch ,click FILE->Open and Open two versions for comparisons .then click TOOLS->Generate patch .

Create Patch using Git :

Many Organisations use Git Version Control has it is more secure and use distributed system for concurrent access . If you are new to Git version Control Try Git . 

To create patch in Git ,just open the Git console and if you want to create a patch file for last commit ,type git show > patchforgsoc.txt .

 If you want to create patch for 2 commits you can type git diff commit1 commit2 > patchforgsoc.txt
So modified differences are placed in patchforgsoc.txt text file .

In general the git patch format looks like this git format-patch [options] . Check the detailed explanation for git patch Options here.


0 comments:

Post a Comment