def orig_data(self, index): commit = self._commits[index.row()] column = index.column() field = self._columns[column] if field in TIME_FIELDS: if field == 'authored_date': _timestamp = commit.authored_date _utc_offset = altz_to_utctz_str(commit.author_tz_offset) _tz = Timezone(_utc_offset) elif field == 'committed_date': _timestamp = commit.committed_date _utc_offset = altz_to_utctz_str(commit.committer_tz_offset) _tz = Timezone(_utc_offset) value = (_timestamp, _tz) elif field in ACTOR_FIELDS: actor = eval("commit." + field.split('_')[0]) if '_email' in field: value = actor.email else: value = actor.name elif field == "message": value = commit.message elif field == "children": if commit in self._children: value = list(self._children[commit]) else: value = [] elif field == "parents": value = list(commit.parents) else: value = eval("commit." + field) return value
def orig_data(self, index): commit = self._commits[index.row()] column = index.column() field = self._columns[column] if field in TIME_FIELDS: if field == "authored_date": _timestamp = commit.authored_date _utc_offset = altz_to_utctz_str(commit.author_tz_offset) _tz = Timezone(_utc_offset) elif field == "committed_date": _timestamp = commit.committed_date _utc_offset = altz_to_utctz_str(commit.committer_tz_offset) _tz = Timezone(_utc_offset) value = (_timestamp, _tz) elif field in ACTOR_FIELDS: actor = eval("commit." + field.split("_")[0]) if "_email" in field: value = actor.email else: value = actor.name elif field == "message": value = commit.message elif field == "children": if commit in self._children: value = list(self._children[commit]) else: value = [] elif field == "parents": value = list(commit.parents) else: value = eval("commit." + field) return value
def __repr__(self): """Representation of ourselves in git reflog format""" act = self.actor time = self.time return self._fmt % (self.oldhexsha, self.newhexsha, act.name, act.email, time[0], altz_to_utctz_str( time[1]), self.message)
def format(self): """:return: a string suitable to be placed in a reflog file""" act = self.actor time = self.time return u"{0} {1} {2} <{3}> {4!s} {5}\t{6}\n".format( self.oldhexsha, self.newhexsha, act.name, act.email, time[0], altz_to_utctz_str(time[1]), self.message)
def format(self): """:return: a string suitable to be placed in a reflog file""" act = self.actor time = self.time return u"{0} {1} {2} <{3}> {4!s} {5}\t{6}\n".format( self.oldhexsha, self.newhexsha, act.name, act.email, time[0], altz_to_utctz_str(time[1]), self.message )
def commit(self): # Calc tree hash treedata = b'' for entry in sorted(os.listdir(self.repo_path)): if entry == '.git': continue with open(os.path.join(self.repo_path, entry)) as f: data_hash = git_object_hash('blob', f.read().encode()).digest() treedata += b'100644 ' + entry.encode() + b'\x00' + data_hash tree_hash = git_object_hash('tree', treedata).hexdigest() # Serialize commit commit_data = b'tree ' + tree_hash.encode() + b'\n' commit_data += b'parent ' + self.repo.head.commit.hexsha.encode( ) + b'\n' # Random author author = Actor(get_full_name(), get_email_address()) # Calc timestamp unix_time = int(time()) is_dst = daylight and localtime().tm_isdst > 0 offset = altzone if is_dst else timezone datetime = str(unix_time) + ' ' + altz_to_utctz_str(offset) commit_data += b'author ' + author.name.encode( ) + b' <' + author.email.encode() + b'> ' + datetime.encode() + b'\n' commit_data += b'committer ' + author.name.encode( ) + b' <' + author.email.encode() + b'> ' + datetime.encode() + b'\n' commit_data += b'\n' # Randomize commit message to feature proof-of-work msg = calc_pow(commit_data) return self.repo.index.commit(msg, author=author, committer=author, author_date=datetime, commit_date=datetime)
def commit_from_binsha(repo, binsha, org_commit, parents=None): tree = Tree.new(repo, bin_to_hex(binsha)) env = os.environ offset = altz_to_utctz_str(org_commit.author_tz_offset) date = org_commit.authored_date env[Commit.env_author_date] = '{} {}'.format(date, offset) offset = altz_to_utctz_str(org_commit.committer_tz_offset) date = org_commit.committed_date env[Commit.env_committer_date] = '{} {}'.format(date, offset) return Commit.create_from_tree(repo, tree, org_commit.message, parents, head=True, author=org_commit.author, committer=org_commit.committer)
def format(self) -> str: """:return: a string suitable to be placed in a reflog file""" act = self.actor time = self.time return "{} {} {} <{}> {!s} {}\t{}\n".format(self.oldhexsha, self.newhexsha, act.name, act.email, time[0], altz_to_utctz_str(time[1]), self.message)
def assert_rval(rval, veri_time, offset=0): assert len(rval) == 2 assert isinstance(rval[0], int) and isinstance(rval[1], int) assert rval[0] == veri_time assert rval[1] == offset # now that we are here, test our conversion functions as well utctz = altz_to_utctz_str(offset) assert isinstance(utctz, string_types) assert utctz_to_altz(verify_utctz(utctz)) == offset
def assert_rval(rval, veri_time, offset=0): assert len(rval) == 2 assert isinstance(rval[0], int) and isinstance(rval[1], int) assert rval[0] == veri_time assert rval[1] == offset # now that we are here, test our conversion functions as well utctz = altz_to_utctz_str(offset) assert isinstance(utctz, string_types) assert utctz_to_altz(verify_utctz(utctz)) == offset
def assert_rval(rval, veri_time, offset=0): self.assertEqual(len(rval), 2) self.assertIsInstance(rval[0], int) self.assertIsInstance(rval[1], int) self.assertEqual(rval[0], veri_time) self.assertEqual(rval[1], offset) # now that we are here, test our conversion functions as well utctz = altz_to_utctz_str(offset) self.assertIsInstance(utctz, string_types) self.assertEqual(utctz_to_altz(verify_utctz(utctz)), offset)
def assert_rval(rval, veri_time, offset=0): self.assertEqual(len(rval), 2) self.assertIsInstance(rval[0], int) self.assertIsInstance(rval[1], int) self.assertEqual(rval[0], veri_time) self.assertEqual(rval[1], offset) # now that we are here, test our conversion functions as well utctz = altz_to_utctz_str(offset) self.assertIsInstance(utctz, string_types) self.assertEqual(utctz_to_altz(verify_utctz(utctz)), offset)
def commit_from_binsha(repo, binsha, org_commit, parents=None): env = os.environ author_date = "%d %s" % (org_commit.authored_date, altz_to_utctz_str(org_commit.author_tz_offset)) env[Commit.env_author_date] = author_date committer_date = "%d %s" % (org_commit.committed_date, altz_to_utctz_str(org_commit.committer_tz_offset)) env[Commit.env_committer_date] = committer_date env[Actor.env_author_name] = org_commit.author.name.encode(org_commit.encoding) env[Actor.env_author_email] = org_commit.author.email or "" env[Actor.env_committer_name] = org_commit.committer.name.encode(org_commit.encoding) env[Actor.env_committer_email] = org_commit.committer.email or "" message = org_commit.message.encode(org_commit.encoding) tree = Tree.new(repo, bin_to_hex(binsha)) return Commit.create_from_tree(repo, tree, message, parents, True)
def __repr__(self): """Representation of ourselves in git reflog format""" act = self.actor time = self.time return self._fmt % (self.oldhexsha, self.newhexsha, act.name, act.email, time[0], altz_to_utctz_str(time[1]), self.message)