comparison mercurial/commands.py @ 50857:de3191c0cec9

config: use the writefile() utility to create the sample hgrc This function uses a context manager.
author Matt Harbison <matt_harbison@yahoo.com>
date Sun, 20 Aug 2023 01:12:26 -0400
parents 7d54b877782e
children 57ae6063c494
comparison
equal deleted inserted replaced
50856:7d54b877782e 50857:de3191c0cec9
16 nullid, 16 nullid,
17 nullrev, 17 nullrev,
18 short, 18 short,
19 wdirrev, 19 wdirrev,
20 ) 20 )
21 from .pycompat import open
22 from . import ( 21 from . import (
23 archival, 22 archival,
24 bookmarks, 23 bookmarks,
25 bundle2, 24 bundle2,
26 bundlecaches, 25 bundlecaches,
2352 samplehgrc = uimod.samplehgrcs[b'local'] 2351 samplehgrc = uimod.samplehgrcs[b'local']
2353 else: 2352 else:
2354 samplehgrc = uimod.samplehgrcs[b'user'] 2353 samplehgrc = uimod.samplehgrcs[b'user']
2355 2354
2356 f = paths[0] 2355 f = paths[0]
2357 fp = open(f, b"wb") 2356 util.writefile(f, util.tonativeeol(samplehgrc))
2358 fp.write(util.tonativeeol(samplehgrc))
2359 fp.close()
2360 2357
2361 editor = ui.geteditor() 2358 editor = ui.geteditor()
2362 ui.system( 2359 ui.system(
2363 b"%s \"%s\"" % (editor, f), 2360 b"%s \"%s\"" % (editor, f),
2364 onerr=error.InputError, 2361 onerr=error.InputError,