# HG changeset patch # User jrice@netbeans.org # Date 1210937470 -3600 # Node ID 3b13fc76f535bd6fb66568b0b59ab285ab23e0f4 # Parent a451a96f29675c857bc01b1b34a0dc3192e8c3f7 #134775: Automated merge diff problem - need to diff common ancestor diff -r a451a96f2967 -r 3b13fc76f535 mercurial/src/org/netbeans/modules/mercurial/ui/log/DiffResultsView.java --- a/mercurial/src/org/netbeans/modules/mercurial/ui/log/DiffResultsView.java Fri May 16 11:33:14 2008 +0100 +++ b/mercurial/src/org/netbeans/modules/mercurial/ui/log/DiffResultsView.java Fri May 16 12:31:10 2008 +0100 @@ -239,7 +239,8 @@ class DiffResultsView implements Ancesto if (rev.getFile() == null) return; long revision2 = Long.parseLong(rev.getLogInfoHeader().getLog().getRevision()); - showDiff(rev, Long.toString(revision2 - 1), Long.toString(revision2), showLastDifference); + String ancestor = rev.getLogInfoHeader().getLog().getAncestor(); + showDiff(rev, ancestor != null? ancestor: Long.toString(revision2 - 1), Long.toString(revision2), showLastDifference); } private void showContainerDiff(RepositoryRevision container, boolean showLastDifference) { @@ -260,7 +261,8 @@ class DiffResultsView implements Ancesto } if (newest.getFile() == null) return; long rev = Long.parseLong(newest.getLogInfoHeader().getLog().getRevision()); - showDiff(newest, Long.toString(rev - 1), Long.toString(rev), showLastDifference); + String ancestor = newest.getLogInfoHeader().getLog().getAncestor(); + showDiff(newest, ancestor != null? ancestor: Long.toString(rev - 1), Long.toString(rev), showLastDifference); } void onNextButton() { diff -r a451a96f2967 -r 3b13fc76f535 mercurial/src/org/netbeans/modules/mercurial/ui/log/HgLogMessage.java --- a/mercurial/src/org/netbeans/modules/mercurial/ui/log/HgLogMessage.java Fri May 16 11:33:14 2008 +0100 +++ b/mercurial/src/org/netbeans/modules/mercurial/ui/log/HgLogMessage.java Fri May 16 12:31:10 2008 +0100 @@ -1,4 +1,4 @@ -/* + /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved. @@ -45,9 +45,12 @@ import java.util.List; import java.util.List; import org.netbeans.modules.mercurial.FileInformation; import org.netbeans.modules.mercurial.FileStatus; +import org.netbeans.modules.mercurial.HgException; import org.netbeans.modules.mercurial.Mercurial; import org.netbeans.modules.mercurial.OutputLogger; +import org.netbeans.modules.mercurial.util.HgCommand; import org.netbeans.modules.mercurial.util.HgUtils; +import org.openide.util.Exceptions; /** * @@ -69,17 +72,35 @@ public class HgLogMessage { private Date date; private String id; private String timeZoneOffset; - + + private String parentOneRev; + private String parentTwoRev; + private boolean bMerged; + private String rootURL; + private OutputLogger logger; + public HgLogMessage(String changeset){ } - public HgLogMessage( String rev, String auth, String desc, String date, String id, - String fm, String fa, String fd, String fc){ + public HgLogMessage(String rootURL, String rev, String auth, String desc, String date, String id, + String parents, String fm, String fa, String fd, String fc){ String splits[]; + String parentSplits[]; + this.rootURL = rootURL; this.rev = rev; this.author = auth; this.desc = desc; + parentSplits = parents != null? parents.split(" "): null; + if((parentSplits != null) && (parentSplits.length == 2)){ + String ps1[] = parentSplits[0].split(":"); // NOI18N + this.parentOneRev = ps1 != null && ps1.length >=1? ps1[0]: null; + String ps2[] = parentSplits[1].split(":"); // NOI18N + this.parentTwoRev = ps2 != null && ps2.length >=1? ps2[0]: null; + } + this.bMerged = this.parentOneRev != null && this.parentTwoRev != null && + !this.parentOneRev.equals("-1") && !this.parentTwoRev.equals("-1")? true: false; + splits = date.split(" "); this.date = new Date(Long.parseLong(splits[0]) * 1000); // UTC in miliseconds this.id = id; @@ -169,6 +190,31 @@ public class HgLogMessage { public String getCSetShortID() { return id; } + + public String getAncestor() { + if(bMerged){ + try{ + return HgCommand.getCommonAncestor(rootURL, parentOneRev, parentTwoRev, getLogger()); + } catch (HgException ex) { + return null; + } + } + int revInt = -1; + try{ + revInt = Integer.parseInt(rev); + }catch(NumberFormatException ex){ + } + revInt = revInt > -1? revInt -1: -1; + return Integer.toString(revInt); + } + + private OutputLogger getLogger() { + if (logger == null) { + logger = Mercurial.getInstance().getLogger(rootURL); + } + return logger; + } + public String getMessage() { return desc; } diff -r a451a96f2967 -r 3b13fc76f535 mercurial/src/org/netbeans/modules/mercurial/util/HgCommand.java --- a/mercurial/src/org/netbeans/modules/mercurial/util/HgCommand.java Fri May 16 11:33:14 2008 +0100 +++ b/mercurial/src/org/netbeans/modules/mercurial/util/HgCommand.java Fri May 16 12:31:10 2008 +0100 @@ -142,7 +142,7 @@ public class HgCommand { private static final String HG_LOG_NO_MERGES_CMD = "-M"; private static final String HG_LOG_DEBUG_CMD = "--debug"; private static final String HG_LOG_TEMPLATE_HISTORY_CMD = - "--template=rev:{rev}\\nauth:{author}\\ndesc:{desc}\\ndate:{date|hgdate}\\nid:{node|short}\\n" + // NOI18N + "--template=rev:{rev}\\nauth:{author}\\ndesc:{desc}\\ndate:{date|hgdate}\\nid:{node|short}\\nparents:{parents}\\n" + // NOI18N "file_mods:{files}\\nfile_adds:{file_adds}\\nfile_dels:{file_dels}\\nfile_copies:\\nendCS:\\n"; // NOI18N private static final String HG_LOG_TEMPLATE_HISTORY_NO_FILEINFO_CMD = "--template=rev:{rev}\\nauth:{author}\\ndesc:{desc}\\ndate:{date|hgdate}\\nid:{node|short}\\n" + // NOI18N @@ -153,6 +153,7 @@ public class HgCommand { private static final String HG_LOG_DESCRIPTION_OUT = "desc:"; // NOI18N private static final String HG_LOG_DATE_OUT = "date:"; // NOI18N private static final String HG_LOG_ID_OUT = "id:"; // NOI18N + private static final String HG_LOG_PARENTS_OUT = "parents:"; // NOI18N private static final String HG_LOG_FILEMODS_OUT = "file_mods:"; // NOI18N private static final String HG_LOG_FILEADDS_OUT = "file_adds:"; // NOI18N private static final String HG_LOG_FILEDELS_OUT = "file_dels:"; // NOI18N @@ -169,6 +170,8 @@ public class HgCommand { private static final String HG_CAT_CMD = "cat"; // NOI18N private static final String HG_FLAG_OUTPUT_CMD = "--output"; // NOI18N + + private static final String HG_COMMONANCESTOR_CMD = "debugancestor"; // NOI18N private static final String HG_ANNOTATE_CMD = "annotate"; // NOI18N private static final String HG_ANNOTATE_FLAGN_CMD = "--number"; // NOI18N @@ -822,10 +825,10 @@ public class HgCommand { return list; } - private static List processLogMessages(List list, final List messages) { - String rev, author, desc, date, id, fm, fa, fd, fc; + private static List processLogMessages(String rootURL, List list, final List messages) { + String rev, author, desc, date, id, parents, fm, fa, fd, fc; if (list != null && !list.isEmpty()) { - rev = author = desc = date = id = fm = fa = fd = fc = null; + rev = author = desc = date = id = parents = fm = fa = fd = fc = null; boolean bEnd = false; for (String s : list) { if (s.indexOf(HG_LOG_REVISION_OUT) == 0) { @@ -838,6 +841,8 @@ public class HgCommand { date = s.substring(HG_LOG_DATE_OUT.length()).trim(); } else if (s.indexOf(HG_LOG_ID_OUT) == 0) { id = s.substring(HG_LOG_ID_OUT.length()).trim(); + } else if (s.indexOf(HG_LOG_PARENTS_OUT) == 0) { + parents = s.substring(HG_LOG_PARENTS_OUT.length()).trim(); } else if (s.indexOf(HG_LOG_FILEMODS_OUT) == 0) { fm = s.substring(HG_LOG_FILEMODS_OUT.length()).trim(); } else if (s.indexOf(HG_LOG_FILEADDS_OUT) == 0) { @@ -853,8 +858,8 @@ public class HgCommand { } if (rev != null & bEnd) { - messages.add(new HgLogMessage(rev, author, desc, date, id, fm, fa, fd, fc)); - rev = author = desc = date = id = fm = fa = fd = fc = null; + messages.add(new HgLogMessage(rootURL, rev, author, desc, date, id, parents, fm, fa, fd, fc)); + rev = author = desc = date = id = parents = fm = fa = fd = fc = null; bEnd = false; } } @@ -870,7 +875,7 @@ public class HgCommand { List list = new LinkedList(); list = HgCommand.doIncomingForSearch(root, toRevision, bShowMerges, logger); - processLogMessages(list, messages); + processLogMessages(rootUrl, list, messages); } catch (HgException ex) { NotifyDescriptor.Exception e = new NotifyDescriptor.Exception(ex); @@ -890,7 +895,7 @@ public class HgCommand { List list = new LinkedList(); list = HgCommand.doOutForSearch(root, toRevision, bShowMerges, logger); - processLogMessages(list, messages); + processLogMessages(rootUrl, list, messages); } catch (HgException ex) { NotifyDescriptor.Exception e = new NotifyDescriptor.Exception(ex); @@ -948,7 +953,7 @@ public class HgCommand { list = HgCommand.doLogForHistory(root, files != null ? new ArrayList(files) : null, fromRevision, toRevision, headRev, bShowMerges, bGetFileInfo, limit, logger); - processLogMessages(list, messages); + processLogMessages(rootUrl, list, messages); } catch (HgException ex) { NotifyDescriptor.Exception e = new NotifyDescriptor.Exception(ex); DialogDisplayer.getDefault().notifyLater(e); @@ -1558,6 +1563,56 @@ public class HgCommand { if (prevFile != null) { doCat(repository, prevFile, outFile, revision, false, logger); //NOI18N } + } + } + + /** + * Get common ancestor for two provided revisions. + * + * @param root for the mercurial repository + * @param first rev to get ancestor for + * @param second rev to get ancestor for + * @param output logger + * @return void + * @throws org.netbeans.modules.mercurial.HgException + */ + public static String getCommonAncestor(String rootURL, String rev1, String rev2, OutputLogger logger) throws HgException { + String res = getCommonAncestor(rootURL, rev1, rev2, false, logger); + if( res == null){ + res = getCommonAncestor(rootURL, rev1, rev2, true, logger); + } + return res; + } + + private static String getCommonAncestor(String rootURL, String rev1, String rev2, boolean bUseIndex, OutputLogger logger) throws HgException { + if (rootURL == null ) return null; + List command = new ArrayList(); + + command.add(getHgCommand()); + command.add(HG_COMMONANCESTOR_CMD); + if(bUseIndex){ + command.add(".hg/store/00changelog.i"); //NOI18N + } + command.add(rev1); + command.add(rev2); + command.add(HG_OPT_REPOSITORY); + command.add(rootURL); + command.add(HG_OPT_CWD_CMD); + command.add(rootURL); + + List list = exec(command); + if (!list.isEmpty()){ + String splits[] = list.get(0).split(":"); // NOI18N + String tmp = splits != null && splits.length >= 1 ? splits[0]: null; + int tmpRev = -1; + try{ + tmpRev = Integer.parseInt(tmp); + }catch(NumberFormatException ex){ + // Ignore + } + return tmpRev > -1? tmp: null; + }else{ + return null; } }