ReZero's Utopia.

ZIT development log

Word count: 870Reading time: 5 min
2021/02/10 Share

ZIT development log

Thanks for the great tutorial: https://www.leshenko.net/p/ugit

Thanks again Nikita!

Resource

I found some good reference material, and I put them under the ./doc directory.

Besides, the follow links maybe help you too.

  • Nick Butler this post is short but enough to help you have a higher level to understand diff
  • jcoglan this posts make a detail description about the diff.
  • visualize if you wanna have a debugger or visualization about diff algorithm, this will be a good choice.

If you feel interested about this project, you can post your idea on the discussion or just contact me with email.

Usage

  1. alias zit='java -jar ../zit-1.0-SNAPSHOT-shaded.jar' alias the zit executable file.

    • windows could set here C:\Program Files\Git\etc\profile.d\aliases.sh
  2. zit init init directory .zit which include objects subdirectory, init index file which would be treated as stage area, and set main branch as default to prevent detached head

    • the default HEAD file content is ref: ref/heads/main
  3. zit hash-object file

    • Get the path of the file to store.
    • Read the file.
    • Hash the content of the file using SHA-1.
    • Store the file under .ugit/objects/{the SHA-1 hash}.
  4. zit cat-file hash [object|tree|commit|...type] print the file content

  5. zit write-tree generate the tree which is the whole description of the repository.

    • after finished add command, it will write tree which is generated by index file
  6. zit read-tree hash

    • pay attention!this action will delete all existing stuff before reading.
    • So you can use cat-file to find which tree is the root, and the logs of write-tree also help you find all the trees.
  7. Although write-tree can save version, but it does not take any context information, so will need to develop zit commit -m "message" command.

    • you can use cat-file hash commit-id to check your commit content
    • HEAD will record your commit with its parent.
  8. Just enjoy commit and the type log to see the logs.

  9. Now we get the first point: checkout. Pick a commit id from the log and checkout whether things as expected.

    • [fixed with getBytes(Charsets.UTF-8)] find bug todo: chinese file or dir name got messy code
    • args could be head alias, hash and ref(branch, tags, HEAD…)
  10. tag will alias commit id, and at this time, you will get first inner core concept.

    • git-ref the official post will help you learn some basic knowledge about the git.
  11. todo: zit lg graph feature with Graphviz

  12. zit branch name [id] so familiar.

    • Every ref under refs/heads will be treated as a branch.
    • file content still just commit id, by default it is the head point
  13. zit show will use diff show changes detail while status only show simply changes info.

  14. zit add will add paths which could be file or directory into stage file: .zit/index.

  15. zit commit will call write tree and update head pointer to the commit id.

    • first time it will create default branch: main and will rewrite the HEAD file content to the commit id
    • the merge HEAD will be deleted and leave the message into commit message
  16. zit status this command will tell you what is the situation you are in now.

    • if you are not detached HEAD, it will log your current HEAD pointed branch first,
    • after that, if you are working in merge, it will log the merge hash id,
    • then it will log changes to be committed which will diff head tree to index(stage items),
    • finally, it will log changes not staged for the next commit which diff index(stage) to work tree.
  17. zit diff the default diff algorithm is myers diff without linear space refinement optimized

  18. zit reset just change head to the current commit, the difference between it and checkout is the // todo

  19. zit merge will check if the merge base equals the head, it will use fast-forward to merge

    • if fast-forward work, it will be no need to commit
    • if not work, we will use diff3 merge to merge the merge base, head tree, other tree
    • pay attention: diff3 will leave merge_head in the zit root directory and that means you need to commit manually.
    • zit merge-base is used to help the merge command find the first common parent commit of the commits which will be merged. But you also can use this command to do debug task.
  20. zit fetch, zit push these two combined commands are used to download or upload objects and update the ref.

Summary

UPDATED 2021.02.21

  • implemented the diff(myers diff but without linear space optimized) and merge algorithms(simple diff3) instead of using unix tools.

  • Ugit use some cool Pythonic code while zit trying to make code easy understood for the other language developer.

TODO

  1. git hash-object todo. When real Git stores objects it does a few extra things, such as writing the size of the object to the file as well, compressing them and dividing the objects into 256 directories. This is done to avoid having directories with huge number of files, which can hurt performance.
CATALOG
  1. 1. ZIT development log
    1. 1.1. Resource
    2. 1.2. Usage
    3. 1.3. Summary
      1. 1.3.1. UPDATED 2021.02.21
      2. 1.3.2. TODO