changeset 5588:083b6e3142a2

churn: avoid division by zero
author Matt Mackall <mpm@selenic.com>
date Sun, 02 Dec 2007 17:04:16 -0600
parents 121f9dbcc236 (diff) b90b72729a72 (current diff)
children 9981b6b19ecf
files contrib/churn.py mercurial/hgweb/hgweb_mod.py
diffstat 14 files changed, 97 insertions(+), 43 deletions(-) [+]
line wrap: on
line diff
--- a/contrib/churn.py	Sun Dec 02 19:39:29 2007 +0100
+++ b/contrib/churn.py	Sun Dec 02 17:04:16 2007 -0600
@@ -125,6 +125,7 @@
         ui.note("rev %d: %d lines by %s\n" % (rev, lines, who))
 
         if progress:
+            nr_revs = max(nr_revs, 1)
             if int(100.0*(cur_rev - 1)/nr_revs) < int(100.0*cur_rev/nr_revs):
                 ui.write("%d%%.." % (int(100.0*cur_rev/nr_revs),))
                 sys.stdout.flush()
@@ -144,6 +145,7 @@
         return s[0:l]
 
     def graph(n, maximum, width, char):
+        maximum = max(1, maximum)
         n = int(n * width / float(maximum))
 
         return char * (n)
@@ -178,6 +180,8 @@
     ordered = stats.items()
     ordered.sort(lambda x, y: cmp(y[1], x[1]))
 
+    if not ordered:
+        return
     maximum = ordered[0][1]
 
     width = get_tty_width()
--- a/doc/hg.1.txt	Sun Dec 02 19:39:29 2007 +0100
+++ b/doc/hg.1.txt	Sun Dec 02 17:04:16 2007 -0600
@@ -89,13 +89,15 @@
     A range acts as a closed interval.  This means that a range of 3:5
     gives 3, 4 and 5.  Similarly, a range of 4:2 gives 4, 3, and 2.
 
+dot=.
+
 FILES
 -----
- .hgignore::
+ repo/.hgignore::
     This file contains regular expressions (one per line) that describe file
     names that should be ignored by hg. For details, see hgignore(5).
 
- .hgtags::
+ repo/.hgtags::
     This file contains changeset hash values and text tag names (one of each
     separated by spaces) that correspond to tagged versions of the repository
     contents.
--- a/mercurial/bdiff.c	Sun Dec 02 19:39:29 2007 +0100
+++ b/mercurial/bdiff.c	Sun Dec 02 17:04:16 2007 -0600
@@ -245,7 +245,7 @@
 
 	/* allocate and fill arrays */
 	t = equatelines(a, an, b, bn);
-	pos = (struct pos *)calloc(bn, sizeof(struct pos));
+	pos = (struct pos *)calloc(bn ? bn : 1, sizeof(struct pos));
 	/* we can't have more matches than lines in the shorter file */
 	l.head = l.base = (struct hunk *)malloc(sizeof(struct hunk) *
 	                                        ((an<bn ? an:bn) + 1));
--- a/mercurial/commands.py	Sun Dec 02 19:39:29 2007 +0100
+++ b/mercurial/commands.py	Sun Dec 02 17:04:16 2007 -0600
@@ -194,6 +194,11 @@
     if op2 != nullid:
         raise util.Abort(_('outstanding uncommitted merge'))
     node = repo.lookup(rev)
+
+    a = repo.changelog.ancestor(op1, node)
+    if a != node:
+        raise util.Abort(_('cannot back out change on a different branch'))
+
     p1, p2 = repo.changelog.parents(node)
     if p1 == nullid:
         raise util.Abort(_('cannot back out a change with no parents'))
@@ -210,6 +215,7 @@
         if opts['parent']:
             raise util.Abort(_('cannot use --parent on non-merge changeset'))
         parent = p1
+
     hg.clean(repo, node, show_stats=False)
     revert_opts = opts.copy()
     revert_opts['date'] = None
@@ -2267,7 +2273,10 @@
         del wlock
 
 def revert(ui, repo, *pats, **opts):
-    """revert files or dirs to their states as of some revision
+    """restore individual files or dirs to an earlier state
+
+    (use update -r to check out earlier revisions, revert does not
+    change the working dir parents)
 
     With no revision specified, revert the named files or directories
     to the contents they had in the parent of the working directory.
@@ -2276,12 +2285,9 @@
     working directory has two parents, you must explicitly specify the
     revision to revert to.
 
