Mercurial > hg > mercurial
comparison mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupport.java @ 299:e9e7d9fcf57d
Use customized xml output from the 'hg log' command instead of running 'hg status' for every commit
author | Dmitry Neverov <dmitry.neverov@jetbrains.com> |
---|---|
date | Thu, 08 Sep 2011 12:56:56 +0400 |
parents | 8c1fd2e565ae |
children | e9cdb499350d |
comparison
equal
deleted
inserted
replaced
298:9b9fd71911eb | 299:e9e7d9fcf57d |
---|---|
115 FileUtil.delete(f); | 115 FileUtil.delete(f); |
116 } finally { | 116 } finally { |
117 unlockWorkDir(f); | 117 unlockWorkDir(f); |
118 } | 118 } |
119 } | 119 } |
120 } | |
121 | |
122 private Collection<ModifiedFile> computeModifiedFilesForMergeCommit(final Settings settings, final ChangeSet cur) throws VcsException { | |
123 File workingDir = getWorkingDir(settings); | |
124 ChangedFilesCommand cfc = new ChangedFilesCommand(settings, workingDir); | |
125 cfc.setRevId(cur.getId()); | |
126 return cfc.execute(); | |
127 } | 120 } |
128 | 121 |
129 private List<VcsChange> toVcsChanges(final List<ModifiedFile> modifiedFiles, String prevVer, String curVer, CheckoutRules rules) { | 122 private List<VcsChange> toVcsChanges(final List<ModifiedFile> modifiedFiles, String prevVer, String curVer, CheckoutRules rules) { |
130 List<VcsChange> files = new ArrayList<VcsChange>(); | 123 List<VcsChange> files = new ArrayList<VcsChange>(); |
131 for (ModifiedFile mf: modifiedFiles) { | 124 for (ModifiedFile mf: modifiedFiles) { |
516 String mergeBase = getMergeBase(settings, baseVersion, branchVersion); | 509 String mergeBase = getMergeBase(settings, baseVersion, branchVersion); |
517 | 510 |
518 if (mergeBase == null) | 511 if (mergeBase == null) |
519 return null; | 512 return null; |
520 | 513 |
521 LogCommand lc = new LogCommand(settings, getWorkingDir(settings)); | 514 LogCommand lc = myCommandFactory.createLog(settings, getWorkingDir(settings)); |
522 lc.setFromRevId(new ChangeSetRevision(mergeBase).getId()); | 515 lc.setFromRevId(new ChangeSetRevision(mergeBase).getId()); |
523 lc.setToRevId(new ChangeSetRevision(branchVersion).getId()); | 516 lc.setToRevId(new ChangeSetRevision(branchVersion).getId()); |
524 lc.showCommitsFromAllBranches(); | 517 lc.showCommitsFromAllBranches(); |
525 List<ChangeSet> changeSets = lc.execute(); | 518 List<ChangeSet> changeSets = lc.execute(); |
526 if (changeSets.size() > 1) {//when branch points to the commit in original branch we get 1 cset | 519 if (changeSets.size() > 1) {//when branch points to the commit in original branch we get 1 cset |
559 } | 552 } |
560 | 553 |
561 | 554 |
562 @NotNull | 555 @NotNull |
563 private String getMinusNthCommit(@NotNull Settings settings, int n) throws VcsException { | 556 private String getMinusNthCommit(@NotNull Settings settings, int n) throws VcsException { |
564 LogCommand log = new LogCommand(settings, getWorkingDir(settings)); | 557 LogCommand log = myCommandFactory.createLog(settings, getWorkingDir(settings)); |
565 log.setFromRevId(settings.getBranchName()); | 558 log.setFromRevId(settings.getBranchName()); |
566 if (n > 0) | 559 if (n > 0) |
567 log.setLimit(n); | 560 log.setLimit(n); |
568 List<ChangeSet> changeSets = log.execute(); | 561 List<ChangeSet> changeSets = log.execute(); |
569 return changeSets.get(changeSets.size() - 1).getId(); | 562 return changeSets.get(changeSets.size() - 1).getId(); |
579 Settings settings = createSettings(root); | 572 Settings settings = createSettings(root); |
580 syncRepository(settings); | 573 syncRepository(settings); |
581 | 574 |
582 // first obtain changes between specified versions | 575 // first obtain changes between specified versions |
583 List<ModificationData> result = new ArrayList<ModificationData>(); | 576 List<ModificationData> result = new ArrayList<ModificationData>(); |
584 if (currentVersion == null) return result; | 577 if (currentVersion == null) |
578 return result; | |
585 | 579 |
586 File workingDir = getWorkingDir(settings); | 580 File workingDir = getWorkingDir(settings); |
587 LogCommand lc = new LogCommand(settings, workingDir); | 581 LogCommand lc = myCommandFactory.createLog(settings, workingDir); |
588 String fromId = new ChangeSetRevision(fromVersion).getId(); | 582 String fromId = new ChangeSetRevision(fromVersion).getId(); |
589 lc.setFromRevId(fromId); | 583 lc.setFromRevId(fromId); |
590 lc.setToRevId(new ChangeSetRevision(currentVersion).getId()); | 584 lc.setToRevId(new ChangeSetRevision(currentVersion).getId()); |
591 List<ChangeSet> changeSets = lc.execute(); | 585 List<ChangeSet> changeSets = lc.execute(); |
592 if (changeSets.isEmpty()) { | 586 if (changeSets.isEmpty()) { |
593 return result; | 587 return result; |
594 } | 588 } |
595 | 589 |
596 // invoke status command for each changeset and determine what files were modified in these changesets | |
597 StatusCommand st = new StatusCommand(settings, workingDir); | |
598 ChangeSet prev = new ChangeSet(fromVersion); | 590 ChangeSet prev = new ChangeSet(fromVersion); |
599 for (ChangeSet cur : changeSets) { | 591 for (ChangeSet cur : changeSets) { |
600 if (cur.getId().equals(fromId)) continue; // skip already reported changeset | 592 if (cur.getId().equals(fromId)) |
593 continue; // skip already reported changeset | |
601 | 594 |
602 List<ChangeSetRevision> curParents = cur.getParents(); | 595 List<ChangeSetRevision> curParents = cur.getParents(); |
603 boolean mergeCommit = curParents.size() > 1; | 596 boolean mergeCommit = curParents.size() > 1; |
604 List<ModifiedFile> modifiedFiles = new ArrayList<ModifiedFile>(); | 597 List<ModifiedFile> modifiedFiles = cur.getModifiedFiles(); |
605 if (mergeCommit) { | |
606 modifiedFiles.addAll(computeModifiedFilesForMergeCommit(settings, cur)); | |
607 } else { | |
608 if (!curParents.isEmpty()) | |
609 st.setFromRevId(curParents.get(0).getId()); | |
610 st.setToRevId(cur.getId()); | |
611 modifiedFiles.addAll(st.execute()); | |
612 } | |
613 | |
614 // changeset full version will be set into VcsChange structure and | |
615 // stored in database (note that getContent method will be invoked with this version) | |
616 List<VcsChange> files = toVcsChanges(modifiedFiles, prev.getFullVersion(), cur.getFullVersion(), checkoutRules); | 598 List<VcsChange> files = toVcsChanges(modifiedFiles, prev.getFullVersion(), cur.getFullVersion(), checkoutRules); |
617 if (files.isEmpty() && !mergeCommit) continue; | 599 if (files.isEmpty() && !mergeCommit) |
600 continue; | |
618 ModificationData md = new ModificationData(cur.getTimestamp(), files, cur.getDescription(), cur.getUser(), root, cur.getFullVersion(), cur.getId()); | 601 ModificationData md = new ModificationData(cur.getTimestamp(), files, cur.getDescription(), cur.getUser(), root, cur.getFullVersion(), cur.getId()); |
619 if (mergeCommit) { | 602 if (mergeCommit) |
620 md.setCanBeIgnored(false); | 603 md.setCanBeIgnored(false); |
621 } | |
622 result.add(md); | 604 result.add(md); |
623 prev = cur; | 605 prev = cur; |
624 } | 606 } |
625 | 607 |
626 return result; | 608 return result; |