def writediffproperties(ctx, diff): """write metadata to diff so patches could be applied losslessly""" params = { b'diff_id': diff[r'id'], b'name': b'hg:meta', b'data': json.dumps({ b'user': ctx.user(), b'date': b'%d %d' % ctx.date(), b'node': ctx.hex(), b'parent': ctx.p1().hex(), }), } callconduit(ctx.repo(), b'differential.setdiffproperty', params) params = { b'diff_id': diff[r'id'], b'name': b'local:commits', b'data': json.dumps({ ctx.hex(): { b'author': stringutil.person(ctx.user()), b'authorEmail': stringutil.email(ctx.user()), b'time': ctx.date()[0], }, }), } callconduit(ctx.repo(), b'differential.setdiffproperty', params)
def convert_to_git_user(authormap, user, rev): mapped_user = authormap.get(user, user) user_person = stringutil.person(mapped_user) user_email = stringutil.email(mapped_user) if GIT_EMAIL_PROHIBITED.match(user_email) or GIT_PERSON_PROHIBITED.match( user_person): raise error.Abort( _(b"Unable to parse user into person and email for revision %s") % rev) if user_person: return b'"' + user_person + b'" <' + user_email + b'>' else: return b"<" + user_email + b">"
def add( self, manifest, files, desc, transaction, p1, p2, user, date=None, extra=None, p1copies=None, p2copies=None, filesadded=None, filesremoved=None, ): parents = [] hp1, hp2 = gitutil.togitnode(p1), gitutil.togitnode(p2) if p1 != nullid: parents.append(hp1) if p2 and p2 != nullid: parents.append(hp2) assert date is not None timestamp, tz = date sig = pygit2.Signature( encoding.unifromlocal(stringutil.person(user)), encoding.unifromlocal(stringutil.email(user)), int(timestamp), -int(tz // 60), ) oid = self.gitrepo.create_commit( None, sig, sig, desc, gitutil.togitnode(manifest), parents ) # Set up an internal reference to force the commit into the # changelog. Hypothetically, we could even use this refs/hg/ # namespace to allow for anonymous heads on git repos, which # would be neat. self.gitrepo.references.create( 'refs/hg/internal/latest-commit', oid, force=True ) # Reindex now to pick up changes. We omit the progress # and log callbacks because this will be very quick. index._index_repo(self.gitrepo, self._db) return oid.raw