-    Modified files are saved with a .orig suffix before reverting.
-    To disable these backups, use --no-backup.
-
     Using the -r option, revert the given files or directories to their
     contents as of a specific revision. This can be helpful to "roll
-    back" some or all of a change that should not have been committed.
+    back" some or all of an earlier  change.
 
     Revert modifies the working directory.  It does not commit any
     changes, or change the parent of the working directory.  If you
@@ -2295,6 +2301,9 @@
     If names are given, all files matching the names are reverted.
 
     If no arguments are given, no files are reverted.
+
+    Modified files are saved with a .orig suffix before reverting.
+    To disable these backups, use --no-backup.
     """
 
     if opts["date"]:
@@ -2445,10 +2454,12 @@
         del wlock
 
 def rollback(ui, repo):
-    """roll back the last transaction in this repository
-
-    Roll back the last transaction in this repository, restoring the
-    project to its state prior to the transaction.
+    """roll back the last transaction
+
+    This command should be used with care. There is only one level of
+    rollback, and there is no way to undo a rollback. It will also
+    restore the dirstate at the time of the last transaction, losing
+    any dirstate changes since that time.
 
     Transactions are used to encapsulate the effects of all commands
     that create new changesets or propagate existing changesets into a
@@ -2461,11 +2472,6 @@
       push (with this repository as destination)
       unbundle
 
-    This command should be used with care. There is only one level of
-    rollback, and there is no way to undo a rollback. It will also
-    restore the dirstate at the time of the last transaction, which
-    may lose subsequent dirstate changes.
-
     This command is not intended for use on public repositories. Once
     changes are visible for pull by other users, rolling a transaction
     back locally is ineffective (someone else may already have pulled
@@ -3068,7 +3074,7 @@
     "recover": (recover, [], _('hg recover')),
     "^remove|rm":
         (remove,
-         [('A', 'after', None, _('record remove that has already occurred')),
+         [('A', 'after', None, _('record remove without deleting')),
           ('f', 'force', None, _('remove file even if modified')),
          ] + walkopts,
          _('hg remove [OPTION]... FILE...')),
@@ -3079,7 +3085,7 @@
            _('forcibly copy over an existing managed file')),
          ] + walkopts + dryrunopts,
          _('hg rename [OPTION]... SOURCE... DEST')),
-    "^revert":
+    "revert":
         (revert,
          [('a', 'all', None, _('revert all changes when no arguments given')),
           ('d', 'date', '', _('tipmost revision matching date')),
--- a/mercurial/hg.py	Sun Dec 02 19:39:29 2007 +0100
+++ b/mercurial/hg.py	Sun Dec 02 17:04:16 2007 -0600
@@ -173,8 +173,15 @@
             src_store = os.path.realpath(src_repo.spath)
             if not os.path.exists(dest):
                 os.mkdir(dest)
-            dest_path = os.path.realpath(os.path.join(dest, ".hg"))
-            os.mkdir(dest_path)
+            try:
+                dest_path = os.path.realpath(os.path.join(dest, ".hg"))
+                os.mkdir(dest_path)
+            except OSError, inst:
+                if inst.errno == errno.EEXIST:
+                    dir_cleanup.close()
+                    raise util.Abort(_("destination '%s' already exists")
+                                     % dest)
+                raise
             if src_repo.spath != src_repo.path:
                 # XXX racy
                 dummy_changelog = os.path.join(dest_path, "00changelog.i")
@@ -203,7 +210,14 @@
             dest_repo = repository(ui, dest)
 
         else:
-            dest_repo = repository(ui, dest, create=True)
+            try:
+                dest_repo = repository(ui, dest, create=True)
+            except OSError, inst:
+                if inst.errno == errno.EEXIST:
+                    dir_cleanup.close()
+                    raise util.Abort(_("destination '%s' already exists")
+                                     % dest)
+                raise
 
             revs = None
             if rev:
--- a/mercurial/hgweb/hgweb_mod.py	Sun Dec 02 19:39:29 2007 +0100
+++ b/mercurial/hgweb/hgweb_mod.py	Sun Dec 02 17:04:16 2007 -0600
@@ -815,7 +815,8 @@
         if not self.reponame:
             self.reponame = (self.config("web", "name")
                              or req.env.get('REPO_NAME')
-                             or req.url.strip('/') or self.repo.root)
+                             or req.url.strip('/')
+                             or os.path.basename(self.repo.root))
 
         self.t = templater.templater(mapfile, templater.common_filters,
                                      defaults={"url": req.url,
--- a/mercurial/merge.py	Sun Dec 02 19:39:29 2007 +0100
+++ b/mercurial/merge.py	Sun Dec 02 17:04:16 2007 -0600
@@ -609,7 +609,10 @@
             try:
                 node = repo.branchtags()[wc.branch()]
             except KeyError:
-                raise util.Abort(_("branch %s not found") % wc.branch())
+                if wc.branch() == "default": # no default branch!
+                    node = repo.lookup("tip") # update to tip
+                else:
+                    raise util.Abort(_("branch %s not found") % wc.branch())
         overwrite = force and not branchmerge
         forcemerge = force and branchmerge
         pl = wc.parents()
--- a/tests/test-backout	Sun Dec 02 19:39:29 2007 +0100
+++ b/tests/test-backout	Sun Dec 02 17:04:16 2007 -0600
@@ -37,6 +37,22 @@
 hg backout -d '3 0' --merge tip
 cat a 2>/dev/null || echo cat: a: No such file or directory
 
+echo '# across branch'
+cd ..
+hg init branch
+cd branch
+echo a > a
+hg ci -Am0 -d '0 0'
+echo b > b
+hg ci -Am1 -d '0 0'
+hg co -C 0
+# should fail
+hg backout -d '0 0' 1
+echo c > c
+hg ci -Am2 -d '0 0'
+# should fail
+hg backout -d '0 0' 1
+
 echo '# backout with merge'
 cd ..
 hg init merge
--- a/tests/test-backout.out	Sun Dec 02 19:39:29 2007 +0100
+++ b/tests/test-backout.out	Sun Dec 02 17:04:16 2007 -0600
@@ -15,6 +15,13 @@
 removing a
 changeset 3:7f6d0f120113 backs out changeset 2:de31bdc76c0d
 cat: a: No such file or directory
+# across branch
+adding a
+adding b
+0 files updated, 0 files merged, 1 files removed, 0 files unresolved
+abort: cannot back out change on a different branch
+adding c
+abort: cannot back out change on a different branch
 # backout with merge
 adding a
 reverting a
--- a/tests/test-globalopts.out	Sun Dec 02 19:39:29 2007 +0100
+++ b/tests/test-globalopts.out	Sun Dec 02 17:04:16 2007 -0600
@@ -175,8 +175,8 @@
  recover      roll back an interrupted transaction
  remove       remove the specified files on the next commit
  rename       rename files; equivalent of copy + remove
- revert       revert files or dirs to their states as of some revision
- rollback     roll back the last transaction in this repository
+ revert       restore individual files or dirs to an earlier state
+ rollback     roll back the last transaction
  root         print the root (top) of the current working dir
  serve        export the repository via HTTP
  showconfig   show combined config settings from all hgrc files
@@ -227,8 +227,8 @@
  recover      roll back an interrupted transaction
  remove       remove the specified files on the next commit
  rename       rename files; equivalent of copy + remove
- revert       revert files or dirs to their states as of some revision
- rollback     roll back the last transaction in this repository
+ revert       restore individual files or dirs to an earlier state
+ rollback     roll back the last transaction
  root         print the root (top) of the current working dir
  serve        export the repository via HTTP
  showconfig   show combined config settings from all hgrc files
--- a/tests/test-help.out	Sun Dec 02 19:39:29 2007 +0100
+++ b/tests/test-help.out	Sun Dec 02 17:04:16 2007 -0600
@@ -15,7 +15,6 @@
  pull       pull changes from the specified source
  push       push changes to the specified destination
  remove     remove the specified files on the next commit
- revert     revert files or dirs to their states as of some revision
  serve      export the repository via HTTP
  status     show changed files in the working directory
  update     update working directory
@@ -34,7 +33,6 @@
  pull       pull changes from the specified source
  push       push changes to the specified destination
  remove     remove the specified files on the next commit
- revert     revert files or dirs to their states as of some revision
  serve      export the repository via HTTP
  status     show changed files in the working directory
  update     update working directory
@@ -75,8 +73,8 @@
  recover      roll back an interrupted transaction
  remove       remove the specified files on the next commit
  rename       rename files; equivalent of copy + remove
- revert       revert files or dirs to their states as of some revision
- rollback     roll back the last transaction in this repository
+ revert       restore individual files or dirs to an earlier state
+ rollback     roll back the last transaction
  root         print the root (top) of the current working dir
  serve        export the repository via HTTP
  showconfig   show combined config settings from all hgrc files
@@ -123,8 +121,8 @@
  recover      roll back an interrupted transaction
  remove       remove the specified files on the next commit
  rename       rename files; equivalent of copy + remove
- revert       revert files or dirs to their states as of some revision
- rollback     roll back the last transaction in this repository
+ revert       restore individual files or dirs to an earlier state
+ rollback     roll back the last transaction
  root         print the root (top) of the current working dir
  serve        export the repository via HTTP
  showconfig   show combined config settings from all hgrc files
@@ -276,7 +274,6 @@
  pull       pull changes from the specified source
  push       push changes to the specified destination
  remove     remove the specified files on the next commit
- revert     revert files or dirs to their states as of some revision
  serve      export the repository via HTTP
  status     show changed files in the working directory
  update     update working directory
@@ -300,7 +297,6 @@
  pull       pull changes from the specified source
  push       push changes to the specified destination
  remove     remove the specified files on the next commit
- revert     revert files or dirs to their states as of some revision
  serve      export the repository via HTTP
  status     show changed files in the working directory
  update     update working directory
--- a/tests/test-rename-dir-merge	Sun Dec 02 19:39:29 2007 +0100
+++ b/tests/test-rename-dir-merge	Sun Dec 02 17:04:16 2007 -0600
@@ -7,9 +7,7 @@
 mkdir a
 echo foo > a/a
 echo bar > a/b
-
-hg add a
-hg ci -m "0" -d "0 0"
+hg ci -Am "0" -d "0 0"
 
 hg co -C 0
 hg mv a b
@@ -17,6 +15,7 @@
 
 hg co -C 0
 echo baz > a/c
+echo quux > a/d
 hg add a/c
 hg ci -m "2 add a/c" -d "0 0"
 
--- a/tests/test-rename-dir-merge.out	Sun Dec 02 19:39:29 2007 +0100
+++ b/tests/test-rename-dir-merge.out	Sun Dec 02 17:04:16 2007 -0600
@@ -12,6 +12,7 @@
   searching for copies back to rev 1
   unmatched files in local:
    a/c
+   a/d
   unmatched files in other:
    b/a
    b/b
@@ -21,6 +22,8 @@
   checking for directory renames
   dir a/ -> b/
   file a/c -> b/c
+  file a/d -> b/d
+ a/d: remote renamed directory to b/d -> d
  a/c: remote renamed directory to b/c -> d
  a/b: other deleted -> r
  a/a: other deleted -> r
@@ -29,11 +32,12 @@
 removing a/a
 removing a/b
 moving a/c to b/c
+moving a/d to b/d
 getting b/a
 getting b/b
-3 files updated, 0 files merged, 2 files removed, 0 files unresolved
+4 files updated, 0 files merged, 2 files removed, 0 files unresolved
 (branch merge, don't forget to commit)
-a/* b/a b/b b/c
+a/* b/a b/b b/c b/d
 M b/a
 M b/b
 A b/c
@@ -41,6 +45,7 @@
 R a/a
 R a/b
 R a/c
+? b/d
 b/c renamed from a/c:354ae8da6e890359ef49ade27b68bbc361f3ca88
 0 files updated, 0 files merged, 1 files removed, 0 files unresolved
 resolving manifests
@@ -50,6 +55,7 @@
   unmatched files in local:
    b/a
    b/b
+   b/d
   unmatched files in other:
    a/c
   all copies found (* = to merge, ! = divergent):
@@ -62,7 +68,8 @@
 getting a/c to b/c
 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
 (branch merge, don't forget to commit)
-a/* b/a b/b b/c
+a/* b/a b/b b/c b/d
 A b/c
   a/c
+? b/d
 b/c renamed from a/c:354ae8da6e890359ef49ade27b68bbc361f3ca88
--- a/tests/test-strict.out	Sun Dec 02 19:39:29 2007 +0100
+++ b/tests/test-strict.out	Sun Dec 02 17:04:16 2007 -0600
@@ -18,7 +18,6 @@
  pull       pull changes from the specified source
  push       push changes to the specified destination
  remove     remove the specified files on the next commit
- revert     revert files or dirs to their states as of some revision
  serve      export the repository via HTTP
  status     show changed files in the working directory
  update     update working directory