-1

I am newbie to JGit (a pure java library for git works) and Git. I am trying to get commit history of particular member using java but i get nothing, to do this I am using JGit. This is my code ,I think there is an error in if statement.

public class GitLogNew {
 static PersonIdent person=new PersonIdent("someone","someone@gmail.com");
 static String name =person.getName();
 static String email=person.getEmailAddress();
public static void main(String[] args) {
    try { 


        test4(name,email);
         //System.out.println("----------------------------------------");

    } catch (Exception e) {
        System.out.println(" ERROR " + e.toString());
    }

}
 public static void test4(String name, String email){

      try {

       File gitWorkDir = new File("E:/test/evaluate_contribution");
        Git git = null;
        git = Git.open(gitWorkDir);
        Repository repo = git.getRepository();

        LogCommand log = git.log();
        log.all();

        ObjectId lastCommitId = repo.resolve(Constants.HEAD);
         RevWalk rw = new RevWalk(repo);
         RevCommit parent = rw.parseCommit(lastCommitId);

         rw.sort(RevSort.COMMIT_TIME_DESC);
    rw.markStart(parent);


        log.setMaxCount(20);
        Iterable<RevCommit> logMsgs = log.call();
        for (RevCommit commit : logMsgs) {
            System.out.println("\n\n\n----------------------------------------");




         if(name == commit.getCommitterIdent().getName()){
            System.out.println("commit    "  + commit);
            System.out.println("commit Id   "  + commit.toObjectId());
            System.out.println("commit authur "  + commit.getAuthorIdent().getName());
            System.out.println("commit email "  + commit.getAuthorIdent().getEmailAddress());
            System.out.println("commit time "  + commit.getAuthorIdent().getWhen());
            System.out.println(" commit Message " + commit.getFullMessage());
            System.out.println("-----------------------------");
          //System.out.println("parents");
         } 


      }
        }catch (Exception e) {
        System.out.println("no head exception : " + e);
    }


 }

1 Answers1

0

Your error is here (and has nothing to do with JGit):

if(name == commit.getCommitterIdent().getName()){

See this question for what the problem is.

Community
  • 1
  • 1
robinst
  • 30,027
  • 10
  • 102
  • 108