make all commands be repo-wide by default
authorBenoit Boissinot <benoit.boissinot@ens-lyon.org>
Thu, 01 Dec 2005 10:51:45 -0600
changeset 1568 1d7d0c07e8f3
parent 1567 b4956bbbadc9
child 1569 dd186cb70a64
child 1572 385b8872b8e3
child 1582 63799b01985c
make all commands be repo-wide by default - refactor code in commands.py so that: if no pattern is given, the command will be repo-wide else it will work on the working dir - update the doc - fix the tests
mercurial/commands.py
tests/test-help.out
tests/test-hgignore
tests/test-walk
--- a/mercurial/commands.py	Thu Dec 01 10:51:33 2005 -0600
+++ b/mercurial/commands.py	Thu Dec 01 10:51:45 2005 -0600
@@ -33,13 +33,17 @@
         return [util.normpath(os.path.join(cwd, x)) for x in args]
     return args
 
-def matchpats(repo, cwd, pats=[], opts={}, head=''):
+def matchpats(repo, pats=[], opts={}, head=''):
+    cwd = repo.getcwd()
+    if not pats and cwd:
+        opts['include'] = [os.path.join(cwd, i) for i in opts['include']]
+        opts['exclude'] = [os.path.join(cwd, x) for x in opts['exclude']]
+        cwd = ''
     return util.cmdmatcher(repo.root, cwd, pats or ['.'], opts.get('include'),
-                        opts.get('exclude'), head)
+                        opts.get('exclude'), head) + (cwd,)
 
 def makewalk(repo, pats, opts, head=''):
-    cwd = repo.getcwd()
-    files, matchfn, anypats = matchpats(repo, cwd, pats, opts, head)
+    files, matchfn, anypats, cwd = matchpats(repo, pats, opts, head)
     exact = dict(zip(files, files))
     def walk():
         for src, fn in repo.walk(files=files, match=matchfn):
@@ -51,7 +55,7 @@
     for r in results:
         yield r
 
