p4fastimport: handle race condition with config users and time delta

Summary: This is a followup diff of this diff: [[ https://phabricator.intern.facebook.com/D5509536 | D5509536 ]]. It makes the ignored user and the constraint on time difference between a user commit and a p4fastimporter import configurable.

Test Plan:
$ cd ~/facebook-hg-rpms/fb-hgext/tests/
$ python ../../hg-crew/tests/run-tests.py test-p4fastimport-gitfusion-race-condition.t
$ python ../../hg-crew/tests/run-tests.py test-p4*

All tests should pass

Reviewers: #idi, davidsp

Reviewed By: davidsp

Subscribers: wlis, medson, mjpieters

Differential Revision: https://phabricator.intern.facebook.com/D5531404

Tasks: 20141882

Signature: t1:5531404:1501866435:25686443d99a2b96f8e8a7fa9e3f660ba8c8393e
This commit is contained in:
Zhihui Huang 2017-08-04 10:58:07 -07:00
parent 43219b38d6
commit 84229312d5
2 changed files with 18 additions and 4 deletions

View File

@ -12,6 +12,12 @@ Config example:
lfsmetadata = PATH
# path to sqlite output file for metadata
metadata = PATH
# certain commits by certain users should be igored so that
# p4fastimporter imports the actual commits we want
ignore-user = None
# heuristic time difference between a ignored user commit
# and a p4fastimporter import
ignore-time-delta = None
"""
from __future__ import absolute_import
@ -169,10 +175,15 @@ def p4fastimport(ui, repo, client, **opts):
# 1. Return all the changelists touching files in a given client view.
ui.note(_('loading changelist numbers.\n'))
changelists = list(itertools.takewhile(
lambda cl: not (cl._user == 'git-fusion-user'
and cl._commit_time_diff < 30),
sorted(p4.parse_changes(client, startcl=startcl))))
ignore_user = ui.config('p4fastimport', 'ignore-user')
ignore_time_delta = ui.config('p4fastimport', 'ignore-time-delta')
if ignore_user is None or ignore_time_delta is None:
changelists = sorted(p4.parse_changes(client, startcl=startcl))
else:
changelists = list(itertools.takewhile(
lambda cl: not (cl._user == ignore_user
and cl._commit_time_diff < ignore_time_delta),
sorted(p4.parse_changes(client, startcl=startcl))))
ui.note(_('%d changelists to import.\n') % len(changelists))
limit = len(changelists)

View File

@ -48,6 +48,9 @@ Submit change as actual user after git-fusion-user
Simple import
$ cd $hgwd
$ echo [p4fastimport] >> $HGRCPATH
$ echo ignore-user='git-fusion-user' >> $HGRCPATH
$ echo ignore-time-delta=30 >> $HGRCPATH
$ hg init --config 'format.usefncache=False'
$ hg p4fastimport --bookmark master --debug -P $P4ROOT hg-p4-import
loading changelist numbers.