add -d and -s to show/set default paths

TK Soh teekaysoh at yahoo.com
Mon Sep 5 00:52:31 CDT 2005


Thought it should be more convient than having to manually edit hgrc, and user
shouldn't need to be aware that symbolic name 'default' carries a special
meaning. Though I seemed to recall Matt saying it's bad to have Hg editing the
file.

The code to change default path was taken from Bryan's recent fix on multiple
paths section.

# HG changeset patch
# User TK Soh <teekaysoh at yahoo.com>
# Node ID c819754541d883229cc95f3d939e5a7ef2325095
# Parent  4003ea6586934cb217db164e3e100d938f271e67
paths: add -d and -s options to show/set default paths

diff -r 4003ea658693 -r c819754541d8 doc/hg.1.txt
--- a/doc/hg.1.txt	Sun Sep  4 22:47:59 2005
+++ b/doc/hg.1.txt	Mon Sep  5 05:49:40 2005
@@ -343,12 +343,16 @@
 parents::
     Print the working directory's parent revisions.
 
-paths [NAME]::
+paths [-d] [-s PATH] [NAME]::
     Show definition of symbolic path name NAME. If no name is given, show
     definition of available names.
 
     Path names are defined in the [paths] section of /etc/mercurial/hgrc
     and $HOME/.hgrc.  If run inside a repository, .hg/hgrc is used, too.
+
+    options:
+    -d  --default           show default repo path
+    -s, --set-default PATH  set default repo to PATH
 
 pull <repository path>::
     Pull changes from a remote repository to a local one.
diff -r 4003ea658693 -r c819754541d8 mercurial/commands.py
--- a/mercurial/commands.py	Sun Sep  4 22:47:59 2005
+++ b/mercurial/commands.py	Mon Sep  5 05:49:40 2005
@@ -1201,19 +1201,43 @@
         if n != nullid:
             show_changeset(ui, repo, changenode=n)
 
-def paths(ui, search=None):
+def paths(ui, search=None, **opts):
     """show definition of symbolic path names"""
+    repo = None
     try:
         repo = hg.repository(ui=ui)
     except hg.RepoError:
         pass
+
+    if opts['set_default']:
+        if not repo:
+            ui.warn("must be inside a repo to set default paths.\n")
+            return 1
+        source = ui.expandpath(opts['set_default'])
+        abspath = os.path.abspath(source)
+        cfg = ConfigParser.SafeConfigParser()
+        try:
+            fp = repo.opener('hgrc', 'r')
+            os.unlink(fp.name)
+            cfg.readfp(fp)
+        except IOError, inst:
+            if inst.errno != errno.ENOENT: raise
+        if not cfg.has_section('paths'): cfg.add_section('paths')
+        cfg.set('paths', 'default', abspath)
+        cfg.write(repo.opener('hgrc', 'w'))
+        return
+    elif opts['default']:
+        if not repo:
+            ui.warn("must be inside a repo to query default paths.\n")
+            return 1
+        search = 'default'
 
     if search:
         for name, path in ui.configitems("paths"):
             if name == search:
                 ui.write("%s\n" % path)
                 return
-        ui.warn("not found!\n")
+        ui.warn("can't find %s in [paths] section!\n" % search)
         return 1
     else:
         for name, path in ui.configitems("paths"):
@@ -1713,7 +1737,10 @@
          [('p', 'patch', None, 'show patch')],
          'hg outgoing [-p] [DEST]'),
     "parents": (parents, [], 'hg parents [REV]'),
-    "paths": (paths, [], 'hg paths [NAME]'),
+    "paths": (paths, 
+         [('d', 'default', None, 'show default repo path'),
+          ('s', 'set-default', "", 'set default repo path')],
+         'hg paths [-d] [-s PATH] [NAME]'),
     "^pull":
         (pull,
          [('u', 'update', None, 'update working directory'),



	
		
______________________________________________________
Click here to donate to the Hurricane Katrina relief effort.
http://store.yahoo.com/redcross-donate3/


More information about the Mercurial mailing list