Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a814533

Browse files
committed
Closes #19966: allow hgtouch to operate on a base dir that is != the repo root.
1 parent 92b1382 commit a814533

1 file changed

Lines changed: 23 additions & 12 deletions

File tree

Tools/hg/hgtouch.py

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,16 @@ def parse_config(repo):
3636
result[o] = inputs
3737
return result
3838

39-
def check_rule(ui, repo, modified, output, inputs):
39+
def check_rule(ui, repo, modified, basedir, output, inputs):
4040
"""Verify that the output is newer than any of the inputs.
4141
Return (status, stamp), where status is True if the update succeeded,
4242
and stamp is the newest time stamp assigned to any file (might be in
43-
the future)."""
44-
f_output = repo.wjoin(output)
43+
the future).
44+
45+
If basedir is nonempty, it gives a directory in which the tree is to
46+
be checked.
47+
"""
48+
f_output = repo.wjoin(os.path.join(basedir, output))
4549
try:
4650
o_time = os.stat(f_output).st_mtime
4751
except OSError:
@@ -51,7 +55,7 @@ def check_rule(ui, repo, modified, output, inputs):
5155
backdate = None
5256
backdate_source = None
5357
for i in inputs:
54-
f_i = repo.wjoin(i)
58+
f_i = repo.wjoin(os.path.join(basedir, i))
5559
try:
5660
i_time = os.stat(f_i).st_mtime
5761
except OSError:
@@ -79,8 +83,14 @@ def check_rule(ui, repo, modified, output, inputs):
7983
# Nothing to update
8084
return True, 0
8185

82-
def do_touch(ui, repo):
83-
modified = repo.status()[0]
86+
def do_touch(ui, repo, basedir):
87+
if basedir:
88+
if not os.path.isdir(repo.wjoin(basedir)):
89+
ui.warn("Abort: basedir %r does not exist\n" % basedir)
90+
return
91+
modified = []
92+
else:
93+
modified = repo.status()[0]
8494
dependencies = parse_config(repo)
8595
success = True
8696
tstamp = 0 # newest time stamp assigned
@@ -93,8 +103,8 @@ def do_touch(ui, repo):
93103
if i in dependencies:
94104
hold_back[output] = inputs
95105
continue
96-
_success, _tstamp = check_rule(ui, repo, modified, output, inputs)
97-
sucess = success and _success
106+
_success, _tstamp = check_rule(ui, repo, modified, basedir, output, inputs)
107+
success = success and _success
98108
tstamp = max(tstamp, _tstamp)
99109
# put back held back rules
100110
dependencies.update(hold_back)
@@ -109,11 +119,12 @@ def do_touch(ui, repo):
109119
return False
110120
return success
111121

112-
def touch(ui, repo):
122+
def touch(ui, repo, basedir):
113123
"touch generated files that are older than their sources after an update."
114-
do_touch(ui, repo)
124+
do_touch(ui, repo, basedir)
115125

116126
cmdtable = {
117-
"touch": (touch, [],
118-
"touch generated files according to the .hgtouch configuration")
127+
"touch": (touch,
128+
[('b', 'basedir', '', 'base dir of the tree to apply touching', 'BASEDIR')],
129+
"hg touch [-b BASEDIR]")
119130
}

0 commit comments

Comments
 (0)