# HG changeset patch # User Christian Ebert # Date 1168218784 -3600 # Node ID 28455872cb0ec628a66a636c23e50f21add170a9 # Parent f7a2a246740caf7cd8723faa8f1341e42e2d421c Fix indent in entire kwrepo.commit function diff -r f7a2a246740c -r 28455872cb0e hgkw/keyword.py --- a/hgkw/keyword.py Sun Jan 07 21:51:57 2007 +0100 +++ b/hgkw/keyword.py Mon Jan 08 02:13:04 2007 +0100 @@ -90,161 +90,160 @@ return filelog.filelog(self.sopener, f, self, self.revlogversion) def commit(self, files=None, text="", user=None, date=None, - match=util.always, force=False, lock=None, wlock=None, - force_editor=False, p1=None, p2=None, extra={}): + match=util.always, force=False, lock=None, wlock=None, + force_editor=False, p1=None, p2=None, extra={}): - commit = [] - remove = [] - changed = [] - use_dirstate = (p1 is None) # not rawcommit - extra = extra.copy() + commit = [] + remove = [] + changed = [] + use_dirstate = (p1 is None) # not rawcommit + extra = extra.copy() - if use_dirstate: - if files: - for f in files: - s = self.dirstate.state(f) - if s in 'nmai': - commit.append(f) - elif s == 'r': - remove.append(f) - else: - ui.warn(_("%s not tracked!\n") % f) - else: - changes = self.status(match=match)[:5] - modified, added, removed, deleted, unknown = changes - commit = modified + added - remove = removed - else: - commit = files - - if use_dirstate: - p1, p2 = self.dirstate.parents() - update_dirstate = True + if use_dirstate: + if files: + for f in files: + s = self.dirstate.state(f) + if s in 'nmai': + commit.append(f) + elif s == 'r': + remove.append(f) + else: + ui.warn(_("%s not tracked!\n") % f) else: - p1, p2 = p1, p2 or nullid - update_dirstate = (self.dirstate.parents()[0] == p1) - - c1 = self.changelog.read(p1) - c2 = self.changelog.read(p2) - m1 = self.manifest.read(c1[0]).copy() - m2 = self.manifest.read(c2[0]) + changes = self.status(match=match)[:5] + modified, added, removed, deleted, unknown = changes + commit = modified + added + remove = removed + else: + commit = files - if use_dirstate: - branchname = self.workingctx().branch() - try: - branchname = branchname.decode('UTF-8').encode('UTF-8') - except UnicodeDecodeError: - raise util.Abort(_('branch name not in UTF-8!')) - else: - branchname = "" + if use_dirstate: + p1, p2 = self.dirstate.parents() + update_dirstate = True + else: + p1, p2 = p1, p2 or nullid + update_dirstate = (self.dirstate.parents()[0] == p1) + + c1 = self.changelog.read(p1) + c2 = self.changelog.read(p2) + m1 = self.manifest.read(c1[0]).copy() + m2 = self.manifest.read(c2[0]) - if use_dirstate: - oldname = c1[5].get("branch", "") # stored in UTF-8 - if not commit and not remove and not force and p2 == nullid and \ - branchname == oldname: - ui.status(_("nothing changed\n")) - return None + if use_dirstate: + branchname = self.workingctx().branch() + try: + branchname = branchname.decode('UTF-8').encode('UTF-8') + except UnicodeDecodeError: + raise util.Abort(_('branch name not in UTF-8!')) + else: + branchname = "" - xp1 = hex(p1) - if p2 == nullid: xp2 = '' - else: xp2 = hex(p2) - - self.hook("precommit", throw=True, parent1=xp1, parent2=xp2) + if use_dirstate: + oldname = c1[5].get("branch", "") # stored in UTF-8 + if not commit and not remove and not force and p2 == nullid and \ + branchname == oldname: + ui.status(_("nothing changed\n")) + return None - if not wlock: - wlock = self.wlock() - if not lock: - lock = self.lock() - tr = self.transaction() + xp1 = hex(p1) + if p2 == nullid: xp2 = '' + else: xp2 = hex(p2) + + self.hook("precommit", throw=True, parent1=xp1, parent2=xp2) + + if not wlock: + wlock = self.wlock() + if not lock: + lock = self.lock() + tr = self.transaction() - # check in files - new = {} - linkrev = self.changelog.count() - commit.sort() - is_exec = util.execfunc(self.root, m1.execf) - is_link = util.linkfunc(self.root, m1.linkf) - for f in commit: - ui.note(f + "\n") - try: - new[f] = self.filecommit(f, m1, m2, linkrev, tr, changed) - m1.set(f, is_exec(f), is_link(f)) - except OSError: - if use_dirstate: - ui.warn(_("trouble committing %s!\n") % f) - raise - else: - remove.append(f) + # check in files + new = {} + linkrev = self.changelog.count() + commit.sort() + is_exec = util.execfunc(self.root, m1.execf) + is_link = util.linkfunc(self.root, m1.linkf) + for f in commit: + ui.note(f + "\n") + try: + new[f] = self.filecommit(f, m1, m2, linkrev, tr, changed) + m1.set(f, is_exec(f), is_link(f)) + except OSError: + if use_dirstate: + ui.warn(_("trouble committing %s!\n") % f) + raise + else: + remove.append(f) - # update manifest - m1.update(new) - remove.sort() - removed = [] + # update manifest + m1.update(new) + remove.sort() + removed = [] - for f in remove: - if f in m1: - del m1[f] - removed.append(f) - mn = self.manifest.add(m1, tr, linkrev, c1[0], c2[0], (new, removed)) + for f in remove: + if f in m1: + del m1[f] + removed.append(f) + mn = self.manifest.add(m1, tr, linkrev, c1[0], c2[0], (new, removed)) - # add changeset - new = new.keys() - new.sort() + # add changeset + new = new.keys() + new.sort() - user = user or ui.username() - if not text or force_editor: - edittext = [] - if text: - edittext.append(text) - edittext.append("") - edittext.append("HG: user: %s" % user) - if p2 != nullid: - edittext.append("HG: branch merge") - edittext.extend(["HG: changed %s" % f for f in changed]) - edittext.extend(["HG: removed %s" % f for f in removed]) - if not changed and not remove: - edittext.append("HG: no files changed") - edittext.append("") - # run editor in the repository root - olddir = os.getcwd() - os.chdir(self.root) - text = ui.edit("\n".join(edittext), user) - os.chdir(olddir) + user = user or ui.username() + if not text or force_editor: + edittext = [] + if text: + edittext.append(text) + edittext.append("") + edittext.append("HG: user: %s" % user) + if p2 != nullid: + edittext.append("HG: branch merge") + edittext.extend(["HG: changed %s" % f for f in changed]) + edittext.extend(["HG: removed %s" % f for f in removed]) + if not changed and not remove: + edittext.append("HG: no files changed") + edittext.append("") + # run editor in the repository root + olddir = os.getcwd() + os.chdir(self.root) + text = ui.edit("\n".join(edittext), user) + os.chdir(olddir) - lines = [line.rstrip() for line in text.rstrip().splitlines()] - while lines and not lines[0]: - del lines[0] - if not lines: - return None - text = '\n'.join(lines) - if branchname: - extra["branch"] = branchname - n = self.changelog.add(mn, changed + removed, text, tr, p1, p2, - user, date, extra) - self.hook('pretxncommit', throw=True, node=hex(n), parent1=xp1, - parent2=xp2) + lines = [line.rstrip() for line in text.rstrip().splitlines()] + while lines and not lines[0]: + del lines[0] + if not lines: + return None + text = '\n'.join(lines) + if branchname: + extra["branch"] = branchname + n = self.changelog.add(mn, changed + removed, text, tr, p1, p2, + user, date, extra) + self.hook('pretxncommit', throw=True, node=hex(n), parent1=xp1, + parent2=xp2) - # substitute keywords - for f in kwfmatches(ui, self, changed): - data = self.wfile(f).read() - if not util.binary(data): - data, kwct = re_kw.subn(lambda m: - kwexpand(m, self, f, changeid=hex(n)), - data) - if kwct: - ui.debug(_('overwriting %s expanding keywords\n' - % f)) - self.wfile(f, 'w').write(data) + # substitute keywords + for f in kwfmatches(ui, self, changed): + data = self.wfile(f).read() + if not util.binary(data): + data, kwct = re_kw.subn(lambda m: + kwexpand(m, self, f, changeid=hex(n)), + data) + if kwct: + ui.debug(_('overwriting %s expanding keywords\n' % f)) + self.wfile(f, 'w').write(data) - tr.close() + tr.close() - if use_dirstate or update_dirstate: - self.dirstate.setparents(n) - if use_dirstate: - self.dirstate.update(new, "n") - self.dirstate.forget(removed) + if use_dirstate or update_dirstate: + self.dirstate.setparents(n) + if use_dirstate: + self.dirstate.update(new, "n") + self.dirstate.forget(removed) - self.hook("commit", node=hex(n), parent1=xp1, parent2=xp2) - return n + self.hook("commit", node=hex(n), parent1=xp1, parent2=xp2) + return n class kwfilelog(filelog.filelog): def __init__(self, opener, path, repo,