Jgit-获取特定贡献者的提交历史

时间:2014-08-24 09:39:06

标签: java git jgit

我是JGit(Git的纯Java库)和Git的新手。我试图使用java获取特定成员的提交历史,但我什么都没得到,为此我正在使用JGit。 这是我的代码,我认为if语句中有错误。

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 个答案:

答案 0 :(得分:0)

您的错误在这里(与JGit无关):

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

请参阅this question了解问题所在。