Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 27 additions & 3 deletions git-p4.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@
# Only labels/tags matching this will be imported/exported
defaultLabelRegexp = r'[a-zA-Z0-9_\-.]+$'

# Valid email regex
validEmail = r"(^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$)"
email_validator = re.compile(validEmail)

# The block size is reduced automatically if required
defaultBlockSize = 1<<20

Expand Down Expand Up @@ -2819,7 +2823,9 @@ def __init__(self):
optparse.make_option("--tmp-dir", dest="tempDir", help="Directory to store temporary files"),
optparse.make_option("--keep-tmp-files", dest="keepTempFiles", help="Do not remove temporary files after commit", action="store_true"),
optparse.make_option("--no-disk-free-check", dest="noDiskFreeCheck", action='store_true',
help="Skip checking if enough free disk space is availaible")
help="Skip checking if enough free disk space is availaible"),
optparse.make_option("--fake-emails", dest="allowFakeEmails",help="Allow git-p4 to create user emails when not found",
action='store_true', )
]
self.description = """Imports from Perforce into a git repository.\n
example:
Expand Down Expand Up @@ -2859,6 +2865,7 @@ def __init__(self):
self.describeBatchSize = 100
self.tempDir = ""
self.keepTempFiles = False
self.allowFakeEmails = False

if gitConfig('git-p4.largeFileSystem'):
largeFileSystemConstructor = globals()[gitConfig('git-p4.largeFileSystem')]
Expand Down Expand Up @@ -3266,9 +3273,26 @@ def prepFileArgs(self, files):

def make_email(self, userid):
if userid in self.users:
return self.users[userid]
if(email_validator.fullmatch(self.users[userid])):
return self.users[userid]
elif(gitConfigBool("gitp4.createFakeEmail") or self.allowFakeEmails ):
try:
email = self.users[userid].split()[1]
email = email[:-1] + ".invalid" + ">"
return f"{userid} {email}"
except IndexError:
return f"{userid} {userid}@{userid}.invalid>"
else:
signal.raise_signal(signal.SIGINT) # needed to stop all threads

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noticed this is needed to prevent us from hanging when we exit

die(f"No valid email found for user {userid} ({self.users[userid]}), set 'gitp4.createFakeEmail' or pass --fake-emails to proceed")
else:
return "%s <a@b>" % userid
if verbose:
print(f"No user found for user:{userid}")
if (gitConfigBool("gitp4.createFakeEmail") or self.allowFakeEmails):
return "%s <%s@%s.invalid>" % userid
else:
signal.raise_signal(signal.SIGINT) # needed to stop all threads
die(f"No valid email found for user {userid} ({self.users[userid]}), set 'gitp4.createFakeEmail' or pass --fake-emails to proceed")

def streamTag(self, gitStream, labelName, labelDetails, commit, epoch):
""" Stream a p4 tag.
Expand Down