diff --git a/.idea/artifacts/jit_ex_jar.xml b/.idea/artifacts/jit_ex_jar.xml
new file mode 100644
index 0000000000000000000000000000000000000000..0d43a798a94585652b6799c6c82c5f998331839c
--- /dev/null
+++ b/.idea/artifacts/jit_ex_jar.xml
@@ -0,0 +1,8 @@
+
+
+ $PROJECT_DIR$/out/artifacts/jit_ex_jar
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/compiler.xml b/.idea/compiler.xml
new file mode 100644
index 0000000000000000000000000000000000000000..63beb5faed807fbd4d118d81f36eedd989a0d1aa
--- /dev/null
+++ b/.idea/compiler.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
index c3dfb3001a828eebc28e3786ae253cce9b213569..05483570e041eb648703359441d61bf9a5feeb13 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -1,6 +1,6 @@
-
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000000000000000000000000000000000000..94a25f7f4cb416c083d265558da75d457237d671
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.jit/HEAD b/.jit/HEAD
deleted file mode 100644
index 72d24fb8a72de5726be58f384ddc3d7ab63e4660..0000000000000000000000000000000000000000
--- a/.jit/HEAD
+++ /dev/null
@@ -1 +0,0 @@
-ref: refs/heads/master
\ No newline at end of file
diff --git a/.jit/config b/.jit/config
deleted file mode 100644
index 8851aacd57a9df7f2af1b273e90d7d295405bd90..0000000000000000000000000000000000000000
--- a/.jit/config
+++ /dev/null
@@ -1,7 +0,0 @@
-[core]
- repositoryformatversion = 0
- filemode = false
- bare = false
- logallrefupdates = true
- symlinks = false
- ignorecase = true
\ No newline at end of file
diff --git a/.jit/description b/.jit/description
deleted file mode 100644
index 536df306fc127f56b921e8f6b09ba40e2d0bd926..0000000000000000000000000000000000000000
--- a/.jit/description
+++ /dev/null
@@ -1 +0,0 @@
-Unnamed repository; edit this file 'description' to name the repository.
\ No newline at end of file
diff --git a/.jit/index b/.jit/index
deleted file mode 100644
index 2cf6aca7634215db153bb58e5ee37da694059394..0000000000000000000000000000000000000000
--- a/.jit/index
+++ /dev/null
@@ -1,5 +0,0 @@
-2aae6c35c94fcfb415dbe95f408b9ce91ee846ed aa.txt 1638161591035
-2aae6c35c94fcfb415dbe95f408b9ce91ee846ed aa.txt 1638161591035
-5929e58a5aa1fde36b80ecc26548c50423ddf943 bb.txt 1638164306675
-5929e58a5aa1fde36b80ecc26548c50423ddf943 bb.txt 1638164306675
-3242150d635bfb77a329a3bfede1365568d802fa bb.txt 1638166335325
diff --git a/.jit/objects/1522310a3d07698c0bced8007b87931a4c1265d3 b/.jit/objects/1522310a3d07698c0bced8007b87931a4c1265d3
deleted file mode 100644
index 8c4ec0e8d44cb54f4e60e8f9ca4460dd8cae99cd..0000000000000000000000000000000000000000
Binary files a/.jit/objects/1522310a3d07698c0bced8007b87931a4c1265d3 and /dev/null differ
diff --git a/.jit/objects/2320df27604a85e1993df8b3cacd6404935677c7 b/.jit/objects/2320df27604a85e1993df8b3cacd6404935677c7
deleted file mode 100644
index 1fb525b6c7fc3048b2df733abbb8d8418fb48255..0000000000000000000000000000000000000000
Binary files a/.jit/objects/2320df27604a85e1993df8b3cacd6404935677c7 and /dev/null differ
diff --git a/.jit/objects/2aae6c35c94fcfb415dbe95f408b9ce91ee846ed b/.jit/objects/2aae6c35c94fcfb415dbe95f408b9ce91ee846ed
deleted file mode 100644
index 61e6c52967c4fbd749510548ea7f01a876eb2f88..0000000000000000000000000000000000000000
Binary files a/.jit/objects/2aae6c35c94fcfb415dbe95f408b9ce91ee846ed and /dev/null differ
diff --git a/.jit/objects/3242150d635bfb77a329a3bfede1365568d802fa b/.jit/objects/3242150d635bfb77a329a3bfede1365568d802fa
deleted file mode 100644
index 2ac6924d3eecd448b154d09a8cdbfe7897cc0365..0000000000000000000000000000000000000000
Binary files a/.jit/objects/3242150d635bfb77a329a3bfede1365568d802fa and /dev/null differ
diff --git a/.jit/objects/5929e58a5aa1fde36b80ecc26548c50423ddf943 b/.jit/objects/5929e58a5aa1fde36b80ecc26548c50423ddf943
deleted file mode 100644
index 9045231eb4873b311f8fe28a1b84cf0b20f9f24a..0000000000000000000000000000000000000000
Binary files a/.jit/objects/5929e58a5aa1fde36b80ecc26548c50423ddf943 and /dev/null differ
diff --git a/aa.txt b/aa.txt
deleted file mode 100644
index 95d09f2b10159347eece71399a7e2e907ea3df4f..0000000000000000000000000000000000000000
--- a/aa.txt
+++ /dev/null
@@ -1 +0,0 @@
-hello world
\ No newline at end of file
diff --git a/bb.txt b/bb.txt
deleted file mode 100644
index b65395a8bf1b4c3e9a145006a134ea2dd4cac6ba..0000000000000000000000000000000000000000
--- a/bb.txt
+++ /dev/null
@@ -1 +0,0 @@
-nice是是是
\ No newline at end of file
diff --git a/out/artifacts/jit_ex_jar/jit-ex.jar b/out/artifacts/jit_ex_jar/jit-ex.jar
new file mode 100644
index 0000000000000000000000000000000000000000..5429e04f38d3d7218bef52beceea6dc36dee43dd
Binary files /dev/null and b/out/artifacts/jit_ex_jar/jit-ex.jar differ
diff --git a/out/production/jit-ex/Client.class b/out/production/jit-ex/Client.class
index 53fc7d1eea0438ec2493a63c4ea2a204fc655efd..cae322954018273840c38419f26cd73a1a12feb1 100644
Binary files a/out/production/jit-ex/Client.class and b/out/production/jit-ex/Client.class differ
diff --git a/out/production/jit-ex/Diff/Difference.class b/out/production/jit-ex/Diff/Difference.class
new file mode 100644
index 0000000000000000000000000000000000000000..d03371410a157a69c2fc8359e3d05ed006807272
Binary files /dev/null and b/out/production/jit-ex/Diff/Difference.class differ
diff --git a/out/production/jit-ex/Diff/Main.class b/out/production/jit-ex/Diff/Main.class
new file mode 100644
index 0000000000000000000000000000000000000000..c75af4d81d3460685d0e4bfad4aa4efe4e05d736
Binary files /dev/null and b/out/production/jit-ex/Diff/Main.class differ
diff --git a/out/production/jit-ex/Diff/MyArray.class b/out/production/jit-ex/Diff/MyArray.class
new file mode 100644
index 0000000000000000000000000000000000000000..0f7dbc8793ae243d88031298c5167943c204a81d
Binary files /dev/null and b/out/production/jit-ex/Diff/MyArray.class differ
diff --git a/out/production/jit-ex/Diff/Myers.class b/out/production/jit-ex/Diff/Myers.class
new file mode 100644
index 0000000000000000000000000000000000000000..f27f93012cf9ccbe5da8aff5c9c91fba733c85ec
Binary files /dev/null and b/out/production/jit-ex/Diff/Myers.class differ
diff --git a/out/production/jit-ex/Diff/Node.class b/out/production/jit-ex/Diff/Node.class
new file mode 100644
index 0000000000000000000000000000000000000000..cdd60f02658deffe352855731573d4cc179dd157
Binary files /dev/null and b/out/production/jit-ex/Diff/Node.class differ
diff --git a/out/production/jit-ex/Diff/util/FileUtil.class b/out/production/jit-ex/Diff/util/FileUtil.class
new file mode 100644
index 0000000000000000000000000000000000000000..40d78d28f1138a6ddac15676f937769d2fb179fd
Binary files /dev/null and b/out/production/jit-ex/Diff/util/FileUtil.class differ
diff --git a/out/production/jit-ex/META-INF/MANIFEST.MF b/out/production/jit-ex/META-INF/MANIFEST.MF
new file mode 100644
index 0000000000000000000000000000000000000000..7709bd3b46707dc422485f32bf2a1d57371d49a9
--- /dev/null
+++ b/out/production/jit-ex/META-INF/MANIFEST.MF
@@ -0,0 +1,3 @@
+Manifest-Version: 1.0
+Main-Class: SwingJit
+
diff --git a/out/production/jit-ex/SwingJit$1.class b/out/production/jit-ex/SwingJit$1.class
index 0d0bbd15e2b6688fa9e3816bb76f37834e7b6b6e..78f013b4d455b9bbc61ed3e57fc59af06776cc4f 100644
Binary files a/out/production/jit-ex/SwingJit$1.class and b/out/production/jit-ex/SwingJit$1.class differ
diff --git a/out/production/jit-ex/SwingJit$10.class b/out/production/jit-ex/SwingJit$10.class
new file mode 100644
index 0000000000000000000000000000000000000000..886f1509d6e3985a7ca5226580e6792936d9f7d6
Binary files /dev/null and b/out/production/jit-ex/SwingJit$10.class differ
diff --git a/out/production/jit-ex/SwingJit$11.class b/out/production/jit-ex/SwingJit$11.class
new file mode 100644
index 0000000000000000000000000000000000000000..e0e3cdfa981da5ae8d18b27f788c883f215f2b6c
Binary files /dev/null and b/out/production/jit-ex/SwingJit$11.class differ
diff --git a/out/production/jit-ex/SwingJit$12.class b/out/production/jit-ex/SwingJit$12.class
new file mode 100644
index 0000000000000000000000000000000000000000..ab4389d565e2cd4f37652401f3c736f0423ee626
Binary files /dev/null and b/out/production/jit-ex/SwingJit$12.class differ
diff --git a/out/production/jit-ex/SwingJit$13.class b/out/production/jit-ex/SwingJit$13.class
new file mode 100644
index 0000000000000000000000000000000000000000..87b5f635223e9703b1e453c9a2702bc66062be9c
Binary files /dev/null and b/out/production/jit-ex/SwingJit$13.class differ
diff --git a/out/production/jit-ex/SwingJit$14.class b/out/production/jit-ex/SwingJit$14.class
new file mode 100644
index 0000000000000000000000000000000000000000..0197127f95bf44eadb14f1c7f5db925f34fd2e42
Binary files /dev/null and b/out/production/jit-ex/SwingJit$14.class differ
diff --git a/out/production/jit-ex/SwingJit$15.class b/out/production/jit-ex/SwingJit$15.class
new file mode 100644
index 0000000000000000000000000000000000000000..bd1c2ee15943affa1592f730afcc0a2a243391f4
Binary files /dev/null and b/out/production/jit-ex/SwingJit$15.class differ
diff --git a/out/production/jit-ex/SwingJit$16.class b/out/production/jit-ex/SwingJit$16.class
new file mode 100644
index 0000000000000000000000000000000000000000..3d56c79168824e30be4da08ca8a3003ba22a1c3d
Binary files /dev/null and b/out/production/jit-ex/SwingJit$16.class differ
diff --git a/out/production/jit-ex/SwingJit$2.class b/out/production/jit-ex/SwingJit$2.class
index ed548cef548fcced7c87ee0100403a86a1d37953..99b94565075b0633b4f878a028abc2e773ec7eec 100644
Binary files a/out/production/jit-ex/SwingJit$2.class and b/out/production/jit-ex/SwingJit$2.class differ
diff --git a/out/production/jit-ex/SwingJit$3.class b/out/production/jit-ex/SwingJit$3.class
index 9bfa71d5fa723b1b7f290e41a0614230c2dac2a7..c249342023f86c30c9734b8a64d022e4838faae8 100644
Binary files a/out/production/jit-ex/SwingJit$3.class and b/out/production/jit-ex/SwingJit$3.class differ
diff --git a/out/production/jit-ex/SwingJit$4.class b/out/production/jit-ex/SwingJit$4.class
index acb76fe4bc196e43b256bfba602d069ebbf6480a..1adf251b4296905a3e4ed34fdfb11c97bb7164bc 100644
Binary files a/out/production/jit-ex/SwingJit$4.class and b/out/production/jit-ex/SwingJit$4.class differ
diff --git a/out/production/jit-ex/SwingJit$5.class b/out/production/jit-ex/SwingJit$5.class
index c999cd143f0b36cc5d16b4ad17fc7ca0ece0d39e..92a9a7df3ddde038615086a217a620fa2ac270d7 100644
Binary files a/out/production/jit-ex/SwingJit$5.class and b/out/production/jit-ex/SwingJit$5.class differ
diff --git a/out/production/jit-ex/SwingJit$6.class b/out/production/jit-ex/SwingJit$6.class
index eca22f1d699fe48d64b949e817c19e909e8f4f08..94faccb936e84dae5b9e72cb3f32ba40f145f791 100644
Binary files a/out/production/jit-ex/SwingJit$6.class and b/out/production/jit-ex/SwingJit$6.class differ
diff --git a/out/production/jit-ex/SwingJit$7.class b/out/production/jit-ex/SwingJit$7.class
new file mode 100644
index 0000000000000000000000000000000000000000..99edfde96e567d32b4daacfebf04af6e9cf883d4
Binary files /dev/null and b/out/production/jit-ex/SwingJit$7.class differ
diff --git a/out/production/jit-ex/SwingJit$8.class b/out/production/jit-ex/SwingJit$8.class
new file mode 100644
index 0000000000000000000000000000000000000000..d75c361bf4286f25f3d0762e2726d9d54a9b139e
Binary files /dev/null and b/out/production/jit-ex/SwingJit$8.class differ
diff --git a/out/production/jit-ex/SwingJit$9.class b/out/production/jit-ex/SwingJit$9.class
new file mode 100644
index 0000000000000000000000000000000000000000..bd8b65191e570003ca0b2d16e3c2f844bf7c5d94
Binary files /dev/null and b/out/production/jit-ex/SwingJit$9.class differ
diff --git a/out/production/jit-ex/SwingJit.class b/out/production/jit-ex/SwingJit.class
index 6025f3c358ab0e93feca0882ef053a35845fba8a..c005ebefdb0d5c755db069b96602fa20b01a54ee 100644
Binary files a/out/production/jit-ex/SwingJit.class and b/out/production/jit-ex/SwingJit.class differ
diff --git a/out/production/jit-ex/branch/Branch.class b/out/production/jit-ex/branch/Branch.class
new file mode 100644
index 0000000000000000000000000000000000000000..267537fde6d4c11a444f70b6114c52cc148dc7fd
Binary files /dev/null and b/out/production/jit-ex/branch/Branch.class differ
diff --git a/out/production/jit-ex/core/JitAdd.class b/out/production/jit-ex/core/JitAdd.class
index af08bb61519689fd0906d3e0ee7d51ac149d42e0..b5352f97f20215a3bc9e31126826521f86aaa9b9 100644
Binary files a/out/production/jit-ex/core/JitAdd.class and b/out/production/jit-ex/core/JitAdd.class differ
diff --git a/out/production/jit-ex/core/JitBranch.class b/out/production/jit-ex/core/JitBranch.class
new file mode 100644
index 0000000000000000000000000000000000000000..bf7a9732440f103365b0b882a920a495de8a92b9
Binary files /dev/null and b/out/production/jit-ex/core/JitBranch.class differ
diff --git a/out/production/jit-ex/core/JitCheckout.class b/out/production/jit-ex/core/JitCheckout.class
new file mode 100644
index 0000000000000000000000000000000000000000..3dd605c11347196d5b508a2054573028eacd2bc4
Binary files /dev/null and b/out/production/jit-ex/core/JitCheckout.class differ
diff --git a/out/production/jit-ex/core/JitCommit.class b/out/production/jit-ex/core/JitCommit.class
index 1ea5d0158ccf4ac37012a4418851cd0b7f843d5b..57e758cbca9380c3a42d23122271894c03e01246 100644
Binary files a/out/production/jit-ex/core/JitCommit.class and b/out/production/jit-ex/core/JitCommit.class differ
diff --git a/out/production/jit-ex/core/JitInit.class b/out/production/jit-ex/core/JitInit.class
index 4e09c9b18940f9503ec0c7633d877fcd9367439e..5391fc95a69ba7acf57fd173c0c27c335395a4fd 100644
Binary files a/out/production/jit-ex/core/JitInit.class and b/out/production/jit-ex/core/JitInit.class differ
diff --git a/out/production/jit-ex/core/JitLoad.class b/out/production/jit-ex/core/JitLoad.class
new file mode 100644
index 0000000000000000000000000000000000000000..7a3957877382cdb36f7915c8914c85352f2313f9
Binary files /dev/null and b/out/production/jit-ex/core/JitLoad.class differ
diff --git a/out/production/jit-ex/core/JitLog.class b/out/production/jit-ex/core/JitLog.class
new file mode 100644
index 0000000000000000000000000000000000000000..c4ace09b4bce080b5f90f4278ca746d5329a96f6
Binary files /dev/null and b/out/production/jit-ex/core/JitLog.class differ
diff --git a/out/production/jit-ex/core/JitOpr.class b/out/production/jit-ex/core/JitOpr.class
new file mode 100644
index 0000000000000000000000000000000000000000..a331c387c338c982b68736a8d7ecb829cd503ac5
Binary files /dev/null and b/out/production/jit-ex/core/JitOpr.class differ
diff --git a/out/production/jit-ex/core/JitReset.class b/out/production/jit-ex/core/JitReset.class
new file mode 100644
index 0000000000000000000000000000000000000000..137f3132b1ebefb6ef46b563a3f0ce388bd99f4e
Binary files /dev/null and b/out/production/jit-ex/core/JitReset.class differ
diff --git a/out/production/jit-ex/core/JitRestore.class b/out/production/jit-ex/core/JitRestore.class
new file mode 100644
index 0000000000000000000000000000000000000000..0ffe7bb820a63eed9fa6348360d3b682234d4d41
Binary files /dev/null and b/out/production/jit-ex/core/JitRestore.class differ
diff --git a/out/production/jit-ex/core/JitRm.class b/out/production/jit-ex/core/JitRm.class
new file mode 100644
index 0000000000000000000000000000000000000000..97187a5012873e4afd30a86b99bde7b740533e99
Binary files /dev/null and b/out/production/jit-ex/core/JitRm.class differ
diff --git a/out/production/jit-ex/gitobject/Blob.class b/out/production/jit-ex/gitobject/Blob.class
index 02f0970b01acb0aed603c8a7525cfcb50183001a..4a354f391c060da84bdb900ec7cce69766c41b79 100644
Binary files a/out/production/jit-ex/gitobject/Blob.class and b/out/production/jit-ex/gitobject/Blob.class differ
diff --git a/out/production/jit-ex/gitobject/Commit.class b/out/production/jit-ex/gitobject/Commit.class
index 2d44355406cf0e77a6751094d3dbf82d211c7881..f7240ca00adeb269f363b4194c44bcc586fdb67c 100644
Binary files a/out/production/jit-ex/gitobject/Commit.class and b/out/production/jit-ex/gitobject/Commit.class differ
diff --git a/out/production/jit-ex/gitobject/GitObject.class b/out/production/jit-ex/gitobject/GitObject.class
index 62c3e34ee32f74c001b721d861e73852d47621b9..87e3c38e4b30157968e81e770ec3f06b4e982fe7 100644
Binary files a/out/production/jit-ex/gitobject/GitObject.class and b/out/production/jit-ex/gitobject/GitObject.class differ
diff --git a/out/production/jit-ex/gitobject/Tree.class b/out/production/jit-ex/gitobject/Tree.class
index c7196291f68c246c6d9ff2b8526628be6bc80d8d..ed7aa3db6474f861b7a9872748c94faeda8c840e 100644
Binary files a/out/production/jit-ex/gitobject/Tree.class and b/out/production/jit-ex/gitobject/Tree.class differ
diff --git a/out/production/jit-ex/repo/Repository.class b/out/production/jit-ex/repo/Repository.class
index 7f4c9dc3b41150a2864d9ab7d32b9ec7e2e88a86..b746b4488dd1bfe1dc09204b08cf0b6fbb16461d 100644
Binary files a/out/production/jit-ex/repo/Repository.class and b/out/production/jit-ex/repo/Repository.class differ
diff --git a/out/production/jit-ex/tmp/Index.class b/out/production/jit-ex/tmp/Index.class
index c7e02c0e06928465600c9323d4de36db28141716..d4bcf1e872f3e9b25b80bfc27e66444277b1b904 100644
Binary files a/out/production/jit-ex/tmp/Index.class and b/out/production/jit-ex/tmp/Index.class differ
diff --git a/out/production/jit-ex/tmp/ObjectNode$VirtualNode.class b/out/production/jit-ex/tmp/ObjectNode$VirtualNode.class
index 3feb8fd206e59dd5057062025a072324b5b5b543..072be18b52e22b8e1afd7b14e95b5de3cc826d08 100644
Binary files a/out/production/jit-ex/tmp/ObjectNode$VirtualNode.class and b/out/production/jit-ex/tmp/ObjectNode$VirtualNode.class differ
diff --git a/out/production/jit-ex/tmp/ObjectNode.class b/out/production/jit-ex/tmp/ObjectNode.class
index 3c2046f73f01b64ee7a7ad60a97abb85057eb17a..b6476a793abf7ec405941edb37e4dc952056433b 100644
Binary files a/out/production/jit-ex/tmp/ObjectNode.class and b/out/production/jit-ex/tmp/ObjectNode.class differ
diff --git a/out/production/jit-ex/tmp/VirtualNode.class b/out/production/jit-ex/tmp/VirtualNode.class
index 8d809a2c3b00384ebc8b997248e7964cd1295cd1..4c365ff86bd2ea7895f52ee5c384f7f81e33e217 100644
Binary files a/out/production/jit-ex/tmp/VirtualNode.class and b/out/production/jit-ex/tmp/VirtualNode.class differ
diff --git a/out/production/jit-ex/utils/Deserialize.class b/out/production/jit-ex/utils/Deserialize.class
index e96bc837330e1af037992616c55355d75384f4d2..60dcf28a7fdab83d5d39790a7f7565a6a1f53ffb 100644
Binary files a/out/production/jit-ex/utils/Deserialize.class and b/out/production/jit-ex/utils/Deserialize.class differ
diff --git a/out/production/jit-ex/utils/FileCreation.class b/out/production/jit-ex/utils/FileCreation.class
index 2fa4cae714514d75dd54133eb9e2e76ca06d3a1a..d0b4a37160a1db4d630eb69b9842f943bc7d8b39 100644
Binary files a/out/production/jit-ex/utils/FileCreation.class and b/out/production/jit-ex/utils/FileCreation.class differ
diff --git a/out/production/jit-ex/utils/FileDeletion.class b/out/production/jit-ex/utils/FileDeletion.class
index 2bd591303ac96b80f4995194a27732f6dcbdbbe4..4aaf4641b9695979d3a76dad7c5ee2f85ece313b 100644
Binary files a/out/production/jit-ex/utils/FileDeletion.class and b/out/production/jit-ex/utils/FileDeletion.class differ
diff --git a/out/production/jit-ex/utils/FileReader.class b/out/production/jit-ex/utils/FileReader.class
index 13ad17547a4407065fcb5e91a67fd8e2c7a2c8e6..4e5b279f7fb42329e2f292507a8a0e71b4699c8b 100644
Binary files a/out/production/jit-ex/utils/FileReader.class and b/out/production/jit-ex/utils/FileReader.class differ
diff --git a/out/production/jit-ex/utils/FileStatus.class b/out/production/jit-ex/utils/FileStatus.class
index 68af247e235cda4a7a3aedb175c8915025ac95d6..6e4dfcea68446f1714a97271733dc0c1822546db 100644
Binary files a/out/production/jit-ex/utils/FileStatus.class and b/out/production/jit-ex/utils/FileStatus.class differ
diff --git a/out/production/jit-ex/utils/SHA1.class b/out/production/jit-ex/utils/SHA1.class
index 44e534516aa6552d2d8894b6b0be73c41d86c93f..81094916a75bb7222419bad9475f27377d341992 100644
Binary files a/out/production/jit-ex/utils/SHA1.class and b/out/production/jit-ex/utils/SHA1.class differ
diff --git a/out/production/jit-ex/utils/Utils.class b/out/production/jit-ex/utils/Utils.class
index 7c867d762239ac6821d5302f2bde3374cdc94012..26b61dc7fd58482f0e2f885dce758a09e7807b1c 100644
Binary files a/out/production/jit-ex/utils/Utils.class and b/out/production/jit-ex/utils/Utils.class differ
diff --git a/out/production/jit-ex/utils/ZLibUtils.class b/out/production/jit-ex/utils/ZLibUtils.class
index e11f5fe9c75a110ad55ffc62a22594cdeeece109..97e9725a53cdad0b656cb23e7ecd68875eaa7df7 100644
Binary files a/out/production/jit-ex/utils/ZLibUtils.class and b/out/production/jit-ex/utils/ZLibUtils.class differ
diff --git a/src/Client.java b/src/Client.java
index 096c919dcfaba428fbebe2fd0263ef3f38137979..d5581903adea696bfa53293e95ec3d2e8f706005 100644
--- a/src/Client.java
+++ b/src/Client.java
@@ -1,5 +1,4 @@
import core.*;
-import repo.Repository;
import utils.Utils;
import java.io.File;
@@ -9,6 +8,29 @@ import java.util.Scanner;
public class Client {
+ public static void jitLoad(String[] args) throws IOException {
+ String path = "";
+ if (args.length <= 2) { //get default working path
+ /**
+ * 项目所在的绝对目录
+ */
+ path = new File(".").getCanonicalPath();
+ JitLoad.load(path);
+ } else if (args[2].equals("-help")) { //see help
+ System.out.println("usage: jit load [] [-help]\r\n" +
+ "\r\n" +
+ "jit load []: Load jit data from path, you should run this method first.");
+ } else {
+ path = args[2];
+ //Utils.setWorkDir(path);
+ if (!new File(path).isDirectory()) { //if the working path input is illegal
+ System.out.println(path + "is not a legal directory.");
+ } else {
+ JitLoad.load(path);
+ }
+ }
+ }
+
/**
* Command 'jit init'
* @param args
@@ -17,42 +39,49 @@ public class Client {
public static void jitInit(String[] args) throws IOException {
String path = "";
if(args.length <= 2) { //get default working path
- /**
- * 项目所在的绝对目录
- */
- path = new File(".").getCanonicalPath();
- Utils.setWorkDir(path);
- JitInit.init(path);
+ if(Utils.getWorkDir()!=null){
+ path = Utils.getWorkDir();
+ JitInit.init(path);
+ }else {
+ /**
+ * 项目所在的绝对目录
+ */
+ path = new File(".").getCanonicalPath();
+ JitLoad.load(path);
+ JitInit.init(path);
+ }
}else if(args[2].equals("-help")){ //see help
System.out.println("usage: jit init [] [-help]\r\n" +
"\r\n" +
"jit init []: Create an empty jit repository or reinitialize an existing one in the path or your default working directory.");
}else {
path = args[2];
- Utils.setWorkDir(path);
+ //Utils.setWorkDir(path);
if(!new File(path).isDirectory()) { //if the working path input is illegal
System.out.println(path + "is not a legal directory. Please init your reposiroty again. See 'jit init -help'.");
}else {
+ JitLoad.load(path);
JitInit.init(path);
}
}
}
public static void jitAdd(String[] args) throws IOException {
- System.out.println("请输入.jit所在目录,输入default表示在默认目录");
+ /*System.out.println("请输入.jit所在目录,输入default表示在默认目录");
Scanner scanner = new Scanner(System.in);
String str = scanner.nextLine();
if(str.equals("default")){
Utils.setWorkDir(new File(".").getCanonicalPath());
- }else Utils.setWorkDir(str);
+ }else Utils.setWorkDir(str);*/
+
+ //new Repository(new File(".").getCanonicalPath());
- new Repository(new File(".").getCanonicalPath());
//String workDir = Repository.getWorkTree();
//System.out.println(workDir);
if(args.length <= 2 || args[2].equals("-help")) {
- System.out.println("""
- for example jit add abc.txt""");
+ System.out.println("for example jit add abc.txt"
+ );
}else {
for(int i = 2; i < args.length; i++) {
String fileName = args[i];
@@ -90,20 +119,17 @@ public class Client {
*/
public static void jitRemove(String[] args) throws IOException {
//String workDir = Repository.getWorkTree();
- Utils.setWorkDir(new File(".").getCanonicalPath());
+ //Utils.setWorkDir(new File(".").getCanonicalPath());
String workDir = Utils.getWorkDir();
if(args.length <= 2 || args[2].equals("-help")) {
- System.out.println("""
- usage: jit remove [...] [-help]\r
- \r
- jit remove [...]: Remove file(s) from stage.""");
+ System.out.println(" usage: jit remove [...] [-help]\n jit remove [...]: Remove file(s) from stage.");
} else {
for(int i = 2; i < args.length; i++) {
String fileName = args[i];
File file = new File(workDir + File.separator + fileName);
try {
- JitRemove.remove(file);
+ JitRm.removeForce(file);
} catch (Exception e) {
e.printStackTrace();
}
@@ -112,12 +138,55 @@ public class Client {
}
public static void jitLog(String[] args) throws Exception {
- Utils.setWorkDir(new File(".").getCanonicalPath());
+ //Utils.setWorkDir(new File(".").getCanonicalPath());
String workDir = Utils.getWorkDir();
- if(args.length <= 2 || args[2].equals("-help")) {
- System.out.println("usage:jit log");
- } else {
+ //System.out.println(workDir);
JitLog.printLog();
+ }
+
+ public static void jitReset(String[] args) throws Exception {
+ if(args.length==2&&args[1].equals("reset")){
+ JitReset.newReset();
+ }else if(args.length==3&&args[1].equals("reset")&&!args[2].equals("--hard")){
+ String commitKey = args[2];
+ JitReset.reset(commitKey);
+ } else if(args[2].equals("-help")) {
+ System.out.println("usage: jit reset [--hard] [--hard commit-id] [-help]\r\n" +
+ "\r\n" +
+ "jit reset --hard: Reset the index and head file to the last commit.\r\n" +
+ "\r\n" +
+ "jit reset --hard [commit]: Reset the worktree and index to a certain commit.");
+ }else if(args.length == 3 && args[2].equals("--hard")) {
+ JitReset.newHardReset();
+ }else if(args.length == 4 && args[2].equals("--hard")) {
+ String commitKey = args[3];
+ JitReset.hardReset(commitKey);
+ }
+ }
+
+
+ public static void jitBranch(String[] args) throws IOException {
+ if(args.length < 2 || (args.length > 2 && args[2].equals("-help"))) { //'jit branch -help'
+ System.out.println(
+ "jit branch: List all local branches.\r\n" +
+ "\r\n" +
+ "jit branch [branch-name]: Create the branch.\r\n" +
+ "\r\n" +
+ "jit branch [branch-name] [commit]: Create the branch and point it to the commit.\r\n" +
+ "\r\n" +
+ "jit branch -d [branch-name]: Delete the branch.");
+ }else if(args.length == 2) {
+ JitBranch.branch();
+ }else if(args.length == 3) {
+ String branchName = args[2];
+ JitBranch.createBranchWithMaster(branchName);
+ }else if(args.length == 4 && args[2].equals("-d")) {
+ String branchName = args[3];
+ JitBranch.deleteBranch(branchName);
+ }else if(args.length == 4) {
+ String branchName = args[2];
+ String commitKey = args[3];
+ JitBranch.branchAdd(branchName, commitKey);
}
}
@@ -139,7 +208,7 @@ public class Client {
"\r\n" +
"work on the current change\r\n" +
" add Add file contents to the index\r\n" +
- " reset Reset current HEAD to the specified state\r\n" +
+ " resetCommit Reset current HEAD to the specified state\r\n" +
" rm Remove files from the working tree and from the index\r\n" +
"\r\n" +
"examine the history and state\r\n" +
@@ -160,6 +229,9 @@ public class Client {
public static void main(String[] args) throws Exception {
Scanner scanner = new Scanner(System.in);
+ System.out.println("请输入Jit的操作路径");
+ String path = scanner.nextLine();
+ Utils.setWorkDir(path);
while (true) {
System.out.println("请输入命令:");
String str = scanner.nextLine();
@@ -175,7 +247,9 @@ public class Client {
} else {
if (arr[1].equals("init")) {
jitInit(arr);
- } else if (arr[1].equals("add")) {
+ } else if (arr[1].equals("load")) {
+ jitLoad(arr);
+ }else if (arr[1].equals("add")) {
jitAdd(arr);
} else if (arr[1].equals("commit")) {
jitCommit(arr);
@@ -183,7 +257,19 @@ public class Client {
jitRemove(arr);
} else if (arr[1].equals("log")){
jitLog(arr);
- } else {
+ } else if (arr[1].equals("cat-file")&&arr[2].equals("-p")&&arr[3]!=null){
+ jitCat(arr);
+ } else if (arr[1].equals("stage")){
+ jitStage();
+ } else if(arr[1].equals("reset")) {
+ jitReset(arr);
+ } else if(arr[1].equals("branch")) {
+ jitBranch(arr);
+ } else if(arr[1].equals("restore")) {
+ jitRestore(arr);
+ } else if(arr[1].equals("checkout")) {
+ jitCheckout(arr);
+ }else {
System.out.println("jit: " + arr[1] + "is not a git command. See 'git help'.");
}
}
@@ -202,4 +288,24 @@ public class Client {
}
}*/
}
+
+ private static void jitCheckout(String[] args) throws Exception {
+ JitCheckout.checkout(args[2]);
+ }
+
+ private static void jitRestore(String[] args) throws Exception {
+ JitRestore.restore();
+ }
+
+ //显示版本库对象的内容
+ private static void jitCat(String[] arr) throws IOException {
+ JitOpr.JitCat(arr[3]);
+ }
+
+ //读取index文件夹的内容
+ private static void jitStage() throws IOException {
+ JitOpr.JitStage();
+ }
+
+
}
diff --git a/src/Diff/Difference.java b/src/Diff/Difference.java
new file mode 100644
index 0000000000000000000000000000000000000000..c16ca9dc6b74e75917bf674a5dc60f9253de20d3
--- /dev/null
+++ b/src/Diff/Difference.java
@@ -0,0 +1,85 @@
+package Diff;
+
+import java.util.List;
+
+public class Difference {
+ private String[] oldLines;
+ private String[] newLines;
+
+ public Difference(String[] oldLines, String[] newLines) {
+ this.oldLines = oldLines;
+ this.newLines = newLines;
+ }
+
+ public Difference(String oldString, String newString) {
+ this.oldLines = oldString.split("\n");
+ this.newLines = newString.split("\n");
+ }
+
+ public String[] getOldLines() {
+ return oldLines;
+ }
+
+ public String[] getNewLines() {
+ return newLines;
+ }
+
+ /**
+ * Show diff in the console between oldString and new String.
+ */
+ public String getDiffString() {
+ Myers myers = new Myers(oldLines, newLines);
+ myers.diff();
+
+ List path = myers.getPath();
+
+ return this.getDiffString(oldLines, newLines, path);
+ }
+
+ private String getDiffString(String[] oldLines, String[] newLines, List path) {
+ Node prevNode = path.get(0);
+ StringBuilder stringBuilder = new StringBuilder();
+ for (int i = 1; i < path.size(); i++) {
+ Node node = path.get(i);
+ int gapDis = (node.getCoordinateX() - node.getCoordinateY())
+ - (prevNode.getCoordinateX() - prevNode.getCoordinateY());
+
+ int posX = prevNode.getCoordinateX();
+ int posY = prevNode.getCoordinateY();
+
+ if (gapDis == 1) {
+ // right
+ stringBuilder
+ .append(this.getStringWithRed("-\t" + oldLines[prevNode.getCoordinateX()]))
+ .append("\n");
+ posX++;
+ } else if (gapDis == -1) {
+ // down
+ stringBuilder
+ .append(this.getStringWithGreen("+\t" + newLines[prevNode.getCoordinateY()]))
+ .append("\n");
+ posY++;
+ }
+
+ for (; posX < node.getCoordinateX() && posY < node.getCoordinateY()
+ && posX < oldLines.length && posY < newLines.length; posX++, posY++) {
+ stringBuilder
+ .append("\t")
+ .append(oldLines[posX])
+ .append("\n");
+ }
+
+ prevNode = node;
+ }
+ return stringBuilder.toString();
+ }
+
+ private String getStringWithRed(String str) {
+ return "\033[31m" + str + "\033[0m";
+ }
+
+
+ private String getStringWithGreen(String str) {
+ return "\033[32m" + str + "\033[0m";
+ }
+}
diff --git a/src/Diff/Main.java b/src/Diff/Main.java
new file mode 100644
index 0000000000000000000000000000000000000000..e752c4b7946e0780d3e469ead08dc7f2acf562b5
--- /dev/null
+++ b/src/Diff/Main.java
@@ -0,0 +1,38 @@
+package Diff;
+
+import Diff.util.FileUtil;
+
+import java.io.IOException;
+
+
+public class Main {
+ /**
+ * 项目入口.
+ * @param args Read args from shell. args[0] is oldString and args[1] is newString.
+ */
+ public static void main(String[] args) {
+
+
+ String oldFilename = "C:\\Users\\ZYC\\Desktop\\111.txt";
+ String newFilename = "C:\\Users\\ZYC\\Desktop\\222.txt";
+
+ String oldString;
+ try {
+ oldString = FileUtil.readToString(oldFilename);
+ } catch (IOException exception) {
+ System.out.println("Can't find file: " + oldFilename);
+ return;
+ }
+
+ String newString;
+ try {
+ newString = FileUtil.readToString(newFilename);
+ } catch (IOException exception) {
+ System.out.println("Can't find file: " + oldFilename);
+ return;
+ }
+
+ Difference difference = new Difference(oldString, newString);
+ System.out.println(difference.getDiffString());
+ }
+}
diff --git a/src/Diff/MyArray.java b/src/Diff/MyArray.java
new file mode 100644
index 0000000000000000000000000000000000000000..436399edc0241b9ccc7e4e50e1a78ca6a99329b0
--- /dev/null
+++ b/src/Diff/MyArray.java
@@ -0,0 +1,22 @@
+package Diff;
+
+/**
+ * Set array in range of (-length, length).
+ */
+class MyArray {
+ private int length;
+ private int[] list;
+
+ public MyArray(int length) {
+ this.length = length;
+ this.list = new int[this.length * 2];
+ }
+
+ public int get(int pos) {
+ return this.list[pos + this.length];
+ }
+
+ public void set(int pos, int value) {
+ this.list[pos + this.length] = value;
+ }
+}
diff --git a/src/Diff/Myers.java b/src/Diff/Myers.java
new file mode 100644
index 0000000000000000000000000000000000000000..988f08fe3d1e39fa82a4957f85c3e6c24ade7fb7
--- /dev/null
+++ b/src/Diff/Myers.java
@@ -0,0 +1,149 @@
+package Diff;
+
+import java.util.*;
+
+public class Myers {
+ private String[] oldLines;
+ private String[] newLines;
+
+ /**
+ * Map currNode to prevNode.
+ * int currNodeInt = currNodeInt.getX() * totalLength + currNodeInt.getY();
+ * int prevNodeInt = prevNode.getX() * totalLength + prevNode.getY();
+ */
+ private Map prevNode;
+ private int gap;
+ private int pathLen;
+
+
+ /**
+ * Constructor of Myers.
+ * @param oldLines String[].
+ * @param newLines String[].
+ */
+ public Myers(String[] oldLines, String[] newLines) {
+ this.oldLines = oldLines;
+ this.newLines = newLines;
+ this.prevNode = new HashMap<>();
+ }
+
+ public int getGap() {
+ return gap;
+ }
+
+ public int getPathLen() {
+ return pathLen;
+ }
+
+ /**
+ * Execute algorithm Myers.
+ * pathLen
is the sum of path steps.
+ * gap = x - y
, where x and y are refer to the end point.
+ * @return int: the sum of different lines between oldString and newString.
+ */
+ public int diff() {
+ int totalLength = this.oldLines.length + this.newLines.length + 1;
+
+ MyArray mapGapToX = new MyArray(totalLength);
+
+ for (int pathLen = 0; pathLen <= totalLength; pathLen++) {
+ for (int gap = -pathLen; gap <= pathLen; gap += 2) {
+ int prevX;
+ int prevY;
+ int currX;
+ int currY;
+ if (pathLen == 0) {
+ prevY = prevX = 0;
+ currY = currX = this.walkDiagonal(prevX, prevY);
+ } else {
+ final boolean down = (gap == -pathLen)
+ || (gap != pathLen
+ && mapGapToX.get(gap - 1) < mapGapToX.get(gap + 1));
+
+ final int prevGap = down ? gap + 1 : gap - 1;
+
+ prevX = mapGapToX.get(prevGap);
+ prevY = prevX - prevGap;
+
+ currX = down ? prevX : prevX + 1;
+ currY = currX - gap;
+
+ currX = this.walkDiagonal(currX, currY);
+ currY = currX - gap;
+ }
+
+ mapGapToX.set(gap, currX);
+
+ this.prevNode.put(currX * totalLength + currY, prevX * totalLength + prevY);
+
+ if (currX >= this.oldLines.length && currY >= this.newLines.length) {
+ this.gap = gap;
+ this.pathLen = pathLen;
+ return this.pathLen;
+ }
+ }
+ }
+
+ return -1;
+ }
+
+ /**
+ * According to this.prevNode
, get node list.
+ * @return return node list from (0, 0) to (oldLines.length, newLines.length).
+ */
+ public List getPath() {
+ List path = new ArrayList<>();
+
+ int totalLength = this.oldLines.length + this.newLines.length + 1;
+
+ Node node = new Node(this.oldLines.length, this.newLines.length);
+ path.add(node);
+
+ // (node.x >= 0 && node.y > 0) || (node.x > 0 && node.y >= 0)
+ // node.x and node.y are both greater or equal to 0.
+ // But they cannot be equal to 0 in the meanwhile.
+ for (; node.getCoordinateX() >= 0 && node.getCoordinateY() >= 0
+ && (node.getCoordinateY() + node.getCoordinateX() > 0); ) {
+ int prevNode = this.prevNode.get(node.getCoordinateX() * totalLength + node.getCoordinateY());
+ int prevX = prevNode / totalLength;
+ int prevY = prevNode % totalLength;
+
+ node = new Node(prevX, prevY);
+ path.add(node);
+ }
+
+ Collections.reverse(path);
+ return path;
+ }
+
+ /**
+ * Walk through diagonal as far as we can, because the path through diagonal is 0.
+ * @param currX the x coordinate.
+ * @param currY the y coordinate.
+ * @return the x coordinate after walking through diagonal.
+ */
+ private int walkDiagonal(int currX, int currY) {
+ while (this.checkBoundary(currX, this.oldLines.length)
+ && this.checkBoundary(currY, this.newLines.length)
+ && this.oldLines[currX].equals(this.newLines[currY])) {
+ currX++;
+ currY++;
+ }
+ return currX;
+ }
+
+ /**
+ * Check whether value is in range of [min, max).
+ * @param value int.
+ * @param max int: max value.
+ * @param min int: min value.
+ * @return whether value is in range of [min, max).
+ */
+ private boolean checkBoundary(int value, int max, int min) {
+ return min <= value && max > value;
+ }
+
+ private boolean checkBoundary(int value, int max) {
+ return this.checkBoundary(value, max, 0);
+ }
+}
diff --git a/src/Diff/Node.java b/src/Diff/Node.java
new file mode 100644
index 0000000000000000000000000000000000000000..624cc41dfb66c4351b34375e25a57c19687c25c1
--- /dev/null
+++ b/src/Diff/Node.java
@@ -0,0 +1,32 @@
+package Diff;
+
+public class Node {
+ private int coordinateX;
+ private int coordinateY;
+
+ public Node(int coordinateX, int coordinateY) {
+ this.coordinateX = coordinateX;
+ this.coordinateY = coordinateY;
+ }
+
+ public int getCoordinateX() {
+ return coordinateX;
+ }
+
+ public int getCoordinateY() {
+ return coordinateY;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj == null) {
+ return false;
+ }
+ if (!(obj instanceof Node)) {
+ return false;
+ }
+ Node node = (Node) obj;
+ return node.getCoordinateX() == this.getCoordinateX()
+ && node.getCoordinateY() == this.getCoordinateY();
+ }
+}
diff --git a/src/Diff/util/FileUtil.java b/src/Diff/util/FileUtil.java
new file mode 100644
index 0000000000000000000000000000000000000000..efa4411554dde8950fe3d6c5a4e7f1dd7c109c95
--- /dev/null
+++ b/src/Diff/util/FileUtil.java
@@ -0,0 +1,27 @@
+package Diff.util;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+
+public final class FileUtil {
+ /**
+ * Read from filename, and return the whole char of it.
+ * @param filename String. The input filename.
+ * @return The whole char reading from filename.
+ * @throws IOException Exception.
+ */
+ public static String readToString(String filename) throws IOException {
+ String encoding = "UTF-8";
+ File file = new File(filename);
+
+ Long fileLength = file.length();
+ byte[] fileContent = new byte[fileLength.intValue()];
+
+ FileInputStream fileInputStream = new FileInputStream(file);
+ fileInputStream.read(fileContent);
+ fileInputStream.close();
+
+ return new String(fileContent, encoding);
+ }
+}
diff --git a/src/META-INF/MANIFEST.MF b/src/META-INF/MANIFEST.MF
new file mode 100644
index 0000000000000000000000000000000000000000..7709bd3b46707dc422485f32bf2a1d57371d49a9
--- /dev/null
+++ b/src/META-INF/MANIFEST.MF
@@ -0,0 +1,3 @@
+Manifest-Version: 1.0
+Main-Class: SwingJit
+
diff --git a/src/SwingJit.java b/src/SwingJit.java
index 97245173931164e5aa4f3e3150b8b8d7d60c4660..2f65249bb56f18a22205583209d202e66605cbe6 100644
--- a/src/SwingJit.java
+++ b/src/SwingJit.java
@@ -1,6 +1,4 @@
-import core.JitAdd;
-import core.JitCommit;
-import core.JitInit;
+import core.*;
import utils.Utils;
import utils.ZLibUtils;
@@ -15,10 +13,12 @@ import java.io.IOException;
public class SwingJit {
- public static void main(String[] args) {
+
+ public static void main(String[] args) throws UnsupportedLookAndFeelException, ClassNotFoundException, InstantiationException, IllegalAccessException {
+ UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
// 创建 JFrame 实例
JFrame frame = new JFrame("JIT- 你不需要使用命令行");
- frame.setSize(600, 370);
+ frame.setSize(1230, 600);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel panel = new JPanel();
@@ -31,19 +31,66 @@ public class SwingJit {
}
public static void placeComponents(JPanel panel,JFrame f) {
-
+ int dep = 70;
panel.setLayout(null);
+////////////////////////////////////////////////JIT----LOAD//////////////////////////////////////////////////
+ JTextField dirPath1 = new JTextField(20);
+ dirPath1.setBounds(160,40,250,40);
+ panel.add(dirPath1);
+ JButton chooseDir1 = new JButton("选择文件夹");
+ chooseDir1.setFont(new Font("黑体",Font.BOLD,16));
+ chooseDir1.setBounds(20, 40, 120, 40);
+ panel.add(chooseDir1);
+ //chooseDir.setActionCommand("dir");
+ chooseDir1.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ JFileChooser fileChooser = new JFileChooser();
+ fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
+ int option = fileChooser.showOpenDialog(f);
+ if(option == JFileChooser.APPROVE_OPTION){
+ File file = fileChooser.getSelectedFile();
+ try {
+ dirPath1.setText(file.getCanonicalPath());
+ } catch (IOException ex) {
+ ex.printStackTrace();
+ }
+ }
+ }
+ });
-
+ final JLabel label1 = new JLabel();
+ label1.setBounds(163,40,120,100);
+ label1.setForeground(Color.blue);
+ label1.setFont(new Font("黑体",Font.BOLD,16));
+ JButton initButton1 = new JButton("load");
+ initButton1.setFont(new Font("黑体",Font.BOLD,16));
+ initButton1.setBounds(430, 40, 120, 40);
+ initButton1.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ String dirpath = dirPath1.getText();
+ Utils.setWorkDir(dirpath);
+ /*try {
+ JitInit.init(dirpath);
+ } catch (IOException ex) {
+ ex.printStackTrace();
+ }*/
+ label1.setText("目录加载完成");
+ }
+ });
+ panel.add(label1);
+ panel.add(initButton1);
+////////////////////////////////////////////////JIT----INIT//////////////////////////////////////////////////
JTextField dirPath = new JTextField(20);
- dirPath.setBounds(160,40,250,40);
+ dirPath.setBounds(160,40+dep,250,40);
panel.add(dirPath);
JButton chooseDir = new JButton("选择文件夹");
chooseDir.setFont(new Font("黑体",Font.BOLD,16));
- chooseDir.setBounds(20, 40, 120, 40);
+ chooseDir.setBounds(20, 40+dep, 120, 40);
panel.add(chooseDir);
//chooseDir.setActionCommand("dir");
chooseDir.addActionListener(new ActionListener() {
@@ -63,18 +110,17 @@ public class SwingJit {
}
});
-
- ////////////////////////////////////////////////JIT----INIT//////////////////////////////////////////////////
final JLabel label = new JLabel();
- label.setBounds(163,40,100,100);
+ label.setBounds(163,40+dep,130,100);
label.setForeground(Color.blue);
label.setFont(new Font("黑体",Font.BOLD,16));
- JButton initButton = new JButton("git init");
+ JButton initButton = new JButton("init");
initButton.setFont(new Font("黑体",Font.BOLD,16));
- initButton.setBounds(430, 40, 120, 40);
+ initButton.setBounds(430, 40+dep, 120, 40);
initButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
+
String dirpath = dirPath.getText();
Utils.setWorkDir(dirpath);
try {
@@ -88,14 +134,14 @@ public class SwingJit {
panel.add(label);
panel.add(initButton);
+ ////////////////////////////////////////////////JIT----ADD//////////////////////////////////////////////////
+
JTextField filePath = new JTextField(20);
- filePath.setBounds(160,110,250,40);
+ filePath.setBounds(160,110+dep,250,40);
panel.add(filePath);
-
-
JButton chooseFile = new JButton("选择文件");
chooseFile.setFont(new Font("黑体",Font.BOLD,16));
- chooseFile.setBounds(20, 110, 120, 40);
+ chooseFile.setBounds(20, 110+dep, 120, 40);
chooseFile.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
@@ -114,22 +160,25 @@ public class SwingJit {
});
panel.add(chooseFile);
- ////////////////////////////////////////////////JIT----ADD//////////////////////////////////////////////////
+
final JLabel label2 = new JLabel();
- label2.setBounds(163,110,150,100);
+ label2.setBounds(163,110+dep,300,100);
label2.setForeground(Color.blue);
label2.setFont(new Font("黑体",Font.BOLD,16));
- JButton addButton = new JButton("git add");
+ JButton addButton = new JButton("add");
addButton.setFont(new Font("黑体",Font.BOLD,16));
- addButton.setBounds(430, 110, 120, 40);
+ addButton.setBounds(430, 110+dep, 120, 40);
addButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String filepath = filePath.getText();
+ String path = filepath.trim();
+ String filename = path.substring(path.lastIndexOf("\\")+1);
try {
JitAdd.add(new File(filepath));
- label2.setText("文件已添加到暂存区");
+ label2.setForeground(Color.BLUE);
+ label2.setText("文件" + filename + "已添加到暂存区");
} catch (Exception ex) {
ex.printStackTrace();
label2.setForeground(Color.RED);
@@ -141,43 +190,69 @@ public class SwingJit {
panel.add(label2);
panel.add(addButton);
- JButton commitButton = new JButton("git commit");
+ ////////////////////////////////////////////////JIT----COMMIT//////////////////////////////////////////////////
+
+ final JLabel labelss = new JLabel();
+ labelss.setBounds(163,110+dep*2,300,100);
+ labelss.setForeground(Color.blue);
+ labelss.setFont(new Font("黑体",Font.BOLD,16));
+
+ final JLabel labelMessage = new JLabel();
+ labelMessage.setBounds(20,150+dep,100,100);
+ labelMessage.setText("MESSAGE");
+ panel.add(labelMessage);
+
+ JTextField messageCont = new JTextField(20);
+ messageCont.setBounds(100,180+dep,310,40);
+ panel.add(messageCont);
+
+
+ JButton commitButton = new JButton("commit");
commitButton.setFont(new Font("黑体",Font.BOLD,16));
- commitButton.setBounds(20, 180, 530, 40);
+ //commitButton.setBounds(20, 180, 530, 40);
+ commitButton.setBounds(430, 180+dep, 120, 40);
commitButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
+ String message = messageCont.getText();
JitCommit jitcommit = new JitCommit();
try {
- jitcommit.commit();
+ //传入提交信息字符串
+ jitcommit.commit(message);
+ labelss.setForeground(Color.BLUE);
+ labelss.setText("提交成功");
} catch (Exception ex) {
ex.printStackTrace();
+ labelss.setForeground(Color.RED);
+ labelss.setText("提交失败,请检查!");
}
}
});
+ panel.add(labelss);
panel.add(commitButton);
final JLabel label3 = new JLabel();
- label3.setBounds(20,220,100,100);
+ label3.setBounds(650,10,100,100);
label3.setText("KEY");
panel.add(label3);
JTextField key = new JTextField(20);
- key.setBounds(60,250,350,40);
+ key.setBounds(700,40,350,40);
panel.add(key);
final JLabel label4 = new JLabel();
- label4.setBounds(60,250,700,200);
+ label4.setBounds(700,100,700,800);
label4.setFont(new Font("黑体",Font.BOLD,18));
-
- JButton value = new JButton("VALUE");
+ label4.setVerticalAlignment(SwingConstants.TOP);
+ //label4.setText(""+"qwfqwfqwfqwf\nwqf\nwfwf"+"");
+ JButton value = new JButton("cat file");
value.setFont(new Font("黑体",Font.BOLD,16));
- value.setBounds(430, 250, 120, 40);
+ value.setBounds(1070, 40, 120, 40);
value.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String keyText = key.getText();
- System.out.println(Utils.getObjectsPath());
+ //System.out.println(Utils.getObjectsPath());
File file = new File(Utils.getObjectsPath() + File.separator + keyText);
FileInputStream is = null;
try {
@@ -190,13 +265,213 @@ public class SwingJit {
String str = new String(output);
str = str.replaceAll("\n","
");
str = ""+str+"";
- System.out.println(str);
+ //System.out.println(str);
label4.setText(str);
+ try {
+ is.close();
+ } catch (IOException ex) {
+ ex.printStackTrace();
+ }
}
});
panel.add(label4);
panel.add(value);
+
+ ////////////////////////////////////////////////JIT----BRANCH//////////////////////////////////////////////////
+ final JLabel labelbr = new JLabel();
+ labelbr.setBounds(163,110+dep*3,300,100);
+ labelbr.setForeground(Color.blue);
+ labelbr.setFont(new Font("黑体",Font.BOLD,16));
+
+
+ final JLabel labelMessage11 = new JLabel();
+ labelMessage11.setBounds(20,150+dep*2,100,100);
+ labelMessage11.setText("Branch");
+ panel.add(labelMessage11);
+
+ JTextField messageCont11 = new JTextField(20);
+ messageCont11.setBounds(100,180+dep*2,310,40);
+ panel.add(messageCont11);
+
+ JButton commitButton11 = new JButton("branch");
+ commitButton11.setFont(new Font("黑体",Font.BOLD,16));
+ //commitButton.setBounds(20, 180, 530, 40);
+ commitButton11.setBounds(430, 180+dep*2, 120, 40);
+ commitButton11.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ String message = messageCont11.getText();
+ try {
+ JitBranch.createBranchWithMaster(message);
+ labelbr.setForeground(Color.BLUE);
+ labelbr.setText("分支"+message+"创建成功");
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ labelbr.setForeground(Color.RED);
+ labelbr.setText("创建分支失败,请重试");
+ }
+ }
+ });
+ panel.add(commitButton11);
+ panel.add(labelbr);
+ //panel.add(commitButton22);
+ /////////////////////////////////////////////////////////
+ JButton commitButton3 = new JButton("list");
+ commitButton3.setFont(new Font("黑体",Font.BOLD,16));
+ //commitButton.setBounds(20, 180, 530, 40);
+ commitButton3.setBounds(20, 180+dep*3, 160, 40);
+ commitButton3.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ String message = null;
+ //JitCommit jitcommit = new JitCommit();
+ try {
+ //传入提交信息字符串
+ message = JitBranch.branch();
+ message = message.replaceAll("\n","
");
+ message = ""+message+"";
+ //System.out.println(str);
+ label4.setText(message);
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+ });
+ panel.add(commitButton3);
+ /////////////////////////////////////////////////////////
+ JButton commitButtondel = new JButton("delete");
+ commitButtondel.setFont(new Font("黑体",Font.BOLD,16));
+ //commitButton.setBounds(20, 180, 530, 40);
+ commitButtondel.setBounds(200, 180+dep*3, 160, 40);
+ commitButtondel.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ String message = messageCont11.getText();
+ //JitCommit jitcommit = new JitCommit();
+ try {
+ //传入提交信息字符串
+ JitBranch.deleteBranch(message);
+ labelbr.setForeground(Color.BLUE);
+ labelbr.setText("分支"+message+"删除成功");
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ labelbr.setForeground(Color.RED);
+ labelbr.setText("分支删除失败,请重试");
+ }
+ }
+ });
+ panel.add(commitButtondel);
+ /////////////////////////////////////////////////////////
+ JButton commitButtoncheck = new JButton("checkout");
+ commitButtoncheck.setFont(new Font("黑体",Font.BOLD,16));
+ //commitButton.setBounds(20, 180, 530, 40);
+ commitButtoncheck.setBounds(380, 180+dep*3, 170, 40);
+ commitButtoncheck.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ String message = messageCont11.getText();
+ //JitCommit jitcommit = new JitCommit();
+
+ try {
+ JitCheckout.checkout(message);
+ labelbr.setForeground(Color.BLUE);
+ labelbr.setText("已切换到"+message+"分支");
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ labelbr.setForeground(Color.RED);
+ labelbr.setText("分支切换失败,请重试");
+ }
+ }
+ });
+ panel.add(commitButtoncheck);
+ /////////////////////////////////////////////////////////
+ JButton commitButtonindex = new JButton("index");
+ commitButtonindex.setFont(new Font("黑体",Font.BOLD,16));
+ //commitButton.setBounds(20, 180, 530, 40);
+ commitButtonindex.setBounds(20, 180+dep*4, 160, 40);
+ commitButtonindex.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ String message = null;
+ try {
+ message = JitOpr.JitStage();
+ message = message.replaceAll("\n","
");
+ message = ""+message+"";
+ //System.out.println(str);
+ label4.setText(message);
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+ });
+ panel.add(commitButtonindex);
+ /////////////////////////////////////////////////////////
+ JButton resbutton = new JButton("restore");
+ resbutton.setFont(new Font("黑体",Font.BOLD,16));
+ //commitButton.setBounds(20, 180, 530, 40);
+ resbutton.setBounds(200, 180+dep*4, 160, 40);
+ resbutton.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ try {
+ JitRestore.restore();
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+ });
+ panel.add(resbutton);
+ /////////////////////////////////////////////////////////
+ JButton logbutton = new JButton("log");
+ logbutton.setFont(new Font("黑体",Font.BOLD,16));
+ //commitButton.setBounds(20, 180, 530, 40);
+ logbutton.setBounds(380, 180+dep*4, 170, 40);
+ logbutton.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ String message = null;
+ try {
+ message = JitLog.printLog();
+ message = message.replaceAll("\n","
");
+ message = ""+message+"";
+ //System.out.println(str);
+ label4.setText(message);
+ //JitLog.printLog();
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+ });
+ panel.add(logbutton);
+
+
+
+
+
+ JButton skin = new JButton("一键换皮肤");
+ skin.setFont(new Font("黑体",Font.BOLD,16));
+ skin.setBounds(1070, 400+dep, 120, 40);
+ skin.addActionListener(new ActionListener() {
+
+ @Override
+ public void actionPerformed(ActionEvent e) {
+
+ String dirpath = dirPath.getText();
+ int random=(int)(Math.random()*4);
+ String[] arr = {"javax.swing.plaf.metal.MetalLookAndFeel","com.sun.java.swing.plaf.windows.WindowsLookAndFeel","com.sun.java.swing.plaf.windows.WindowsClassicLookAndFeel",
+ "com.sun.java.swing.plaf.motif.MotifLookAndFeel"};
+ try {
+ System.out.println(random);
+ UIManager.setLookAndFeel(arr[random]);
+ //System.out.println(UIManager.getLookAndFeel());
+ SwingUtilities.updateComponentTreeUI(f);
+ } catch (UnsupportedLookAndFeelException | ClassNotFoundException | InstantiationException | IllegalAccessException ex) {
+ ex.printStackTrace();
+ }
+ }
+ });
+ panel.add(skin);
}
}
\ No newline at end of file
diff --git a/src/branch/Branch.java b/src/branch/Branch.java
new file mode 100644
index 0000000000000000000000000000000000000000..140c4cf9dac67fdc3b8ed685b12a4207bc59cfc8
--- /dev/null
+++ b/src/branch/Branch.java
@@ -0,0 +1,102 @@
+package branch;
+import gitobject.Commit;
+import repo.Repository;
+import utils.Utils;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileWriter;
+import java.io.IOException;
+
+//Git的分支,其实本质上仅仅是指向提交对象的可变指针
+public class Branch {
+ //分支名
+ private String branchName;
+ //commit的40位16进制数(key)
+ private String commitKey;
+ /////////////////////////
+ //保存分支指向commit key的文件
+ String path = Utils.getJitDir() + File.separator + "refs" + File.separator + "heads";
+ /////////////////////////
+
+ public String getBranchName(){
+ return branchName;
+ }
+ public String getCommitKey(){
+ return commitKey;
+ }
+
+ public void setBranchName(String branchName) {
+ this.branchName = branchName;
+ }
+
+ public void setCommitKey(String commitKey) {
+ this.commitKey = commitKey;
+ }
+
+ //普通构造方法,分别传入分支名和commit key,在JitCommit中会使用到
+ public Branch(String branchName, String commitKey){
+ setBranchName(branchName);
+ setCommitKey(commitKey);
+ //this.branchName = branchName;
+ //this.commitKey = commitKey;
+ }
+
+
+ //重载构造方法,只传入分支名,通过分支名查找refs/heads文件中保存的commit key
+ public Branch(String branchName) throws IOException {
+ //String path = Repository.getGitDir() + File.separator + "refs" + File.separator + "heads";
+ //this.branchName = branchName;
+ setBranchName(branchName);
+ File currBranchFile = new File(path + File.separator + branchName);
+ if(currBranchFile.exists()) {
+ commitKey = Utils.getContentFromFile(currBranchFile);
+ } else {
+ throw new FileNotFoundException("分支不存在,请检查拼写错误");
+ }
+ }
+
+
+ //重新设置commitKey,并且修改refs/heads中的commit key
+ public void resetCommit(String commitKey) throws IOException {
+ setCommitKey(commitKey);
+ addBranch();
+ }
+
+ //确定位于refs/heads的分支文件是否存在
+ public boolean branchExist(){
+ //String path = Repository.getGitDir() + File.separator + "refs" + File.separator + "heads";
+ File branchFile = new File(path + File.separator + branchName);
+ return branchFile.exists();
+ }
+
+ //重载方法,确定位于refs/heads,且名为branchNames的分支文件是否存在
+ //注意:最好不要频繁使用此方法,虽然方便,但会破坏代码逻辑!我本意是要把它放入Utils里
+ public boolean branchExist(String branchNames){
+ File branchFile = new File(path + File.separator + branchNames);
+ return branchFile.exists();
+ }
+
+
+ //改变HEAD文件中的分支名,HEAD文件相当于指针,指向最近操作的分支名
+ public void changeHead() throws IOException {
+ File HEAD = new File(Utils.getJitDir() + File.separator + "HEAD");
+ FileWriter fileWriter = new FileWriter(HEAD);
+ fileWriter.write("ref: refs/heads/" + branchName);
+ fileWriter.close();
+ }
+
+
+ //在refs/heads文件夹内添加或替换branch文件
+ public void addBranch() throws IOException {
+ //String path = Repository.getGitDir() + File.separator + "refs" + File.separator + "heads";
+ File branchFile = new File(path + File.separator + branchName);
+ FileWriter fileWriter = new FileWriter(branchFile);
+ fileWriter.write(commitKey);
+ fileWriter.close();
+ }
+
+
+
+
+}
diff --git a/src/core/JitAdd.java b/src/core/JitAdd.java
index 50aa5b803289ce3777a8c5ec3cbcf8d926d7b784..662a2c2db396a4871872f9e62d98651d4ea67238 100644
--- a/src/core/JitAdd.java
+++ b/src/core/JitAdd.java
@@ -15,11 +15,11 @@ public class JitAdd {
if(file.isFile()){
//表示已经在index类找到了同名的记录
if(idx.inIndex(file) != (-1)) {
- System.out.println("找到了同名记录,现在我们更新吧");
+ System.out.println("找到了同名记录,更新");
idx.deleteItem(file);
}
idx.addIndexs(file);
- idx.outputIndex();
+ idx.saveIndex();
}
else if(file.isDirectory()){
File[] fs = file.listFiles();
diff --git a/src/core/JitBranch.java b/src/core/JitBranch.java
new file mode 100644
index 0000000000000000000000000000000000000000..b4dacb1e920aa5c4c69652402e3fe14878592d38
--- /dev/null
+++ b/src/core/JitBranch.java
@@ -0,0 +1,101 @@
+package core;
+
+import branch.Branch;
+import utils.Utils;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+
+//这里定义对于分支的一系列操作
+public class JitBranch {
+
+ //得到HEAD中存放的branch路径,例如:ref: refs/heads/master,substring(16)就是master
+ //并返回由它得到的branch对象
+ public static Branch getBranch() throws IOException {
+ File HEAD = new File(Utils.getJitDir() + File.separator + "HEAD");
+ //String branchName = GitObject.getValue(HEAD).substring(16).replace("\n","");
+ String branchName = Utils.getContentFromFile(HEAD).substring(16).replace("\n","");
+ Branch branch = new Branch(branchName);
+ return branch;
+ }
+
+ //判断分支名所对应的分支文件是否存在,若存在返回true
+ public static boolean branchExist(String branchName)throws FileNotFoundException {
+
+ File branch = new File(Utils.getJitDir() + File.separator + "refs"
+ + File.separator + "heads" + File.separator + branchName);
+ return branch.isFile();
+ }
+
+ //创建一个新的branch并且把这个branch文件添加到refs/heads文件夹
+ public static void branchAdd(String branchname, String commitId) throws IOException {
+ Branch branch = new Branch(branchname, commitId);
+ branch.addBranch();
+ }
+
+
+ //列出所有现存的分支名
+ public static String branch() throws IOException {
+ StringBuilder str = new StringBuilder("");
+ if(!branchExist("master")){
+ throw new FileNotFoundException("master分支不存在,你应该至少先提交一次");
+ //System.out.println("master分支不存在,你应该至少先提交一次");
+ //return;
+ }
+ Branch currentBranch = getBranch();
+ File[] branchList = new File(Utils.getJitDir() + File.separator + "refs"
+ + File.separator + "heads").listFiles();
+ for(int i = 0; i < branchList.length; i++){
+ //从HEAD文件中读取的branch名和refs/heads中的branch文件名相同,表示是当前分支,前面加上*号
+ if(currentBranch.getBranchName().equals(branchList[i].getName())){
+ System.out.print("*");
+ str.append("*");
+ }
+ else{
+ System.out.print(" ");
+ str.append(" ");
+ }
+ System.out.println(branchList[i].getName());
+ str.append(branchList[i].getName()).append("\n");
+ }
+ return str.toString();
+ }
+
+
+ //在master分支处再创建一个分支
+ public static void createBranchWithMaster(String branchName) throws IOException {
+ if(!branchExist("master")){
+ throw new FileNotFoundException("master分支不存在,你应该至少先提交一次");
+ //System.out.println("master分支不存在,你应该至少先提交一次");
+ //return;
+ }
+ //Branch master = new Branch("master");
+ Branch cur = getBranch();
+ Branch branch = new Branch(branchName, cur.getCommitKey());
+ //这里可以这样理解:
+ //...refs/heads文件夹下,有很多branch文件,我们添加了一个
+ branch.addBranch();
+ }
+
+
+ //删除分支,在此之前请确保
+ // 1、希望删除的分支名存在
+ // 2、删除的分支不是当前分支
+ public static void deleteBranch(String branchName) throws IOException {
+ if(!branchExist(branchName)){
+ System.out.println("错误:找不到名为"+"'"+branchName+"'"+"的分支");
+ }
+ if (branchName.equals(getBranch().getBranchName())){
+ System.out.println("错误:不能删除当前所在的分支 ");
+ }
+ File branch = new File(Utils.getJitDir() + File.separator + "refs" + File.separator +
+ "heads" + File.separator + branchName);
+ if(branch.delete()){
+ System.out.println("名为" + "'" + branchName + "'" +"的分支已经被删除");
+ }else throw new IOException("删除失败,请检查");
+
+ }
+
+
+
+}
diff --git a/src/core/JitCheckout.java b/src/core/JitCheckout.java
new file mode 100644
index 0000000000000000000000000000000000000000..770136ae5c90ba33ed6722984e697e65eed1d440
--- /dev/null
+++ b/src/core/JitCheckout.java
@@ -0,0 +1,66 @@
+package core;
+
+import branch.Branch;
+import gitobject.Commit;
+import gitobject.Tree;
+import tmp.Index;
+import utils.FileCreation;
+import utils.FileDeletion;
+import utils.Utils;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+
+public class JitCheckout {
+
+ static String path = Utils.getJitDir() + File.separator + "refs" + File.separator + "heads";
+
+ //确定位于refs/heads,且名为branchNames的分支文件是否存在
+ //注意:最好不要频繁使用此方法,虽然方便,但会破坏代码逻辑!我本意是要把它放入Utils里
+ public static boolean branchExist(String branchNames){
+ File branchFile = new File(path + File.separator + branchNames);
+ return branchFile.exists();
+ }
+
+ //切换到名为branchName的分支,它比changeHead方法多了一个条件判断
+ public static void checkout(String branchName) throws Exception {
+ if(branchExist(branchName)){
+ //在工作目录删除所有文件(除了.jit外)
+ System.out.println("HEAD当前指向"+branchName);
+ System.out.println("删除的文件位于"+Utils.getWorkDir());
+ File[] worktree = new File(Utils.getWorkDir()).listFiles();
+ for (File file : worktree) {
+ if (!file.getName().equals(".jit")) {
+ FileDeletion.deleteFile(file);
+ System.out.println("-"+file.getName());
+ }
+ }
+ changeHead(branchName);
+ Branch branch = JitBranch.getBranch();
+ Commit commit = new Commit(branch.getCommitKey());
+ Tree tree = new Tree(commit.getTree());
+ System.out.println("树对象是"+commit.getTree());
+ //通过树对象恢复所有的文件
+ FileCreation.recoverWorkTree(tree, Utils.getWorkDir());
+ //删除所有index文件
+ Index index = new Index();
+ index.clear();
+ //把目前的所有文件记录添加到index中
+ File[] workTree = new File(Utils.getWorkDir()).listFiles();
+ for(int i = 0; i < workTree.length; i++){
+ if(!workTree[i].getName().equals(".jit"))
+ JitAdd.add(workTree[i]);
+ }
+ } else{
+ System.out.println(branchName + "不存在,无法切换");
+ }
+ }
+
+ //改变HEAD文件中的分支名,HEAD文件相当于指针,指向最近操作的分支名
+ public static void changeHead(String branchName) throws IOException {
+ File HEAD = new File(Utils.getJitDir() + File.separator + "HEAD");
+ FileWriter fileWriter = new FileWriter(HEAD);
+ fileWriter.write("ref: refs/heads/" + branchName);
+ fileWriter.close();
+ }
+}
diff --git a/src/core/JitCommit.java b/src/core/JitCommit.java
index 1c40dceb6c156d9749c955380ce2455e343a3eae..a898640cbd1f195880943e95235344197b92185a 100644
--- a/src/core/JitCommit.java
+++ b/src/core/JitCommit.java
@@ -1,5 +1,6 @@
package core;
+import branch.Branch;
import gitobject.*;
import tmp.*;
@@ -10,13 +11,11 @@ import java.io.IOException;
import java.util.*;
public class JitCommit {
- /**
- * Creating commit and write it to repository.
- * @throws Exception
- */
+
+ //创建commit对象并保存到repository,并且把commit的key写入branch文件
public void commit() throws Exception {
Tree tree = buildTree();
- String author = System.getProperty("user.name") + " " + String.valueOf(new Date().getTime());
+ String author = System.getProperty("user.name") + " " + String.valueOf(new Date().toString());
String committer = System.getProperty("user.name");
System.out.println("Please enter the commit message: ");
@@ -24,13 +23,32 @@ public class JitCommit {
String message = sc.nextLine();
Commit commit = new Commit(tree, author, committer, message);
- Index index = new Index();
- //提交完成后,删除index文件
- index.clear();
- //updateBranch(commit);
- //sc.close();
+ //Index index = new Index();
+ //index.clear();
+
+ updateBranch(commit);
}
-
+
+ //SwingJIT专用的方法,传入自定义的提交信息,其余步骤和上一个方法一致
+ public void commit(String message) throws Exception {
+ Tree tree = buildTree();
+ String author = System.getProperty("user.name") + " " + String.valueOf(new Date().toString());
+ String committer = System.getProperty("user.name");
+ Commit commit = new Commit(tree, author, committer, message);
+ //Index index = new Index();
+ //index.clear();
+ updateBranch(commit);
+ }
+
+ //更新branch,把commit key信息写入refs/heads中
+ public void updateBranch(Commit commit) throws IOException {
+ String commitKey = commit.getKey();
+ //得到当前的branch,该路径位于.jit文件夹中的HEAD文件中
+ Branch branch = JitBranch.getBranch();
+ //分为两步,第一步修改branch对象的commitkey,第二步把commitkey写入到branch文件中
+ branch.resetCommit(commitKey);
+ }
+
//从现有的index文件中创建indexTree对象
public TreeMap buildIndexTree() throws IOException {
diff --git a/src/core/JitInit.java b/src/core/JitInit.java
index 91cacfa70e0ba358c178d2b1a97d27b27fef0480..98e8df57ad00fc70dbc74b3525e2b258ae9c6d54 100644
--- a/src/core/JitInit.java
+++ b/src/core/JitInit.java
@@ -1,9 +1,13 @@
package core;
+import branch.Branch;
import utils.FileDeletion;
import repo.Repository;
+import utils.Utils;
+import java.io.File;
import java.io.IOException;
+import java.util.Objects;
public class JitInit {
/**
@@ -14,16 +18,15 @@ public class JitInit {
public static void init(String workTree) throws IOException {
Repository repo = new Repository(workTree);
if(!repo.exist()){
-/* if(repo.isDirectory()){
- FileDeletion.deleteFile(Repository.getGitDir());
- }
- else if(repo.isFile()){
- throw new IOException(".jit is a file, please check");
- }*/
- System.out.println(".jit仓库不存在,现在建立");
+ System.out.println("Jit仓库不存在,现在建立");
repo.createRepo();
}
-
- System.out.println("Jit repository has been initiated successfully.");
+ System.out.println("Jit仓库已经存在了.");
+ //这里建立master分支文件
+ File file = new File(Utils.getJitDir() + File.separator + "refs" + File.separator + "heads");
+ if(Objects.requireNonNull(file.list()).length == 0) {
+ Branch master = new Branch("master", "null");
+ master.addBranch();
+ }
}
}
diff --git a/src/core/JitLoad.java b/src/core/JitLoad.java
new file mode 100644
index 0000000000000000000000000000000000000000..d2cd8852d7b71e750ef961d70c22b8773202991d
--- /dev/null
+++ b/src/core/JitLoad.java
@@ -0,0 +1,9 @@
+package core;
+
+import utils.Utils;
+
+public class JitLoad {
+ public static void load(String path){
+ Utils.setWorkDir(path);
+ }
+}
diff --git a/src/core/JitLog.java b/src/core/JitLog.java
index ef33c5c2246de3b035ebda5a8f78896d186853f8..fd3cec0732e3a1b06dfec9dd137b7f5e13d6b126 100644
--- a/src/core/JitLog.java
+++ b/src/core/JitLog.java
@@ -1,19 +1,46 @@
package core;
+import branch.Branch;
+import gitobject.Commit;
import utils.Utils;
import java.io.File;
import java.io.IOException;
+import static core.JitBranch.getBranch;
+
public class JitLog {
- public static void printLog() throws Exception {
+ public static String printLog() throws Exception {
+ StringBuilder stringBuilder = new StringBuilder();
+ Branch currentBranch = getBranch();
+ String commitKey = currentBranch.getCommitKey();
+ Commit curCommit = new Commit(commitKey);
+ stringBuilder.append("--------------------------------------------------").
+ append("\n").append(curCommit.getValue()).append("\n");
+ System.out.println("--------------------------------------------------");
+ System.out.println(curCommit.getValue());
+ String parentKey = curCommit.getParent();
- File file = new File(Utils.getWorkDir()+File.separator+".jit"+File.separator+"LOG");
- if(file.exists()){
- String res = Utils.getContentFromFile(file);
- System.out.println(res);
- }else {
- throw new IOException();
+ while (!parentKey.equals("null")) {
+ Commit commit = new Commit(parentKey);
+ stringBuilder.append("--------------------------------------------------").append("\n")
+ .append(commit.getValue()).append("\n").append("--------------------------------------------------");
+ System.out.println("--------------------------------------------------");
+ System.out.println(commit.getValue());
+ System.out.println("--------------------------------------------------");
+ parentKey = commit.getParent();
}
-
+ String str = stringBuilder.toString();
+ return str;
}
+
+ /*public void logCommitHistory() throws IOException {
+ System.out.println(getValue());
+ String parentId = getParent();
+ while(parentId != null){
+ Commit commit = new Commit(parentId);
+ System.out.println(commit.getValue());
+ parentId = commit.getParent();
+ }
+ }*/
+
}
diff --git a/src/core/JitOpr.java b/src/core/JitOpr.java
new file mode 100644
index 0000000000000000000000000000000000000000..a71946a5dc7c50ed882702b0e4d96ab44fda831c
--- /dev/null
+++ b/src/core/JitOpr.java
@@ -0,0 +1,48 @@
+package core;
+
+import utils.Utils;
+import utils.ZLibUtils;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+
+public class JitOpr {
+ public static void JitCat(String key) throws IOException {
+ File file = new File(Utils.getObjectsPath() + File.separator + key);
+ FileInputStream is = null;
+ try {
+ is = new FileInputStream(file);
+ } catch (FileNotFoundException ex) {
+ ex.printStackTrace();
+ }
+ byte[] output = ZLibUtils.decompress(is);
+ //label4.setText(new String(output));
+ String str = new String(output);
+ //str = str.replaceAll("\n","
");
+ //str = ""+str+"";
+ System.out.println(str);
+ is.close();
+ }
+
+ public static String JitRec(String key) throws IOException {
+ File file = new File(Utils.getObjectsPath() + File.separator + key);
+ FileInputStream is = null;
+ try {
+ is = new FileInputStream(file);
+ } catch (FileNotFoundException ex) {
+ ex.printStackTrace();
+ }
+ byte[] output = ZLibUtils.decompress(is);
+ String str = new String(output);
+ is.close();
+ return str;
+ }
+
+ public static String JitStage() throws IOException {
+ File file = new File(Utils.getJitDir()+File.separator+"index");
+ System.out.println(Utils.getContentFromFile(file));
+ return Utils.getContentFromFile(file);
+ }
+}
diff --git a/src/core/JitReset.java b/src/core/JitReset.java
new file mode 100644
index 0000000000000000000000000000000000000000..d5f66587a3b63617263c565d5f3255129537182c
--- /dev/null
+++ b/src/core/JitReset.java
@@ -0,0 +1,71 @@
+package core;
+
+import branch.Branch;
+import gitobject.Blob;
+import gitobject.Commit;
+import gitobject.GitObject;
+import gitobject.Tree;
+import tmp.Index;
+import utils.FileCreation;
+import utils.FileDeletion;
+import utils.FileReader;
+import utils.Utils;
+
+import java.io.*;
+import java.util.ArrayList;
+
+
+public class JitReset {
+
+ //重置到最近一次提交,只重置暂存区
+ public static void newReset() throws Exception {
+ reset(JitBranch.getBranch().getCommitKey());
+ }
+
+ //重置到特定的提交(commitKey),只重置暂存区
+ public static void reset(String commitKey) throws IOException {
+ Index idx = new Index();
+ idx.clear();
+ Branch branch = JitBranch.getBranch();
+ branch.resetCommit(commitKey);
+ Commit commit = new Commit(commitKey);
+ Tree tree = new Tree(commit.getTree());
+ File indexFile = new File(Utils.getJitDir() + File.separator + "index");
+ FileWriter fw = new FileWriter(indexFile);
+ fw.write(tree.getValue());
+ fw.flush();
+ fw.close();
+ }
+
+ //重置到最近一次提交
+ public static void newHardReset() throws Exception {
+ hardReset(JitBranch.getBranch().getCommitKey());
+ }
+
+ //重置到特定的提交(commitKey),工作区和暂存区的文件也同步重置
+ public static void hardReset(String commitKey) throws Exception {
+ //在工作目录删除所有文件(除了.jit外)
+ File[] worktree = new File(Utils.getWorkDir()).listFiles();
+ for(int i = 0; i < worktree.length;i++){
+ if(!worktree[i].getName().equals(".jit")){
+ FileDeletion.deleteFile(worktree[i]);
+ }
+ }
+ Branch branch = JitBranch.getBranch();
+ branch.resetCommit(commitKey);
+ Commit commit = new Commit(commitKey);
+ Tree tree = new Tree(commit.getTree());
+
+ //通过树对象恢复所有的文件
+ FileCreation.recoverWorkTree(tree, Utils.getWorkDir());
+ //删除所有index文件
+ Index index = new Index();
+ index.clear();
+ //把目前的所有文件记录添加到index中
+ File[] workTree = new File(Utils.getWorkDir()).listFiles();
+ for(int i = 0; i < workTree.length; i++){
+ if(!workTree[i].getName().equals(".jit"))
+ JitAdd.add(workTree[i]);
+ }
+ }
+}
diff --git a/src/core/JitRestore.java b/src/core/JitRestore.java
new file mode 100644
index 0000000000000000000000000000000000000000..e265c44d08a169d878e9a4be5fd0bd513e9a0fd1
--- /dev/null
+++ b/src/core/JitRestore.java
@@ -0,0 +1,43 @@
+package core;
+
+import branch.Branch;
+import gitobject.Blob;
+import gitobject.Commit;
+import gitobject.GitObject;
+import gitobject.Tree;
+import tmp.Index;
+import utils.FileCreation;
+import utils.FileDeletion;
+import utils.FileReader;
+import utils.Utils;
+
+import java.io.File;
+import java.util.ArrayList;
+
+//git restore命令,会撤销文件的修改,使暂存区的文件恢复到工作区,即最近一次执行完jit add的状态
+//注意:没有放入暂存区的文件会消失
+public class JitRestore {
+ public static void restore() throws Exception {
+ //在工作目录删除所有文件(除了.jit外)
+ File[] worktree = new File(Utils.getWorkDir()).listFiles();
+ for(int i = 0; i < worktree.length;i++){
+ if(!worktree[i].getName().equals(".jit")){
+ FileDeletion.deleteFile(worktree[i]);
+ }
+ }
+ Index idx = new Index();
+ ArrayList idxList = idx.getIndexs();
+ for(int i=0;i());
+ setType("tree");
+ setNum("040000");
+ try{
+ File file = new File(Utils.getObjectsPath() + File.separator + key);
+ if(file.exists()){
+ setKey(key);
+ //key = Id;
+ FileInputStream is = new FileInputStream(file);
+ byte[] output = ZLibUtils.decompress(is);
+ is.close();
+ setValue(new String(output));
+ genTreeList();
+ }
+ else{
+ throw new IOException();
+ }
+ }catch (Exception e){
+ e.printStackTrace();
+ }
+
+ }
+ /**
+ * Generate treelist from the value of an existed tree object.
+ * @throws IOException
+ */
+ public void genTreeList() throws IOException {
+ ArrayList list = FileReader.readByBufferReader(getValue());
+ for(int i = 0; i < list.size(); i++){
+ if(FileReader.readObjectFmt(list.get(i)).equals("blob")){
+ Blob blob = new Blob(FileReader.readObjectKey(list.get(i)));
+ treeList.add(blob);
+ }
+ else{
+ Tree tree = new Tree(FileReader.readObjectKey(list.get(i)));
+ treeList.add(tree);
+ }
+ }
+ }
/**
* Generate the key of a tree object from index.
* @param indexTree
@@ -70,7 +115,7 @@ public class Tree extends GitObject{
tree.compressWrite();
setValue(getValue()+"040000 tree " + tree.getKey() + "\t" + pair.getKey() + "\n");
}else {
- System.out.println("这里"+pair.getValue().blobKey);
+ //System.out.println("这里"+pair.getValue().blobKey);
Blob blob = new Blob(pair.getValue().blobKey);
treeList.add(blob);
//不需要compresseWrite,因为在git add之后,即生成index时,已经对所有文件进行了compresseWrite压缩写入!
diff --git a/src/repo/Repository.java b/src/repo/Repository.java
index 4cf86270d26235075eb572018be0a319f7b76876..7df2011a4d423fd2271357462a68b083c7a94c82 100644
--- a/src/repo/Repository.java
+++ b/src/repo/Repository.java
@@ -20,7 +20,7 @@ public class Repository {
*/
public Repository() throws IOException {
if(gitDir == ""){
- throw new IOException("The repository does not exist!");
+ throw new IOException("The repository does not branchExist!");
}
}
diff --git a/src/tmp/Index.java b/src/tmp/Index.java
index dc14937fb36703ad5cc90d202653e9b511901948..fba9393551de3b967d6eb113195a26622e02c6d5 100644
--- a/src/tmp/Index.java
+++ b/src/tmp/Index.java
@@ -17,7 +17,7 @@ public class Index {
//如果index文件存在,读取index文件中的数据项,如果index文件不存在,创建index文件
public Index() throws IOException {
- System.out.println(path);
+ //System.out.println(path);
if(!new File(path + File.separator + "index").exists()) {
//System.out.println("错误附近的path"+path);
//在.jit文件夹内,创建名为index的文件
@@ -25,7 +25,7 @@ public class Index {
}else {
//即表示已经存在,加载已经存在的index文件
- index = getExistData();
+ index = getObjFromIndex();
}
}
//get方法,返回创建完成的index对象
@@ -34,7 +34,7 @@ public class Index {
}
//反序列化,将index文件中的每条数据读入ArrayList中。
- public ArrayList getExistData() throws IOException {
+ public ArrayList getObjFromIndex() throws IOException {
if(new File(path + File.separator + "index").exists()) {
File indexFile = new File(path + File.separator + "index");
FileInputStream is = new FileInputStream(indexFile);
@@ -68,7 +68,7 @@ public class Index {
}
//按照一行一行的形式保存index信息到.jit/index
- public void outputIndex() throws IOException {
+ public void saveIndex() throws IOException {
if(new File(path + File.separator + "index").exists()) {
File indexFile = new File(path + File.separator + "index");
FileWriter fw = new FileWriter(indexFile);
@@ -122,6 +122,8 @@ public class Index {
int idx = inIndex(file);
if(idx != -1) {
index.remove(idx);
+ }else {
+ System.out.println("想要移除的文件不存在,请先检查");
}
}
diff --git a/src/utils/FileCreation.java b/src/utils/FileCreation.java
index 40255feceb6904dbf42ff9b75a96f06b1ada3a1e..75de81a5498bf87019247c1a8eff001f02c53d95 100644
--- a/src/utils/FileCreation.java
+++ b/src/utils/FileCreation.java
@@ -19,7 +19,7 @@ public class FileCreation {
*/
public static void createFile(String parentPath, String filename, String text) throws IOException {
if(!new File(parentPath).isDirectory()){
- throw new IOException("The path doesn't exist!");
+ throw new IOException("The path doesn't branchExist!");
}
File file = new File(parentPath + File.separator + filename);
@@ -41,7 +41,7 @@ public class FileCreation {
*/
public static void createDirectory(String parentPath, String... paths) throws IOException{
if(!new File(parentPath).isDirectory()){
- throw new IOException("The path doesn't exist!");
+ throw new IOException("The path doesn't branchExist!");
}
String path = parentPath;
FileDeletion.deleteFile(path + File.separator + paths[0]);
@@ -57,16 +57,17 @@ public class FileCreation {
* @param parentTree
* @throws IOException
*/
-/* public static void recoverWorkTree(Tree t, String parentTree) throws Exception {
+ public static void recoverWorkTree(Tree t, String parentTree) throws Exception {
ArrayList list = FileReader.readByBufferReader(t.getValue());
ArrayList treeList = t.getTreeList();
for(int i = 0; i < list.size(); i++){
if(FileReader.readObjectFmt(list.get(i)).equals("blob")){
//读取blob的key
- Blob blob = new Blob(FileReader.readObjectKey(list.get(i)),1);
+ Blob blob = new Blob(FileReader.readObjectKey(list.get(i)));
String fileName = FileReader.readObjectFileName(list.get(i));
createFile(parentTree, fileName, blob.getValue());
+ System.out.println("+"+fileName);
}
else{
//读取tree的key
@@ -76,5 +77,5 @@ public class FileCreation {
recoverWorkTree(tree, parentTree + File.separator + dirName);
}
}
- }*/
+ }
}
diff --git a/src/utils/FileDeletion.java b/src/utils/FileDeletion.java
index 84ca3aad40ce96de5acbf631db2bdf10ea6c3ec7..7689474d92aa209818982c915d6bd1dc114f5854 100644
--- a/src/utils/FileDeletion.java
+++ b/src/utils/FileDeletion.java
@@ -10,9 +10,12 @@ public class FileDeletion {
* @param file
*/
public static void deleteFile(File file){
- if(!file.exists())return;
- if(file.isFile())file.delete();
- else{
+ if(!file.exists()){
+ return;
+ }
+ if(file.isFile()) {
+ file.delete();
+ } else {
File[] fileList = file.listFiles();
for(int i = 0; i < fileList.length; i++){
deleteFile(fileList[i]);
diff --git a/src/utils/FileStatus.java b/src/utils/FileStatus.java
index b43cc2e75aae86d2be80551274959f809ffe1cd8..0791992616ca15cc9a5b09deb58615d05dd960aa 100644
--- a/src/utils/FileStatus.java
+++ b/src/utils/FileStatus.java
@@ -15,8 +15,7 @@ public class FileStatus {
* @throws FileNotFoundException
*/
public static boolean branchExist(String branchname)throws FileNotFoundException {
- /*File branch = new File(Repository.getGitDir() + File.separator + "refs"
- + File.separator + "heads" + File.separator + branchname);*/
+
File branch = new File(Utils.getJitDir() + File.separator + "refs"
+ File.separator + "heads" + File.separator + branchname);
return branch.isFile();
diff --git a/src/utils/Utils.java b/src/utils/Utils.java
index 6671439aad6a576d575550b349b9ef988561968f..03575b4205f2d5cf159615031895b9b5e2fbcb69 100644
--- a/src/utils/Utils.java
+++ b/src/utils/Utils.java
@@ -19,10 +19,12 @@ public class Utils {
public static void setWorkDir(String workDir) {
Utils.workDir = workDir;
}
+
//获取工作路径,即包含.jit的文件夹
public static String getWorkDir() {
return workDir;
}
+
//获取.jit所在的路径
public static String getJitDir() {
return workDir + File.separator + ".jit";
@@ -60,6 +62,7 @@ public class Utils {
FileInputStream fileInputStream = new FileInputStream(file);
bytes = new byte[fileInputStream.available()];
fileInputStream.read(bytes);
+ fileInputStream.close();
}catch (FileNotFoundException e){
System.out.println("文件没有找到1");
}