1

我提到了一个打印所有存储库详细信息的程序。现在我想提供 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(至今)

更新的代码不起作用

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
4

1 回答 1

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.

于 2015-08-26T11:02:06.407 回答