| 1 |
#testcases dirstate-v1 dirstate-v2 |
| 2 |
|
| 3 |
#if dirstate-v2 |
| 4 |
$ cat >> $HGRCPATH << EOF |
| 5 |
> [format] |
| 6 |
> use-dirstate-v2=1 |
| 7 |
> [storage] |
| 8 |
> dirstate-v2.slow-path=allow |
| 9 |
> EOF |
| 10 |
#endif |
| 11 |
|
| 12 |
$ hg init repo |
| 13 |
$ cd repo |
| 14 |
$ echo a > a |
| 15 |
$ hg add a |
| 16 |
$ hg commit -m test |
| 17 |
|
| 18 |
Do we ever miss a sub-second change?: |
| 19 |
|
| 20 |
$ for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20; do |
| 21 |
> hg update -qC 0 |
| 22 |
> echo b > a |
| 23 |
> hg st |
| 24 |
> done |
| 25 |
M a |
| 26 |
M a |
| 27 |
M a |
| 28 |
M a |
| 29 |
M a |
| 30 |
M a |
| 31 |
M a |
| 32 |
M a |
| 33 |
M a |
| 34 |
M a |
| 35 |
M a |
| 36 |
M a |
| 37 |
M a |
| 38 |
M a |
| 39 |
M a |
| 40 |
M a |
| 41 |
M a |
| 42 |
M a |
| 43 |
M a |
| 44 |
M a |
| 45 |
|
| 46 |
$ echo test > b |
| 47 |
$ mkdir dir1 |
| 48 |
$ echo test > dir1/c |
| 49 |
$ echo test > d |
| 50 |
|
| 51 |
$ echo test > e |
| 52 |
#if execbit |
| 53 |
A directory will typically have the execute bit -- make sure it doesn't get |
| 54 |
confused with a file with the exec bit set |
| 55 |
$ chmod +x e |
| 56 |
#endif |
| 57 |
|
| 58 |
$ hg add b dir1 d e |
| 59 |
adding dir1/c |
| 60 |
$ hg commit -m test2 |
| 61 |
|
| 62 |
$ cat >> $TESTTMP/dirstaterace.py << EOF |
| 63 |
> from mercurial import ( |
| 64 |
> context, |
| 65 |
> extensions, |
| 66 |
> ) |
| 67 |
> def extsetup(ui): |
| 68 |
> extensions.wrapfunction(context.workingctx, '_checklookup', overridechecklookup) |
| 69 |
> def overridechecklookup(orig, self, *args, **kwargs): |
| 70 |
> # make an update that changes the dirstate from underneath |
| 71 |
> self._repo.ui.system(br"sh '$TESTTMP/dirstaterace.sh'", |
| 72 |
> cwd=self._repo.root) |
| 73 |
> return orig(self, *args, **kwargs) |
| 74 |
> EOF |
| 75 |
|
| 76 |
$ hg debugrebuilddirstate |
| 77 |
$ hg debugdirstate |
| 78 |
n 0 -1 unset a |
| 79 |
n 0 -1 unset b |
| 80 |
n 0 -1 unset d |
| 81 |
n 0 -1 unset dir1/c |
| 82 |
n 0 -1 unset e |
| 83 |
|
| 84 |
XXX Note that this returns M for files that got replaced by directories. This is |
| 85 |
definitely a bug, but the fix for that is hard and the next status run is fine |
| 86 |
anyway. |
| 87 |
|
| 88 |
$ cat > $TESTTMP/dirstaterace.sh <<EOF |
| 89 |
> rm b && rm -r dir1 && rm d && mkdir d && rm e && mkdir e |
| 90 |
> EOF |
| 91 |
|
| 92 |
$ sleep 1 # ensure non-ambiguous mtime |
| 93 |
$ hg status --config extensions.dirstaterace=$TESTTMP/dirstaterace.py |
| 94 |
M d |
| 95 |
M e |
| 96 |
! b |
| 97 |
! dir1/c |
| 98 |
$ hg debugdirstate |
| 99 |
n 644 2 * a (glob) |
| 100 |
n 0 -1 unset b |
| 101 |
n 0 -1 unset d |
| 102 |
n 0 -1 unset dir1/c |
| 103 |
n 0 -1 unset e |
| 104 |
|
| 105 |
$ hg status |
| 106 |
! b |
| 107 |
! d |
| 108 |
! dir1/c |
| 109 |
! e |
| 110 |
|
| 111 |
$ rmdir d e |
| 112 |
$ hg update -C -q . |
| 113 |
|
| 114 |
Test that dirstate changes aren't written out at the end of "hg |
| 115 |
status", if .hg/dirstate is already changed simultaneously before |
| 116 |
acquisition of wlock in workingctx._poststatusfixup(). |
| 117 |
|
| 118 |
This avoidance is important to keep consistency of dirstate in race |
| 119 |
condition (see issue5584 for detail). |
| 120 |
|
| 121 |
$ hg parents -q |
| 122 |
1:* (glob) |
| 123 |
|
| 124 |
$ hg debugrebuilddirstate |
| 125 |
$ hg debugdirstate |
| 126 |
n 0 -1 unset a |
| 127 |
n 0 -1 unset b |
| 128 |
n 0 -1 unset d |
| 129 |
n 0 -1 unset dir1/c |
| 130 |
n 0 -1 unset e |
| 131 |
|
| 132 |
$ cat > $TESTTMP/dirstaterace.sh <<EOF |
| 133 |
> # This script assumes timetable of typical issue5584 case below: |
| 134 |
> # |
| 135 |
> # 1. "hg status" loads .hg/dirstate |
| 136 |
> # 2. "hg status" confirms clean-ness of FILE |
| 137 |
> # 3. "hg update -C 0" updates the working directory simultaneously |
| 138 |
> # (FILE is removed, and FILE is dropped from .hg/dirstate) |
| 139 |
> # 4. "hg status" acquires wlock |
| 140 |
> # (.hg/dirstate is re-loaded = no FILE entry in dirstate) |
| 141 |
> # 5. "hg status" marks FILE in dirstate as clean |
| 142 |
> # (FILE entry is added to in-memory dirstate) |
| 143 |
> # 6. "hg status" writes dirstate changes into .hg/dirstate |
| 144 |
> # (FILE entry is written into .hg/dirstate) |
| 145 |
> # |
| 146 |
> # To reproduce similar situation easily and certainly, #2 and #3 |
| 147 |
> # are swapped. "hg cat" below ensures #2 on "hg status" side. |
| 148 |
> |
| 149 |
> hg update -q -C 0 |
| 150 |
> hg cat -r 1 b > b |
| 151 |
> # make sure the timestamps is not ambiguous and a write will be issued |
| 152 |
> touch -t 198606251012 b |
| 153 |
> EOF |
| 154 |
|
| 155 |
"hg status" below should excludes "e", of which exec flag is set, for |
| 156 |
portability of test scenario, because unsure but missing "e" is |
| 157 |
treated differently in _checklookup() according to runtime platform. |
| 158 |
|
| 159 |
- "missing(!)" on POSIX, "pctx[f].cmp(self[f])" raises ENOENT |
| 160 |
- "modified(M)" on Windows, "self.flags(f) != pctx.flags(f)" is True |
| 161 |
|
| 162 |
$ hg status --config extensions.dirstaterace=$TESTTMP/dirstaterace.py --debug -X path:e |
| 163 |
skip updating dirstate: identity mismatch |
| 164 |
M a |
| 165 |
! d |
| 166 |
! dir1/c |
| 167 |
|
| 168 |
$ hg parents -q |
| 169 |
0:* (glob) |
| 170 |
$ hg files |
| 171 |
a |
| 172 |
$ hg debugdirstate |
| 173 |
n * * * a (glob) |
| 174 |
|
| 175 |
$ rm b |
| 176 |
|
| 177 |
#if fsmonitor |
| 178 |
|
| 179 |
Create fsmonitor state. |
| 180 |
|
| 181 |
$ hg status |
| 182 |
$ f --type .hg/fsmonitor.state |
| 183 |
.hg/fsmonitor.state: file |
| 184 |
|
| 185 |
Test that invalidating fsmonitor state in the middle (which doesn't require the |
| 186 |
wlock) causes the fsmonitor update to be skipped. |
| 187 |
hg debugrebuilddirstate ensures that the dirstaterace hook will be called, but |
| 188 |
it also invalidates the fsmonitor state. So back it up and restore it. |
| 189 |
|
| 190 |
$ mv .hg/fsmonitor.state .hg/fsmonitor.state.tmp |
| 191 |
$ hg debugrebuilddirstate |
| 192 |
$ mv .hg/fsmonitor.state.tmp .hg/fsmonitor.state |
| 193 |
|
| 194 |
$ cat > $TESTTMP/dirstaterace.sh <<EOF |
| 195 |
> rm .hg/fsmonitor.state |
| 196 |
> EOF |
| 197 |
|
| 198 |
$ hg status --config extensions.dirstaterace=$TESTTMP/dirstaterace.py --debug |
| 199 |
skip updating fsmonitor.state: identity mismatch |
| 200 |
$ f .hg/fsmonitor.state |
| 201 |
.hg/fsmonitor.state: file not found |
| 202 |
|
| 203 |
#endif |
| 204 |
|
| 205 |
Set up a rebase situation for issue5581. |
| 206 |
|
| 207 |
$ echo c2 > a |
| 208 |
$ echo c2 > b |
| 209 |
$ hg add b |
| 210 |
$ hg commit -m c2 |
| 211 |
created new head |
| 212 |
$ echo c3 >> a |
| 213 |
$ hg commit -m c3 |
| 214 |
$ hg update 2 |
| 215 |
1 files updated, 0 files merged, 0 files removed, 0 files unresolved |
| 216 |
$ echo c4 >> a |
| 217 |
$ echo c4 >> b |
| 218 |
$ hg commit -m c4 |
| 219 |
created new head |
| 220 |
|
| 221 |
Configure a merge tool that runs status in the middle of the rebase. The goal of |
| 222 |
the status call is to trigger a potential bug if fsmonitor's state is written |
| 223 |
even though the wlock is held by another process. The output of 'hg status' in |
| 224 |
the merge tool goes to /dev/null because we're more interested in the results of |
| 225 |
'hg status' run after the rebase. |
| 226 |
|
| 227 |
$ cat >> $TESTTMP/mergetool-race.sh << EOF |
| 228 |
> echo "custom merge tool" |
| 229 |
> printf "c2\nc3\nc4\n" > \$1 |
| 230 |
> hg --cwd "$TESTTMP/repo" status > /dev/null |
| 231 |
> echo "custom merge tool end" |
| 232 |
> EOF |
| 233 |
$ cat >> $HGRCPATH << EOF |
| 234 |
> [extensions] |
| 235 |
> rebase = |
| 236 |
> [merge-tools] |
| 237 |
> test.executable=sh |
| 238 |
> test.args=$TESTTMP/mergetool-race.sh \$output |
| 239 |
> EOF |
| 240 |
|
| 241 |
$ hg rebase -s . -d 3 --tool test |
| 242 |
rebasing 4:b08445fd6b2a tip "c4" |
| 243 |
merging a |
| 244 |
custom merge tool |
| 245 |
custom merge tool end |
| 246 |
saved backup bundle to $TESTTMP/repo/.hg/strip-backup/* (glob) |
| 247 |
|
| 248 |
This hg status should be empty, whether or not fsmonitor is enabled (issue5581). |
| 249 |
|
| 250 |
$ hg status |