##// END OF EJS Templates
log: add -f/--follow option, to follow rename/copy
Vadim Gelfer -
r2741:ae5ce345 default
parent child Browse files
Show More
@@ -0,0 +1,30 b''
1 #!/bin/sh
2
3 hg init a
4
5 cd a
6 echo a > a
7 hg ci -Ama -d '1 0'
8
9 hg cp a b
10 hg ci -mb -d '2 0'
11
12 mkdir dir
13 hg mv b dir
14 hg ci -mc -d '3 0'
15
16 hg mv a b
17 hg ci -md -d '4 0'
18
19 hg mv dir/b e
20 hg ci -me -d '5 0'
21
22 hg log a
23 echo % -f, directory
24 hg log -f dir
25 echo % -f, but no args
26 hg log -f
27 echo % one rename
28 hg log -vf a
29 echo % many renames
30 hg log -vf e
@@ -0,0 +1,78 b''
1 adding a
2 changeset: 0:8580ff50825a
3 user: test
4 date: Thu Jan 01 00:00:01 1970 +0000
5 summary: a
6
7 % -f, directory
8 abort: can only follow copies/renames for explicit file names
9 % -f, but no args
10 changeset: 4:8c1c8408f737
11 tag: tip
12 user: test
13 date: Thu Jan 01 00:00:05 1970 +0000
14 summary: e
15
16 changeset: 3:c4ba038c90ce
17 user: test
18 date: Thu Jan 01 00:00:04 1970 +0000
19 summary: d
20
21 changeset: 2:21fba396af4c
22 user: test
23 date: Thu Jan 01 00:00:03 1970 +0000
24 summary: c
25
26 changeset: 1:c0296dabce9b
27 user: test
28 date: Thu Jan 01 00:00:02 1970 +0000
29 summary: b
30
31 changeset: 0:8580ff50825a
32 user: test
33 date: Thu Jan 01 00:00:01 1970 +0000
34 summary: a
35
36 % one rename
37 changeset: 0:8580ff50825a50c8f716709acdf8de0deddcd6ab
38 user: test
39 date: Thu Jan 01 00:00:01 1970 +0000
40 files: a
41 description:
42 a
43
44
45 % many renames
46 changeset: 4:8c1c8408f7371319750ea2d4fa7969828effbcf4
47 tag: tip
48 user: test
49 date: Thu Jan 01 00:00:05 1970 +0000
50 files: dir/b e
51 description:
52 e
53
54
55 changeset: 2:21fba396af4c801f9717de6c415b6cc9620437e8
56 user: test
57 date: Thu Jan 01 00:00:03 1970 +0000
58 files: b dir/b
59 description:
60 c
61
62
63 changeset: 1:c0296dabce9bf0cd3fdd608de26693c91cd6bbf4
64 user: test
65 date: Thu Jan 01 00:00:02 1970 +0000
66 files: b
67 description:
68 b
69
70
71 changeset: 0:8580ff50825a50c8f716709acdf8de0deddcd6ab
72 user: test
73 date: Thu Jan 01 00:00:01 1970 +0000
74 files: a
75 description:
76 a
77
78
@@ -125,6 +125,7 b' def walkchangerevs(ui, repo, pats, opts)'
125
125
126
126
127 files, matchfn, anypats = matchpats(repo, pats, opts)
127 files, matchfn, anypats = matchpats(repo, pats, opts)
128 follow = opts.get('follow')
128
129
129 if repo.changelog.count() == 0:
130 if repo.changelog.count() == 0:
130 return [], False, matchfn
131 return [], False, matchfn
@@ -144,37 +145,54 b' def walkchangerevs(ui, repo, pats, opts)'
144 if not slowpath and not files:
145 if not slowpath and not files:
145 # No files, no patterns. Display all revs.
146 # No files, no patterns. Display all revs.
146 wanted = dict(zip(revs, revs))
147 wanted = dict(zip(revs, revs))
148 copies = []
147 if not slowpath:
149 if not slowpath:
148 # Only files, no patterns. Check the history of each file.
150 # Only files, no patterns. Check the history of each file.
149 def filerevgen(filelog):
151 def filerevgen(filelog, node):
150 cl_count = repo.changelog.count()
152 cl_count = repo.changelog.count()
151 for i, window in increasing_windows(filelog.count()-1, -1):
153 if node is None:
154 last = filelog.count() - 1
155 else:
156 last = filelog.rev(node)
157 for i, window in increasing_windows(last, -1):
152 revs = []
158 revs = []
153 for j in xrange(i - window, i + 1):
159 for j in xrange(i - window, i + 1):
154 revs.append(filelog.linkrev(filelog.node(j)))
160 n = filelog.node(j)
161 revs.append((filelog.linkrev(n),
162 follow and filelog.renamed(n)))
155 revs.reverse()
163 revs.reverse()
156 for rev in revs:
164 for rev in revs:
157 # only yield rev for which we have the changelog, it can
165 # only yield rev for which we have the changelog, it can
158 # happen while doing "hg log" during a pull or commit
166 # happen while doing "hg log" during a pull or commit
159 if rev < cl_count:
167 if rev[0] < cl_count:
160 yield rev
168 yield rev
161
169 def iterfiles():
170 for filename in files:
171 yield filename, None
172 for filename_node in copies:
173 yield filename_node
162 minrev, maxrev = min(revs), max(revs)
174 minrev, maxrev = min(revs), max(revs)
163 for file_ in files:
175 for file_, node in iterfiles():
164 filelog = repo.file(file_)
176 filelog = repo.file(file_)
165 # A zero count may be a directory or deleted file, so
177 # A zero count may be a directory or deleted file, so
166 # try to find matching entries on the slow path.
178 # try to find matching entries on the slow path.
167 if filelog.count() == 0:
179 if filelog.count() == 0:
168 slowpath = True
180 slowpath = True
169 break
181 break
170 for rev in filerevgen(filelog):
182 for rev, copied in filerevgen(filelog, node):
171 if rev <= maxrev:
183 if rev <= maxrev:
172 if rev < minrev:
184 if rev < minrev:
173 break
185 break
174 fncache.setdefault(rev, [])
186 fncache.setdefault(rev, [])
175 fncache[rev].append(file_)
187 fncache[rev].append(file_)
176 wanted[rev] = 1
188 wanted[rev] = 1
189 if follow and copied:
190 copies.append(copied)
177 if slowpath:
191 if slowpath:
192 if follow:
193 raise util.Abort(_('can only follow copies/renames for explicit '
194 'file names'))
195
178 # The slow path checks files modified in every changeset.
196 # The slow path checks files modified in every changeset.
179 def changerevgen():
197 def changerevgen():
180 for i, window in increasing_windows(repo.changelog.count()-1, -1):
198 for i, window in increasing_windows(repo.changelog.count()-1, -1):
@@ -1930,7 +1948,12 b' def locate(ui, repo, *pats, **opts):'
1930 def log(ui, repo, *pats, **opts):
1948 def log(ui, repo, *pats, **opts):
1931 """show revision history of entire repository or files
1949 """show revision history of entire repository or files
1932
1950
1933 Print the revision history of the specified files or the entire project.
1951 Print the revision history of the specified files or the entire
1952 project.
1953
1954 File history is shown without following rename or copy history of
1955 files. Use -f/--follow to follow history across renames and
1956 copies.
1934
1957
1935 By default this command outputs: changeset id and hash, tags,
1958 By default this command outputs: changeset id and hash, tags,
1936 non-trivial parents, user, date and time, and a summary for each
1959 non-trivial parents, user, date and time, and a summary for each
@@ -3043,6 +3066,8 b' table = {'
3043 "^log|history":
3066 "^log|history":
3044 (log,
3067 (log,
3045 [('b', 'branches', None, _('show branches')),
3068 [('b', 'branches', None, _('show branches')),
3069 ('f', 'follow', None,
3070 _('follow file history across copies and renames')),
3046 ('k', 'keyword', [], _('search for a keyword')),
3071 ('k', 'keyword', [], _('search for a keyword')),
3047 ('l', 'limit', '', _('limit number of changes displayed')),
3072 ('l', 'limit', '', _('limit number of changes displayed')),
3048 ('r', 'rev', [], _('show the specified revision or range')),
3073 ('r', 'rev', [], _('show the specified revision or range')),
General Comments 0
You need to be logged in to leave comments. Login now