Index: ui/annotate/AnnotateAction.java =================================================================== RCS file: /shared/data/ccvs/repository/versioncontrol/mercurial/src/org/netbeans/modules/mercurial/ui/annotate/AnnotateAction.java,v retrieving revision 1.5 diff -u -r1.5 AnnotateAction.java --- ui/annotate/AnnotateAction.java 3 Oct 2007 18:00:41 -0000 1.5 +++ ui/annotate/AnnotateAction.java 19 Nov 2007 10:20:36 -0000 @@ -246,10 +246,12 @@ int i = 0; for (String line : annotations) { int endAuthor = line.indexOf(" "); // NOI18N - int endRevision = line.indexOf(":", endAuthor + 1); // NOI18N + int endFile = line.indexOf(":", endAuthor + 1); // NOI18N + int endRevision = line.indexOf(" ", endAuthor + 1); // NOI18N lines[i] = new AnnotateLine(); lines[i].setAuthor(line.substring(0, endAuthor)); - lines[i].setContent(line.substring(endRevision + 2)); + lines[i].setContent(line.substring(endFile + 2)); + lines[i].setFileName(line.substring(endRevision + 1, endFile).trim()); lines[i].setLineNum(i + 1); lines[i].setRevision(line.substring(endAuthor, endRevision).trim()); i++; Index: ui/annotate/AnnotateLine.java =================================================================== RCS file: /shared/data/ccvs/repository/versioncontrol/mercurial/src/org/netbeans/modules/mercurial/ui/annotate/AnnotateLine.java,v retrieving revision 1.5 diff -u -r1.5 AnnotateLine.java --- ui/annotate/AnnotateLine.java 3 Oct 2007 18:00:41 -0000 1.5 +++ ui/annotate/AnnotateLine.java 19 Nov 2007 10:20:36 -0000 @@ -51,6 +51,7 @@ private String author; private String revision; + private String file; private Date date; private String content; private int lineNum; @@ -82,6 +83,21 @@ */ public void setAuthor(String author) { this.author = author; + } + + /** + * Returns the file of this line. + */ + public String getFileName() { + return file; + } + + /** + /** + * Sets the file of this line. + */ + public void setFileName(String file) { + this.file = file; } /** Index: ui/annotate/AnnotationBar.java =================================================================== RCS file: /shared/data/ccvs/repository/versioncontrol/mercurial/src/org/netbeans/modules/mercurial/ui/annotate/AnnotationBar.java,v retrieving revision 1.6 diff -u -r1.6 AnnotationBar.java --- ui/annotate/AnnotationBar.java 13 Nov 2007 11:06:36 -0000 1.6 +++ ui/annotate/AnnotationBar.java 19 Nov 2007 10:20:36 -0000 @@ -156,6 +156,11 @@ private String recentRevision; /** + * File for revision associated with caret line. + */ + private File recentFile; + + /** * Request processor to create threads that may be cancelled. */ RequestProcessor requestProcessor = null; @@ -374,7 +379,7 @@ public void actionPerformed(ActionEvent e) { if (recentRevision != null) { if (getPreviousRevision(recentRevision) != null) { - DiffAction.diff(file, getPreviousRevision(recentRevision), recentRevision); + DiffAction.diff(recentFile, getPreviousRevision(recentRevision), recentRevision); } } } @@ -515,6 +520,8 @@ String revision = al.getRevision(); if (revision.equals(recentRevision) == false) { recentRevision = revision; + File file = Mercurial.getInstance().getTopmostManagedParent(getCurrentFile()); + recentFile = new File(file, al.getFileName()); recentRevisionCanBeRolledBack = al.canBeRolledBack(); repaint(); Index: util/HgCommand.java =================================================================== RCS file: /shared/data/ccvs/repository/versioncontrol/mercurial/src/org/netbeans/modules/mercurial/util/HgCommand.java,v retrieving revision 1.53 diff -u -r1.53 HgCommand.java --- util/HgCommand.java 14 Nov 2007 20:38:54 -0000 1.53 +++ util/HgCommand.java 19 Nov 2007 10:20:36 -0000 @@ -102,6 +102,7 @@ private static final String HG_BRANCH_REV_TEMPLATE_CMD = "--template={rev}\\n"; // NOI18N private static final String HG_BRANCH_SHORT_CS_TEMPLATE_CMD = "--template={node|short}\\n"; // NOI18N private static final String HG_BRANCH_INFO_TEMPLATE_CMD = "--template={branches}:{rev}:{node|short}\\n"; // NOI18N + private static final String HG_GET_PREVIOUS_TEMPLATE_CMD = "--template={files}\\n"; // NOI18N private static final String HG_CREATE_CMD = "init"; // NOI18N private static final String HG_CLONE_CMD = "clone"; // NOI18N @@ -587,10 +588,10 @@ /** * Determines whether anything has been committed to the repository * - * @param String repository of the mercurial repository + * @param File repository of the mercurial repository's root directory * @return Boolean which is true if the repository has revision history. */ - public static Boolean hasHistory(String repository) throws HgException { + public static Boolean hasHistory(File repository) { if (repository == null ) return false; List command = new ArrayList(); @@ -599,40 +600,63 @@ command.add(HG_LOG_CMD); command.add(HG_LOG_LIMIT_CMD); command.add(HG_OPT_REPOSITORY); - command.add(repository); + command.add(repository.getAbsolutePath()); - List list = exec(command); - if (!list.isEmpty() && isErrorAbort(list.get(0))) - handleError(command, list, NbBundle.getMessage(HgCommand.class, "MSG_COMMAND_ABORTED")); - return !list.isEmpty(); + try { + List list = exec(command); + if (!list.isEmpty() && isErrorAbort(list.get(0))) + return false; + else + return !list.isEmpty(); + } catch (HgException e) { + return false; + } } - + /** - * Determines whether anything has been committed to the repository + * Determines the previous name of the specified file + * We make the assumption that the previous file name is in the + * list of files returned by hg log command immediately befor + * the file we started with. * * @param File repository of the mercurial repository's root directory - * @return Boolean which is true if the repository has revision history. + * @param File file of the file whose previous name is required + * @param String revision which the revision to start from. + * @return File for the previous name of the file */ - public static Boolean hasHistory(File repository) { - if (repository == null ) return false; + private static File getPreviousName(File repository, File file, String revision) throws HgException { + if (repository == null ) return null; + if (revision == null ) return null; List command = new ArrayList(); command.add(getHgCommand()); command.add(HG_LOG_CMD); - command.add(HG_LOG_LIMIT_CMD); + command.add(HG_OPT_FOLLOW); command.add(HG_OPT_REPOSITORY); command.add(repository.getAbsolutePath()); + command.add(HG_FLAG_REV_CMD); + command.add(revision); + command.add(HG_GET_PREVIOUS_TEMPLATE_CMD); + + command.add(file.getAbsolutePath()); + List list = exec(command); try { - List list = exec(command); + list = exec(command); if (!list.isEmpty() && isErrorAbort(list.get(0))) - return false; - else - return !list.isEmpty(); + return null; } catch (HgException e) { - return false; + return null; } + String[] fileNames = list.get(0).split(" "); + for (int j = fileNames.length -1 ; j > 0; j--) { + File name = new File(repository, fileNames[j]); + if (name.equals(file)) { + return new File(repository, fileNames[j-1]); + } + } + return null; } /** @@ -724,7 +748,7 @@ * @throws org.netbeans.modules.mercurial.HgException */ public static void doCat(File repository, File file, File outFile) throws HgException { - doCat(repository, file, outFile, "tip"); //NOI18N + doCat(repository, file, outFile, "tip", false); //NOI18N } /** @@ -740,6 +764,10 @@ * @throws org.netbeans.modules.mercurial.HgException */ public static void doCat(File repository, File file, File outFile, String revision) throws HgException { + doCat(repository, file, outFile, revision, true); //NOI18N + } + + public static void doCat(File repository, File file, File outFile, String revision, boolean retry) throws HgException { if (repository == null) return; if (file == null) return; @@ -766,6 +794,14 @@ handleError(command, list, NbBundle.getMessage(HgCommand.class, "MSG_COMMAND_ABORTED")); } } + if (outFile.length() == 0 && retry) { + // Perhaps the file has changed its name + String newRevision = Integer.toString(Integer.parseInt(revision)+1); + File prevFile = getPreviousName(repository, file, newRevision); + if (prevFile != null) { + doCat(repository, prevFile, outFile, revision, false); //NOI18N + } + } } /** @@ -1078,6 +1114,7 @@ } command.add(HG_ANNOTATE_FLAGN_CMD); command.add(HG_ANNOTATE_FLAGU_CMD); + command.add(HG_OPT_FOLLOW); command.add(file.getAbsolutePath()); List list = exec(command); if (!list.isEmpty()) {