আমরা আরও একটি সমাধান উদ্ভাবন করতে বাধ্য হয়েছিলাম, কারণ আমাদের বিশেষভাবে পরিবর্তনের সময় প্রয়োজন ছিল এবং সময়গুলি প্রতিশ্রুতিবদ্ধ না, এবং সমাধানটিও বহনযোগ্য হতে পারে (যেমন উইন্ডোজগুলির গিট ইনস্টলশনে অজগর পাওয়া সত্যিই একটি সহজ কাজ নয়) এবং দ্রুত। এটি ডেভিড হার্ডম্যানের সমাধানের সাথে সাদৃশ্যপূর্ণ, যা আমি নথির অভাবের কারণে ব্যবহার না করার সিদ্ধান্ত নিয়েছিলাম (সংগ্রহশালা থেকে আমি তার কোডটি ঠিক কী করে তা ধারণা পেতে সক্ষম হইনি)।
এই সমাধানটি একটি ফাইলের মধ্যে মাইটাইমগুলি সঞ্চয় করে it গিট সংগ্রহস্থলের সময়গুলিতে, সেগুলি অনুযায়ী কমিটগুলিতে আপডেট করে (নির্বাচিতভাবে স্টেজযুক্ত ফাইলগুলির মাইটাইমস) এবং তাদের চেকআউটে প্রয়োগ করে। এটি গিগের সাইগউইন / মিংডউ সংস্করণগুলির সাথেও কাজ করে (তবে আপনাকে স্ট্যান্ডার্ড সাইগউইন থেকে গিটের ফোল্ডারে কিছু ফাইল অনুলিপি করতে হবে)
সমাধানটিতে 3 টি ফাইল থাকে:
- এমটাইমস্টোর - মূল স্ক্রিপ্ট 3 টি বিকল্প সরবরাহ করে - একটি (সমস্ত সংরক্ষণ করুন - ইতিমধ্যে বিদ্যমান রেপোতে শুরু করার জন্য (গিট-বুদ্ধিযুক্ত ফাইলগুলির সাথে কাজ করে)), -এস (পর্যায়যুক্ত পরিবর্তনগুলি সংরক্ষণ করতে), এবং -r সেগুলি পুনরুদ্ধার করতে। এটি আসলে ২ টি সংস্করণে আসে - একটি ব্যাশ ওয়ান (পোর্টেবল, দুর্দান্ত, সহজেই পড়তে / পরিবর্তন করতে পারে), এবং সি সংস্করণ (নোংরা একটি তবে দ্রুত, কারণ মিংডাব্যাশ ব্যাশ মারাত্মকভাবে ধীর হয় যা বড় প্রকল্পগুলিতে ব্যাশ সমাধানটি ব্যবহার করা অসম্ভব করে তোলে)
- প্রাক কমিট হুক
- পোস্ট-চেকআউট হুক
পূর্ব-প্রতিশ্রুতিবদ্ধ:
#!/bin/bash
mtimestore -s
git add .mtimes
পোস্ট-চেকআউট
#!/bin/bash
mtimestore -r
এমটাইমস্টোর - ব্যাশ:
#!/bin/bash
function usage
{
echo "Usage: mtimestore (-a|-s|-r)"
echo "Option Meaning"
echo " -a save-all - saves state of all files in a git repository"
echo " -s save - saves mtime of all staged files of git repository"
echo " -r restore - touches all files saved in .mtimes file"
exit 1
}
function echodate
{
echo "$(stat -c %Y "$1")|$1" >> .mtimes
}
IFS=$'\n'
while getopts ":sar" optname
do
case "$optname" in
"s")
echo "saving changes of staged files to file .mtimes"
if [ -f .mtimes ]
then
mv .mtimes .mtimes_tmp
pattern=".mtimes"
for str in $(git diff --name-only --staged)
do
pattern="$pattern\|$str"
done
cat .mtimes_tmp | grep -vh "|\($pattern\)\b" >> .mtimes
else
echo "warning: file .mtimes does not exist - creating new"
fi
for str in $(git diff --name-only --staged)
do
echodate "$str"
done
rm .mtimes_tmp 2> /dev/null
;;
"a")
echo "saving mtimes of all files to file .mtimes"
rm .mtimes 2> /dev/null
for str in $(git ls-files)
do
echodate "$str"
done
;;
"r")
echo "restorim dates from .mtimes"
if [ -f .mtimes ]
then
cat .mtimes | while read line
do
timestamp=$(date -d "1970-01-01 ${line%|*} sec GMT" +%Y%m%d%H%M.%S)
touch -t $timestamp "${line##*|}"
done
else
echo "warning: .mtimes not found"
fi
;;
":")
usage
;;
*)
usage
;;
esac
এমটাইমস্টোর - সি ++
#include <time.h>
#include <utime.h>
#include <sys/stat.h>
#include <iostream>
#include <cstdlib>
#include <fstream>
#include <string>
#include <cerrno>
#include <cstring>
#include <sys/types.h>
#include <ctime>
#include <map>
void changedate(int time, const char* filename)
{
try
{
struct utimbuf new_times;
struct stat foo;
stat(filename, &foo);
new_times.actime = foo.st_atime;
new_times.modtime = time;
utime(filename, &new_times);
}
catch(...)
{}
}
bool parsenum(int& num, char*& ptr)
{
num = 0;
if(!isdigit(*ptr))
return false;
while(isdigit(*ptr))
{
num = num*10 + (int)(*ptr) - 48;
ptr++;
}
return true;
}
//splits line into numeral and text part - return numeral into time and set ptr to the position where filename starts
bool parseline(const char* line, int& time, char*& ptr)
{
if(*line == '\n' || *line == '\r')
return false;
time = 0;
ptr = (char*)line;
if( parsenum(time, ptr))
{
ptr++;
return true;
}
else
return false;
}
//replace \r and \n (otherwise is interpretted as part of filename)
void trim(char* string)
{
char* ptr = string;
while(*ptr != '\0')
{
if(*ptr == '\n' || *ptr == '\r')
*ptr = '\0';
ptr++;
}
}
void help()
{
std::cout << "version: 1.4" << std::endl;
std::cout << "usage: mtimestore <switch>" << std::endl;
std::cout << "options:" << std::endl;
std::cout << " -a saves mtimes of all git-versed files into .mtimes file (meant to be done on intialization of mtime fixes)" << std::endl;
std::cout << " -s saves mtimes of modified staged files into .mtimes file(meant to be put into pre-commit hook)" << std::endl;
std::cout << " -r restores mtimes from .mtimes file (that is meant to be stored in repository server-side and to be called in post-checkout hook)" << std::endl;
std::cout << " -h show this help" << std::endl;
}
void load_file(const char* file, std::map<std::string,int>& mapa)
{
std::string line;
std::ifstream myfile (file, std::ifstream::in);
if(myfile.is_open())
{
while ( myfile.good() )
{
getline (myfile,line);
int time;
char* ptr;
if( parseline(line.c_str(), time, ptr))
{
if(std::string(ptr) != std::string(".mtimes"))
mapa[std::string(ptr)] = time;
}
}
myfile.close();
}
}
void update(std::map<std::string, int>& mapa, bool all)
{
char path[2048];
FILE *fp;
if(all)
fp = popen("git ls-files", "r");
else
fp = popen("git diff --name-only --staged", "r");
while(fgets(path, 2048, fp) != NULL)
{
trim(path);
struct stat foo;
int err = stat(path, &foo);
if(std::string(path) != std::string(".mtimes"))
mapa[std::string(path)]=foo.st_mtime;
}
}
void write(const char * file, std::map<std::string, int>& mapa)
{
std::ofstream outputfile;
outputfile.open(".mtimes", std::ios::out);
for(std::map<std::string, int>::iterator itr = mapa.begin(); itr != mapa.end(); ++itr)
{
if(*(itr->first.c_str()) != '\0')
{
outputfile << itr->second << "|" << itr->first << std::endl;
}
}
outputfile.close();
}
int main(int argc, char *argv[])
{
if(argc >= 2 && argv[1][0] == '-')
{
switch(argv[1][1])
{
case 'r':
{
std::cout << "restoring modification dates" << std::endl;
std::string line;
std::ifstream myfile (".mtimes");
if (myfile.is_open())
{
while ( myfile.good() )
{
getline (myfile,line);
int time, time2;
char* ptr;
parseline(line.c_str(), time, ptr);
changedate(time, ptr);
}
myfile.close();
}
}
break;
case 'a':
case 's':
{
std::cout << "saving modification times" << std::endl;
std::map<std::string, int> mapa;
load_file(".mtimes", mapa);
update(mapa, argv[1][1] == 'a');
write(".mtimes", mapa);
}
break;
default:
help();
return 0;
}
} else
{
help();
return 0;
}
return 0;
}
- নোট করুন যে হুকগুলি তাদের স্থান নির্ধারণের জন্য স্বয়ংক্রিয় করতে টেমপ্লেট-ডিরেক্টরিতে স্থাপন করা যেতে পারে
আরও তথ্য এখানে পাওয়া যাবে
https://github.com/kareltucek/git-mtime- এক্সটেনশন
কিছু পুরানো তথ্য
http://www.ktweb.cz/blog/index.php?page=page&id=116 এ রয়েছে
// সম্পাদনা - সি ++ সংস্করণ আপডেট হয়েছে:
- এখন সি ++ সংস্করণ বর্ণানুক্রমিক ক্রম -> কম সংহত বিবাদগুলি বজায় রাখে।
- কুৎসিত সিস্টেম () কলগুলি থেকে মুক্তি পেয়েছে।
- পোস্ট-চেকআউট হুক থেকে $ গিট আপডেট-ইনডেক্স - রিফ্রেশ le মুছে ফেলা হয়েছে। কচ্ছপের গিটের অধীনে ফিরে যাওয়ার কিছু সমস্যা সৃষ্টি করে এবং যাইহোক এটি খুব গুরুত্বপূর্ণ বলে মনে হয় না।
- আমাদের উইন্ডোজ প্যাকেজটি http://ktweb.cz/blog/download/git-mtimestore-1.4.rr এ ডাউনলোড করা যাবে
// সম্পাদনা আপ টু ডেট সংস্করণ জন্য গিথুব দেখুন