# HG changeset patch # User jrice@netbeans.org # Date 1201733440 0 # Node ID d28df42b4215259cc4c494574edc8ba518ab6b43 # Parent 2bfe3308b32071a2e7abef43cb85094350d31491 #125704: Support for Fetch Extension - also prompts user and modifies ~/.hgrc if fecth extension not there diff -r 2bfe3308b320 -r d28df42b4215 mercurial/src/org/netbeans/modules/mercurial/Bundle.properties --- a/mercurial/src/org/netbeans/modules/mercurial/Bundle.properties Wed Jan 30 19:17:18 2008 +0000 +++ b/mercurial/src/org/netbeans/modules/mercurial/Bundle.properties Wed Jan 30 22:50:40 2008 +0000 @@ -104,14 +104,15 @@ CTL_PopupMenuItem_ExportDiff = E&xport D CTL_PopupMenuItem_ExportDiff = E&xport Diff... CTL_PopupMenuItem_ImportDiff = Im&port Patches... CTL_PopupMenuItem_Ignore = &Toggle Ignore +CTL_PopupMenuItem_FetchLocal = &Fetch CTL_PopupMenuItem_PushOther = Pu&sh Other... CTL_PopupMenuItem_PushLocal = Push &to - default CTL_PopupMenuItem_PullOther = Pu&ll Other... -CTL_PopupMenuItem_PullLocal = Pull &from - default +CTL_PopupMenuItem_PullLocal = Pull f&rom - default CTL_PopupMenuItem_Rollback = Rollbac&k CTL_PopupMenuItem_Revert = Re&vert Modifications CTL_PopupMenuItem_Merge = M&erge -CTL_PopupMenuItem_Resolve = &Resolve Conflicts +CTL_PopupMenuItem_Resolve = Resolve Confl&icts CTL_PopupMenuItem_MarkResolved = M&ark as Resolved CTL_PopupMenuItem_Log = Show Histor&y diff -r 2bfe3308b320 -r d28df42b4215 mercurial/src/org/netbeans/modules/mercurial/MercurialAnnotator.java --- a/mercurial/src/org/netbeans/modules/mercurial/MercurialAnnotator.java Wed Jan 30 19:17:18 2008 +0000 +++ b/mercurial/src/org/netbeans/modules/mercurial/MercurialAnnotator.java Wed Jan 30 22:50:40 2008 +0000 @@ -72,6 +72,7 @@ import org.netbeans.modules.mercurial.ui import org.netbeans.modules.mercurial.ui.log.LogAction; import org.netbeans.modules.mercurial.ui.merge.MergeAction; import org.netbeans.modules.mercurial.ui.properties.PropertiesAction; +import org.netbeans.modules.mercurial.ui.pull.FetchAction; import org.netbeans.modules.mercurial.ui.pull.PullAction; import org.netbeans.modules.mercurial.ui.pull.PullOtherAction; import org.netbeans.modules.mercurial.ui.push.PushAction; @@ -363,6 +364,8 @@ public class MercurialAnnotator extends actions.add(new PullOtherAction(loc.getString("CTL_PopupMenuItem_PullOther"), ctx)); // NOI18N actions.add(new MergeAction(NbBundle.getMessage(MercurialAnnotator.class, "CTL_PopupMenuItem_Merge"), ctx)); // NOI18N actions.add(null); + actions.add(new FetchAction(NbBundle.getMessage(MercurialAnnotator.class, "CTL_PopupMenuItem_FetchLocal"), ctx)); // NOI18N + actions.add(null); AnnotateAction tempA = new AnnotateAction(loc.getString("CTL_PopupMenuItem_ShowAnnotations"), ctx); // NOI18N if (tempA.visible(nodes)) { tempA = new AnnotateAction(loc.getString("CTL_PopupMenuItem_HideAnnotations"), ctx); // NOI18N @@ -398,6 +401,9 @@ public class MercurialAnnotator extends "CTL_PopupMenuItem_PullLocal"), ctx)); // NOI18N actions.add(new MergeAction(NbBundle.getMessage(MercurialAnnotator.class, "CTL_PopupMenuItem_Merge"), ctx)); // NOI18N + actions.add(null); + actions.add(new FetchAction(NbBundle.getMessage(MercurialAnnotator.class, + "CTL_PopupMenuItem_FetchLocal"), ctx)); // NOI18N actions.add(null); if (!onlyFolders) { diff -r 2bfe3308b320 -r d28df42b4215 mercurial/src/org/netbeans/modules/mercurial/config/HgConfigFiles.java --- a/mercurial/src/org/netbeans/modules/mercurial/config/HgConfigFiles.java Wed Jan 30 19:17:18 2008 +0000 +++ b/mercurial/src/org/netbeans/modules/mercurial/config/HgConfigFiles.java Wed Jan 30 22:50:40 2008 +0000 @@ -47,13 +47,9 @@ import java.io.BufferedOutputStream; import java.io.BufferedOutputStream; import java.io.FileOutputStream; import java.io.IOException; -import java.util.ArrayList; import java.util.Iterator; -import java.util.List; import java.util.Set; import java.util.Properties; -import java.util.StringTokenizer; -import java.util.prefs.Preferences; import java.util.logging.Level; import org.ini4j.Ini; import org.netbeans.modules.mercurial.Mercurial; @@ -69,6 +65,14 @@ public class HgConfigFiles { public class HgConfigFiles { public static final String HG_EXTENSIONS = "extensions"; // NOI18N public static final String HG_EXTENSIONS_HGK = "hgext.hgk"; // NOI18N + public static final String HG_EXTENSIONS_FETCH = "fetch"; // NOI18N + public static final String HG_UI_SECTION = "ui"; // NOI18N + public static final String HG_USERNAME = "username"; // NOI18N + public static final String HG_PATHS_SECTION = "paths"; // NOI18N + public static final String HG_DEFAULT_PUSH = "default-push"; // NOI18N + public static final String HG_DEFAULT_PUSH_VALUE = "default-push"; // NOI18N + public static final String HG_DEFAULT_PULL = "default-pull"; // NOI18N + public static final String HG_DEFAULT_PULL_VALUE = "default"; // NOI18N /** The HgConfigFiles instance for user and system defaults */ private static HgConfigFiles instance; @@ -79,17 +83,18 @@ public class HgConfigFiles { /** The repository directory if this instance is for a repository */ private File dir; - private static final String UNIX_CONFIG_DIR = ".hg/"; // NOI18N private static final String WINDOWS_USER_APPDATA = getAPPDATA(); private static final String WINDOWS_CONFIG_DIR = WINDOWS_USER_APPDATA + "\\Mercurial"; // NOI18N private static final String WINDOWS_GLOBAL_CONFIG_DIR = getGlobalAPPDATA() + "\\Mercurial"; // NOI18N + private static final String HG_RC_FILE = "hgrc"; // NOI18N + private static final String HG_REPO_DIR = ".hg"; // NOI18N /** * Creates a new instance */ private HgConfigFiles() { // get the system hgrc file - hgrc = loadFile("hgrc"); // NOI18N + hgrc = loadFile(HG_RC_FILE); } /** @@ -106,22 +111,28 @@ public class HgConfigFiles { public HgConfigFiles(File file) { dir = file; - hgrc = loadFile(file, "hgrc"); // NOI18N + hgrc = loadFile(file, HG_RC_FILE); } - + public void setProperty(String name, String value) { - if (name.equals("username")) { // NOI18N - setProperty("ui", "username", value); // NOI18N - } else if (name.equals("default-push")) { // NOI18N - setProperty("paths", "default-push", value); // NOI18N - } else if (name.equals("default-pull")) { // NOI18N - setProperty("paths", "default", value); // NOI18N - } else if (name.equals("hgext.hgk")) { // NOI18N + if (name.equals(HG_USERNAME)) { + setProperty(HG_UI_SECTION, HG_USERNAME, value); + } else if (name.equals(HG_DEFAULT_PUSH)) { + setProperty(HG_PATHS_SECTION, HG_DEFAULT_PUSH_VALUE, value); + } else if (name.equals(HG_DEFAULT_PULL)) { + setProperty(HG_PATHS_SECTION, HG_DEFAULT_PULL_VALUE, value); + } else if (name.equals(HG_EXTENSIONS_HGK)) { // Allow hgext.hgk to be set to some other user defined value if required - if(getProperty("extensions", "hgext.hgk").equals("")){ // NOI18N - setProperty("extensions", "hgext.hgk", value, true); // NOI18N + if(getProperty(HG_EXTENSIONS, HG_EXTENSIONS_HGK).equals("")){ + setProperty(HG_EXTENSIONS, HG_EXTENSIONS_HGK, value, true); + } + } else if (name.equals(HG_EXTENSIONS_FETCH)) { + // Allow fetch to be set to some other user defined value if required + if(getProperty(HG_EXTENSIONS, HG_EXTENSIONS_FETCH).equals("")){ + setProperty(HG_EXTENSIONS, HG_EXTENSIONS_FETCH, value, true); } } + } public void setProperty(String section, String name, String value, boolean allowEmpty) { @@ -136,7 +147,7 @@ public class HgConfigFiles { Ini.Section inisection = getSection(hgrc, section, true); inisection.put(name, value); } - storeIni(hgrc, "hgrc"); // NOI18N + storeIni(hgrc, HG_RC_FILE); } public void setProperty(String section, String name, String value) { @@ -144,7 +155,7 @@ public class HgConfigFiles { } public void setUserName(String value) { - setProperty("ui", "username", value); // NOI18N + setProperty(HG_UI_SECTION, HG_USERNAME, value); } public String getUserName() { @@ -167,7 +178,7 @@ public class HgConfigFiles { Ini.Section inisection = getSection(hgrc, section, false); if (inisection != null) { inisection.clear(); - storeIni(hgrc, "hgrc"); // NOI18N + storeIni(hgrc, HG_RC_FILE); } } @@ -175,7 +186,7 @@ public class HgConfigFiles { Ini.Section inisection = getSection(hgrc, section, false); if (inisection != null) { inisection.remove(name); - storeIni(hgrc, "hgrc"); // NOI18N + storeIni(hgrc, HG_RC_FILE); } } @@ -183,16 +194,16 @@ public class HgConfigFiles { if (reload) { doReload(); } - return getProperty("paths", "default"); // NOI18N + return getProperty(HG_PATHS_SECTION, HG_DEFAULT_PULL_VALUE); } public String getDefaultPush(Boolean reload) { if (reload) { doReload(); } - String value = getProperty("paths", "default-push"); // NOI18N + String value = getProperty(HG_PATHS_SECTION, HG_DEFAULT_PUSH); if (value.length() == 0) { - value = getProperty("paths", "default"); // NOI18N + value = getProperty(HG_PATHS_SECTION, HG_DEFAULT_PULL_VALUE); } return value; } @@ -201,7 +212,7 @@ public class HgConfigFiles { if (reload) { doReload(); } - return getProperty("ui", "username"); // NOI18N + return getProperty(HG_UI_SECTION, HG_USERNAME); } public String getProperty(String section, String name) { @@ -217,9 +228,9 @@ public class HgConfigFiles { private void doReload () { if (dir == null) { - hgrc = loadFile("hgrc"); // NOI18N + hgrc = loadFile(HG_RC_FILE); } else { - hgrc = loadFile(dir, "hgrc"); // NOI18N + hgrc = loadFile(dir, HG_RC_FILE); } } @@ -235,7 +246,7 @@ public class HgConfigFiles { try { String filePath; if (dir != null) { - filePath = dir.getAbsolutePath() + File.separator + ".hg" + File.separator + iniFile; // NOI18N + filePath = dir.getAbsolutePath() + File.separator + HG_REPO_DIR + File.separator + iniFile; // NOI18N } else { filePath = getUserConfigPath() + iniFile; } @@ -264,7 +275,7 @@ public class HgConfigFiles { } private Ini loadFile(File dir, String fileName) { - String filePath = dir.getAbsolutePath() + File.separator + ".hg" + File.separator + fileName; // NOI18N + String filePath = dir.getAbsolutePath() + File.separator + HG_REPO_DIR + File.separator + fileName; // NOI18N File file = FileUtil.normalizeFile(new File(filePath)); Ini system = null; try { diff -r 2bfe3308b320 -r d28df42b4215 mercurial/src/org/netbeans/modules/mercurial/ui/pull/Bundle.properties --- a/mercurial/src/org/netbeans/modules/mercurial/ui/pull/Bundle.properties Wed Jan 30 19:17:18 2008 +0000 +++ b/mercurial/src/org/netbeans/modules/mercurial/ui/pull/Bundle.properties Wed Jan 30 22:50:40 2008 +0000 @@ -73,3 +73,15 @@ MSG_PULL_LOCALMODS_CONFIRM_TITLE = Confi MSG_PULL_LOCALMODS_CONFIRM_TITLE = Confirm Pull with Local Modifications MSG_PULL_LOCALMODS_CANCEL = INFO Pull cancelled by user as there are conflict/locally modified/new file(s). MSG_PULL_OVERWRITE_LOCAL = WARNING Pull will overwrite the following conflict/locally modified/new file(s): + +MSG_FETCH_TITLE = Mercurial Fetch +MSG_FETCH_TITLE_SEP = --------------- +MSG_FETCH_LAUNCH_INFO = INFO: Running Fetch for {0} +MSG_FETCH_PROGRESS = Fetching... + +MSG_FETCH_SETFETCH_PROP_CONFIRM_TITLE = Add Fetch Extension +MSG_FETCH_SETFETCH_PROP_CONFIRM_QUERY= To work fetch requires the Fetch extension to be added to your .hgrc config file.\n\nDo you want this extension added now? +MSG_FETCH_SETHGK_PROP_DO_INFO = INFO: Setting fetch in your .hgrc config file +MSG_FETCH_NOTSETHGK_PROP_INFO = INFO: fetch not set in your .hgrc config file, so Fetch can not be run + +MSG_FETCH_DONE = INFO: End of Mercurial Fetch diff -r 2bfe3308b320 -r d28df42b4215 mercurial/src/org/netbeans/modules/mercurial/ui/pull/FetchAction.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mercurial/src/org/netbeans/modules/mercurial/ui/pull/FetchAction.java Wed Jan 30 22:50:40 2008 +0000 @@ -0,0 +1,145 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * Contributor(s): + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun + * Microsystems, Inc. All Rights Reserved. + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + */ +package org.netbeans.modules.mercurial.ui.pull; + +import org.netbeans.modules.mercurial.ui.view.*; +import org.netbeans.modules.versioning.spi.VCSContext; +import org.netbeans.modules.mercurial.Mercurial; +import org.netbeans.modules.mercurial.HgException; +import org.netbeans.modules.mercurial.util.HgCommand; +import org.netbeans.modules.mercurial.util.HgUtils; +import org.openide.DialogDisplayer; +import org.openide.NotifyDescriptor; +import org.openide.util.RequestProcessor; + +import java.io.File; +import javax.swing.*; +import java.awt.event.ActionEvent; +import java.util.List; +import org.netbeans.modules.mercurial.HgProgressSupport; +import org.netbeans.modules.mercurial.config.HgConfigFiles; +import org.openide.util.NbBundle; + +/** + * Fetch action for mercurial: + * hg fetch - launch hg view to view the dependency tree for the repository + * Pull changes from a remote repository, merge new changes if needed. + * This finds all changes from the repository at the specified path + * or URL and adds them to the local repository. + * + * If the pulled changes add a new head, the head is automatically + * merged, and the result of the merge is committed. Otherwise, the + * working directory is updated. + * + * @author John Rice + */ +public class FetchAction extends AbstractAction { + + private final VCSContext context; + + public FetchAction(String name, VCSContext context) { + this.context = context; + putValue(Action.NAME, name); + } + + public void actionPerformed(ActionEvent e) { + if(!Mercurial.getInstance().isGoodVersionAndNotify()) return; + final File root = HgUtils.getRootFile(context); + if (root == null) return; + + RequestProcessor rp = Mercurial.getInstance().getRequestProcessor(root); + HgProgressSupport support = new HgProgressSupport() { + public void perform() { performFetch(root); } }; + + support.start(rp, root.getAbsolutePath(), org.openide.util.NbBundle.getMessage(FetchAction.class, "MSG_FETCH_PROGRESS")); // NOI18N + } + + static void performFetch(File root) { + try { + HgUtils.outputMercurialTabInRed(NbBundle.getMessage(FetchAction.class, "MSG_FETCH_TITLE")); // NOI18N + HgUtils.outputMercurialTabInRed(NbBundle.getMessage(FetchAction.class, "MSG_FETCH_TITLE_SEP")); // NOI18N + + boolean bFetchPropExists = HgConfigFiles.getInstance().containsProperty( + HgConfigFiles.HG_EXTENSIONS, HgConfigFiles.HG_EXTENSIONS_FETCH); + + if(!bFetchPropExists){ + boolean bConfirmSetFetchProp = false; + bConfirmSetFetchProp = HgUtils.confirmDialog( + FetchAction.class, "MSG_FETCH_SETFETCH_PROP_CONFIRM_TITLE", // NOI18N + "MSG_FETCH_SETFETCH_PROP_CONFIRM_QUERY"); // NOI18N + if (bConfirmSetFetchProp) { + HgUtils.outputMercurialTabInRed( + NbBundle.getMessage(FetchAction.class, "MSG_FETCH_SETHGK_PROP_DO_INFO")); // NOI18N + HgConfigFiles.getInstance().setProperty(HgConfigFiles.HG_EXTENSIONS_FETCH, ""); // NOI18N + }else{ + HgUtils.outputMercurialTabInRed( + NbBundle.getMessage(FetchAction.class, "MSG_FETCH_NOTSETHGK_PROP_INFO")); // NOI18N + HgUtils.outputMercurialTab(""); // NOI18N + return; + } + } + + HgUtils.outputMercurialTabInRed(NbBundle.getMessage(FetchAction.class, + "MSG_FETCH_LAUNCH_INFO", root.getAbsolutePath())); // NOI18N + + List list; + list = HgCommand.doFetch(root); + + if (list != null && !list.isEmpty()) { + HgUtils.outputMercurialTab(list); + } + } catch (HgException ex) { + NotifyDescriptor.Exception e = new NotifyDescriptor.Exception(ex); + DialogDisplayer.getDefault().notifyLater(e); + }finally{ + HgUtils.outputMercurialTabInRed(NbBundle.getMessage(FetchAction.class, "MSG_FETCH_DONE")); // NOI18N + HgUtils.outputMercurialTab(""); // NOI18N + } + } + + public boolean isEnabled() { + File root = HgUtils.getRootFile(context); + if (root == null) + return false; + else + return true; + } +} diff -r 2bfe3308b320 -r d28df42b4215 mercurial/src/org/netbeans/modules/mercurial/ui/view/Bundle.properties --- a/mercurial/src/org/netbeans/modules/mercurial/ui/view/Bundle.properties Wed Jan 30 19:17:18 2008 +0000 +++ b/mercurial/src/org/netbeans/modules/mercurial/ui/view/Bundle.properties Wed Jan 30 22:50:40 2008 +0000 @@ -45,7 +45,7 @@ MSG_VIEW_HGK_NOT_FOUND_TITLE = Hgk not f MSG_VIEW_HGK_NOT_FOUND_TITLE = Hgk not found MSG_VIEW_HGK_NOT_FOUND_INFO = INFO: hgk is not on your PATH, please install hgk or if installed, modify your PATH MSG_VIEW_SETHGK_PROP_CONFIRM_TITLE = Add Hgk Extension -MSG_VIEW_SETHGK_PROP_CONFIRM_QUERY = To work View requires the hgk extension to be added to your ~/.hgrc.\n\nDo you want this extension added now? -MSG_VIEW_SETHGK_PROP_DO_INFO = INFO: Setting hgkext.hgk in ~/.hgrc +MSG_VIEW_SETHGK_PROP_CONFIRM_QUERY = To work View requires the hgk extension to be added to your .hgrc config file.\n\nDo you want this extension added now? +MSG_VIEW_SETHGK_PROP_DO_INFO = INFO: Setting hgkext.hgk in your .hgrc config file -MSG_VIEW_NOTSETHGK_PROP_INFO = INFO: hgkext.hgk not set in ~/.hgrc so View can not be launched +MSG_VIEW_NOTSETHGK_PROP_INFO = INFO: hgkext.hgk not set in your .hgrc config file, so View can not be launched diff -r 2bfe3308b320 -r d28df42b4215 mercurial/src/org/netbeans/modules/mercurial/util/HgCommand.java --- a/mercurial/src/org/netbeans/modules/mercurial/util/HgCommand.java Wed Jan 30 19:17:18 2008 +0000 +++ b/mercurial/src/org/netbeans/modules/mercurial/util/HgCommand.java Wed Jan 30 22:50:40 2008 +0000 @@ -201,6 +201,7 @@ public class HgCommand { private static final String HG_OUTGOING_CMD = "outgoing"; // NOI18N private static final String HG_VIEW_CMD = "view"; // NOI18N private static final String HG_VERBOSE_CMD = "-v"; // NOI18N + private static final String HG_FETCH_CMD = "fetch"; // NOI18N private static final String HG_MERGE_NEEDED_ERR = "(run 'hg heads' to see heads, 'hg merge' to merge)"; // NOI18N public static final String HG_MERGE_CONFLICT_ERR = "conflicts detected in "; // NOI18N @@ -594,7 +595,32 @@ public class HgCommand { } return list; } + + /** + * Run the fetch extension for the specified repository + * + * @param File repository of the mercurial repository's root directory + * @throws org.netbeans.modules.mercurial.HgException + */ + public static List doFetch(File repository) throws HgException { + if (repository == null) return null; + List command = new ArrayList(); + command.add(getHgCommand()); + command.add(HG_FETCH_CMD); + command.add(HG_OPT_REPOSITORY); + command.add(repository.getAbsolutePath()); + + List list; + list = exec(command); + + if (!list.isEmpty()) { + if (isErrorAbort(list.get(list.size() -1))) { + handleError(command, list, NbBundle.getMessage(HgCommand.class, "MSG_COMMAND_ABORTED")); + } + } + return list; + } public static HgLogMessage[] getLogMessages(final String rootUrl, final Set files, String fromRevision, String toRevision) { final List messages = new ArrayList(0);