[PATCH 1 of 1 RFC] scmutil: eliminate util.samestat

Adrian Buehlmann adrian at cadifra.com
Tue Jun 12 18:03:51 CDT 2012


On 2012-06-13 00:32, Adrian Buehlmann wrote:
> On 2012-06-13 00:04, Matt Mackall wrote:
>> On Sat, 2012-06-09 at 11:58 +0200, Adrian Buehlmann wrote:
>>> # HG changeset patch
>>> # User Adrian Buehlmann <adrian at cadifra.com>
>>> # Date 1339182525 -7200
>>> # Node ID 48649541c9a2002a148699136cff71865b18dc60
>>> # Parent  2255950e1f7663a9faa6b57040cc5c0debe7d4dd
>>> scmutil: eliminate util.samestat
>>>
>>> It's impossible to implement that on Windows.
>>
>> First, I don't know why that in itself is an argument for removing it.
>> We have plenty of utility functions that are only relevant to one
>> platform.
>>
>> Second, I don't believe it's impossible to implement and happen to know
>> that analogous functions exist. For instance, GetFileInformationByHandle
>> has fields that would serve the same purpose (volume serial number and
>> file index):
>>
>>  http://msdn.microsoft.com/en-us/library/aa363788%28VS.85%29.aspx
>>
> 
> That works only for files, for directories, samestat is impossible.
> 
>> (We might need to tweak the interface to work on file handles rather
>> than stat results, but the use cases remain the same.)
>>
>> So while this function might be smack in the middle of some buggy code,
>> there is nothing at all conceptually wrong with having a utility
>> function that represents the concept: "tell me if two files are the same
>> if you can" and using that to short-circuit a longer check.
>>
>> In fact, ripping it out is a step back from doing it right eventually,
>> because to add a Windows implementation where the Python library is
>> lacking, we'll need to add a util method.
>>

$ python
Python 2.6.6 (r266:84297, Aug 24 2010, 18:46:32) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from mercurial import win32
>>> win32.samefile('C:/Users/adi', 'C:/Users/adi')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "mercurial\win32.py", line 220, in samefile
    res1 = _getfileinfo(fpath1)
  File "mercurial\win32.py", line 197, in _getfileinfo
    _raiseoserror(name)
  File "mercurial\win32.py", line 190, in _raiseoserror
    raise OSError(err.errno, '%s: %s' % (name, err.strerror))
OSError: [Errno 13] C:/Users/adi: Access is denied.
>>>
>>>
>>> win32.samefile('C:/Users/adi/mercurial.ini', 'C:/Users/adi/mercurial.ini')
True
>>> win32.samefile('C:/Users/adi/mercurial.ini', 'C:/Users/adi/.gitconfig')
False




More information about the Mercurial-devel mailing list