我需要编写一个python脚本来获取给定2个日期的mercurial的存储库详细信息

时间:2015-08-26 10:38:27

标签: python mercurial mercurial-api

我推荐了一个打印所有存储库详细信息的程序。现在我想提供2个日期,即从日期和日期作为参数,并且需要提取这两个日期之间的存储库详细信息。如何才能做到这一点。我不确定使用哪种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 = 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(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

1 个答案:

答案 0 :(得分:1)

您可以使用revsets来限制更改集。我不确定它如何转换为hglib API,但它也有一个revsets接口。在普通的CLI中,您可以这样做:

hg log -r"date('>2015-01-01') and date('<2015-03-25')"

结帐hg help revsetshg help dates

顺便说一句:如果存在修剪或过时的变更集,则数字修订版计数revs = int(client.tip().rev)的输出将是错误的(太大),例如可以通过hg commit --amend轻松创建。< / p>