[hg]研究筆記 commit 流程詳細探討

  • 7088
  • 0

[hg]研究筆記 commit 流程詳細探討

在上一篇中,試著逐句翻譯官網文章,覺得很拗口。於是直接研究 source code 來確定有無看錯。

首先從 localrepo.py 的 class localrepository 的 def commit {1149} 開始。

要先 lock .hg 目錄,但 .hg/store 不用 lock。所以使用 wlock function{1169}。

使用def status{1458} 找出 change{1179},這個 change 是一個 tuple,由 7 個 list 所組成modified, added, removed, deleted, unknown, ignored, clean{1582}。

cctx = context.workingctx(self, text, user, date, extra, changes) {1257} 是取得一個方便的 working directory 的 context。

ms = mergemod.mergestate(self){1267} 可以方便找出是否有 unresolved 的檔案。

p1, p2 = self.dirstate.parents(){1292} 利用 def dirstate{387} 找出 p1, p2。

ret = self.commitctx(cctx, True){1297} 利用 def commitctx {1317} 執行 commit 動作。

在執行完 commit 動作後,更新 bookmarks{1305}、dirstate{1306}、mergestate{1307}。

接下來看一下def commitctx{1317} 又做了什麼事?

首先把整個 .hg 都鎖住 lock = self.lock(){1327}。

在 working directory 的 context 裡,如果沒有檔案,那很單純,使用 p1 的 manifestnode{1368} 加到 localrepository 的 changelog{373} 物件裡。如果有檔案{1332},在更新到檔案的資訊(修改、新增、刪除的各個檔案)後,用 p1 的 manifest 當 base,整理出一個新的 manifest,然後把該 manifest 加到 localrepository 的 manifest 記錄中{1364}{382}。

在處理完 manifest 之後,接下來是處理 changelog{1373},然後就結束 commit 動作。

註:大括號裡的是原始碼的行號。版本是 8c69c69dbcd2

 

 

 

分享