package com.perforce.cvs.process; import java.io.File; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.perforce.common.ConverterException; import com.perforce.common.Stats; import com.perforce.common.StatsType; import com.perforce.common.depot.DepotInterface; import com.perforce.common.node.Action; import com.perforce.common.process.ChangeInfo; import com.perforce.common.process.ProcessChange; import com.perforce.common.process.ProcessFactory; import com.perforce.common.process.ProcessLabel; import com.perforce.config.CFG; import com.perforce.config.CaseSensitivity; import com.perforce.config.Config; import com.perforce.cvs.BranchNavigator; import com.perforce.cvs.BranchSorter; import com.perforce.cvs.RevisionEntry; import com.perforce.cvs.RevisionNavigator; import com.perforce.cvs.RevisionSorter; import com.perforce.cvs.asset.CvsContentReader; import com.perforce.cvs.parser.RcsFileFinder; import com.perforce.cvs.parser.RcsReader; import com.perforce.cvs.parser.rcstypes.RcsObjectNum; import com.perforce.svn.change.ChangeInterface; import com.perforce.svn.prescan.Progress; import com.perforce.svn.query.QueryInterface; public class CvsProcessChange extends ProcessChange { private static Logger logger = LoggerFactory .getLogger(CvsProcessChange.class); private DepotInterface depot; private int nodeID = 0; public CvsProcessChange() throws Exception { if (logger.isDebugEnabled()) { logger.debug(Config.summary()); } // Read configuration settings for locals revStart = (Long) Config.get(CFG.P4_START); revEnd = (Long) Config.get(CFG.P4_END); } protected void processChange() throws Exception { // Initialise labels isLabels = (Boolean) Config.get(CFG.CVS_LABELS); // Create revision tree and depot String depotPath = (String) Config.get(CFG.P4_DEPOT_PATH); CaseSensitivity caseMode = (CaseSensitivity) Config.get(CFG.P4_CASE); depot = ProcessFactory.getDepot(depotPath, caseMode); if (logger.isDebugEnabled()) { logger.debug(Config.summary()); } // Check for pending changes, abort if any are found QueryInterface query = ProcessFactory.getQuery(depot); int pending = query.getPendingChangeCount(); if (pending > 0) { String err = "Pending change detected, conversion aborted"; logger.error(err); throw new ConverterException(err); } // Find all RCS files in CVSROOT String cvsroot = (String) Config.get(CFG.CVS_ROOT); RcsFileFinder rcsFiles = find(cvsroot); // Sort branches BranchSorter brSort = buildBranchList(rcsFiles); // Build revision list RevisionSorter revSort = buildRevisionList(rcsFiles, brSort); // Sort revisions by date/time revSort.sort(); // Sort revisions into changes ChangeSorter changeSort = new ChangeSorter(); // changeSort.load("cvsChanges.json"); changeSort.build(revSort); // changeSort.store("cvsChanges.json"); // Set imported change range long lastRev = changeSort.getLastChange(); setChangeRange(lastRev); // Iterate over changes and submit for (CvsChange cvsChange : changeSort.getChanges()) { // initialise labels if (isLabels) { processLabel = new ProcessLabel(depot); } ChangeInterface change; long sequence = cvsChange.getChange(); long p4Change = sequence + (Long) Config.get(CFG.P4_OFFSET); // skip revision outside of starting position if (sequence < revStart) { logger.info("skipping change " + sequence + "..."); continue; } RevisionEntry changeEntry = cvsChange.getChangeInfo(); ChangeInfo info = new ChangeInfo(changeEntry, sequence); change = ProcessFactory.getChange(p4Change, info, depot); super.setCurrentChange(change); for (RevisionEntry rev : cvsChange.getRevisions()) { buildChange(rev, change, sequence); } submit(); // update counters nodeID = 0; if (super.isStop() || (sequence >= revEnd && revEnd != 0)) { if (super.isStop()) { // Premature stop -- update end rev Config.set(CFG.P4_END, sequence); } // Close changelist close(); return; } } // finish up conversion close(); } /** * Adds Entry to current change-list * * @param entry * @param revs * @param change * @throws Exception */ private void buildChange(RevisionEntry entry, ChangeInterface change, long sequence) throws Exception { if (logger.isTraceEnabled()) { logger.trace("... adding: " + entry); } // update entry entry.setNodeID(nodeID); entry.setCvsChange(sequence); // and add node to current change CvsProcessNode node; node = new CvsProcessNode(change, depot, entry); node.process(); // tag any labels if (isLabels) { RcsObjectNum id = entry.getId(); if (entry.getState() == Action.REMOVE && id.getMinor() == 1) { logger.info("skip labelling dead revision: " + id); } else { processLabel.labelRev(entry, change.getChange()); } } nodeID++; } /** * Returns a list of RCS files under a path defined by the CVSROOT and * MODULE if set. Only returns ',v' files. * * @return * @throws Exception */ public static RcsFileFinder find(String cvsroot) throws Exception { // Find all revisions in CVSROOT if (!new File(cvsroot).exists()) { String err = "Invalid path for CVSROOT: " + cvsroot; logger.error(err + "\n"); throw new Exception(); } else { if (!cvsroot.endsWith("/")) { cvsroot = new String(cvsroot + "/"); } if (!cvsroot.startsWith("/")) { cvsroot = new String("/" + cvsroot); } } // Append module to search path String module = (String) Config.get(CFG.CVS_MODULE); String cvsSearch = cvsroot + module + "/"; if (!new File(cvsSearch).exists()) { cvsSearch = cvsroot; } logger.info("Searching for RCS files:"); RcsFileFinder files = new RcsFileFinder(cvsSearch); int count = files.getFiles().size(); logger.info("... found " + count + " RCS files\n"); return files; } /** * Finds Labels/Branches and builds a list of true branches. * * @return */ private BranchSorter buildBranchList(RcsFileFinder rcsFiles) { logger.info("Building branch list:"); BranchSorter brSort = new BranchSorter(); BranchNavigator brNav = new BranchNavigator(brSort); Progress progress = new Progress(rcsFiles.getFiles().size()); int count = 0; for (File file : rcsFiles.getFiles()) { try { RcsReader rcs = new RcsReader(file, false); brNav.add(rcs); progress.update(++count); } catch (Exception e) { logger.warn("Unable to process file: " + file.getAbsolutePath()); Stats.inc(StatsType.warningCount); e.printStackTrace(); } } logger.info("... done \n"); if (logger.isDebugEnabled()) { logger.debug("Sorted branch list:"); logger.debug(brSort.toString()); } return brSort; } /** * Return a list of all CVS revisions * * @param brSorter * @return */ private RevisionSorter buildRevisionList(RcsFileFinder rcsFiles, BranchSorter brSorter) { logger.info("Building revision list:"); RevisionSorter revSorter = new RevisionSorter(false); RevisionNavigator revNav = new RevisionNavigator(revSorter, brSorter); Progress progress = new Progress(rcsFiles.getFiles().size()); int count = 0; for (File file : rcsFiles.getFiles()) { try { if ((Boolean) Config.get(CFG.CVS_TMPLOG_ENABLED)) { TmpFileLogger.logRcsFile(file); } RcsReader rcs = new RcsReader(file, true); revNav.add(rcs); // Extract all RCS deltas to tmp store CvsContentReader content = new CvsContentReader(rcs); content.cacheContent(); progress.update(++count); } catch (Exception e) { logger.warn("Unable to process file: " + file.getAbsolutePath()); Stats.inc(StatsType.warningCount); e.printStackTrace(); } } logger.info("... done \n"); return revSorter; } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#1 | 13876 | Paul Allen | Rename/move file(s) | ||
//guest/paul_allen/p4convert-maven/src/com/perforce/cvs/process/CvsProcessChange.java | |||||
#1 | 13873 | Paul Allen | Branching using p4convert-maven | ||
//guest/perforce_software/p4convert/src/com/perforce/cvs/process/CvsProcessChange.java | |||||
#29 | 13776 | Paul Allen |
CVS: Update to node Action detection. The RCS State is normally set to 'Exp' and 'dead', but this change allows more user defined states. - Move Action class to common.node package. - Modified test case061 to test custom states. |
||
#28 | 12890 | Paul Allen |
Extended start/stop change limits to CVS. - Moved start and stop configuration options out of SVN name space to the generic P4 space. - Abstracted shared range logic to ProcessChange #review-12880 |
||
#27 | 12521 | Paul Allen |
CVS: Audit logging when generating Tmp files from RCS. Creates a file "tmpFile.log" under the com.perforce.cvs.tmpDir and logging is enabled by default. com.perforce.cvs.audit.tmp=true |
||
#26 | 12441 | Paul Allen |
CVS: Toggle off CVS change list storage. - Disabled until resume feature is complete. |
||
#25 | 12440 | Paul Allen | CVS: More efficient parsing of RCS files. | ||
#24 | 12406 | Paul Allen |
CVS: Bug fix for labels on dead RCS *n.1 revisions. Skip labeling a 'dead' RCS file if it is the first revision on that branch, as 'dead' revisions are not added to Perforce, there is not revision to Label. |
||
#23 | 12405 | Paul Allen |
CVS: Save change list data to a JSON formatted file 'changes.json'. (Work-In-Progress) - need to add load option and resume flags |
||
#22 | 12397 | Paul Allen |
CVS: Separate sort behaviour from Perforce changelist processing. - In preperation for saving CVS changes list state. - Updated test case 045 back (case rename in two changes) |
||
#21 | 12185 | Paul Allen |
CVS: Avoid labeling dead revisions. - includes a fix for missing revisions resulting from non-branched orphans. - test case 060 @rjackson |
||
#20 | 11263 | Paul Allen | Refactor the enum Action outside of ChangeAction. | ||
#19 | 11195 | Paul Allen | Back out changelist 11188 | ||
#18 | 11188 | Paul Allen |
CVS: Added OutOfOrderException to trap CVS branch issues. @rjackson (Untested and includes debug code) |
||
#17 | 11186 | Paul Allen |
Support standard command line arguments. Important change please note... @rjackson @nmorse The change was needed to extend the current features like --info and --user for CVS and future SCM support. Please check the documentation and CLI usage for the new usage. - CVS support for --users - Unit tests for CLI arguments Example: standard usage. java -jar p4convert.jar --config=myFile.cfg Example: generate a CVS configuration file. java -jar p4convert.jar --type=CVS --default Example: report Subversion repository usage. java -jar p4convert.jar --type=SVN --repo=/path/to/repo.dump --info |
||
#16 | 11040 | Paul Allen |
SVN: Static label support - Push up shared label code for CVS/SVN - Update label description base for CVS test case 030 |
||
#15 | 10997 | Paul Allen |
CVS: use a dynamic time window when processing pseudo branches. - Prevent branches getting ahead of the source. - Used parent equals method in RevisionEntry to fix for drop method in RevisionSorter. |
||
#14 | 10984 | Paul Allen |
CVS: Tidy up logging - added revision count. |
||
#13 | 10979 | Paul Allen |
CVS: offload Pseudo branches to the delayed list, before revision that are already opened. - should fix empty change lists |
||
#12 | 10978 | Paul Allen |
CVS redesign of RCS Revision Navigation. - Disabled reverse RCS tag lookup for the moment. |
||
#11 | 10952 | Paul Allen |
CVS add 1ms delay to pseudo branches. - extra trace debug |
||
#10 | 10944 | Paul Allen |
CVS change-list processing. Create a delayed list for pseudo branches to prevent them falling into the wrong change. - updated test cases 006 007 047 |
||
#9 | 10921 | Paul Allen | String.intern() null protection. | ||
#8 | 10910 | Paul Allen | CVS progress counters for large conversion. | ||
#7 | 10882 | Paul Allen |
CVS non branched revisions. Address issue when adding files to a branch that have no connection to main. CVS identifies these as 'dead' revisions on main with a branch. - replaced CVS test case 047 |
||
#6 | 10771 | Paul Allen |
Update warning counter, on error/warn state. Stats.inc(StatsType.warningCount); |
||
#5 | 10770 | Paul Allen | Switched off debug/trace reporting. | ||
#4 | 10730 | Paul Allen |
CVS: Fix for Labels in Import mode. Unable to label a revision in a pending change, so store all tag entries and add them to label after the change is submitted. Includes basic test case 030 |
||
#3 | 10728 | Paul Allen |
CVS: new Label feature. Scans the RCS tree counting revisions on a branch. If the branch only has one revision it gets downgraded to a Label. Support added for Import and Convert mode. Activate using: com.p4convert.cvs.labels=true or in java Config.set(CFG.CVS_LABELS, true); (manual testing only -- automated tests will follow this change) |
||
#2 | 10719 | Paul Allen |
CVS: Activate old label code and add config option. disabled by default -- for the moment until it works (set log level from trace -> debug) |
||
#1 | 9807 | Paul Allen | Initial import of p4-convert (from change 894340) |