- OK来搞我的实验作业了
- 打算模拟一个简单的git
- 在我看来一个简单的git,无非就是上传和下载
- 没有版本控制,没有分支控制,什么也没有
- 仅作为一个云端保存代码的工具
- 那么问题来了,如果没有版本控制的功能,还能称之为git吗
- git版本控制原理
功能设计
需求就是我要完成作业啦
> GitClient init [repository name]
- 将当前工作目录注册到远程reponsity,之后再在此目录下的commit操作将把此目录下的文件上传到远程的reponsity文件夹中
- > GitClient show
- 显示远程repository及其绑定的工作目录
- > GitClient del [repository name]
- 删除远程reponsity文件夹
- > GitClient info [repository name] [detail]
- 显示远程reponsity文件夹下的文件,并打印其对应的本地工作目录
- > GitClient commit [repository name]
- 将当前工作目录下的文件夹上传到注册的reponsity中
- 不允许同一本地工作目录对应多个远程reponsity
- > GitClient clone [repository name]
- 将远程reponsity文件夹里的文件下载到当前工作目录
RMI设计
- IGit接口设计(部分)
- regRepository(String path,String repository)
- delRepository(String repository)
- showReponsities()
- 上传三件套
- uploadFileStart(String repository,String filepath)
- uploadFile(String uploadID,byte[] data,int start,int len)
- uploadFileEnd(String uploadID)
- 下载三件套
- downloadRepositoryStart(String repository)
- download_next(String downloadID)
- downloadFile(String downloadID)
- mkdir(String repository,String dir)
- clearRepository(String repository)
- infoRepository(String repository)
上传和下载
上传部分
- String uploadFileStart(String repository,String filepath)
- client调用此函数,声明上传的repository和相对于repository的filepath
- server建立outputstream,生成一个随机的id与此输出流绑定,并返回此id作为该文件的uoloadid
- client获得uploadid
- uploadFile(String uploadID,byte[] data,int start,int len)
- client根据uploadid上传对应的数据
- uploadFileEnd(String uploadID)
- client上传结束后,通知server上传文件完成
下载部分
- String downloadRepositoryStart(String repository)
- client请求下载某个repository
- server收到请求,遍历此repository下的所有文件,并将数据分块形成一个数据队列中(存在于server端的内存里)
- server生成一个随机的id与此队列绑定,并返回此id作为downloadid
- client收到downloadid
- download_next(String downloadID)
- client根据downloadid,询问server端数据队列是否为空
- downloadFile(String downloadID)
- 若server端数据队列非空,则凭借downloadid,client可以获取一块数据