我已經提到了一個打印所有存儲庫詳細信息的程序。現在我想提供兩個日期,即從日期和日期作爲參數,這兩個日期之間的資料庫詳細信息需要被提取出來。如何才能做到這一點。我不確定使用哪一種可用的api。我需要編寫一個python腳本來爲給定的日期提取mercurial的存儲庫詳細信息
import sys
import hglib
# repo path
# figure out what repo path to use
repo = "."
if len(sys.argv) > 3:
repo = sys.argv[1],
from_date = sys.argv[2],
to_date = sys.argv[3]
# connect to hg
client = hglib.open(repo)
# gather some stats
revs = int(client.tip().rev)
files = len(list(client.manifest()))
heads = len(client.heads())
branches = len(client.branches())
tags = len(client.tags()) - 1 # don't count tip
authors = {}
for e in client.log():
authors[e.author] = True
description = {}
for e in client.log():
description[e.desc] = True
merges = 0
for e in client.log(onlymerges=True):
merges += 1
print "%d revisions" % revs
print "%d merges" % merges
print "%d files" % files
print "%d heads" % heads
print "%d branches" % branches
print "%d tags" % tags
print "%d authors" % len(authors)
print "%s authors name" % authors.keys()
print "%d desc" % len(description)
這打印出存儲庫中的一切,我需要拉兩個給定日期之間的細節在於2015-07-12(來自日)和2015年8月20日(TODATE)
更新代碼不起作用
import sys
import hglib
import datetime as dt
# repo path
# figure out what repo path to use
repo = "."
if len(sys.argv) > 1:
repo = sys.argv[1]
#from_date = sys.argv[2],
#to_date = sys.argv[3]
# connect to hg
client = hglib.open(repo)
# define time ranges
d1 = dt.datetime(2015,7,7)
d2 = dt.datetime(2015,8,31)
#if "date('>05/07/07') and date('<06/08/8')"
#logdetails = client.log()
description = {}
for e in client.log():
if (description[e.date] >= d1 and description[e.date] <=d2):
description[e.desc] = True
print "%s desc" % description
有一種方法可以從回購權獲取日期嗎? – mjz19910