def main(argv): o = options.Options("crampi dedupe", optspec) (opt, flags, extra) = o.parse(argv[1:]) if len(extra) != 1: o.fatal('exactly one argument expected; use "crampi log" for a list') g = gitdb.GitDb(opt.gitdb) dstbranch = extra[0] dst = g.commitid_latest(dstbranch) if not dst: o.fatal("invalid argument; specify a valid refname") if not opt.using: o.fatal("you must provide --using") if opt.using == extra[0]: o.fatal("--using option %r must differ from destination branch %r" % (opt.using, extra[0])) if g.commit(opt.using): src = opt.using else: src = g.commitid_latest(opt.using) if not src: o.fatal("invalid --using; specify a valid refname or commitid") esrc = entry.load_tree_from_commit(g, src) edst = entry.load_tree_from_commit(g, dst) def _keygen(e): k = ((e.d.get("lastname") or "").strip().lower(), (e.d.get("firstname") or "").strip().lower()) if not filter(None, k): # all sub-elements are blank k = ((e.d.get("company") or "").strip(),) if not filter(None, k): return None else: return k srcdict = {} for e in esrc.entries: key = _keygen(e) srcdict[key] = e edst.reindex() for e in edst.entries: if not e.lid: print "barf: ", e key = _keygen(e) se = srcdict.get(key) if key and se and not edst.uuids.get(se.uuid): print e.uuid, se.uuid del srcdict[key] # max one mapping each e.uuid = se.uuid edst.save_commit(g, dstbranch, "deduplicated from %r@%r into %r@%r" % (opt.using, src, dstbranch, dst)) g.flush()
def main(argv): o = options.Options("crampi fake-merge", optspec) (opt, flags, extra) = o.parse(argv[1:]) if len(extra): o.fatal("no arguments expected") if not opt.branch: o.fatal("you must specify the -b option") if not opt.merge: o.fatal("you must specify the -m option") g = gitdb.GitDb(opt.gitdb) cid = g.commitid_latest(opt.branch) if not cid: o.fatal("nonexistent commit: %r" % opt.branch) el = entry.load_tree_from_commit(g, cid) print merge.run( g, el, opt.branch, opt.merge, opt.verbose, add_contact=lambda d: None, update_contact=lambda lid, d, changes: None, commit_contacts=lambda: None, reload_entrylist=lambda el: el, ) g.flush()
def main(argv): o = options.Options('crampi dump', optspec) (opt, flags, extra) = o.parse(argv[1:]) if len(extra) != 1: o.fatal('exactly one argument expected; use "crampi log" for a list') g = gitdb.GitDb(opt.gitdb) if g.commit(extra[0]): commitid = extra[0] else: commitid = g.commitid_latest(extra[0]) if not commitid: o.fatal('invalid argument; specify a valid refname or commitid') entries = entry.load_tree_from_commit(g, commitid) for e in entries.entries: print e.uuid for k,v in sorted(e.d.items()): if isinstance(v, dict): print '%s:' % k for dk,dv in sorted(v.items()): print ' %s: %r' % (dk, dv) else: print '%s: %r' % (k,v) print
def main(argv): o = options.Options('crampi diff', optspec) (opt, flags, extra) = o.parse(argv[1:]) if len(extra) != 2: o.fatal('exactly two arguments expected; use "crampi log" for a list') g = gitdb.GitDb(opt.gitdb) def lookup(s): if g.commit(s): return s else: c = g.commitid_latest(s) if not c: o.fatal('%r: not found; specify a valid refname or commitid' % s) return c c1 = lookup(extra[0]) c2 = lookup(extra[1]) entries1 = entry.load_tree_from_commit(g, c1) entries2 = entry.load_tree_from_commit(g, c2) def printrow(key, old, new): if key: key = '%s: ' % key else: key = '' if old != None and old == new: uprint(' %s%s' % (key, old)) else: if old: uprint('-%s%s' % (key, old)) if new: uprint('+%s%s' % (key, new)) for uuid,ad,bd in entry.diff(entries1, entries2): if not ad: ad = {} if not bd: bd = {} if ad == bd: continue printrow(None, ad and uuid or None, bd and uuid or None) if not opt.short: for key in sorted(set(ad.keys()) | set(bd.keys())): printrow(key, ad.get(key), bd.get(key)) print
def main(argv): o = options.Options('crampi validate', optspec) (opt, flags, extra) = o.parse(argv[1:]) if extra: o.fatal('no arguments expected') g = gitdb.GitDb(opt.gitdb) for r,ref,msg in reversed(list(g.commits(refname=None))): print '%-6d %-10s %s' % (r,ref,msg) el = entry.load_tree_from_commit(g, r) el.reindex()
def run(g, el, branch, merged_refname, verbose, add_contact, update_contact, commit_contacts, reload_entrylist): a_id = g.commitid_lastmerge(refname=branch, merged_refname=merged_refname) b_id = g.commitid_latest(merged_refname) print 'aid=%s bid=%s' % (a_id, b_id) a = entry.load_tree_from_commit(g, a_id) b = entry.load_tree_from_commit(g, b_id) nel = el.clone() for (lid,uuid,ed,ad,bd) in entry.merge(el, a, b): d = None e = None if ed == None: # add mode = 'A' assert(bd != None) assert(uuid) lid = add_contact(bd) if lid: e = entry.Entry(lid, uuid, bd) el.add(e) elif ad and not bd: # del mode = 'D' e = el.uuids[uuid] # do nothing: deletes are too dangerous to merge elif ad != bd: # modify mode = 'M' e = el.uuids[uuid] changes = e.patch(ad, bd) if changes: update_contact(lid, e.d, changes) else: mode = '' e = el.uuids[uuid] if mode or verbose: print '%1s %s' % (mode, e) commit_contacts() el = reload_entrylist(el) return el.save_commit(g, branch, merged_commit=b_id, msg='merged from %s:%s..%s on %s' % (merged_refname, a_id, b_id, time.asctime()))