Mercurial > hg
comparison hgext/graphlog.py @ 7716:4ad12930a459
graphlog: extract large parts of repeated code from incoming/outgoing
author | Dirkjan Ochtman <dirkjan@ochtman.nl> |
---|---|
date | Mon, 26 Jan 2009 16:50:27 +0100 |
parents | fd3266287b40 |
children | cdc913e7fc5f |
comparison
equal
deleted
inserted
replaced
7715:fd3266287b40 | 7716:4ad12930a459 |
---|---|
280 if path: # could be reset in canonpath | 280 if path: # could be reset in canonpath |
281 revdag = filerevs(repo, path, start, stop) | 281 revdag = filerevs(repo, path, start, stop) |
282 else: | 282 else: |
283 revdag = revisions(repo, start, stop) | 283 revdag = revisions(repo, start, stop) |
284 | 284 |
285 repo_parents = repo.dirstate.parents() | 285 graphdag = graphabledag(ui, repo, revdag, opts) |
286 ascii(ui, grapher(graphdag)) | |
287 | |
288 def graphrevs(repo, nodes, opts): | |
289 nodes.reverse() | |
290 include = util.set(nodes) | |
291 limit = cmdutil.loglimit(opts) | |
292 count = 0 | |
293 for node in nodes: | |
294 if count >= limit: | |
295 break | |
296 ctx = repo[node] | |
297 parents = [p.rev() for p in ctx.parents() if p.node() in include] | |
298 parents.sort() | |
299 yield (ctx, parents) | |
300 count += 1 | |
301 | |
302 def graphabledag(ui, repo, revdag, opts): | |
303 showparents = [ctx.node() for ctx in repo[None].parents()] | |
286 displayer = show_changeset(ui, repo, opts, buffered=True) | 304 displayer = show_changeset(ui, repo, opts, buffered=True) |
287 def graphabledag(): | 305 for (ctx, parents) in revdag: |
288 for (ctx, parents) in revdag: | 306 displayer.show(ctx) |
289 # log_strings is the list of all log strings to draw alongside | 307 lines = displayer.hunk.pop(ctx.rev()).split('\n')[:-1] |
290 # the graph. | 308 char = ctx.node() in showparents and '@' or 'o' |
291 displayer.show(ctx) | 309 yield (ctx.rev(), parents, char, lines) |
292 lines = displayer.hunk.pop(ctx.rev()).split("\n")[:-1] | 310 |
293 char = ctx.node() in repo_parents and '@' or 'o' | 311 def goutgoing(ui, repo, dest=None, **opts): |
294 yield (ctx.rev(), parents, char, lines) | 312 """show the outgoing changesets alongside an ASCII revision graph |
295 | 313 |
296 ascii(ui, grapher(graphabledag())) | 314 Print the outgoing changesets alongside a revision graph drawn with |
297 | 315 ASCII characters. |
298 def outgoing_revs(ui, repo, dest, opts): | 316 |
299 """cset DAG generator yielding (node, [parents]) tuples | 317 Nodes printed as an @ character are parents of the working |
300 | 318 directory. |
301 This generator function walks through the revisions not found | 319 """ |
302 in the destination | 320 |
303 """ | 321 check_unsupported_flags(opts) |
304 limit = cmdutil.loglimit(opts) | |
305 dest, revs, checkout = hg.parseurl( | 322 dest, revs, checkout = hg.parseurl( |
306 ui.expandpath(dest or 'default-push', dest or 'default'), | 323 ui.expandpath(dest or 'default-push', dest or 'default'), |
307 opts.get('rev')) | 324 opts.get('rev')) |
308 cmdutil.setremoteconfig(ui, opts) | 325 cmdutil.setremoteconfig(ui, opts) |
309 if revs: | 326 if revs: |
312 ui.status(_('comparing with %s\n') % url.hidepassword(dest)) | 329 ui.status(_('comparing with %s\n') % url.hidepassword(dest)) |
313 o = repo.findoutgoing(other, force=opts.get('force')) | 330 o = repo.findoutgoing(other, force=opts.get('force')) |
314 if not o: | 331 if not o: |
315 ui.status(_("no changes found\n")) | 332 ui.status(_("no changes found\n")) |
316 return | 333 return |
334 | |
317 o = repo.changelog.nodesbetween(o, revs)[0] | 335 o = repo.changelog.nodesbetween(o, revs)[0] |
318 o.reverse() | 336 revdag = graphrevs(repo, o, opts) |
319 revdict = {} | 337 graphdag = graphabledag(ui, repo, revdag, opts) |
320 for n in o: | 338 ascii(ui, grapher(graphdag)) |
321 revdict[repo.changectx(n).rev()]=True | |
322 count = 0 | |
323 for n in o: | |
324 if count >= limit: | |
325 break | |
326 ctx = repo.changectx(n) | |
327 parents = [p.rev() for p in ctx.parents() if p.rev() in revdict] | |
328 parents.sort() | |
329 yield (ctx, parents) | |
330 count += 1 | |
331 | |
332 def goutgoing(ui, repo, dest=None, **opts): | |
333 """show the outgoing changesets alongside an ASCII revision graph | |
334 | |
335 Print the outgoing changesets alongside a revision graph drawn with | |
336 ASCII characters. | |
337 | |
338 Nodes printed as an @ character are parents of the working | |
339 directory. | |
340 """ | |
341 check_unsupported_flags(opts) | |
342 revdag = outgoing_revs(ui, repo, dest, opts) | |
343 repo_parents = repo.dirstate.parents() | |
344 displayer = show_changeset(ui, repo, opts, buffered=True) | |
345 def graphabledag(): | |
346 for (ctx, parents) in revdag: | |
347 # log_strings is the list of all log strings to draw alongside | |
348 # the graph. | |
349 displayer.show(ctx) | |
350 lines = displayer.hunk.pop(ctx.rev()).split("\n")[:-1] | |
351 char = ctx.node() in repo_parents and '@' or 'o' | |
352 yield (ctx.rev(), parents, char, lines) | |
353 | |
354 ascii(ui, grapher(graphabledag())) | |
355 | |
356 def incoming_revs(other, chlist, opts): | |
357 """cset DAG generator yielding (node, [parents]) tuples | |
358 | |
359 This generator function walks through the revisions of the destination | |
360 not found in repo | |
361 """ | |
362 limit = cmdutil.loglimit(opts) | |
363 chlist.reverse() | |
364 revdict = {} | |
365 for n in chlist: | |
366 revdict[other.changectx(n).rev()]=True | |
367 count = 0 | |
368 for n in chlist: | |
369 if count >= limit: | |
370 break | |
371 ctx = other.changectx(n) | |
372 parents = [p.rev() for p in ctx.parents() if p.rev() in revdict] | |
373 parents.sort() | |
374 yield (ctx, parents) | |
375 count += 1 | |
376 | 339 |
377 def gincoming(ui, repo, source="default", **opts): | 340 def gincoming(ui, repo, source="default", **opts): |
378 """show the incoming changesets alongside an ASCII revision graph | 341 """show the incoming changesets alongside an ASCII revision graph |
379 | 342 |
380 Print the incoming changesets alongside a revision graph drawn with | 343 Print the incoming changesets alongside a revision graph drawn with |
401 ui.status(_("no changes found\n")) | 364 ui.status(_("no changes found\n")) |
402 return | 365 return |
403 | 366 |
404 cleanup = None | 367 cleanup = None |
405 try: | 368 try: |
369 | |
406 fname = opts["bundle"] | 370 fname = opts["bundle"] |
407 if fname or not other.local(): | 371 if fname or not other.local(): |
408 # create a bundle (uncompressed if other repo is not local) | 372 # create a bundle (uncompressed if other repo is not local) |
409 if revs is None: | 373 if revs is None: |
410 cg = other.changegroup(incoming, "incoming") | 374 cg = other.changegroup(incoming, "incoming") |
418 if not other.local(): | 382 if not other.local(): |
419 # use the created uncompressed bundlerepo | 383 # use the created uncompressed bundlerepo |
420 other = bundlerepo.bundlerepository(ui, repo.root, fname) | 384 other = bundlerepo.bundlerepository(ui, repo.root, fname) |
421 | 385 |
422 chlist = other.changelog.nodesbetween(incoming, revs)[0] | 386 chlist = other.changelog.nodesbetween(incoming, revs)[0] |
423 revdag = incoming_revs(other, chlist, opts) | 387 revdag = graphrevs(other, chlist, opts) |
424 other_parents = [] | 388 other_parents = [] |
425 displayer = show_changeset(ui, other, opts, buffered=True) | 389 displayer = show_changeset(ui, other, opts, buffered=True) |
426 def graphabledag(): | 390 graphdag = graphabledag(ui, repo, revdag, opts) |
427 for (ctx, parents) in revdag: | 391 ascii(ui, grapher(graphdag)) |
428 # log_strings is the list of all log strings to draw alongside | 392 |
429 # the graph. | |
430 displayer.show(ctx) | |
431 lines = displayer.hunk.pop(ctx.rev()).split("\n")[:-1] | |
432 char = ctx.node() in other_parents and '@' or 'o' | |
433 yield (ctx.rev(), parents, char, lines) | |
434 | |
435 ascii(ui, grapher(graphabledag())) | |
436 finally: | 393 finally: |
437 if hasattr(other, 'close'): | 394 if hasattr(other, 'close'): |
438 other.close() | 395 other.close() |
439 if cleanup: | 396 if cleanup: |
440 os.unlink(cleanup) | 397 os.unlink(cleanup) |