Advertisement
selebry

Untitled

Dec 8th, 2022 (edited)
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. import os
  2. import zlib
  3. import graphviz
  4. def clearMessage(message):
  5. return message.decode()
  6. def clearParents(dt):
  7. return [parent.split(b" ")[-1].decode() for parent in dt if parent.startswith(b"parent")]
  8. def deserialize(data):
  9. dt = data.split(b"\n")
  10. dt.remove(b"")
  11. dt.remove(b'')
  12. roughMessage = dt[-1]
  13. parents = clearParents(dt)
  14. message = clearMessage(roughMessage)
  15. return [parents, message]
  16. def buildGraph(way, graph):
  17. digraph = graphviz.Digraph(comment='Git Log for {way}')
  18. digraph.attr('node', shape='octagon')
  19. for node in graph:
  20. for parent in node[1]:
  21. digraph.edge(parent, node[0], label=node[2])
  22. digraph.render('{way}.gv', view=True)
  23.  
  24.  
  25.  
  26. unpack = zlib.decompressobj()
  27. graph = []
  28.  
  29. way = "C:\\Users\\selebry\\test_repository\\.git\\objects"
  30. os.chdir(way)
  31. for path, directories, files in os.walk("."):
  32. if files !=0:
  33. for file in files:
  34. with open(path + "\\" + file, "rb") as f:
  35.  
  36. data = zlib.decompress(f.read())
  37. if data[:6] == b"commit":
  38. commit_id = path[-2:] + file
  39.  
  40. parents, message = deserialize(data)
  41. graph.append([commit_id, parents, message])
  42. f.close()
  43. os.chdir("C:\\Users\\selebry\\Desktop")
  44. buildGraph(way,graph)
  45. #
  46.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement