Mercurial > hg
view tests/f @ 23923:ab6fd3205dad stable
largefiles: fix commit of a directory with no largefile changes (issue4330)
When a directory is named in the commit file list, the previous behavior was to
walk the list, and if no normal files in the directory were also named, add the
corresponding standin for each largefile in that directory. The directory is
then dropped from the list, so that committing a directory with no normal file
changes works. It then added the corresponding standin directory for the first
largefile seen, by prefixing it with '.hglf/'.
The latter is unnecessary since each affected largefile is explicitly referenced
by its standin in the list. It also caused an abort if there were no changed
largefiles in the directory, because none of its standins changed:
abort: .hglf/foo/bar: no match under directory!
This list of files is used to tweak a matcher in lfutil.updatestandinsbymatch(),
which is what is passed to commit().
The status() call that is ultimately done in the commit code with this matcher
seems to have some OS specific differences. It is not necessary to append '.'
for Windows to run the largefiles tests cleanly. But if '.' is not added to the
list, the match function isn't called on Linux, so status() would miss any
normal files that were also in a named directory. The commit then proceeds
without those normal files, or says "nothing changed" if there were no changed
largefiles in the directory. This is not filesystem specific, as VFAT on Linux
had the same behavior as when run on ext4. It is also not an issue with
lfilesrepo.status(), since that only calls the overridden implementation when
paths are passed to commit. I dont have access to an OS X machine ATM to test
there.
Maybe there's a better way to do this. But since the standin directory for the
first largefile was previously being added, and that caused the same walk in
status(), there's no preformance change to this. There is no danger of
erroneously committing files in '.', because the original match function is
called, and if it fails, the lfutil.updatestandinsbymatch() tweaked matcher only
indicates a match if the file is in the list of standins- and '.' never is. The
added tests confirm this.
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Sun, 18 Jan 2015 15:15:40 -0500 |
parents | 7d0aa6269ece |
children | 6686ae524f94 |
line wrap: on
line source
#!/usr/bin/env python """ Utility for inspecting files in various ways. This tool is like the collection of tools found in a unix environment but are cross platform and stable and suitable for our needs in the test suite. This can be used instead of tools like: [ dd find head hexdump ls md5sum readlink sha1sum stat tail test readlink.py md5sum.py """ import sys, os, errno, re, glob, optparse def visit(opts, filenames, outfile): """Process filenames in the way specified in opts, writing output to outfile.""" for f in sorted(filenames): isstdin = f == '-' if not isstdin and not os.path.lexists(f): outfile.write('%s: file not found\n' % f) continue quiet = opts.quiet and not opts.recurse or isstdin isdir = os.path.isdir(f) islink = os.path.islink(f) isfile = os.path.isfile(f) and not islink dirfiles = None content = None facts = [] if isfile: if opts.type: facts.append('file') if opts.hexdump or opts.dump or opts.md5: content = file(f).read() elif islink: if opts.type: facts.append('link') content = os.readlink(f) elif isstdin: content = sys.stdin.read() if opts.size: facts.append('size=%s' % len(content)) elif isdir: if opts.recurse or opts.type: dirfiles = glob.glob(f + '/*') facts.append('directory with %s files' % len(dirfiles)) elif opts.type: facts.append('type unknown') if not isstdin: stat = os.lstat(f) if opts.size and not isdir: facts.append('size=%s' % stat.st_size) if opts.mode and not islink: facts.append('mode=%o' % (stat.st_mode & 0777)) if opts.links: facts.append('links=%s' % stat.st_nlink) if opts.newer: # mtime might be in whole seconds so newer file might be same if stat.st_mtime >= os.stat(opts.newer).st_mtime: facts.append('newer than %s' % opts.newer) else: facts.append('older than %s' % opts.newer) if opts.md5 and content is not None: try: from hashlib import md5 except ImportError: from md5 import md5 facts.append('md5=%s' % md5(content).hexdigest()[:opts.bytes]) if opts.sha1 and content is not None: try: from hashlib import sha1 except ImportError: from sha import sha as sha1 facts.append('sha1=%s' % sha1(content).hexdigest()[:opts.bytes]) if isstdin: outfile.write(', '.join(facts) + '\n') elif facts: outfile.write('%s: %s\n' % (f, ', '.join(facts))) elif not quiet: outfile.write('%s:\n' % f) if content is not None: chunk = content if not islink: if opts.lines: if opts.lines >= 0: chunk = ''.join(chunk.splitlines(True)[:opts.lines]) else: chunk = ''.join(chunk.splitlines(True)[opts.lines:]) if opts.bytes: if opts.bytes >= 0: chunk = chunk[:opts.bytes] else: chunk = chunk[opts.bytes:] if opts.hexdump: for i in range(0, len(chunk), 16): s = chunk[i:i+16] outfile.write('%04x: %-47s |%s|\n' % (i, ' '.join('%02x' % ord(c) for c in s), re.sub('[^ -~]', '.', s))) if opts.dump: if not quiet: outfile.write('>>>\n') outfile.write(chunk) if not quiet: if chunk.endswith('\n'): outfile.write('<<<\n') else: outfile.write('\n<<< no trailing newline\n') if opts.recurse and dirfiles: assert not isstdin visit(opts, dirfiles, outfile) if __name__ == "__main__": parser = optparse.OptionParser("%prog [options] [filenames]") parser.add_option("-t", "--type", action="store_true", help="show file type (file or directory)") parser.add_option("-m", "--mode", action="store_true", help="show file mode") parser.add_option("-l", "--links", action="store_true", help="show number of links") parser.add_option("-s", "--size", action="store_true", help="show size of file") parser.add_option("-n", "--newer", action="store", help="check if file is newer (or same)") parser.add_option("-r", "--recurse", action="store_true", help="recurse into directories") parser.add_option("-S", "--sha1", action="store_true", help="show sha1 hash of the content") parser.add_option("-M", "--md5", action="store_true", help="show md5 hash of the content") parser.add_option("-D", "--dump", action="store_true", help="dump file content") parser.add_option("-H", "--hexdump", action="store_true", help="hexdump file content") parser.add_option("-B", "--bytes", type="int", help="number of characters to dump") parser.add_option("-L", "--lines", type="int", help="number of lines to dump") parser.add_option("-q", "--quiet", action="store_true", help="no default output") (opts, filenames) = parser.parse_args(sys.argv[1:]) if not filenames: filenames = ['-'] visit(opts, filenames, sys.stdout)