Skip to content

Commit

Permalink
Merge pull request #206 from UDAAN-LEAP/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
Ashish2831 authored Dec 28, 2022
2 parents 7a58f29 + 56a6f5e commit 9eacef5
Show file tree
Hide file tree
Showing 23 changed files with 1,171 additions and 463 deletions.
298 changes: 157 additions & 141 deletions FrameWorkCode/Project.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,7 @@ void Project::set_verifier(){
QString id=user_id;
std::string role = id.toUtf8().constData();
auto c = doc.child("Project").child("Metadata");
c.child("Verifier").first_child().set_value(role.c_str());
c.child("Verifier").first_child().set_value("None");
save_xml();
}

Expand All @@ -686,148 +686,164 @@ void Project::set_verifier(){
* \param branchName
* \return bool
*/
bool Project::push(QString branchName) {
// lg2_add();
// git_libgit2_init();
// login_tries = 1;
// git_remote * remote = NULL;

// QByteArray array = branchName.toLocal8Bit();
// char* char_arr = array.data();
// char * refspec = (char*)"refs/heads/";
// char buffer[256];
// strncpy(buffer, refspec, sizeof(buffer));
// strncat(buffer, char_arr, sizeof(buffer));
// qDebug()<<"Buffer"<<buffer<<endl;
// char * d= (char*)buffer;
// const git_strarray refspecs = { &d,1 };

// git_fetch_options fetch_opts;
// git_merge_options merge_opts = GIT_MERGE_OPTIONS_INIT;
// git_checkout_options checkout_opts = GIT_CHECKOUT_OPTIONS_INIT;
// checkout_opts.checkout_strategy = GIT_CHECKOUT_SAFE;
// git_annotated_commit *heads[1] = {NULL};
// git_reference *theirs_ref = NULL, *head_ref = NULL;
// git_index *index = NULL;
// git_oid id, tree_oid;
// git_signature *signature = NULL;
// git_tree *tree = NULL;
// git_commit **parents = (git_commit **)calloc(2, sizeof(git_commit *));
// git_push_options push_opts;

// // Store remote info from repo
// int error = git_remote_lookup(&remote, repo, "origin");
// if(error){
// std::cout<<0<<endl;
// //goto cleanup;
// }
bool Project::push(QString gDirTwoLevelUp) {
QString branchName;
QString gDir = gDirTwoLevelUp+"/.git/config";
lg2_add();
git_libgit2_init();
login_tries = 1;
git_remote * remote = NULL;
QFile f(gDir);
f.open(QIODevice::ReadOnly);
while(!f.atEnd()) {
QString line = f.readLine();
if(line.contains("branch")){
QStringList l = line.split(" ");
l[1] = l[1].remove("\"");
branchName = l[1].remove("]").simplified();
break;
}
}
f.close();
QByteArray array = branchName.toLocal8Bit();
char* char_arr = array.data();
char * refspec = (char*)"refs/heads/";
char buffer[256];
strncpy(buffer, refspec, sizeof(buffer));
strncat(buffer, char_arr, sizeof(buffer));
qDebug()<<"Buffer"<<buffer<<endl;
char * d= (char*)buffer;
const git_strarray refspecs = { &d,1 };

git_fetch_options fetch_opts;
git_merge_options merge_opts = GIT_MERGE_OPTIONS_INIT;
git_checkout_options checkout_opts = GIT_CHECKOUT_OPTIONS_INIT;
checkout_opts.checkout_strategy = GIT_CHECKOUT_SAFE;
git_annotated_commit *heads[1] = {NULL};
git_reference *theirs_ref = NULL, *head_ref = NULL;
git_index *index = NULL;
git_oid id, tree_oid;
git_signature *signature = NULL;
git_tree *tree = NULL;
git_commit **parents = (git_commit **)calloc(2, sizeof(git_commit *));
git_push_options push_opts;

// Store remote info from repo
int error = git_remote_lookup(&remote, repo, "origin");
if(error){
std::cout<<0<<endl;
//goto cleanup;
}


// /* Fetch objects from remote repository
// * Direct pull is not available via libgit2
// */
// git_fetch_init_options(&fetch_opts, GIT_FETCH_OPTIONS_VERSION);
// fetch_opts.callbacks.credentials = credentials_cb;
// error = git_remote_fetch( remote, NULL, &fetch_opts, NULL );
// if(error){
// std::cout<<1<<endl;
// //goto cleanup;
// }
// // cache the credentials
// is_cred_cached = true;

// /* Merge fetched objects with local branch
// * It will update index and current working area
// */
// /*char* string=(char*)"refs/remotes/origin/";
// char buffer1[256];
// strncpy(buffer1, string, sizeof(buffer1));
// strncat(buffer1, char_arr, sizeof(buffer1));
// qDebug()<<"Buffer1"<<buffer1<<endl;
//*/
// error = (git_reference_lookup(&theirs_ref, repo, "refs/remotes/origin/master") != GIT_OK);
// qDebug()<<"Error"<<error<<endl;
// if (!error)
// {
// error = (git_annotated_commit_from_ref(heads, repo, theirs_ref) != GIT_OK)
// || (git_merge(repo, (const git_annotated_commit **)heads, 1, &merge_opts, &checkout_opts) != GIT_OK);

// if(error){
// std::cout<<2<<endl;
// //goto cleanup;
// }

// /* Get the needed ref, index, sign and tree
// */
// error = (git_repository_head(&head_ref, repo))
// || (git_repository_index(&index, repo))
// || (git_signature_now(&signature, mName.c_str(), mEmail.c_str()))
// || (git_index_write_tree(&tree_oid, index))
// || (git_tree_lookup(&tree, repo, &tree_oid));

// if(error){
// std::cout<<3<<endl;
// //goto cleanup;
// }

// /* Commit the merge and cleanup repo state
// */
// error = (git_reference_peel((git_object **)&parents[0], head_ref, GIT_OBJ_COMMIT))
// || (git_commit_lookup(&parents[1], repo, git_annotated_commit_id(heads[0])))
// || (git_commit_create(&id, repo, "HEAD", signature, signature, NULL, "Merge commit - Udaan Translation Tool", tree, 2, (const git_commit **)parents))
// || (git_repository_state_cleanup(repo));

// if(error){
// std::cout<<4<<endl;
// //goto cleanup;
// }
// }
// error = git_remote_push(remote, &refspecs , &push_opts);
// qDebug()<<"Error"<<error<<endl;
// error = git_push_init_options(&push_opts, GIT_PUSH_OPTIONS_VERSION);
// push_opts.callbacks.credentials = credentials_cb;
// //std::string str="refs/remotes/origin/master";
// //char * c = (char*)"refs/heads/master";
// //const git_strarray abc = { &c,1 };
// /*cleanup:
// if(remote)
// git_remote_free(remote);
// if(heads[0])
// git_annotated_commit_free(*heads);
// if(theirs_ref)
// git_reference_free(theirs_ref);
// if(head_ref)
// git_reference_free(head_ref);
// if(index)
// git_index_free(index);
// if(signature)
// git_signature_free(signature);
// if(tree)
// git_tree_free(tree);
// if(parents)
// free(parents);
// */
// if (error)
// return false;

// /* Finding the last commit on current repo and saves the entry in commit history table
// * Email | Commit_no
// * So that we can see users commit history based on his/her email id without github account
// */
// char fullsha[42] = {0};
// git_oid_tostr(fullsha, 41, &id);
// QString sha = QString::fromStdString(fullsha);
// //qDebug()<<"Last commit full hash :"<<sha;
// QSettings settings("IIT-B", "OpenOCRCorrect");
// settings.beginGroup("login");
// QString email = settings.value("email").toString();
// //qDebug()<<"email"<<email;
// settings.endGroup();
// QProcess process;
// process.execute("curl -d -X -k -POST --header "
// "\"Content-type:application/x-www-form-urlencoded\" https://udaaniitb.aicte-india.org/udaan/commits/ -d \"commit_no="+sha+"&email="+email+"\" ");;

// return true;//No errors
/* Fetch objects from remote repository
* Direct pull is not available via libgit2
*/
git_fetch_init_options(&fetch_opts, GIT_FETCH_OPTIONS_VERSION);
fetch_opts.callbacks.credentials = credentials_cb;
error = git_remote_fetch( remote, NULL, &fetch_opts, NULL );
if(error){
std::cout<<1<<endl;
//goto cleanup;
}
// cache the credentials
is_cred_cached = true;

/* Merge fetched objects with local branch
* It will update index and current working area
*/
/*char* string=(char*)"refs/remotes/origin/";
char buffer1[256];
strncpy(buffer1, string, sizeof(buffer1));
strncat(buffer1, char_arr, sizeof(buffer1));
qDebug()<<"Buffer1"<<buffer1<<endl;
*/
QString name_ref = "refs/remotes/origin/"+branchName;
QByteArray name_ref_ar = name_ref.toLatin1();
error = (git_reference_lookup(&theirs_ref, repo, name_ref_ar.data()) != GIT_OK);
qDebug()<<"Error"<<error<<endl;
if (!error)
{
error = (git_annotated_commit_from_ref(heads, repo, theirs_ref) != GIT_OK)
|| (git_merge(repo, (const git_annotated_commit **)heads, 1, &merge_opts, &checkout_opts) != GIT_OK);

if(error){
std::cout<<2<<endl;
//goto cleanup;
}

/* Get the needed ref, index, sign and tree
*/
error = (git_repository_head(&head_ref, repo))
|| (git_repository_index(&index, repo))
|| (git_signature_now(&signature, mName.c_str(), mEmail.c_str()))
|| (git_index_write_tree(&tree_oid, index))
|| (git_tree_lookup(&tree, repo, &tree_oid));

if(error){
std::cout<<3<<endl;
//goto cleanup;
}

/* Commit the merge and cleanup repo state
*/
error = (git_reference_peel((git_object **)&parents[0], head_ref, GIT_OBJ_COMMIT))
|| (git_commit_lookup(&parents[1], repo, git_annotated_commit_id(heads[0])))
|| (git_commit_create(&id, repo, "HEAD", signature, signature, NULL, "Merge commit - Udaan Translation Tool", tree, 2, (const git_commit **)parents))
|| (git_repository_state_cleanup(repo));

if(error){
std::cout<<4<<endl;
//goto cleanup;
}
}
error = git_push_init_options(&push_opts, GIT_PUSH_OPTIONS_VERSION);
push_opts.callbacks.credentials = credentials_cb;
error = git_remote_push(remote, &refspecs , &push_opts);
qDebug()<<"Error"<<error<<endl;

//std::string str="refs/remotes/origin/master";
//char * c = (char*)"refs/heads/master";
//const git_strarray abc = { &c,1 };
/*cleanup:
if(remote)
git_remote_free(remote);
if(heads[0])
git_annotated_commit_free(*heads);
if(theirs_ref)
git_reference_free(theirs_ref);
if(head_ref)
git_reference_free(head_ref);
if(index)
git_index_free(index);
if(signature)
git_signature_free(signature);
if(tree)
git_tree_free(tree);
if(parents)
free(parents);
*/
if (error)
return false;

/* Finding the last commit on current repo and saves the entry in commit history table
* Email | Commit_no
* So that we can see users commit history based on his/her email id without github account
*/
char fullsha[42] = {0};
git_oid_tostr(fullsha, 41, &id);
QString sha = QString::fromStdString(fullsha);
//qDebug()<<"Last commit full hash :"<<sha;
QSettings settings("IIT-B", "OpenOCRCorrect");
settings.beginGroup("login");
QString email = settings.value("email").toString();
//qDebug()<<"email"<<email;
settings.endGroup();
QProcess process;
process.execute("curl -d -X -k -POST --header "
"\"Content-type:application/x-www-form-urlencoded\" https://udaaniitb.aicte-india.org/udaan/commits/ -d \"commit_no="+sha+"&email="+email+"\" ");;

return true;//No errors
}

/*!
Expand Down
3 changes: 2 additions & 1 deletion FrameWorkCode/Symbols.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ SymbolsView::SymbolsView(QWidget *parent) : QDialog(parent, Qt::WindowCloseButto

ui->SpecialCharacters->setText(R"(¶ ¦ Ȝ ȝ — – ‑ ° · † ‡ § ऽ ❀ ✿ ✽ ꕥ 💮
A᳒ B᳒ C᳒ D᳒ E᳒ F᳒ G᳒ H᳒ I᳒ J᳒ K᳒ L᳒ M᳒ N᳒ O᳒ P᳒ Q᳒ R᳒ S᳒ T᳒ U᳒ V᳒ W᳒ X᳒ Y᳒ Z᳒
A᳙ B᳙ C᳙ D᳙ E᳙ F᳙ G᳙ H᳙ I᳙ J᳙ K᳙ L᳙ M᳙ N᳙ O᳙ P᳙ Q᳙ R᳙ S᳙ T᳙ U᳙ V᳙ W᳙ X᳙ Y᳙ Z᳙ )");
A᳙ B᳙ C᳙ D᳙ E᳙ F᳙ G᳙ H᳙ I᳙ J᳙ K᳙ L᳙ M᳙ N᳙ O᳙ P᳙ Q᳙ R᳙ S᳙ T᳙ U᳙ V᳙ W᳙ X᳙ Y᳙ Z᳙
• ⊙ ◉ ○ ◌ ● ⦿ ◆ ◇ ★ □ ✓ ✦ ➔ ➢ ➣ ➤ ▶ ▷ ⬛ ◼ ◾ ♦ ⚫ #⃣ ℹ ⛔ ⚠ ➡ *⃣ )");
setWindowTitle("Special Symbols");
ui->Diacritics->setText(
R"(A
Expand Down
3 changes: 3 additions & 0 deletions FrameWorkCode/Symbols.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ public slots:
void on_copyButton_clicked();
void tabChanged(int idx);

private slots:


private:
Ui::SymbolsView *ui;
QTextEdit *currentTab;
Expand Down
Loading

0 comments on commit 9eacef5

Please sign in to comment.