-def walkchangerevs(ui, repo, cwd, pats, opts):
+def walkchangerevs(ui, repo, pats, opts):
     '''Iterate over files and the revs they changed in.
 
     Callers most commonly need to iterate backwards over the history
@@ -81,12 +85,7 @@
     if repo.changelog.count() == 0:
         return [], False
 
-    cwd = repo.getcwd()
-    if not pats and cwd:
-        opts['include'] = [os.path.join(cwd, i) for i in opts['include']]
-        opts['exclude'] = [os.path.join(cwd, x) for x in opts['exclude']]
-    files, matchfn, anypats = matchpats(repo, (pats and cwd) or '',
-                                        pats, opts)
+    files, matchfn, anypats, cwd = matchpats(repo, pats, opts)
     revs = map(int, revrange(ui, repo, opts['rev'] or ['tip:0']))
     wanted = {}
     slowpath = anypats
@@ -483,8 +482,7 @@
 
     The files will be added to the repository at the next commit.
 
-    If no names are given, add all files in the current directory and
-    its subdirectories.
+    If no names are given, add all files in the repository.
     """
 
     names = []
@@ -759,7 +757,7 @@
     Commit changes to the given files into the repository.
 
     If a list of files is omitted, all changes reported by "hg status"
-    from the root of the repository will be commited.
+    will be commited.
 
     The HGEDITOR or EDITOR environment variables are used to start an
     editor to add a commit comment.
@@ -782,12 +780,7 @@
 
     if opts['addremove']:
         addremove(ui, repo, *pats, **opts)
-    cwd = repo.getcwd()
-    if not pats and cwd:
-        opts['include'] = [os.path.join(cwd, i) for i in opts['include']]
-        opts['exclude'] = [os.path.join(cwd, x) for x in opts['exclude']]
-    fns, match, anypats = matchpats(repo, (pats and repo.getcwd()) or '',
-                                    pats, opts)
+    fns, match, anypats, cwd = matchpats(repo, pats, opts)
     if pats:
         c, a, d, u = repo.changes(files=fns, match=match)
         files = c + a + [fn for fn in d if repo.dirstate.state(fn) == 'r']
@@ -1097,7 +1090,7 @@
         ui.write("%s\n" % line.rstrip())
 
 def diff(ui, repo, *pats, **opts):
-    """diff working directory (or selected files)
+    """diff repository (or selected files)
 
     Show differences between revisions for the specified files.
 
@@ -1123,7 +1116,7 @@
     if len(revs) > 2:
         raise util.Abort(_("too many revisions to diff"))
 
-    fns, matchfn, anypats = matchpats(repo, repo.getcwd(), pats, opts)
+    fns, matchfn, anypats, cwd = matchpats(repo, pats, opts)
 
     dodiff(sys.stdout, ui, repo, node1, node2, fns, match=matchfn,
            text=opts['text'])
@@ -1294,7 +1287,7 @@
 
     fstate = {}
     skip = {}
-    changeiter, getchange = walkchangerevs(ui, repo, repo.getcwd(), pats, opts)
+    changeiter, getchange = walkchangerevs(ui, repo, pats, opts)
     count = 0
     incrementing = False
     for st, rev, fns in changeiter:
@@ -1557,12 +1550,7 @@
                 self.write(*args)
         def __getattr__(self, key):
             return getattr(self.ui, key)
-    cwd = repo.getcwd()
-    if not pats and cwd:
-        opts['include'] = [os.path.join(cwd, i) for i in opts['include']]
-        opts['exclude'] = [os.path.join(cwd, x) for x in opts['exclude']]
-    changeiter, getchange = walkchangerevs(ui, repo, (pats and cwd) or '',
-                                           pats, opts)
+    changeiter, getchange = walkchangerevs(ui, repo, pats, opts)
     for st, rev, fns in changeiter:
         if st == 'window':
             du = dui(ui)
@@ -1871,13 +1859,12 @@
 
     If names are given, all files matching the names are reverted.
 
-    If no names are given, all files in the current directory and
-    its subdirectories are reverted.
+    If no arguments are given, all files in the repository are reverted.
     """
     node = opts['rev'] and repo.lookup(opts['rev']) or \
            repo.dirstate.parents()[0]
 
-    files, choose, anypats = matchpats(repo, repo.getcwd(), pats, opts)
+    files, choose, anypats, cwd = matchpats(repo, pats, opts)
     (c, a, d, u) = repo.changes(match=choose)
     repo.forget(a)
     repo.undelete(d)
@@ -2000,9 +1987,8 @@
 def status(ui, repo, *pats, **opts):
     """show changed files in the working directory
 
-    Show changed files in the working directory.  If no names are
-    given, all files are shown.  Otherwise, only files matching the
-    given names are shown.
+    Show changed files in the repository.  If names are
+    given, only files that match are shown.
 
     The codes used to show the status of files are:
     M = modified
@@ -2011,8 +1997,7 @@
     ? = not tracked
     """
 
-    cwd = repo.getcwd()
-    files, matchfn, anypats = matchpats(repo, cwd, pats, opts)
+    files, matchfn, anypats, cwd = matchpats(repo, pats, opts)
     (c, a, d, u) = [[util.pathto(cwd, x) for x in n]
                     for n in repo.changes(files=files, match=matchfn)]
 
--- a/tests/test-help.out	Thu Dec 01 10:51:33 2005 -0600
+++ b/tests/test-help.out	Thu Dec 01 10:51:45 2005 -0600
@@ -6,7 +6,7 @@
  annotate   show changeset information per file line
  clone      make a copy of an existing repository
  commit     commit the specified files or all outstanding changes
- diff       diff working directory (or selected files)
+ diff       diff repository (or selected files)
  export     dump the header and diffs for one or more changesets
  init       create a new repository in the given directory
  log        show revision history of entire repository or files
@@ -22,7 +22,7 @@
  annotate   show changeset information per file line
  clone      make a copy of an existing repository
  commit     commit the specified files or all outstanding changes
- diff       diff working directory (or selected files)
+ diff       diff repository (or selected files)
  export     dump the header and diffs for one or more changesets
  init       create a new repository in the given directory
  log        show revision history of entire repository or files
@@ -46,7 +46,7 @@
  clone       make a copy of an existing repository
  commit      commit the specified files or all outstanding changes
  copy        mark files as copied for the next commit
- diff        diff working directory (or selected files)
+ diff        diff repository (or selected files)
  export      dump the header and diffs for one or more changesets
  forget      don't add the specified files on the next commit
  grep        search for a pattern in specified files and revisions
@@ -88,7 +88,7 @@
  clone       make a copy of an existing repository
  commit      commit the specified files or all outstanding changes
  copy        mark files as copied for the next commit
- diff        diff working directory (or selected files)
+ diff        diff repository (or selected files)
  export      dump the header and diffs for one or more changesets
  forget      don't add the specified files on the next commit
  grep        search for a pattern in specified files and revisions
@@ -130,8 +130,7 @@
 
     The files will be added to the repository at the next commit.
 
-    If no names are given, add all files in the current directory and
-    its subdirectories.
+    If no names are given, add all files in the repository.
 
 options:
 
@@ -146,8 +145,7 @@
 
     The files will be added to the repository at the next commit.
 
-    If no names are given, add all files in the current directory and
-    its subdirectories.
+    If no names are given, add all files in the repository.
 
 options:
 
@@ -155,7 +153,7 @@
  -X --exclude  exclude names matching the given patterns
 hg diff [-a] [-I] [-X] [-r REV1 [-r REV2]] [FILE]...
 
-diff working directory (or selected files)
+diff repository (or selected files)
 
     Show differences between revisions for the specified files.
 
@@ -181,9 +179,8 @@
 
 show changed files in the working directory
 
-    Show changed files in the working directory.  If no names are
-    given, all files are shown.  Otherwise, only files matching the
-    given names are shown.
+    Show changed files in the repository.  If names are
+    given, only files that match are shown.
 
     The codes used to show the status of files are:
     M = modified
@@ -215,7 +212,7 @@
  annotate   show changeset information per file line
  clone      make a copy of an existing repository
  commit     commit the specified files or all outstanding changes
- diff       diff working directory (or selected files)
+ diff       diff repository (or selected files)
  export     dump the header and diffs for one or more changesets
  init       create a new repository in the given directory
  log        show revision history of entire repository or files
@@ -236,7 +233,7 @@
  annotate   show changeset information per file line
  clone      make a copy of an existing repository
  commit     commit the specified files or all outstanding changes
- diff       diff working directory (or selected files)
+ diff       diff repository (or selected files)
  export     dump the header and diffs for one or more changesets
  init       create a new repository in the given directory
  log        show revision history of entire repository or files
--- a/tests/test-hgignore	Thu Dec 01 10:51:33 2005 -0600
+++ b/tests/test-hgignore	Thu Dec 01 10:51:45 2005 -0600
@@ -42,4 +42,4 @@
 echo "--" ; hg status
 
 cd dir
-echo "--" ; hg status
+echo "--" ; hg status .
--- a/tests/test-walk	Thu Dec 01 10:51:33 2005 -0600
+++ b/tests/test-walk	Thu Dec 01 10:51:45 2005 -0600
@@ -20,14 +20,14 @@
 hg commit -m "commit #0" -d "0 0"
 hg debugwalk
 cd mammals
-hg debugwalk
+hg debugwalk .
 hg debugwalk Procyonidae
 cd Procyonidae
-hg debugwalk
+hg debugwalk .
 hg debugwalk ..
 cd ..
 hg debugwalk ../beans
-hg debugwalk
+hg debugwalk .
 cd ..
 hg debugwalk -Ibeans
 hg debugwalk 'glob:mammals/../beans/b*'