Commit Graph

75 Commits

Author SHA1 Message Date
Vadim Gelfer
ff1f653af7 eliminate backtrace when piping output on windows.
this fixes issue 54.
2006-01-02 15:25:33 -08:00
Matt Mackall
2df834f9a4 Merge with crew 2005-12-16 11:13:08 -06:00
Benoit Boissinot
f88ffe1792 do not copy atime and mtime in util.copyfiles
it is unsupported on some fs (vfat) and we don't need to copy
it one clone anyway
2005-12-16 01:32:44 -06:00
Benoit Boissinot
78898f92b4 if a filename contains spaces, patch adds quote around it 2005-12-15 17:50:10 +01:00
Vadim Gelfer
3ec3d8787c delete unintended print statement 2005-12-12 07:50:43 -08:00
Vadim Gelfer
c968155220 merge with crew 2005-12-11 15:38:42 -08:00
Arun Sharma
ee55457e68 Handle hg under / 2005-12-01 10:48:42 -06:00
Robin Farine
42b0262a8a export patkind() from util 2005-12-01 10:48:22 -06:00
Benoit Boissinot
f7ef42efdd close file before renaming it (since it doesn't work the other way on windows) 2005-11-14 21:47:07 +01:00
twaldmann@thinkmo.de
55d74a6b77 fixed some stuff pychecker shows, marked unclear/wrong stuff with XXX 2005-11-14 03:59:35 +02:00
Benoit Boissinot
4aae3736a7 add an atomic argument to util.opener
when atomic is used, the file while be renamed on close
2005-11-11 15:33:59 -08:00
Benoit Boissinot
8a08aa0106 copy the mode of the file when breaking hardlinks 2005-11-09 13:38:46 -08:00
Vadim Gelfer
c9f1399932 make mercurial look in more places for config files.
now it searches <install dir>/etc/mercurial, /etc/mercurial, and user
hgrc.

this allows site-wide configuration to be shared over automounted nfs
partition, instead of chenging on every system.  option of having local
configuration on every system remains.

old code for searching /etc/mercurial/hgrc.d never worked, this code
is tested and works.
2005-11-04 11:51:01 -08:00
Benoit Boissinot
8be93f3049 fix handling of daylight saving time 2005-10-31 10:56:42 -07:00
Benoit Boissinot
bc51f024c7 fix a bug where hg could remove file ending with .tmp
util.opener used a fixed filename for writing tempfile
instead of using the tempfile module.
2005-10-28 17:18:50 -07:00
Benoit Boissinot
93854a176d further fix traceback on invalid .hgignore patterns
Please apply this little fix (matchfn return None if no patterns are
specified).
2005-10-26 16:10:56 -07:00
Benoit Boissinot
0e649f370c abort on invalid pattern in matcher 2005-10-25 14:58:11 -07:00
olivier.maquelin@intel.com
fa3a9847db Avoid insertion/deletion of CRs on stdio during hg serve 2005-10-24 14:34:48 -07:00
Benoit Boissinot
abe08fd52f refactor some unlink/remove code and make sure we prune empty dir 2005-10-19 00:10:52 -07:00
Benoit Boissinot
6c6a4b138f Do not use 'glob' expansion by default on OS != 'nt' 2005-10-19 00:02:41 -07:00
Benoit Boissinot
06e39e559b i18n part2: use '_' for all strings who are part of the user interface 2005-10-18 18:38:39 -07:00
Benoit Boissinot
e38e94088a i18n first part: make '_' available for files who need it 2005-10-18 18:37:48 -07:00
Zbynek Winkler
f5c4f54863 Try to use ini-file in the same directory as the exe as the default on NT. 2005-10-18 17:57:27 -07:00
Matt Mackall
42508becda Fix patch failure reporting exception 2005-10-15 15:04:45 -07:00
Eric Hopper
01737b862f Fixed a bug in my changes to httprepo.py 2005-10-03 16:07:54 -07:00
mpm@selenic.com
d701e53cd5 Add support for /etc/mercurial/hgrc.d/*.rc 2005-09-23 19:35:23 -07:00
Bryan O'Sullivan
139919b045 Allow files to be opened in text mode, even on Windows. 2005-09-23 10:28:55 -07:00
Bryan O'Sullivan
566df77193 Clean up date and timezone handling.
We used to pass changelog dates around as a "unixtime timezone" string
containing a pair of encoded ints.  Now, they get passed around as a
(unixtime, timezone) tuple of numbers, which makes much more sense.
2005-09-22 23:19:47 -07:00
Bryan O'Sullivan
f46e4d82a5 Fix up representation of dates in hgweb.
Date display is now uniform both on the command line and via the web
interface.
2005-09-22 22:46:50 -07:00
mpm@selenic.com
9282c26f18 Merge with TAH 2005-09-22 09:41:34 -07:00
Bryan O'Sullivan
ffb420798b Enhance the file filtering capabilities.
We now allow filtering through either pipes or pairs of temporary
files.  The latter appear to be mandatory for use on Windows.
2005-09-21 11:44:08 -07:00
Bryan O'Sullivan
1cc739dd2e Use platform-appropriate rc file names. 2005-09-21 09:56:30 -07:00
Thomas Arendsen Hein
455a56454d Cleanup of tabs and trailing spaces. 2005-09-21 07:56:19 +02:00
Volker Kleinfeld
7880184af1 Make 'hg import' platform independent.
- moved popen("patch ...") from commands.py to util.py

- files may not be single quoted in popen under windows: fixed

- patch returns the files quoted under windows. quotes need to
  be stripped off: fixed
2005-09-20 21:35:51 -07:00
Bryan O'Sullivan
ae02dc4df3 Switch to new syntax for .hgignore files.
Here is the new syntax, in summary.
Trailing white space is dropped.
The escape character is "\".
Comments start with #.
Empty lines are skipped.
Lines can be of the following formats:
syntax: regexp # defaults following lines to non-rooted regexps
syntax: glob   # defaults following lines to non-rooted globs
re:pattern     # non-rooted regular expression
glob:pattern   # non-rooted glob
pattern        # pattern of the current default type
The default pattern type is regexp, which is completely backwards
compatible with the old hgignore syntax.
In the dirstate class, the ignore method has been reworked to be based
on the util.matcher function, by way of a new dirstate.hgignore
method.
2005-09-17 00:27:27 -07:00
mpm@selenic.com
eac251ef7c Add file encoding/decoding support 2005-09-15 02:59:16 -05:00
Stephen Darnell
b2e16a8dbf Add support for cloning with hardlinks on windows.
In order to use hardlinks, the win32file module is needed, and this is
present in ActivePython.  If it isn't present, or hardlinks are not supported
on the underlying filesystem, a regular copy is used.

When using hardlinks the biggest benefit is probably the saving in space,
but cloning can be much quicker.  For example cloning the Xen tree
(non trivial) without an update goes from about 95s to 15s.

Unix-like platforms should be unaffected, although should be more tolerant on
filesystems that don't support hard links.

(tweaked by mpm to deal with new copyfiles function)

--- hg.orig/mercurial/commands.py	2005-09-13 19:32:53.000000000 -0500
+++ hg/mercurial/commands.py	2005-09-14 12:11:34.000000000 -0500
@@ -620,10 +620,6 @@ def clone(ui, source, dest=None, **opts)

     if other.dev() != -1:
         abspath = os.path.abspath(source)
-        copyfile = (os.stat(dest).st_dev == other.dev()
-                    and getattr(os, 'link', None) or shutil.copy2)
-        if copyfile is not shutil.copy2:
-            ui.note("cloning by hardlink\n")

         # we use a lock here because if we race with commit, we can
         # end up with extra data in the cloned revlogs that's not
@@ -638,7 +634,7 @@ def clone(ui, source, dest=None, **opts)
         for f in files.split():
             src = os.path.join(source, ".hg", f)
             dst = os.path.join(dest, ".hg", f)
-            util.copyfiles(src, dst, copyfile)
+            util.copyfiles(src, dst)

         repo = hg.repository(ui, dest)

Index: hg/mercurial/util.py
===================================================================
--- hg.orig/mercurial/util.py	2005-09-08 00:15:25.000000000 -0500
+++ hg/mercurial/util.py	2005-09-14 12:16:49.000000000 -0500
@@ -12,7 +12,7 @@ platform-specific details from the core.

 import os, errno
 from demandload import *
-demandload(globals(), "re cStringIO")
+demandload(globals(), "re cStringIO shutil")

 def binary(s):
     """return true if a string is binary data using diff's heuristic"""
@@ -217,17 +217,28 @@ def rename(src, dst):
         os.unlink(dst)
         os.rename(src, dst)

-def copyfiles(src, dst, copyfile):
-    """Copy a directory tree, files are copied using 'copyfile'."""
+def copyfiles(src, dst, hardlink=None):
+    """Copy a directory tree using hardlinks if possible"""
+
+    if hardlink is None:
+        hardlink = (os.stat(src).st_dev ==
+                    os.stat(os.path.dirname(dst)).st_dev)

     if os.path.isdir(src):
         os.mkdir(dst)
         for name in os.listdir(src):
             srcname = os.path.join(src, name)
             dstname = os.path.join(dst, name)
-            copyfiles(srcname, dstname, copyfile)
+            copyfiles(srcname, dstname, hardlink)
     else:
-        copyfile(src, dst)
+        if hardlink:
+            try:
+                os_link(src, dst)
+            except:
+                hardlink = False
+                shutil.copy2(src, dst)
+        else:
+            shutil.copy2(src, dst)

 def opener(base):
     """
@@ -244,13 +255,13 @@ def opener(base):

         if mode[0] != "r":
             try:
-                s = os.stat(f)
+                nlink = nlinks(f)
             except OSError:
                 d = os.path.dirname(f)
                 if not os.path.isdir(d):
                     os.makedirs(d)
             else:
-                if s.st_nlink > 1:
+                if nlink > 1:
                     file(f + ".tmp", "wb").write(file(f, "rb").read())
                     rename(f+".tmp", f)

@@ -266,10 +277,41 @@ def _makelock_file(info, pathname):
 def _readlock_file(pathname):
     return file(pathname).read()

+def nlinks(pathname):
+    """Return number of hardlinks for the given file."""
+    return os.stat(pathname).st_nlink
+
+if hasattr(os, 'link'):
+    os_link = os.link
+else:
+    def os_link(src, dst):
+        raise OSError(0, "Hardlinks not supported")
+
 # Platform specific variants
 if os.name == 'nt':
     nulldev = 'NUL:'

+    try: # ActivePython can create hard links using win32file module
+        import win32file
+
+        def os_link(src, dst): # NB will only succeed on NTFS
+            win32file.CreateHardLink(dst, src)
+
+        def nlinks(pathname):
+            """Return number of hardlinks for the given file."""
+            try:
+                fh = win32file.CreateFile(pathname,
+                    win32file.GENERIC_READ, win32file.FILE_SHARE_READ,
+                    None, win32file.OPEN_EXISTING, 0, None)
+                res = win32file.GetFileInformationByHandle(fh)
+                fh.Close()
+                return res[7]
+            except:
+                return os.stat(pathname).st_nlink
+
+    except ImportError:
+        pass
+
     def is_exec(f, last):
         return last
2005-09-14 12:22:20 -05:00
mpm@selenic.com
489a50d0a3 Rewrite copytree as copyfiles
This inverts the logic of copytree to allow copying single files at
the top level.
2005-09-07 19:21:38 -07:00
Bryan O'Sullivan
648041175d Minor cleanups. 2005-09-04 14:21:53 -07:00
Eric Hopper
6b43642f9a Created a class in util called chunkbuffer that buffers reads from an
iterator over strings (aka chunks).

Also added to util (for future use) is a generator function that
iterates over a file n bytes at a time.

Lastly, localrepo was changed to use this new chunkbuffer class when
reading changegroups form the local repository.
2005-09-04 14:11:51 -07:00
Thomas Arendsen Hein
8a6c4666d1 Reverted changeset a180d5833ef6f90ff01b9322f3473017bce7ae55
Volker Kleinfeld agreed that this is dead code and tried to fix a problem
which was already fixed somewhere else.
2005-08-30 21:26:27 +02:00
mpm@selenic.com
e6e4ecb803 localrepo: minor opener usage restructuring 2005-08-27 16:34:54 -07:00
mpm@selenic.com
f1273ca2af Separate out old-http support
- create new statichttprepo class
- pull remote bits out of localrepo
- pull remote bits out of util.opener
- switch hg.repository to use statichttprepo
2005-08-27 16:28:53 -07:00
mpm@selenic.com
06162e7dd0 Move opener to utils
- move the opener code down to util
- add docstring
- change commands.py users to simply use file instead
2005-08-27 14:31:41 -07:00
mpm@selenic.com
8805469355 Update util.py docstrings, fix walk test 2005-08-27 01:13:28 -07:00
mpm@selenic.com
6737d1c923 Change canonpath to not know about repo objects
Code in util should not have any knowledge about repo objects
2005-08-26 23:29:10 -07:00
Volker.Kleinfeld@gmx.de
b206d3baac Fixed system command abord reason on windows. 2005-08-26 19:20:04 -07:00
benoit.boissinot@ens-lyon.fr
95b97f01ed pep-0008 cleanup
- Don't use spaces around the '=' sign when used to indicate a
      keyword argument or a default parameter value.
2005-08-26 13:06:58 +02:00
Bryan O'Sullivan
8b3b079822 Rewrite log command. New version is faster and more featureful.
The original implementation of log walked backwards through history,
which had terrible behaviour.  It took several minutes to view
complete kernel change history on a fast machine, for example.
The rewrite uses a windowed approach to walk hunks of history
forwards, while still giving results in reverse order.  This reduces
run time from five minutes to five seconds on my system.
In addition, the rewrite uses our normal name handling mechanisms, so
you can run a command like "hg log net/ipv4/**.c" and get a useful
answer.  It optimises for three different cases (no arguments, only
files, and anything goes), so it performs well in all circumstances
I've tested.
2005-08-24 12:39:10 -07:00
mpm@selenic.com
af3be1f6a1 Add automatic binary file detection to diff and export
Based on a patch by Fuming Wang

- add util.binary which decides whether a file is binary if it has any NUL
  characters in the first 1K.
- teach mdiff.unidiff to print "binary file <x> has changed" for binary files
- add text flag to cause unidiff and dodiff to treat all files as text
- add -a and --text flags (like diff(1)) to hg diff and export
- update docs
2005-08-23 19:58:46 -07:00