当我运行以下示例代码时:
<?php
if(count($_POST)>0) {
/* Form Required Field Validation */
foreach($_POST as $key=>$value) {
if(empty($_POST[$key])) {
$message = ucwords($key) . " field is required";
break;
}
}
/* Password Matching Validation */
if($_POST['password'] != $_POST['confirm_password']){
$message = 'Passwords should be same<br>';
}
/* Email Validation */
if(!isset($message)) {
if (!filter_var($_POST["userEmail"], FILTER_VALIDATE_EMAIL)) {
$message = "Invalid UserEmail";
}
}
/* Validation to check if gender is selected */
if(!isset($message)) {
if(!isset($_POST["gender"])) {
$message = " Gender field is required";
}
}
/* Validation to check if Terms and Conditions are accepted */
if(!isset($message)) {
if(!isset($_POST["terms"])) {
$message = "Accept Terms and conditions before submit";
}
}
if(!isset($message)) {
require_once("dbcontroller.php");
$db_handle = new DBController();
$query = "INSERT INTO registered_users (user_name, first_name, last_name, password, email, gender) VALUES
('" . $_POST["userName"] . "', '" . $_POST["firstName"] . "', '" . $_POST["lastName"] . "', '" . md5($_POST["password"]) . "', '" . $_POST["userEmail"] . "', '" . $_POST["gender"] . "')";
$result = $db_handle->insertQuery($query);
if(!empty($result)) {
$message = "You have been successfully registered!";
unset($_POST);
} else {
$message = "Problem in registration. Try Again!";
}
}
}
?>
<html>
<head>
<title>PHP User Registration Form</title>
<style>
.message {color: #FF0000;font-weight: bold;text-align: center;width: 100%;padding: 10;}
body{width:610px;}
.demo-table {background:#FFDFDF;width: 100%;border-spacing: initial;margin: 20px 0px;word-break: break-word;table-layout: auto;line-height:1.8em;color:#333;}
.demo-table td {padding: 20px 15px 10px 15px;}
.demoInputBox {padding: 7px;border: #F0F0F0 1px solid;border-radius: 4px;}
.btnRegister {padding: 10px;background-color: #09F;border: 0;color: #FFF;cursor: pointer;}
</style>
</head>
<body>
<form name="frmRegistration" method="post" action="">
<table border="0" width="500" align="center" class="demo-table">
<div class="message"><?php if(isset($message)) echo $message; ?></div>
<tr>
<td>Username</td>
<td><input type="text" class="demoInputBox" name="userName" value="<?php if(isset($_POST['userName'])) echo $_POST['userName']; ?>"></td>
</tr>
<tr>
<td>First Name</td>
<td><input type="text" class="demoInputBox" name="firstName" value="<?php if(isset($_POST['firstName'])) echo $_POST['firstName']; ?>"></td>
</tr>
<tr>
<td>Last Name</td>
<td><input type="text" class="demoInputBox" name="lastName" value="<?php if(isset($_POST['lastName'])) echo $_POST['lastName']; ?>"></td>
</tr>
<tr>
<td>Password</td>
<td><input type="password" class="demoInputBox" name="password" value=""></td>
</tr>
<tr>
<td>Confirm Password</td>
<td><input type="password" class="demoInputBox" name="confirm_password" value=""></td>
</tr>
<tr>
<td>Email</td>
<td><input type="text" class="demoInputBox" name="userEmail" value="<?php if(isset($_POST['userEmail'])) echo $_POST['userEmail']; ?>"></td>
</tr>
<tr>
<td>Gender</td>
<td><input type="radio" name="gender" value="Male" <?php if(isset($_POST['gender']) && $_POST['gender']=="Male") { ?>checked<?php } ?>> Male
<input type="radio" name="gender" value="Female" <?php if(isset($_POST['gender']) && $_POST['gender']=="Female") { ?>checked<?php } ?>> Female
</td>
</tr>
<tr>
<td></td>
<td><input type="checkbox" name="terms"> I accept Terms and Conditions</td>
</tr>
</table>
<div>
<input type="submit" name="submit" value="Register" class="btnRegister">
</div>
</form>
</body></html>
this file的结果如下:
public static void main(String[] args) throws IOException, GitAPIException {
Git git = new Git(new FileRepository(PATH_TO_REPO);
BlameCommand blameCommand = git.blame();
blameCommand.setStartCommit(git.getRepository().resolve("HEAD"));
blameCommand.setFilePath(PATH_TO_FILE);
BlameResult blameResult = blameCommand.call();
Set<Integer> iterations = new HashSet<>();
Set<Integer> gitSourceLines = new HashSet<>();
RawText rawText = blameResult.getResultContents();
for (int i = 0; i < rawText.size(); i++) {
iterations.add(i);
gitSourceLines.add(blameResult.getSourceLine(i));
System.out.println("i = " + i +
", getSourceLine(i) = " + blameResult.getSourceLine(i));
}
System.out.println("iterations size: " + iterations.size());
System.out.println("sourceLines size: " + gitSourceLines.size());
}
可以注意到,在责备结果中会跳过某些代码行。不仅方法 getSourceLine(i)会跳过它们,还会跳过其他方法,例如 getSourceCommit(i)和 getSourceAuthor(i)。 我在不同的文件和不同的存储库上尝试了相同的代码,结果总是不可预测的(如上所述)。
我的代码是否有失败或者我得到的结果是否有解释?
P.S。:我的目的是计算每个修订版属于多少行。因此,如果这个失败是JGit中的一个错误,我会很感激在java中执行git blame的任何替代解决方案。