Mercurial > hg > gitweb
comparison mercurial/commands.py @ 898:3616c0d7ab88
Add searching for named branches
named branching is when you identify a head by a tag on an earlier revision.
This patch adds repo.branchlookup for searching through the tree to
find branch tags for heads.
hg update -b tag is added to checkout based on branch tags
hg heads -b is added to print the tag associated with each head
author | mason@suse.com |
---|---|
date | Sun, 14 Aug 2005 12:23:45 -0800 |
parents | 01215ad04283 |
children | aa5b726e9619 |
comparison
equal
deleted
inserted
replaced
897:fe30f5434b51 | 898:3616c0d7ab88 |
---|---|
192 for f in d: | 192 for f in d: |
193 to = repo.file(f).read(mmap[f]) | 193 to = repo.file(f).read(mmap[f]) |
194 tn = None | 194 tn = None |
195 fp.write(mdiff.unidiff(to, date1, tn, date2, f, r)) | 195 fp.write(mdiff.unidiff(to, date1, tn, date2, f, r)) |
196 | 196 |
197 def show_changeset(ui, repo, rev=0, changenode=None, filelog=None): | 197 def show_changeset(ui, repo, rev=0, changenode=None, filelog=None, brinfo=None): |
198 """show a single changeset or file revision""" | 198 """show a single changeset or file revision""" |
199 changelog = repo.changelog | 199 changelog = repo.changelog |
200 if filelog: | 200 if filelog: |
201 log = filelog | 201 log = filelog |
202 filerev = rev | 202 filerev = rev |
233 ui.status("tag: %s\n" % tag) | 233 ui.status("tag: %s\n" % tag) |
234 for parent in parents: | 234 for parent in parents: |
235 ui.write("parent: %d:%s\n" % parent) | 235 ui.write("parent: %d:%s\n" % parent) |
236 if filelog: | 236 if filelog: |
237 ui.debug("file rev: %d:%s\n" % (filerev, hg.hex(filenode))) | 237 ui.debug("file rev: %d:%s\n" % (filerev, hg.hex(filenode))) |
238 | |
239 if brinfo and changenode in brinfo: | |
240 br = brinfo[changenode] | |
241 ui.write("branch: %s\n" % " ".join(br)) | |
238 | 242 |
239 ui.debug("manifest: %d:%s\n" % (repo.manifest.rev(changes[0]), | 243 ui.debug("manifest: %d:%s\n" % (repo.manifest.rev(changes[0]), |
240 hg.hex(changes[0]))) | 244 hg.hex(changes[0]))) |
241 ui.status("user: %s\n" % changes[1]) | 245 ui.status("user: %s\n" % changes[1]) |
242 ui.status("date: %s\n" % time.asctime( | 246 ui.status("date: %s\n" % time.asctime( |
673 if repo.dirstate.state(abs) == 'a': | 677 if repo.dirstate.state(abs) == 'a': |
674 forget.append(abs) | 678 forget.append(abs) |
675 if rel not in q: ui.status('forgetting ', rel, '\n') | 679 if rel not in q: ui.status('forgetting ', rel, '\n') |
676 repo.forget(forget) | 680 repo.forget(forget) |
677 | 681 |
678 def heads(ui, repo): | 682 def heads(ui, repo, **opts): |
679 """show current repository heads""" | 683 """show current repository heads""" |
684 heads = repo.changelog.heads() | |
685 br = None | |
686 if opts['branches']: | |
687 br = repo.branchlookup(heads) | |
680 for n in repo.changelog.heads(): | 688 for n in repo.changelog.heads(): |
681 show_changeset(ui, repo, changenode=n) | 689 show_changeset(ui, repo, changenode=n, brinfo=br) |
682 | 690 |
683 def identify(ui, repo): | 691 def identify(ui, repo): |
684 """print information about the working copy""" | 692 """print information about the working copy""" |
685 parents = [p for p in repo.dirstate.parents() if p != hg.nullid] | 693 parents = [p for p in repo.dirstate.parents() if p != hg.nullid] |
686 if not parents: | 694 if not parents: |
1148 a change is visible for pull by other users, undoing it locally is | 1156 a change is visible for pull by other users, undoing it locally is |
1149 ineffective. | 1157 ineffective. |
1150 """ | 1158 """ |
1151 repo.undo() | 1159 repo.undo() |
1152 | 1160 |
1153 def update(ui, repo, node=None, merge=False, clean=False): | 1161 def update(ui, repo, node=None, merge=False, clean=False, branch=None): |
1154 '''update or merge working directory | 1162 '''update or merge working directory |
1155 | 1163 |
1156 If there are no outstanding changes in the working directory and | 1164 If there are no outstanding changes in the working directory and |
1157 there is a linear relationship between the current version and the | 1165 there is a linear relationship between the current version and the |
1158 requested version, the result is the requested version. | 1166 requested version, the result is the requested version. |
1161 current working directory and the requested version. Files that | 1169 current working directory and the requested version. Files that |
1162 changed between either parent are marked as changed for the next | 1170 changed between either parent are marked as changed for the next |
1163 commit and a commit must be performed before any further updates | 1171 commit and a commit must be performed before any further updates |
1164 are allowed. | 1172 are allowed. |
1165 ''' | 1173 ''' |
1166 node = node and repo.lookup(node) or repo.changelog.tip() | 1174 if branch: |
1175 br = repo.branchlookup(branch=branch) | |
1176 found = [] | |
1177 for x in br: | |
1178 if branch in br[x]: | |
1179 found.append(x) | |
1180 if len(found) > 1: | |
1181 ui.warn("Found multiple heads for %s\n" % branch) | |
1182 for x in found: | |
1183 show_changeset(ui, repo, changenode=x, brinfo=br) | |
1184 return 1 | |
1185 if len(found) == 1: | |
1186 node = found[0] | |
1187 ui.warn("Using head %s for branch %s\n" % (hg.short(node), branch)) | |
1188 else: | |
1189 ui.warn("branch %s not found\n" % (branch)) | |
1190 return 1 | |
1191 else: | |
1192 node = node and repo.lookup(node) or repo.changelog.tip() | |
1167 return repo.update(node, allow=merge, force=clean) | 1193 return repo.update(node, allow=merge, force=clean) |
1168 | 1194 |
1169 def verify(ui, repo): | 1195 def verify(ui, repo): |
1170 """verify the integrity of the repository""" | 1196 """verify the integrity of the repository""" |
1171 return repo.verify() | 1197 return repo.verify() |
1234 "forget": | 1260 "forget": |
1235 (forget, | 1261 (forget, |
1236 [('I', 'include', [], 'include path in search'), | 1262 [('I', 'include', [], 'include path in search'), |
1237 ('X', 'exclude', [], 'exclude path from search')], | 1263 ('X', 'exclude', [], 'exclude path from search')], |
1238 "hg forget FILE..."), | 1264 "hg forget FILE..."), |
1239 "heads": (heads, [], 'hg heads'), | 1265 "heads": (heads, [('b', 'branches', None, 'find branch info')], 'hg heads'), |
1240 "help": (help_, [], 'hg help [COMMAND]'), | 1266 "help": (help_, [], 'hg help [COMMAND]'), |
1241 "identify|id": (identify, [], 'hg identify'), | 1267 "identify|id": (identify, [], 'hg identify'), |
1242 "import|patch": | 1268 "import|patch": |
1243 (import_, | 1269 (import_, |
1244 [('p', 'strip', 1, 'path strip'), | 1270 [('p', 'strip', 1, 'path strip'), |
1318 "tags": (tags, [], 'hg tags'), | 1344 "tags": (tags, [], 'hg tags'), |
1319 "tip": (tip, [], 'hg tip'), | 1345 "tip": (tip, [], 'hg tip'), |
1320 "undo": (undo, [], 'hg undo'), | 1346 "undo": (undo, [], 'hg undo'), |
1321 "^update|up|checkout|co": | 1347 "^update|up|checkout|co": |
1322 (update, | 1348 (update, |
1323 [('m', 'merge', None, 'allow merging of conflicts'), | 1349 [('b', 'branch', "", 'checkout the head of a specific branch'), |
1350 ('m', 'merge', None, 'allow merging of conflicts'), | |
1324 ('C', 'clean', None, 'overwrite locally modified files')], | 1351 ('C', 'clean', None, 'overwrite locally modified files')], |
1325 'hg update [-m] [-C] [REV]'), | 1352 'hg update [-m] [-C] [REV]'), |
1326 "verify": (verify, [], 'hg verify'), | 1353 "verify": (verify, [], 'hg verify'), |
1327 "version": (show_version, [], 'hg version'), | 1354 "version": (show_version, [], 'hg version'), |
1328 } | 1355 } |