Mercurial > public > mercurial-scm > hg
comparison mercurial/commands.py @ 20293:2f6b3900be64
cat: increase perf when catting single files
Special case the single file case in hg cat. This allows us to avoid
parsing the manifest, which shaves 15% off hg cat perf. This is worth
it, since automation often uses hg cat for retrieving single files.
author | Durham Goode <durham@fb.com> |
---|---|
date | Tue, 14 Jan 2014 13:38:16 -0800 |
parents | 2cfb720592fe |
children | a6cf48b2880d 7f865a94691e |
comparison
equal
deleted
inserted
replaced
20292:8dc254198a8f | 20293:2f6b3900be64 |
---|---|
1166 Returns 0 on success. | 1166 Returns 0 on success. |
1167 """ | 1167 """ |
1168 ctx = scmutil.revsingle(repo, opts.get('rev')) | 1168 ctx = scmutil.revsingle(repo, opts.get('rev')) |
1169 err = 1 | 1169 err = 1 |
1170 m = scmutil.match(ctx, (file1,) + pats, opts) | 1170 m = scmutil.match(ctx, (file1,) + pats, opts) |
1171 for abs in ctx.walk(m): | 1171 |
1172 def write(path): | |
1172 fp = cmdutil.makefileobj(repo, opts.get('output'), ctx.node(), | 1173 fp = cmdutil.makefileobj(repo, opts.get('output'), ctx.node(), |
1173 pathname=abs) | 1174 pathname=path) |
1174 data = ctx[abs].data() | 1175 data = ctx[path].data() |
1175 if opts.get('decode'): | 1176 if opts.get('decode'): |
1176 data = repo.wwritedata(abs, data) | 1177 data = repo.wwritedata(path, data) |
1177 fp.write(data) | 1178 fp.write(data) |
1178 fp.close() | 1179 fp.close() |
1180 | |
1181 # Automation often uses hg cat on single files, so special case it | |
1182 # for performance to avoid the cost of parsing the manifest. | |
1183 if len(m.files()) == 1 and not m.anypats(): | |
1184 file = m.files()[0] | |
1185 mf = repo.manifest | |
1186 mfnode = ctx._changeset[0] | |
1187 if mf.find(mfnode, file)[0]: | |
1188 write(file) | |
1189 return 0 | |
1190 | |
1191 for abs in ctx.walk(m): | |
1192 write(abs) | |
1179 err = 0 | 1193 err = 0 |
1180 return err | 1194 return err |
1181 | 1195 |
1182 @command('^clone', | 1196 @command('^clone', |
1183 [('U', 'noupdate', None, | 1197 [('U', 'noupdate', None, |