我需要编写一个python脚本来获取mercurial在给定2个日期的存储库详细信息
我引用了一个打印所有存储库详细信息的程序。现在,我想提供两个日期,即开始日期和结束日期作为参数,需要提取这两个日期之间的存储库详细信息。如何做到这一点。我不确定要使用哪个mercurial api我需要编写一个python脚本来获取mercurial在给定2个日期的存储库详细信息,python,mercurial,mercurial-api,Python,Mercurial,Mercurial Api,我引用了一个打印所有存储库详细信息的程序。现在,我想提供两个日期,即开始日期和结束日期作为参数,需要提取这两个日期之间的存储库详细信息。如何做到这一点。我不确定要使用哪个mercurial api 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 = s
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-13(起始日期)和2015-08-20(截止日期)这两个给定日期之间提取详细信息
更新的代码不工作
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
导入系统
导入hglib
将日期时间导入为dt
#回购路径
#找出要使用的回购路径
repo=“”
如果len(sys.argv)>1:
回购=系统argv[1]
#from_date=sys.argv[2],
#截止日期=sys.argv[3]
#连接到hg
客户端=hglib.open(repo)
#定义时间范围
d1=日期时间(2015,7,7)
d2=日期时间(2015,8,31)
#如果“date('>05/07/07')和date('),您可以使用revset来限制变更集。我不确定它如何转换为hglib API,但它也有一个revset接口。在普通CLI中,您可以执行以下操作:
hg log -r"date('>2015-01-01') and date('<2015-03-25')"
hg log-r”日期('>2015-01-01')和日期('有一种方法可以从回购协议中获得正确的日期?我已经尝试了一些方法(请参考文章开头的更新代码),但不起作用,如果(description[e.date]>=d1和description[e.date],则给出此错误